From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1408B45F41 for ; Wed, 19 Apr 2023 19:23:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AAFB268BE29; Wed, 19 Apr 2023 22:23:50 +0300 (EEST) Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 81AB068AAB3 for ; Wed, 19 Apr 2023 22:23:44 +0300 (EEST) Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-b8bf64a4999so48835276.1 for ; Wed, 19 Apr 2023 12:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681932223; x=1684524223; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=5vhd90OTWjpNIdHS4cnx4Lti+oC6DAOmvjE/DyV3wSo=; b=ArrI4uEcKTBQfYa93iiYqBZGatDsU7iItpdCjtjBoFRW9X+d8fEmx/S+0jgX9dHSWL uprdSWhx1ZwUeeHyQYj60WmD81glYq/mEmk7L2RjKvmf1RTAyBIcx2L/caAcoDTAtf8B y69p9otXLiIu63fo9pgEUDeAYKfO2mGiy0JMXq1lott8sqefkSBAP/X44PgUQL/MYnIJ QA293AIpzAxrcoXOpnoHMrDpna8ZroHSxBskkTXW5S+voGAWfI3BJnyQaM8ofT+ogrMx RWXx+mAA3pbE0/NoBa7X5vvvREIqORwhVkmJYKoQ3eendolUQe4p5a6wL2ZJoafhFhkc EzBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681932223; x=1684524223; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5vhd90OTWjpNIdHS4cnx4Lti+oC6DAOmvjE/DyV3wSo=; b=DLdagS2FyqwnADnDcJP3stGZX14AWz+e/IJ5aiJFC8TP0aGBiMc9od2roFPAyZrDS5 xPAaExbzKSBT7072Eery74/fzv1aAdLLjdqVQRkzXm0WC3sjFa2NW3A8Ork18sRDXcw5 LVE3bjtxtnItyah8tSQlas9kkfLUzdIPaNVrXAt3SgYZIe6IdD1X+f+QsWiF0ANuUjvV 4zth8iCpv+lvSTB4kmfrKnf5qWjAQdYQ1jDjJcf7xIaHAa6ol+8lKoYDBvmboja2Vc3w nWh17ju42T2MRdOY4V6WkEYtOppOVpx/5mRt89LedPfVps+dQOOUFosi1bPIBZg9OdZm PqPw== X-Gm-Message-State: AAQBX9cg06skGjFL5KLTG+B8o8B7JhvVM7DluCC7M7jSG906w7PVdLRN uCmeIxY6P9mBGnQw2KqVS6jsw3yFGiw= X-Google-Smtp-Source: AKy350Z0WapK1YR4p3gpCjgCGvBn19CZf4qAFn6HNhLUbtlLghGP4yrcPm7YSJ8NAv6y4AGyy+S6Rg== X-Received: by 2002:a81:1953:0:b0:54f:a9b3:35bc with SMTP id 80-20020a811953000000b0054fa9b335bcmr17844677ywz.0.1681932222477; Wed, 19 Apr 2023 12:23:42 -0700 (PDT) Received: from [192.168.1.35] (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id u1-20020a817901000000b00545a08184b5sm4599983ywc.69.2023.04.19.12.23.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Apr 2023 12:23:42 -0700 (PDT) Message-ID: <1e1d5c0d-7b06-3215-706c-edfc65a72801@gmail.com> Date: Wed, 19 Apr 2023 15:23:41 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 To: ffmpeg-devel@ffmpeg.org References: <20230419181126.38662-1-leo.izen@gmail.com> <20230419181126.38662-2-leo.izen@gmail.com> <20230419185838.GS275832@pb2> Content-Language: en-US-large From: Leo Izen In-Reply-To: <20230419185838.GS275832@pb2> Subject: Re: [FFmpeg-devel] [PATCH v3 1/3] avcodec/mjpegdec: fix non-subsampled RGB JPEGs X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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".