From patchwork Thu Sep 26 07:06:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 15306 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 85CA344A09D for ; Thu, 26 Sep 2019 10:08:05 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6036E68A297; Thu, 26 Sep 2019 10:08:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-2.mx.upcmail.net (vie01a-dmta-pe05-2.mx.upcmail.net [84.116.36.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 93FC5689DD1 for ; Thu, 26 Sep 2019 10:07:58 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1iDNsc-0005ob-2Z for ffmpeg-devel@ffmpeg.org; Thu, 26 Sep 2019 09:07:58 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id DNrdi1p4JwlysDNrdiASE6; Thu, 26 Sep 2019 09:06:58 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=pGLkceISAAAA:8 a=4v0u3E9u9aMMngLc16MA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 26 Sep 2019 09:06:28 +0200 Message-Id: <20190926070628.22693-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfESnXZJKGjXs44v5gLWb47mlZtoraX+5zLq4OLcxZcp+H3nJeWTDeJzfxbMpSCAVobPeqXjoBO++WcyQAB+sPL2FXYMFqSQA1n8zocVmNNlB2D8HWYay of9OoMjcIMUQkIUy+Z3cFLq6aD4tz03X1qPhaDV0irghVmSkso5cDG5ifS4OU6k8n6fj/4hVYy+NMbyZIeoOzESinH6gLI46Rxo= Subject: [FFmpeg-devel] [PATCH] avcodec/tiff: Try to fix subsampling default 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 Cc: Skakov Pavel Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This ensures the default ycbcr_subsampling is 2 while also ensuring the subsampling values are correct for all pixel formats. This solution while it takes a few lines more code should be more robust Found-by: Skakov Pavel Signed-off-by: Michael Niedermayer --- libavcodec/tiff.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 9f24796a88..13a38bd64f 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -74,6 +74,7 @@ typedef struct TiffContext { enum TiffPhotometric photometric; int planar; int subsampling[2]; + int ycbcr_subsampling[2]; int fax_opts; int predictor; int fill_order; @@ -1101,6 +1102,8 @@ static int init_image(TiffContext *s, ThreadFrame *frame) break; case 243: if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) { + s->subsampling[0] = s->ycbcr_subsampling[0]; + s->subsampling[1] = s->ycbcr_subsampling[1]; if (s->subsampling[0] == 1 && s->subsampling[1] == 1) { s->avctx->pix_fmt = AV_PIX_FMT_YUV444P; } else if (s->subsampling[0] == 2 && s->subsampling[1] == 1) { @@ -1511,10 +1514,10 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame) return AVERROR_INVALIDDATA; } for (i = 0; i < count; i++) { - s->subsampling[i] = ff_tget(&s->gb, type, s->le); - if (s->subsampling[i] <= 0) { - av_log(s->avctx, AV_LOG_ERROR, "subsampling %d is invalid\n", s->subsampling[i]); - s->subsampling[i] = 1; + s->ycbcr_subsampling[i] = ff_tget(&s->gb, type, s->le); + if (s->ycbcr_subsampling[i] <= 0) { + av_log(s->avctx, AV_LOG_ERROR, "subsampling %d is invalid\n", s->ycbcr_subsampling[i]); + s->ycbcr_subsampling[i] = 1; return AVERROR_INVALIDDATA; } } @@ -2066,6 +2069,8 @@ static av_cold int tiff_init(AVCodecContext *avctx) s->height = 0; s->subsampling[0] = s->subsampling[1] = 1; + s->ycbcr_subsampling[0] = 2; + s->ycbcr_subsampling[1] = 2; s->avctx = avctx; ff_lzw_decode_open(&s->lzw); if (!s->lzw)