From patchwork Wed Jul 8 19:20:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Ramakrishnan X-Patchwork-Id: 20902 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 5F94944BC59 for ; Wed, 8 Jul 2020 22:50:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 409E9689E40; Wed, 8 Jul 2020 22:50:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A3C06880FB for ; Wed, 8 Jul 2020 22:50:18 +0300 (EEST) Received: by mail-io1-f66.google.com with SMTP id l1so6375606ioh.5 for ; Wed, 08 Jul 2020 12:50:18 -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; bh=egFBhqhWLI7K9IiY2aizwyOHOGQQbzympSrEXt1h8+o=; b=Yd2DZ2hcwhCGEFb8mZzXYSZbj/HVd56pjO0q26Sx76prGN3JGgxDL/+NQ7iDGAj+Qp JsLdQvYm0fLUh2uaCB1Q6jm9CdA78y7YnOCxP2bhrl7xprBmL+MIxNjzQsRc4q4HtOcG 6Nvy8cz3ImjY12zBwt5jsrGE0Ulv0V3MmLUWrZLKQMd/U2nC5tApdRBTyWkYVYQSdDsN WrynRaTFxs60hW17aMR/Po8wQmotGIW6VMQ2MtSabm7RPVf7P8s2HmZ3I1WiApJpHEV9 uyUa+UP4evgwwSb6K56OwMvoNILx9x6HZJoBvcWjyzR7YvVUkHpOXGtHGUqEqXxbWDrs /8yg== 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; bh=egFBhqhWLI7K9IiY2aizwyOHOGQQbzympSrEXt1h8+o=; b=mzzbdT7/R0R//sj3rAJ0YHkfF9SmACtdZdOoEcas0s3PorHulcVr5Ccxz/v2aVQ+p2 /u2Brj0WrQx2fvBzw6EoUmUwSLkWsF/RuKJWnWRnQGAq35l7jKQbmRXRCuII0YA0XuSp h4dT1HLO6Q22PX7ioVyrOl/iH2zw1JQMfNfviI9+pU6KFZsFPFvv0z1xC7JfAGAodMGu ruS6Wf14Q5JxnMqY+79sLfRU9KIsPbC9+p1lKOmPsEkVFeTyqZc/J7iYFfb81hcl5p74 Tarc3mx/zPa4o4TSSfONwJacSs2Wvi2G9XkqbH3SM+Kbe/PwHvL/oiR7QVfU+aOB6c6Y E7dQ== X-Gm-Message-State: AOAM530w/+qrClqsgsmJItZrl7XOcIjqYWP1ga3YIZfvNCrkJBJki9XG tjf+xdPso7UphzW4aOl4x473ARumRxwbpg== X-Google-Smtp-Source: ABdhPJyvLOHkeCuATWTqKkkQXZqwS5VlIvgymZACX5iJpXSI2BRyRxy3ZQaxdaSNE3x2Xc8k+SEAlQ== X-Received: by 2002:a65:6714:: with SMTP id u20mr50964990pgf.121.1594236026743; Wed, 08 Jul 2020 12:20:26 -0700 (PDT) Received: from localhost.localdomain ([223.226.75.84]) by smtp.gmail.com with ESMTPSA id n188sm496242pfn.104.2020.07.08.12.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 12:20:25 -0700 (PDT) From: gautamramk@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jul 2020 00:50:19 +0530 Message-Id: <20200708192019.8051-1-gautamramk@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] libavcodec/jpeg2000dec: Fix RPCL progression order 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: Gautam Ramakrishnan MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Gautam Ramakrishnan This patch fixes a check in the RPCL progression order, making it similar to the openjpeg implementation. --- libavcodec/jpeg2000dec.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 18a933077e..3ea939f7d9 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -1393,22 +1393,28 @@ static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2 uint8_t reducedresno = codsty->nreslevels - 1 -reslevelno; // ==> N_L - r Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno; unsigned prcx, prcy; + int trx0, try0; - int xc = x / s->cdx[compno]; - int yc = y / s->cdy[compno]; + if (!s->cdx[compno] || !s->cdy[compno]) + return AVERROR_INVALIDDATA; + + trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reslevelno); + try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reslevelno); if (reslevelno >= codsty->nreslevels) continue; - if (yc % (1LL << (rlevel->log2_prec_height + reducedresno)) && y != tile->coord[1][0]) //FIXME this is a subset of the check + if (!(y % ((uint64_t)s->cdy[compno] << (rlevel->log2_prec_height + reducedresno)) == 0 || + (y == tile->coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height))))) continue; - if (xc % (1LL << (rlevel->log2_prec_width + reducedresno)) && x != tile->coord[0][0]) //FIXME this is a subset of the check + if (!(x % ((uint64_t)s->cdx[compno] << (rlevel->log2_prec_width + reducedresno)) == 0 || + (x == tile->coord[0][0] && (trx0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_width))))) continue; // check if a precinct exists - prcx = ff_jpeg2000_ceildivpow2(xc, reducedresno) >> rlevel->log2_prec_width; - prcy = ff_jpeg2000_ceildivpow2(yc, reducedresno) >> rlevel->log2_prec_height; + prcx = ff_jpeg2000_ceildiv(x, s->cdx[compno] << reducedresno) >> rlevel->log2_prec_width; + prcy = ff_jpeg2000_ceildiv(y, s->cdy[compno] << reducedresno) >> rlevel->log2_prec_height; prcx -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width; prcy -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height; @@ -1906,7 +1912,6 @@ static inline void tile_codeblocks(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile continue; x = cblk->coord[0][0] - band->coord[0][0]; y = cblk->coord[1][0] - band->coord[1][0]; - if (comp->roi_shift) roi_scale_cblk(cblk, comp, &t1); if (codsty->transform == FF_DWT97)