From patchwork Thu Aug 8 20:52:25 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: 14326 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 7996B44A056 for ; Thu, 8 Aug 2019 23:55:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6501E68ABB2; Thu, 8 Aug 2019 23:55:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5944968AB80 for ; Thu, 8 Aug 2019 23:55:31 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id c2so93000074wrm.8 for ; Thu, 08 Aug 2019 13:55:31 -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=UJPb3AAjz6L9+J7IdFgkvRqGSYh+RGWaxML2wbIvqw0=; b=tPIFfPynwU64HaEJ5YQ6V8peIGigJJtoFKo7Z9F8km+6D516l8wKsig8LimCV7Klbz jUE3ei2NME9h5qtRHAOS6gDKtC3pPPRy7qkUV9sAf8zG/tLobK5fWYiV3nz4RIzoko4g Pl9DkiLhNNVYo8FRMDhi0FN7hoG6zmWqXDd5fGjvysT4g5T+ngaffHI5HWnXJaeO9V3L F66UPmunoE3taReiC+HhhyDv13qVjlco/Ed3VFdtTbGNyM36QCSN3aqr9QP0I89OBKcZ n/Qa+TVrsaXY1UvZpQKg7erixiijyvPCZrTYdtZpJd21sziGw5toFbvu/wkJvOVa8GzE 9w6Q== 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=UJPb3AAjz6L9+J7IdFgkvRqGSYh+RGWaxML2wbIvqw0=; b=ibpCUKBeqaF51Pqu7L4UOOn/WD0eOtUmExZ9eCGo7ceRft7VQejCRUHBFDiiG61LcI G+C5UnN+0Is4BH6O2ydSEI9yBYH2e+D98NXnHtHwwi8HJlthcIwXZbdK137cG7piC+6U UEvKU1kbOsD3ttu/zQshKQ3B8e7q9zBYWyBY6E3RK0uad7TperEZoZYbGg5g9jWw7faU iJLo4PVIsQ1wQo6hjSro9uJWbawUSIbey/Pa81oLiBAuXxFp4rDJT/doxatetNBjkdU2 78eA6SNbOAiIEgoZAB1+Xp1uq269kKinfri6xNVNGxepvQGsUP2ev0EatyrjOhBe51T1 2sIw== X-Gm-Message-State: APjAAAW+C144aRbe8gjg4GKJTrYYbMkesdn7sweD2fonpCxbQJFcMElE 09kAv0+w2lIEBVE5E71KVxzuMbefy34= X-Google-Smtp-Source: APXvYqxN/fYHnIe7OZe48GrewrVfDKON31ccV3SULQPzbvRfC3nS9gW5/Ml613PMdq5Ri2PrA5uthg== X-Received: by 2002:adf:eb4e:: with SMTP id u14mr19422782wrn.168.1565297730652; Thu, 08 Aug 2019 13:55:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:2409:5200:1de8:6b2e:8289:ee0e]) by smtp.gmail.com with ESMTPSA id g25sm3446686wmk.18.2019.08.08.13.55.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 13:55:30 -0700 (PDT) From: velocityra@gmail.com X-Google-Original-From: velocityra@gmail To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Aug 2019 23:52:25 +0300 Message-Id: <20190808205233.16368-6-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190808205233.16368-1-velocityra@gmail.com> References: <20190808205233.16368-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v11 06/14] 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 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 4620508d53..37fda15162 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;