* [FFmpeg-devel] [PATCH] avcodec/mjpegdec: support weird RGB subsampling with progressive
@ 2023-03-14 20:03 Leo Izen
2023-03-16 3:11 ` Andreas Rheinhardt
0 siblings, 1 reply; 3+ messages in thread
From: Leo Izen @ 2023-03-14 20:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Leo Izen
This allows weird subsampling with progressive JPEGs to be decoded,
such as full-RG and only B subsampled.
---
libavcodec/mjpegdec.c | 38 ++++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index c833d66c4d..062730f3e1 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -571,10 +571,15 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
case 0x22221100:
case 0x22112200:
case 0x11222200:
- if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
- else
+ if (s->bits > 8)
goto unk_pixfmt;
- s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
+ if (s->adobe_transform == 0 || s->component_id[0] == 'R' &&
+ s->component_id[1] == 'G' && s->component_id[2] == 'B') {
+ s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
+ } else {
+ s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
+ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
+ }
break;
case 0x11000000:
case 0x13000000:
@@ -673,10 +678,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
avpriv_report_missing_feature(s->avctx, "Lowres for weird subsampling");
return AVERROR_PATCHWELCOME;
}
- if ((AV_RB32(s->upscale_h) || AV_RB32(s->upscale_v)) && s->progressive && s->avctx->pix_fmt == AV_PIX_FMT_GBRP) {
- avpriv_report_missing_feature(s->avctx, "progressive for weird subsampling");
- return AVERROR_PATCHWELCOME;
- }
if (s->ls) {
memset(s->upscale_h, 0, sizeof(s->upscale_h));
memset(s->upscale_v, 0, sizeof(s->upscale_v));
@@ -1697,9 +1698,6 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,
s->h_scount[i] = s->h_count[index];
s->v_scount[i] = s->v_count[index];
- if((nb_components == 1 || nb_components == 3) && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P)
- index = (index+2)%3;
-
s->comp_index[i] = index;
s->dc_index[i] = get_bits(&s->gb, 4);
@@ -2745,6 +2743,26 @@ the_end:
}
}
}
+
+ if (s->avctx->pix_fmt == AV_PIX_FMT_GBRP) {
+ int w = s->picture_ptr->width;
+ int h = s->picture_ptr->height;
+ av_assert0(s->nb_components == 3);
+ for (int i = 0; i < h; i++) {
+ uint8_t *dst[3];
+ for (int index = 0; index < 3; index++)
+ dst[index] = s->picture_ptr->data[index] + i * s->picture_ptr->linesize[index];
+ for (int j = 0; j < w; j++) {
+ uint8_t r = dst[0][j];
+ uint8_t g = dst[1][j];
+ uint8_t b = dst[2][j];
+ dst[0][j] = g;
+ dst[1][j] = b;
+ dst[2][j] = r;
+ }
+ }
+ }
+
if (s->adobe_transform == 2 && s->avctx->pix_fmt == AV_PIX_FMT_YUVA444P) {
int w = s->picture_ptr->width;
int h = s->picture_ptr->height;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/mjpegdec: support weird RGB subsampling with progressive
2023-03-14 20:03 [FFmpeg-devel] [PATCH] avcodec/mjpegdec: support weird RGB subsampling with progressive Leo Izen
@ 2023-03-16 3:11 ` Andreas Rheinhardt
2023-03-16 15:50 ` Leo Izen
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Rheinhardt @ 2023-03-16 3:11 UTC (permalink / raw)
To: ffmpeg-devel
Leo Izen:
> This allows weird subsampling with progressive JPEGs to be decoded,
> such as full-RG and only B subsampled.
> ---
> libavcodec/mjpegdec.c | 38 ++++++++++++++++++++++++++++----------
> 1 file changed, 28 insertions(+), 10 deletions(-)
>
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index c833d66c4d..062730f3e1 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -571,10 +571,15 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
> case 0x22221100:
> case 0x22112200:
> case 0x11222200:
> - if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
> - else
> + if (s->bits > 8)
> goto unk_pixfmt;
> - s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
> + if (s->adobe_transform == 0 || s->component_id[0] == 'R' &&
> + s->component_id[1] == 'G' && s->component_id[2] == 'B') {
> + s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
> + } else {
> + s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
> + s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
> + }
> break;
> case 0x11000000:
> case 0x13000000:
> @@ -673,10 +678,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
> avpriv_report_missing_feature(s->avctx, "Lowres for weird subsampling");
> return AVERROR_PATCHWELCOME;
> }
> - if ((AV_RB32(s->upscale_h) || AV_RB32(s->upscale_v)) && s->progressive && s->avctx->pix_fmt == AV_PIX_FMT_GBRP) {
> - avpriv_report_missing_feature(s->avctx, "progressive for weird subsampling");
> - return AVERROR_PATCHWELCOME;
> - }
> if (s->ls) {
> memset(s->upscale_h, 0, sizeof(s->upscale_h));
> memset(s->upscale_v, 0, sizeof(s->upscale_v));
> @@ -1697,9 +1698,6 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,
> s->h_scount[i] = s->h_count[index];
> s->v_scount[i] = s->v_count[index];
>
> - if((nb_components == 1 || nb_components == 3) && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P)
> - index = (index+2)%3;
> -
> s->comp_index[i] = index;
>
> s->dc_index[i] = get_bits(&s->gb, 4);
> @@ -2745,6 +2743,26 @@ the_end:
> }
> }
> }
> +
> + if (s->avctx->pix_fmt == AV_PIX_FMT_GBRP) {
> + int w = s->picture_ptr->width;
> + int h = s->picture_ptr->height;
> + av_assert0(s->nb_components == 3);
> + for (int i = 0; i < h; i++) {
> + uint8_t *dst[3];
> + for (int index = 0; index < 3; index++)
> + dst[index] = s->picture_ptr->data[index] + i * s->picture_ptr->linesize[index];
> + for (int j = 0; j < w; j++) {
> + uint8_t r = dst[0][j];
> + uint8_t g = dst[1][j];
> + uint8_t b = dst[2][j];
> + dst[0][j] = g;
> + dst[1][j] = b;
> + dst[2][j] = r;
> + }
> + }
> + }
Is there a reason you are not just swapping the pointers?
> +
> if (s->adobe_transform == 2 && s->avctx->pix_fmt == AV_PIX_FMT_YUVA444P) {
> int w = s->picture_ptr->width;
> int h = s->picture_ptr->height;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/mjpegdec: support weird RGB subsampling with progressive
2023-03-16 3:11 ` Andreas Rheinhardt
@ 2023-03-16 15:50 ` Leo Izen
0 siblings, 0 replies; 3+ messages in thread
From: Leo Izen @ 2023-03-16 15:50 UTC (permalink / raw)
To: ffmpeg-devel
On 3/15/23 23:11, Andreas Rheinhardt wrote:
> Leo Izen:
>> This allows weird subsampling with progressive JPEGs to be decoded,
>> such as full-RG and only B subsampled.
>> ---
>> libavcodec/mjpegdec.c | 38 ++++++++++++++++++++++++++++----------
>> 1 file changed, 28 insertions(+), 10 deletions(-)
>>
>> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
>> index c833d66c4d..062730f3e1 100644
>> --- a/libavcodec/mjpegdec.c
>> +++ b/libavcodec/mjpegdec.c
>> @@ -571,10 +571,15 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
>> case 0x22221100:
>> case 0x22112200:
>> case 0x11222200:
>> - if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
>> - else
>> + if (s->bits > 8)
>> goto unk_pixfmt;
>> - s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
>> + if (s->adobe_transform == 0 || s->component_id[0] == 'R' &&
>> + s->component_id[1] == 'G' && s->component_id[2] == 'B') {
>> + s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
>> + } else {
>> + s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
>> + s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
>> + }
>> break;
>> case 0x11000000:
>> case 0x13000000:
>> @@ -673,10 +678,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
>> avpriv_report_missing_feature(s->avctx, "Lowres for weird subsampling");
>> return AVERROR_PATCHWELCOME;
>> }
>> - if ((AV_RB32(s->upscale_h) || AV_RB32(s->upscale_v)) && s->progressive && s->avctx->pix_fmt == AV_PIX_FMT_GBRP) {
>> - avpriv_report_missing_feature(s->avctx, "progressive for weird subsampling");
>> - return AVERROR_PATCHWELCOME;
>> - }
>> if (s->ls) {
>> memset(s->upscale_h, 0, sizeof(s->upscale_h));
>> memset(s->upscale_v, 0, sizeof(s->upscale_v));
>> @@ -1697,9 +1698,6 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,
>> s->h_scount[i] = s->h_count[index];
>> s->v_scount[i] = s->v_count[index];
>>
>> - if((nb_components == 1 || nb_components == 3) && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P)
>> - index = (index+2)%3;
>> -
>> s->comp_index[i] = index;
>>
>> s->dc_index[i] = get_bits(&s->gb, 4);
>> @@ -2745,6 +2743,26 @@ the_end:
>> }
>> }
>> }
>> +
>> + if (s->avctx->pix_fmt == AV_PIX_FMT_GBRP) {
>> + int w = s->picture_ptr->width;
>> + int h = s->picture_ptr->height;
>> + av_assert0(s->nb_components == 3);
>> + for (int i = 0; i < h; i++) {
>> + uint8_t *dst[3];
>> + for (int index = 0; index < 3; index++)
>> + dst[index] = s->picture_ptr->data[index] + i * s->picture_ptr->linesize[index];
>> + for (int j = 0; j < w; j++) {
>> + uint8_t r = dst[0][j];
>> + uint8_t g = dst[1][j];
>> + uint8_t b = dst[2][j];
>> + dst[0][j] = g;
>> + dst[1][j] = b;
>> + dst[2][j] = r;
>> + }
>> + }
>> + }
>
> Is there a reason you are not just swapping the pointers?
No particular reason, other than I tried that and messed it up when
testing (probably because I didn't do it properly). I'll send a v2 and
swap these.
- Leo Izen (thebombzen)
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-16 15:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 20:03 [FFmpeg-devel] [PATCH] avcodec/mjpegdec: support weird RGB subsampling with progressive Leo Izen
2023-03-16 3:11 ` Andreas Rheinhardt
2023-03-16 15:50 ` Leo Izen
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git