From patchwork Wed Aug 28 12:27:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: velocityra@gmail.com X-Patchwork-Id: 14738 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 EC245449447 for ; Wed, 28 Aug 2019 15:28:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D716868AD40; Wed, 28 Aug 2019 15:28:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C7D4E68AB25 for ; Wed, 28 Aug 2019 15:28:35 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id e16so2312308wro.5 for ; Wed, 28 Aug 2019 05:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/BQHcPF480yjhYt8fCv+7d0HcHe/pbqJ/obzTQCngBU=; b=NvKkJjTMBWHKXguwl5GJO930bHejOYa/Zd43n6maL7Xb5clUoamV8FHPvAcZPrLwD4 estA8f9sPX2qx3gr25g+NgCDe7IR4cx0UglRYdnnSJ++AN8JPjBqIvJLJPrWQ/d3yRBD Icgnnwq5dI/FhKWevG+8i2oN5fFAADhpqgTYY1IF94Dd/7wh2nMNLQzsgDe/zm68ZARM m2f1fbt99aDt5gjSM4tC60BEgikXXzVDCFrkNQq+UGBLNNG3XOceXW2yyzBzVH+rjAgV 1uAPmQVr/22nMFQifGedLllP051yHwZy6XWlOwA0vw39hEHm8FNtI7MouFQdpBd8LMM7 7zfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/BQHcPF480yjhYt8fCv+7d0HcHe/pbqJ/obzTQCngBU=; b=IyHlrK/c0x8T816NElGGgk1xHWk0pEgpU29CIGs5AOF5Sqo1FjDOEBtdXkUr36vX2B wh7zrUB1+JD1RGFh7cVoa4veIHx9odHnNPh+Tkdx/Lg+p4ZjVqQq6VOcBjk7jYrNpZcI uNKW75/rapkJyjIaia4mnbzdq41iDfyhFAuvQPZ/H0wO1fG4nBeD3MUOulqaQfZLCbWc +I+drwuD7ZUX2AWWncEICn616ROh6Pmxe+pI2iCxbAp7lm/6T+7BsbT64ckjJqRM7pit NKarYuNRsRaD5i7yCIZMYaS+tslxoHTDrBkAukuVxAwB+JYHEcSr9Ukl/U3zYlxwsJHG F2pA== X-Gm-Message-State: APjAAAUPU5NmUO7Dm+/vYAj8GcKKtBzx+rSxQ5HMQIOxGFZF4Mm3F6J/ mR5jvbTTWNfNXYS/d9h154IzXppq X-Google-Smtp-Source: APXvYqxIoEuO36W1HppAiCys8iGlnzAL6VZNjgYn/So9LwpHupQve5uIq+ml1uCUcBACP91wCidD+A== X-Received: by 2002:adf:eb8c:: with SMTP id t12mr3211903wrn.84.1566995300147; Wed, 28 Aug 2019 05:28:20 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:240d:9b00:f046:3e76:1fc3:c038]) by smtp.gmail.com with ESMTPSA id a17sm2588958wmm.47.2019.08.28.05.28.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Aug 2019 05:28:19 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Aug 2019 15:27:14 +0300 Message-Id: <20190828122723.19640-6-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190828122723.19640-1-velocityra@gmail.com> References: <20190822125635.GD23202@sunshine.barsnick.net> <20190828122723.19640-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v16 06/15] lavc/tiff: Fix edge case with full-length/width tiles 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: Nick Renieris Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Nick Renieris When the height is equal to the tile length (full-height tile) after `height % tile_length` is applied with the current code, it results in the operating tile_length to be 0. This commit makes this leftover logic only applies if it's necessary. Signed-off-by: Nick Renieris --- libavcodec/tiff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 78b4bd5301..3bf2b3e557 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -887,10 +887,14 @@ static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame) int tile_byte_count_offset, tile_byte_count; int tile_count_x, tile_count_y; int tile_width, tile_length; + int has_width_leftover, has_height_leftover; int tile_x = 0, tile_y = 0; int pos_x = 0, pos_y = 0; int ret; + has_width_leftover = (s->width % s->tile_width != 0); + has_height_leftover = (s->height % s->tile_length != 0); + /* Calculate tile counts (round up) */ tile_count_x = (s->width + s->tile_width - 1) / s->tile_width; tile_count_y = (s->height + s->tile_length - 1) / s->tile_length; @@ -900,12 +904,12 @@ static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame) tile_x = tile_idx % tile_count_x; tile_y = tile_idx / tile_count_x; - if (tile_x == tile_count_x - 1) // If on the right edge + if (has_width_leftover && tile_x == tile_count_x - 1) // If on the right-most tile tile_width = s->width % s->tile_width; else tile_width = s->tile_width; - if (tile_y == tile_count_y - 1) // If on the bottom edge + if (has_height_leftover && tile_y == tile_count_y - 1) // If on the bottom-most tile tile_length = s->height % s->tile_length; else tile_length = s->tile_length;