From: Leo Izen <leo.izen@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v3 1/3] avcodec/mjpegdec: fix non-subsampled RGB JPEGs
Date: Wed, 19 Apr 2023 15:23:41 -0400
Message-ID: <1e1d5c0d-7b06-3215-706c-edfc65a72801@gmail.com> (raw)
In-Reply-To: <20230419185838.GS275832@pb2>
On 4/19/23 14:58, Michael Niedermayer wrote:
> On Wed, Apr 19, 2023 at 02:11:24PM -0400, Leo Izen wrote:
>> The change introduced in b18a9c29713abc3a1b081de3f320ab53a47120c6
>> created a regression for non-subsampled progressive RGB jpegs. This
>> should fix that.
>> ---
>> libavcodec/mjpegdec.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
>> index 01537d4774..1e3ddb72fb 100644
>> --- a/libavcodec/mjpegdec.c
>> +++ b/libavcodec/mjpegdec.c
>> @@ -1698,7 +1698,8 @@ 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 == 3 && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBRP)
>> + if((nb_components == 3 || nb_components == 1) && s->nb_components == 3
>> + && s->avctx->pix_fmt == AV_PIX_FMT_GBRP && !s->progressive)
>> index = (index+2)%3;
>
> Why is progressive/!progressive special cased in all the new RGB code ?
>
With progressive, I decode RGB in RGB-order, and then pivot it into
GBR-order, whereas baseline is just decoded directly into GBR-order. If
you decode progressive directly in GBR-order the buffers will be the
wrong size and it will overrun the subsampled buffer when filling it
with a non-subsampled one. See the allocation block on line 766 of
mjpegdec.c. This depends on h_count and v_count, which cannot be changed
or pivoted as if you do so, progressive JPEGs will fail to decode at all
(invalid VLC entries, etc.)
Ideally, you'd just alloc them the right size, but s->component_index[i]
won't refer to the right index for many progressive files, depending on
whether the SOS marker has 1 or 3 components. If you have SOS markers
with one component it will not properly pivot the colors.
Initially, I didn't have the checks and just always decoded in RGB order
and then pivoted, but that broke some baseline files like the ones in
Trac #4045. I used some casework so I could handle all files I tested
with this.
If anyone has any suggestions on how to make the casework more elegant
I'm all ears but this is the solution I found to work with every sample
I tested.
- Leo Izen (Traneptora/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".
next prev parent reply other threads:[~2023-04-19 19:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 18:11 [FFmpeg-devel] [PATCH v3 0/3] RGB mjpeg fixes (with FATE tests) Leo Izen
2023-04-19 18:11 ` [FFmpeg-devel] [PATCH v3 1/3] avcodec/mjpegdec: fix non-subsampled RGB JPEGs Leo Izen
2023-04-19 18:58 ` Michael Niedermayer
2023-04-19 19:23 ` Leo Izen [this message]
2023-04-19 20:37 ` Michael Niedermayer
2023-04-19 21:15 ` Leo Izen
2023-04-20 6:35 ` Caleb Etemesi
2023-04-20 9:50 ` Michael Niedermayer
2023-04-20 16:27 ` Leo Izen
2023-04-19 18:11 ` [FFmpeg-devel] [PATCH v3 2/3] avcodec/mjpeg: fix weird RGB-subsampled baseline JPEGs Leo Izen
2023-04-19 18:11 ` [FFmpeg-devel] [PATCH v3 3/3] fate: add tests for RGB jpegs Leo Izen
2023-04-19 18:52 ` Michael Niedermayer
2023-04-19 18:38 ` [FFmpeg-devel] [PATCH v3 0/3] RGB mjpeg fixes (with FATE tests) Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1e1d5c0d-7b06-3215-706c-edfc65a72801@gmail.com \
--to=leo.izen@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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