From patchwork Tue Aug 20 13:37:38 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: 14612 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 2C6784481F9 for ; Tue, 20 Aug 2019 16:38:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C59A68AA08; Tue, 20 Aug 2019 16:38:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06BD4688391 for ; Tue, 20 Aug 2019 16:38:25 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id l2so2700937wmg.0 for ; Tue, 20 Aug 2019 06:38:24 -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; bh=dEeKD3J+r1OB+D8Wwohh4UD90FMwykDUUiUGXZzPI4I=; b=P3flMtl31qCwIZ3P6anmFKfQ449+5aVDlbyKC/Unz/KD3jfB9oHrw76C67auLoYMxQ hOXLB3nMCV+64Euw5fSjJFNOG1kMM3shWSaenZh4Xvw6dtZ22E0FrVlVqP4nB5LZbZes 3+17kPsNZscuGfSIXC/pvGsFatI1+grarq6GcLlQxxemB6IIzhIRQyFFKTQuj4kEyV4y oEM6f3jAFsydtu4NnZDT/NlHWbjtpPxOKTR8Fd8o9fSY2Jna8Ie4noZjOLQtmO48oIqC rBpN4ZVGm/D0QUKuuaxxvObke4Wfc/LENJYTmaqRwmg5S3YDUmKsCERO71QkFal8xixV FaDw== 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; bh=dEeKD3J+r1OB+D8Wwohh4UD90FMwykDUUiUGXZzPI4I=; b=K01wkYpQxDvG+jB+xskqWeDqpQ/BEZuQ/jx/+Dt4Lw1ebm2IF4H9cAt+pk+4pu7jKk OG5TwyzFDGaUEy+pAf/corazKqw7QoqDxAErro+qLg4aAyq7gl/+BW2XsfKOVbhm318Q jk8Dv7xfCsGgjJ5xFqOq9Kx/M35JeebQKw0776RnvDIY0tvRsJ0+VRbjZHIUZnVzC+vD xawKpx2ZpiFSPICewPdNyExvuibyhSBkD7EzCTVpGNttfbK9upNjrES0M50FvPmwKOUE 4ioJwWAPDjyZuauTgEuGYcJFYx4wd89hDx3Ke4OX7weNZuhnAg9fr2L4RgifCa+It+Pt hCEw== X-Gm-Message-State: APjAAAWkjUB1A6dNIU/QSxlrYBWeg5sPMeUDGNpt06b7c0UIBEi1u7Lh pzytTgB5iB0F2KyxWXpgRCYM7x1d X-Google-Smtp-Source: APXvYqzGQ28v/QXYsMo85K34LPKeO1XDavbrt3/MZDIXILlXYHLFoOa49lfqBF2YH416qMSTVgqfGA== X-Received: by 2002:a7b:ca54:: with SMTP id m20mr65760wml.102.1566308304289; Tue, 20 Aug 2019 06:38:24 -0700 (PDT) Received: from localhost.localdomain (ppp-94-66-223-133.home.otenet.gr. [94.66.223.133]) by smtp.gmail.com with ESMTPSA id t14sm11545882wrs.58.2019.08.20.06.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2019 06:38:23 -0700 (PDT) From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Aug 2019 16:37:38 +0300 Message-Id: <20190820133747.30983-6-velocityra@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190820133747.30983-1-velocityra@gmail.com> References: <20190811144542.11704-13-velocityra@gmail.com> <20190820133747.30983-1-velocityra@gmail.com> Subject: [FFmpeg-devel] [PATCH v15 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" In an image [1], the height was equal to the tile length (full-height tile) and after `height % tile_length` was applied to them with the current code, it resulted 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 dd1295fad6..257230c386 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;