From patchwork Fri Jan 11 02:23:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 11701 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 67F4544D469 for ; Fri, 11 Jan 2019 04:23:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8557568A7DF; Fri, 11 Jan 2019 04:23:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it1-f196.google.com (mail-it1-f196.google.com [209.85.166.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 398E8689E50 for ; Fri, 11 Jan 2019 04:23:40 +0200 (EET) Received: by mail-it1-f196.google.com with SMTP id w18so186923ite.1 for ; Thu, 10 Jan 2019 18:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=RzdJrb3SJ8zTT+S5T6SqqPggxOrdasmG10ugNLpaFRo=; b=gW5PMSs0gFT2z0w74JJN+1NyHr7422qUv8x2SMDo4gkXstMMDrz6ACtINoYOvYIXgV 9NVy9dBUzBM2WlwTIH8tWa9EYl8v6uk1ueAP/T/b3PDt3F1pPW7SZbeeyWCoesTKI8tj tUmzlqY8f6De2aRR7PmyzOYRLUGsDwwlyRGQSsHsQ+XPFgBB3btQSMMT+RSK4dyY7Gp9 fGo3pyMWB8w6rUAYEI2DgOGmxotA9d+Exxqu+UScCpyRmbRcM6rQviUjFqJB8u1Ut8nK UfTrCZzIv+xPMRMoZkIyC7iRDzM2m7lSetOnYETpz7BFG3GyLf9A+icTOiaJNqla2v4H bVxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=RzdJrb3SJ8zTT+S5T6SqqPggxOrdasmG10ugNLpaFRo=; b=phBFc2KJ2NV642KzwK7uB97VvdfZF3xayC62Rd3aS4DdQarHeZhu4QEW3ozq6wVptP URsjLMH/MGqHzdbtetPSAL3OY1COzC044wZFe6r468aDThkx/Vv6SEdAqA1Iis+vADAd UEBiEAqJxasM8++7IpPtNBboYmOkTwObo3AWqd4t5mS8yCcHzQchZw88xFOA6tQXIsH0 L1y7Mlzovg6JnV3R4Z99ahSQVLaflHMpMICWspZrLRMqMgK/Xy+hRSQW33udHCu7mf7T 5H6VbTC5ZAWF6tjBVX6xXgA1LljOpBsOziELOe4XOJDZED46DaAF6eU40VFqyAf7XpDO yPPA== X-Gm-Message-State: AJcUuke0sZ62ndl1boXhR/W+SoB5v1J6OCrrUY+ZCcRafYGq2BdWMKSR DbaJCVKSXJ7ICutUApBn5Ihx5ifiQ5IOLo+mbuZudA== X-Google-Smtp-Source: ALg8bN64wPSy1YHm5YamsjWRdL01laW2NgW/pILDQ2BBoT/RnEmGZLRcNEDf0WQwBYnhyVZFTkgaZndmdG4UYy2obv8= X-Received: by 2002:a24:b64a:: with SMTP id d10mr78153itj.149.1547173430619; Thu, 10 Jan 2019 18:23:50 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a02:5f11:0:0:0:0:0 with HTTP; Thu, 10 Jan 2019 18:23:49 -0800 (PST) In-Reply-To: References: From: Carl Eugen Hoyos Date: Fri, 11 Jan 2019 03:23:49 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images 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" 2019-01-11 2:55 GMT+01:00, Carl Eugen Hoyos : > Hi! > > Attached patch fixes ticket #6797, please comment. New patch with 16bit support attached. Please comment, Carl Eugen From 5f879539ee7fecd57bd3de9f7c6363d9b7779b5b Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Fri, 11 Jan 2019 03:20:38 +0100 Subject: [PATCH] lavc/psd: Support CMYK images. Based on a05635e by Michael Niedermayer. Fixes ticket #6797. --- libavcodec/psd.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/libavcodec/psd.c b/libavcodec/psd.c index 4381447..a31f738 100644 --- a/libavcodec/psd.c +++ b/libavcodec/psd.c @@ -337,6 +337,30 @@ static int decode_frame(AVCodecContext *avctx, void *data, } avctx->pix_fmt = AV_PIX_FMT_PAL8; break; + case PSD_CMYK: + if (s->channel_count == 4) { + if (s->channel_depth == 8) { + avctx->pix_fmt = AV_PIX_FMT_GBRP; + } else if (s->channel_depth == 16) { + avctx->pix_fmt = AV_PIX_FMT_GBRP16BE; + } else { + avpriv_report_missing_feature(avctx, "channel depth %d for cmyk", s->channel_depth); + return AVERROR_PATCHWELCOME; + } + } else if (s->channel_count == 5) { + if (s->channel_depth == 8) { + avctx->pix_fmt = AV_PIX_FMT_GBRAP; + } else if (s->channel_depth == 16) { + avctx->pix_fmt = AV_PIX_FMT_GBRAP16BE; + } else { + avpriv_report_missing_feature(avctx, "channel depth %d for cmyk", s->channel_depth); + return AVERROR_PATCHWELCOME; + } + } else { + avpriv_report_missing_feature(avctx, "channel count %d for cmyk", s->channel_count); + return AVERROR_PATCHWELCOME; + } + break; case PSD_RGB: if (s->channel_count == 3) { if (s->channel_depth == 8) { @@ -435,6 +459,66 @@ static int decode_frame(AVCodecContext *avctx, void *data, } } } + } else if (s->color_mode == PSD_CMYK) { + uint8_t *dst[4] = { picture->data[0], picture->data[1], picture->data[2], picture->data[3] }; + const uint8_t *src[5] = { ptr_data }; + src[1] = src[0] + s->line_size * s->height; + src[2] = src[1] + s->line_size * s->height; + src[3] = src[2] + s->line_size * s->height; + src[4] = src[3] + s->line_size * s->height; + if (s->channel_depth == 8) { + for (y = 0; y < s->height; y++) { + for (x = 0; x < s->width; x++) { + int k = src[3][x]; + int r = src[0][x] * k; + int g = src[1][x] * k; + int b = src[2][x] * k; + dst[0][x] = g * 257 >> 16; + dst[1][x] = b * 257 >> 16; + dst[2][x] = r * 257 >> 16; + } + dst[0] += picture->linesize[0]; + dst[1] += picture->linesize[1]; + dst[2] += picture->linesize[2]; + src[0] += s->line_size; + src[1] += s->line_size; + src[2] += s->line_size; + src[3] += s->line_size; + } + if (avctx->pix_fmt == AV_PIX_FMT_GBRAP) { + for (y = 0; y < s->height; y++) { + memcpy(dst[3], src[4], s->line_size); + src[4] += s->line_size; + dst[3] += picture->linesize[3]; + } + } + } else { + for (y = 0; y < s->height; y++) { + for (x = 0; x < s->width; x++) { + int64_t k = AV_RB16(&src[3][x * 2]); + int64_t r = AV_RB16(&src[0][x * 2]) * k; + int64_t g = AV_RB16(&src[1][x * 2]) * k; + int64_t b = AV_RB16(&src[2][x * 2]) * k; + AV_WB16(&dst[0][x * 2], g * 65537 >> 32); + AV_WB16(&dst[1][x * 2], b * 65537 >> 32); + AV_WB16(&dst[2][x * 2], r * 65537 >> 32); + } + dst[0] += picture->linesize[0]; + dst[1] += picture->linesize[1]; + dst[2] += picture->linesize[2]; + src[0] += s->line_size; + src[1] += s->line_size; + src[2] += s->line_size; + src[3] += s->line_size; + } + if (avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) { + for (y = 0; y < s->height; y++) { + memcpy(dst[3], src[4], s->line_size); + src[4] += s->line_size; + dst[3] += picture->linesize[3]; + } + } + } } else {/* Planar */ if (s->channel_count == 1)/* gray 8 or gray 16be */ eq_channel[0] = 0;/* assign first channel, to first plane */ -- 1.7.10.4