84 version = bytestream2_get_be16(&
s->gb);
92 s->channel_count = bytestream2_get_be16(&
s->gb);
93 if ((
s->channel_count < 1) || (
s->channel_count > 56)) {
98 s->height = bytestream2_get_be32(&
s->gb);
102 "Height > 30000 is experimental, add "
103 "'-strict %d' if you want to try to decode the picture.\n",
108 s->width = bytestream2_get_be32(&
s->gb);
111 "Width > 30000 is experimental, add "
112 "'-strict %d' if you want to try to decode the picture.\n",
120 s->channel_depth = bytestream2_get_be16(&
s->gb);
122 color_mode = bytestream2_get_be16(&
s->gb);
123 switch (color_mode) {
154 len_section = bytestream2_get_be32(&
s->gb);
155 if (len_section < 0) {
168 for (
i = 0;
i <
FFMIN(256, len_section / 3);
i++)
169 s->palette[
i * 4 + (
HAVE_BIGENDIAN ? j : 2 - j)] = bytestream2_get_byteu(&
s->gb);
170 len_section -=
i * 3;
175 len_section = bytestream2_get_be32(&
s->gb);
176 if (len_section < 0) {
188 len_section = bytestream2_get_be32(&
s->gb);
189 if (len_section < 0) {
206 s->compression = bytestream2_get_be16(&
s->gb);
207 switch (
s->compression) {
226 unsigned int scanline_count;
227 unsigned int sl, count;
228 unsigned long target_index = 0;
231 unsigned int repeat_count;
234 scanline_count =
s->height *
s->channel_count;
244 for (sl = 0; sl < scanline_count; sl++) {
247 while (count < s->line_size) {
248 rle_char = bytestream2_get_byte(&
s->gb);
251 repeat_count = rle_char * -1;
258 if (target_index + repeat_count >=
s->uncompressed_size) {
263 v = bytestream2_get_byte(&
s->gb);
264 for (p = 0; p <= repeat_count; p++) {
265 s->tmp[target_index++] = v;
267 count += repeat_count + 1;
274 if (target_index + rle_char >=
s->uncompressed_size) {
279 for (p = 0; p <= rle_char; p++) {
280 v = bytestream2_get_byte(&
s->gb);
281 s->tmp[target_index++] = v;
283 count += rle_char + 1;
297 int index_out,
c, y, x, p;
298 uint8_t eq_channel[4] = {2,0,1,3};
305 s->channel_count = 0;
306 s->channel_depth = 0;
315 s->pixel_size =
s->channel_depth >> 3;
316 s->line_size =
s->width *
s->pixel_size;
318 switch (
s->color_mode) {
320 if (
s->channel_depth != 1 ||
s->channel_count != 1) {
322 "Invalid bitmap file (channel_depth %d, channel_count %d)\n",
323 s->channel_depth,
s->channel_count);
326 s->line_size =
s->width + 7 >> 3;
330 if (
s->channel_depth != 8 ||
s->channel_count != 1) {
332 "Invalid indexed file (channel_depth %d, channel_count %d)\n",
333 s->channel_depth,
s->channel_count);
339 if (
s->channel_count == 4) {
340 if (
s->channel_depth == 8) {
342 }
else if (
s->channel_depth == 16) {
348 }
else if (
s->channel_count == 5) {
349 if (
s->channel_depth == 8) {
351 }
else if (
s->channel_depth == 16) {
363 if (
s->channel_count == 3) {
364 if (
s->channel_depth == 8) {
366 }
else if (
s->channel_depth == 16) {
372 }
else if (
s->channel_count == 4) {
373 if (
s->channel_depth == 8) {
375 }
else if (
s->channel_depth == 16) {
389 if (
s->channel_count == 1) {
390 if (
s->channel_depth == 8) {
392 }
else if (
s->channel_depth == 16) {
394 }
else if (
s->channel_depth == 32) {
400 }
else if (
s->channel_count == 2) {
401 if (
s->channel_depth == 8) {
403 }
else if (
s->channel_depth == 16) {
419 s->uncompressed_size =
s->line_size *
s->height *
s->channel_count;
443 ptr_data =
s->gb.buffer;
448 ptr = picture->
data[0];
449 for (
c = 0;
c <
s->channel_count;
c++) {
450 for (y = 0; y <
s->height; y++) {
451 for (x = 0; x <
s->width; x++) {
452 index_out = y * picture->
linesize[0] + x *
s->channel_count *
s->pixel_size +
c *
s->pixel_size;
453 for (p = 0; p <
s->pixel_size; p++) {
454 ptr[index_out + p] = *ptr_data;
463 src[1] =
src[0] +
s->line_size *
s->height;
464 src[2] =
src[1] +
s->line_size *
s->height;
465 src[3] =
src[2] +
s->line_size *
s->height;
466 src[4] =
src[3] +
s->line_size *
s->height;
467 if (
s->channel_depth == 8) {
468 for (y = 0; y <
s->height; y++) {
469 for (x = 0; x <
s->width; x++) {
471 int r =
src[0][x] * k;
472 int g =
src[1][x] * k;
473 int b =
src[2][x] * k;
474 dst[0][x] =
g * 257 >> 16;
475 dst[1][x] =
b * 257 >> 16;
476 dst[2][x] =
r * 257 >> 16;
481 src[0] +=
s->line_size;
482 src[1] +=
s->line_size;
483 src[2] +=
s->line_size;
484 src[3] +=
s->line_size;
487 for (y = 0; y <
s->height; y++) {
488 memcpy(dst[3],
src[4],
s->line_size);
489 src[4] +=
s->line_size;
494 for (y = 0; y <
s->height; y++) {
495 for (x = 0; x <
s->width; x++) {
500 AV_WB16(&dst[0][x * 2],
g * 65537 >> 32);
501 AV_WB16(&dst[1][x * 2],
b * 65537 >> 32);
502 AV_WB16(&dst[2][x * 2],
r * 65537 >> 32);
507 src[0] +=
s->line_size;
508 src[1] +=
s->line_size;
509 src[2] +=
s->line_size;
510 src[3] +=
s->line_size;
513 for (y = 0; y <
s->height; y++) {
514 memcpy(dst[3],
src[4],
s->line_size);
515 src[4] +=
s->line_size;
521 if (
s->channel_count == 1)
524 for (
c = 0;
c <
s->channel_count;
c++) {
525 plane_number = eq_channel[
c];
526 ptr = picture->
data[plane_number];
527 for (y = 0; y <
s->height; y++) {
528 memcpy(ptr, ptr_data,
s->line_size);
529 ptr += picture->
linesize[plane_number];
530 ptr_data +=
s->line_size;
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define MKTAG(a, b, c, d)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
static const char signature[]
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
@ AV_PIX_FMT_GRAYF32BE
IEEE-754 single precision Y, 32bpp, big-endian.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
static int decode_header(PSDContext *s)
static int decode_rle(PSDContext *s)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int palette_has_changed
Tell user application that palette has changed from previous frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
enum PsdColorMode color_mode
enum PsdCompr compression
uint64_t uncompressed_size
uint8_t palette[AVPALETTE_SIZE]
#define avpriv_request_sample(...)