From patchwork Fri Dec 30 13:48:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 1990 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2856491vsb; Fri, 30 Dec 2016 05:48:30 -0800 (PST) X-Received: by 10.194.56.234 with SMTP id d10mr45067555wjq.78.1483105710784; Fri, 30 Dec 2016 05:48:30 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w69si58637668wmd.78.2016.12.30.05.48.29; Fri, 30 Dec 2016 05:48:30 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 861EF689CF7; Fri, 30 Dec 2016 15:48:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe01-1.mx.upcmail.net (vie01a-qmta-pe01-1.mx.upcmail.net [62.179.121.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 19F8568077F for ; Fri, 30 Dec 2016 15:48:16 +0200 (EET) Received: from [172.31.218.42] (helo=vie01a-dmta-pe04-3.mx.upcmail.net) by vie01a-pqmta-pe01.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1cMxXf-0000tY-GS for ffmpeg-devel@ffmpeg.org; Fri, 30 Dec 2016 14:48:19 +0100 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe04.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1cMxXZ-0005n8-QK for ffmpeg-devel@ffmpeg.org; Fri, 30 Dec 2016 14:48:13 +0100 Received: from [192.168.1.3] ([80.110.104.126]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id SDoC1u00v2jePg001DoD4f; Fri, 30 Dec 2016 14:48:13 +0100 X-SourceIP: 80.110.104.126 From: Carl Eugen Hoyos To: FFmpeg development discussions and patches Date: Fri, 30 Dec 2016 14:48:12 +0100 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Message-Id: <201612301448.12403.cehoyos@ag.or.at> Subject: [FFmpeg-devel] [PATCH]lavc/psd: Support indexed files X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi! Attached patch fixes ticket #6045. Please comment, Carl Eugen From 0bd8d59e1ad0009f88aa6871d4ed915a12f5900d Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Fri, 30 Dec 2016 14:45:36 +0100 Subject: [PATCH] lavc/psd: Support indexed files. Fixes ticket #6045. --- libavcodec/psd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libavcodec/psd.c b/libavcodec/psd.c index 3181a41..1ca4dc9 100644 --- a/libavcodec/psd.c +++ b/libavcodec/psd.c @@ -60,6 +60,8 @@ typedef struct PSDContext { enum PsdCompr compression; enum PsdColorMode color_mode; + + uint8_t palette[AVPALETTE_SIZE]; } PSDContext; static int decode_header(PSDContext * s) @@ -159,6 +161,15 @@ static int decode_header(PSDContext * s) av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n"); return AVERROR_INVALIDDATA; } + if (len_section) { + int i,j; + for (i = 0; i < 256; i++) + s->palette[i * 4 + 3 * !HAVE_BIGENDIAN] = 0xffu; + for (j = HAVE_BIGENDIAN; j < 3 + HAVE_BIGENDIAN; j++) + for (i = 0; i < FFMIN(256, len_section / 3); i++) + s->palette[i * 4 + (HAVE_BIGENDIAN ? j : 2 - j)] = bytestream2_get_byteu(&s->gb); + len_section -= i * 3; + } bytestream2_skip(&s->gb, len_section); /* image ressources */ @@ -309,6 +320,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, s->uncompressed_size = s->line_size * s->height * s->channel_count; switch (s->color_mode) { + case PSD_INDEXED: + if (s->channel_depth != 8 || s->channel_count != 1) { + av_log(s->avctx, AV_LOG_ERROR, + "Invalid indexed file (channel_depth %d, channel_count %d)\n", + s->channel_depth, s->channel_count); + return AVERROR_INVALIDDATA; + } + avctx->pix_fmt = AV_PIX_FMT_PAL8; + break; case PSD_RGB: if (s->channel_count == 3) { if (s->channel_depth == 8) { @@ -416,6 +436,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, } } + if (s->color_mode == PSD_INDEXED) { + picture->palette_has_changed = 1; + memcpy(picture->data[1], s->palette, AVPALETTE_SIZE); + } + av_freep(&s->tmp); picture->pict_type = AV_PICTURE_TYPE_I;