Re: [FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images

2019-01-12 Thread Carl Eugen Hoyos
2019-01-11 7:17 GMT+01:00, Peter Ross :
> On Fri, Jan 11, 2019 at 03:23:49AM +0100, Carl Eugen Hoyos wrote:
>> 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
>
>> +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;
>> +}
>
> the same algorithm exists in libavcodec/mjpegdec.c, with alpha channel
> support.
> i guess it is trivial enough to be duplicated here.
>
> otherwise looks good.

Patch applied.

Thanks everybody, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images

2019-01-11 Thread Derek Buitenhuis
On 11/01/2019 14:20, Carl Eugen Hoyos wrote:
> Yes, but they can have different representations in FFmpeg.

I suppose the "correct" fix is to put it in swscale, but noone is going
to want to do that.

> Is this patch ok?

No strong opinion. I doubt anyone will want to patch swscale, so I
suppose it is OK.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images

2019-01-11 Thread Carl Eugen Hoyos
2019-01-11 14:05 GMT+01:00, Derek Buitenhuis :
> On 11/01/2019 06:17, Peter Ross wrote:
>> the same algorithm exists in libavcodec/mjpegdec.c, with alpha channel
>> support.
>> i guess it is trivial enough to be duplicated here.
>
> Is it worth deduplicating? Plenty of image formats have CMYK.

Yes, but they can have different representations in FFmpeg.

Is this patch ok?

Thank you, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images

2019-01-11 Thread Derek Buitenhuis
On 11/01/2019 06:17, Peter Ross wrote:
> the same algorithm exists in libavcodec/mjpegdec.c, with alpha channel 
> support.
> i guess it is trivial enough to be duplicated here.

Is it worth deduplicating? Plenty of image formats have CMYK.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images

2019-01-10 Thread Peter Ross
On Fri, Jan 11, 2019 at 03:23:49AM +0100, Carl Eugen Hoyos wrote:
> 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

> +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;
> +}

the same algorithm exists in libavcodec/mjpegdec.c, with alpha channel support.
i guess it is trivial enough to be duplicated here.

otherwise looks good.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images

2019-01-10 Thread Carl Eugen Hoyos
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([3][x * 2]);
+int64_t r = AV_RB16([0][x * 2]) * k;
+int64_t g = AV_RB16([1][x * 2]) * k;
+int64_t b = AV_RB16([2][x * 2]) * k;
+AV_WB16([0][x * 2], g * 65537 >> 32);
+AV_WB16([1][x * 2], b * 65537 >> 32);
+AV_WB16([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

___

[FFmpeg-devel] [PATCH]lavc/psd: Support CMYK images

2019-01-10 Thread Carl Eugen Hoyos
Hi!

Attached patch fixes ticket #6797, please comment.

Carl Eugen
From f0d1c43a791f44eee5ae3174baf367a73e59283e Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Fri, 11 Jan 2019 02:53:06 +0100
Subject: [PATCH] lavc/psd: Support CMYK images.

Fixes ticket #6797.
---
 libavcodec/psd.c |   43 +++
 1 file changed, 43 insertions(+)

diff --git a/libavcodec/psd.c b/libavcodec/psd.c
index 4381447..200e3ad 100644
--- a/libavcodec/psd.c
+++ b/libavcodec/psd.c
@@ -337,6 +337,19 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 }
 avctx->pix_fmt = AV_PIX_FMT_PAL8;
 break;
+case PSD_CMYK:
+if (s->channel_count == 5) {
+if (s->channel_depth == 8) {
+avctx->pix_fmt = AV_PIX_FMT_GBRAP;
+} 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 +448,36 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 }
 }
 }
+} else if (s->color_mode == PSD_CMYK && avctx->pix_fmt == AV_PIX_FMT_GBRAP) {
+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;
+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;
+}
+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

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel