89 version = bytestream2_get_be16(&
s->gb);
97 s->channel_count = bytestream2_get_be16(&
s->gb);
98 if ((
s->channel_count < 1) || (
s->channel_count > 56)) {
103 s->height = bytestream2_get_be32(&
s->gb);
107 "Height > 30000 is experimental, add "
108 "'-strict %d' if you want to try to decode the picture.\n",
113 s->width = bytestream2_get_be32(&
s->gb);
116 "Width > 30000 is experimental, add "
117 "'-strict %d' if you want to try to decode the picture.\n",
125 s->channel_depth = bytestream2_get_be16(&
s->gb);
127 color_mode = bytestream2_get_be16(&
s->gb);
128 switch (color_mode) {
159 len_section = bytestream2_get_be32(&
s->gb);
160 if (len_section < 0) {
172 for (j = HAVE_BIGENDIAN; j < 3 + HAVE_BIGENDIAN; j++)
173 for (
i = 0;
i <
FFMIN(256, len_section / 3);
i++)
174 s->palette[
i * 4 + (HAVE_BIGENDIAN ? j : 2 - j)] = bytestream2_get_byteu(&
s->gb);
175 len_section -=
i * 3;
180 len_section = bytestream2_get_be32(&
s->gb);
181 if (len_section < 0) {
193 len_section = bytestream2_get_be32(&
s->gb);
194 if (len_section < 0) {
199 if (len_section >= 6) {
202 s->layer_count = bytestream2_get_be16(&
s->gb);
218 s->compression = bytestream2_get_be16(&
s->gb);
219 switch (
s->compression) {
238 unsigned int scanline_count;
239 unsigned int sl, count;
240 unsigned long target_index = 0;
243 unsigned int repeat_count;
246 scanline_count =
s->height *
s->channel_count;
256 for (sl = 0; sl < scanline_count; sl++) {
259 while (count < s->line_size) {
260 rle_char = bytestream2_get_byte(&
s->gb);
263 repeat_count = rle_char * -1;
270 if (target_index + repeat_count >=
s->uncompressed_size) {
275 v = bytestream2_get_byte(&
s->gb);
276 for (p = 0; p <= repeat_count; p++) {
277 s->tmp[target_index++] = v;
279 count += repeat_count + 1;
286 if (target_index + rle_char >=
s->uncompressed_size) {
291 for (p = 0; p <= rle_char; p++) {
292 v = bytestream2_get_byte(&
s->gb);
293 s->tmp[target_index++] = v;
295 count += rle_char + 1;
308 const uint8_t *ptr_data;
309 int index_out,
c, y, x, p;
310 uint8_t eq_channel[4] = {2,0,1,3};
311 uint8_t plane_number;
315 s->channel_count = 0;
316 s->channel_depth = 0;
317 s->primary_channels = 0;
327 s->pixel_size =
s->channel_depth >> 3;
328 s->line_size =
s->width *
s->pixel_size;
330 switch (
s->color_mode) {
332 if (
s->channel_depth != 1 ||
s->channel_count < 1) {
334 "Invalid bitmap file (channel_depth %d, channel_count %d)\n",
335 s->channel_depth,
s->channel_count);
338 s->line_size =
s->width + 7 >> 3;
339 s->primary_channels = 1;
343 if (
s->channel_depth != 8 ||
s->channel_count < 1) {
345 "Invalid indexed file (channel_depth %d, channel_count %d)\n",
346 s->channel_depth,
s->channel_count);
349 s->primary_channels = 1;
353 if (
s->layer_count < 0 &&
s->channel_count >= 5) {
354 if (
s->channel_depth == 8) {
356 }
else if (
s->channel_depth == 16) {
362 s->primary_channels = 5;
363 }
else if (
s->channel_count >= 4) {
364 if (
s->channel_depth == 8) {
366 }
else if (
s->channel_depth == 16) {
372 s->primary_channels = 4;
375 "Invalid cmyk file (channel_count %d)\n",
381 if (
s->layer_count < 0 &&
s->channel_count >= 4) {
382 if (
s->channel_depth == 8) {
384 }
else if (
s->channel_depth == 16) {
390 s->primary_channels = 4;
391 }
else if (
s->channel_count >= 3) {
392 if (
s->channel_depth == 8) {
394 }
else if (
s->channel_depth == 16) {
400 s->primary_channels = 3;
403 "Invalid rgb file (channel_count %d)\n",
412 if (
s->layer_count < 0 &&
s->channel_count >= 2) {
413 if (
s->channel_depth == 8) {
415 }
else if (
s->channel_depth == 16) {
421 s->primary_channels = 2;
422 }
else if (
s->channel_count >= 1) {
423 if (
s->channel_depth == 8) {
425 }
else if (
s->channel_depth == 16) {
427 }
else if (
s->channel_depth == 32) {
433 s->primary_channels = 1;
436 "Invalid grayscale file (channel_count %d)\n",
446 s->uncompressed_size =
s->line_size *
s->height *
s->channel_count;
467 ptr_data =
s->gb.buffer;
475 ptr = picture->
data[0];
476 for (
c = 0;
c < 2;
c++) {
477 for (y = 0; y <
s->height; y++) {
478 for (x = 0; x <
s->width; x++) {
479 index_out = y * picture->
linesize[0] + x * 2 *
s->pixel_size +
c *
s->pixel_size;
480 for (p = 0; p <
s->pixel_size; p++) {
481 ptr[index_out + p] = *ptr_data;
488 uint8_t *
dst[4] = { picture->
data[0], picture->
data[1], picture->
data[2], picture->
data[3] };
489 const uint8_t *
src[5] = { ptr_data };
490 src[1] =
src[0] +
s->line_size *
s->height;
491 src[2] =
src[1] +
s->line_size *
s->height;
492 src[3] =
src[2] +
s->line_size *
s->height;
493 src[4] =
src[3] +
s->line_size *
s->height;
494 if (
s->channel_depth == 8) {
495 for (y = 0; y <
s->height; y++) {
496 for (x = 0; x <
s->width; x++) {
498 int r =
src[0][x] * k;
499 int g =
src[1][x] * k;
500 int b =
src[2][x] * k;
501 dst[0][x] =
g * 257 >> 16;
502 dst[1][x] =
b * 257 >> 16;
503 dst[2][x] =
r * 257 >> 16;
508 src[0] +=
s->line_size;
509 src[1] +=
s->line_size;
510 src[2] +=
s->line_size;
511 src[3] +=
s->line_size;
514 for (y = 0; y <
s->height; y++) {
515 memcpy(
dst[3],
src[4],
s->line_size);
516 src[4] +=
s->line_size;
521 for (y = 0; y <
s->height; y++) {
522 for (x = 0; x <
s->width; x++) {
534 src[0] +=
s->line_size;
535 src[1] +=
s->line_size;
536 src[2] +=
s->line_size;
537 src[3] +=
s->line_size;
540 for (y = 0; y <
s->height; y++) {
541 memcpy(
dst[3],
src[4],
s->line_size);
542 src[4] +=
s->line_size;
548 if (
s->primary_channels == 1)
551 for (
c = 0;
c <
s->primary_channels;
c++) {
552 plane_number = eq_channel[
c];
553 ptr = picture->
data[plane_number];
554 for (y = 0; y <
s->height; y++) {
555 memcpy(ptr, ptr_data,
s->line_size);
556 ptr += picture->
linesize[plane_number];
557 ptr_data +=
s->line_size;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_psd_decoder
static av_always_inline int bytestream2_get_bytes_left(const 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 i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#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[]
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define MKTAG(a, b, c, d)
Memory handling functions.
@ 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, AVFrame *picture, 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.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
uint16_t primary_channels
enum PsdColorMode color_mode
enum PsdCompr compression
uint64_t uncompressed_size
uint8_t palette[AVPALETTE_SIZE]
#define avpriv_request_sample(...)