From patchwork Mon May 27 16:24:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 49301 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:542:0:b0:460:55fa:d5ed with SMTP id 63csp3375002vqf; Mon, 27 May 2024 09:25:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXG4SbDV1I4WNm1UYAY0BUQHMuyQmYi/bBhj+kawBgHDEYlGBPMktmAQoLYpBZVO2+QP+RnR05MqRIG32KI8f7AmGnmex+zF68d1Q== X-Google-Smtp-Source: AGHT+IHMgonw+erivy0vZ/MWAvYUwCVZvArnhVHOKfGSI9DKBFYwrPCjLl0/2V5JrNW2PKJs8CNt X-Received: by 2002:a17:906:ad99:b0:a5a:8d7f:f17b with SMTP id a640c23a62f3a-a62642da948mr664163266b.9.1716827121896; Mon, 27 May 2024 09:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716827121; cv=none; d=google.com; s=arc-20160816; b=cOIvHY4YlvwAwSdV+sriVunmuS7K6QX4YbpnqKa3pxXvIRLUZa6N7+zQJYgYFJ0HGP aVWCG9+aeAmss7/57jf+QlXtXTomQHrOp+pBVu5dXPbXsien+i8gxHAHNzIwdp3VsTIF XCqUT7yfAwl89DZCmQ/lpNJV4RjGs0cLSFIrbmSu8hJIvaMgO20FL4qtGUxaOMmjQJ/b Gosw7eQMFF/IT78bUiyKhbtKZ0yvNYtSkceeryeggMhTF1HjeyJENt4eSTw3cQcbzOGC 5TTgV1cFUiQ080DcHl7nuUqvrDOZj66Uv/CEZsaw0sDLDfLj7BmLweYRiDwrPrY+GfVg guYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=WdZLcOg1i8+oJN9TSZYJcuouZhnQmGjhG6Dy1xc4Ang=; fh=SpvibYDCwbgGmPwsj5KsF+XKLLCD1BHk1Tnzebw/zc0=; b=mkdWq4c9nx866LXa8jhJE+JfrOXMNZJ1CnY6ZuzYdGI6Wl6FcSTgrahjVJK5iHWPkx YBJfUDqtTHo7yuI7V6acnVBA49HifGaaLhedeJ5V72ACFZugoGFZBdzKcoAxVIexTu8F kUbTapOzVGbjYRE6uI97+c0GPPDwByahXgbC3dFEtDhbRtpWrTlmLxmrnaAaPDqSAYXD WYg3M+97kCIf8VUBapns/ZEnCzQsMx5vEvzy8rg7f5mGOAItpyna/oTRPflf6n3A8Q1f Z3/UjHEmjC+VjCfBFp3O1alwC2GNwNd7pgr7u39g6EpJcdq1T5f8UWinNfXNG0zGwuf1 qSCQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a626cd954dasi400919466b.830.2024.05.27.09.25.21; Mon, 27 May 2024 09:25:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A025368D392; Mon, 27 May 2024 19:25:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 83A9468BA20 for ; Mon, 27 May 2024 19:25:10 +0300 (EEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6f8e819cf60so2850685b3a.0 for ; Mon, 27 May 2024 09:25:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716827108; x=1717431908; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=peA57h+xDa0gx47G/UWEdEzKMIvT8rGjRJ+kpguvTsw=; b=aCMAieUVSbFllf0ioZtyDy7YBKZarqemOnBCDUyLBeYX+vLnybAbktuT5p/Bybz31C TZFdW+aRpoJkKgYX5Mo13RdT1fNINtl2hRD8ZI+ekxuSKW7ZSdd2PKXk42pq1q4zUG5c dtcKJFI4Us7g4o9TQe3LRrVHD7UDPjA5V24HjPCokE/26TdDqJHzD+hnlT1SoIZ4vRrW oex4wlTBmOkPHOpauYOZLemEZX0y4fr/Nwn43edZOHiisp1PVUNVOelpbP75nsNFMvLo xo8QNc6PmXrvPlVxohY+CAQv+TPaW3axtRSAjGwwjdH/Q2ZZ6J0FjhgJbGy/mQhuJdtG 9NdQ== X-Gm-Message-State: AOJu0YzAEtu78rdydrQFxdayOm/s+LcgGmC54oDt3mVleKMMT2bMpDwo KzQfGb9CDKr3MsEkAUeJtSC/GZ7vRrW0ByGJ1T7J2Y03lJyE8f5yLqVjhg== X-Received: by 2002:a05:6a20:2d13:b0:1b1:d7a3:a76b with SMTP id adf61e73a8af0-1b212d3802fmr17523583637.33.1716827107917; Mon, 27 May 2024 09:25:07 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fc36d274sm5038847b3a.81.2024.05.27.09.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 09:25:07 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Mon, 27 May 2024 09:25:06 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 May 2024 09:24:50 -0700 Message-Id: <20240527162450.27756-1-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/jpeg2000dec: fix HT block decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Osamu Watanabe , Pierre-Anthony Lemieux , Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2THWuuA2mKvn From: Pierre-Anthony Lemieux Addresses https://trac.ffmpeg.org/ticket/10905 Co-authored-by: Osamu Watanabe Signed-off-by: Pierre-Anthony Lemieux --- libavcodec/jpeg2000htdec.c | 122 ++++++++++++----------- tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 | 2 +- 2 files changed, 63 insertions(+), 61 deletions(-) diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c index fa704b665e..eba0936089 100644 --- a/libavcodec/jpeg2000htdec.c +++ b/libavcodec/jpeg2000htdec.c @@ -196,7 +196,7 @@ static void jpeg2000_bitbuf_refill_forward(StateVars *buffer, const uint8_t *arr while (buffer->bits_left < 32) { buffer->tmp = 0xFF; buffer->bits = (buffer->last == 0xFF) ? 7 : 8; - if (buffer->pos <= length) { + if (buffer->pos < length) { buffer->tmp = array[buffer->pos]; buffer->pos += 1; buffer->last = buffer->tmp; @@ -413,7 +413,7 @@ static void recover_mag_sgn(StateVars *mag_sgn, uint8_t pos, uint16_t q, int32_t static int jpeg2000_import_bit(StateVars *stream, const uint8_t *array, uint32_t length) { - int cond = stream->pos <= length; + int cond = stream->pos < length; int pos = FFMIN(stream->pos, length); if (stream->bits == 0) { stream->bits = (stream->tmp == 0xFF) ? 7 : 8; @@ -427,7 +427,7 @@ static int jpeg2000_import_bit(StateVars *stream, const uint8_t *array, uint32_t static int jpeg2000_peek_bit(StateVars *stream, const uint8_t *array, uint32_t length) { if (stream->bits == 0) { - int cond = stream->pos <= length; + int cond = stream->pos < length; int pos = FFMIN(stream->pos, length); stream->bits = (stream->tmp == 0xFF) ? 7 : 8; stream->pos += cond; @@ -508,17 +508,17 @@ static int jpeg2000_decode_sig_emb(const Jpeg2000DecoderContext *s, MelDecoderSt } av_always_inline -static int jpeg2000_get_state(int x1, int x2, int width, int shift_by, +static int jpeg2000_get_state(int x1, int x2, int stride, int shift_by, const uint8_t *block_states) { - return (block_states[(x1 + 1) * (width + 2) + (x2 + 1)] >> shift_by) & 1; + return (block_states[(x1 + 1) * stride + (x2 + 1)] >> shift_by) & 1; } av_always_inline -static void jpeg2000_modify_state(int x1, int x2, int width, - int value, uint8_t *block_states) +static void jpeg2000_modify_state(int x1, int x2, int stride, + int value, uint8_t *block_states) { - block_states[(x1 + 1) * (width + 2) + (x2 + 1)] |= value; + block_states[(x1 + 1) * stride + (x2 + 1)] |= value; } av_always_inline @@ -528,8 +528,8 @@ static int jpeg2000_decode_ht_cleanup_segment(const Jpeg2000DecoderContext *s, StateVars *mel_stream, StateVars *vlc_stream, StateVars *mag_sgn_stream, const uint8_t *Dcup, uint32_t Lcup, uint32_t Pcup, uint8_t pLSB, - int width, int height, int32_t *sample_buf, - uint8_t *block_states) + int width, int height, const int stride, + int32_t *sample_buf, uint8_t *block_states) { uint16_t q = 0; // Represents current quad position uint16_t q1, q2; @@ -958,26 +958,26 @@ static int jpeg2000_decode_ht_cleanup_segment(const Jpeg2000DecoderContext *s, j1 = 2 * y; j2 = 2 * x; - sample_buf[j2 + (j1 * width)] = (int32_t)*mu; - jpeg2000_modify_state(j1, j2, width, *sigma, block_states); + sample_buf[j2 + (j1 * stride)] = (int32_t)*mu; + jpeg2000_modify_state(j1, j2, stride, *sigma, block_states); sigma += 1; mu += 1; x1 = y != quad_height - 1 || is_border_y == 0; - sample_buf[j2 + ((j1 + 1) * width)] = ((int32_t)*mu) * x1; - jpeg2000_modify_state(j1 + 1, j2, width, (*sigma) * x1, block_states); + sample_buf[j2 + ((j1 + 1) * stride)] = ((int32_t)*mu) * x1; + jpeg2000_modify_state(j1 + 1, j2, stride, (*sigma) * x1, block_states); sigma += 1; mu += 1; x2 = x != quad_width - 1 || is_border_x == 0; - sample_buf[(j2 + 1) + (j1 * width)] = ((int32_t)*mu) * x2; - jpeg2000_modify_state(j1, j2 + 1, width, (*sigma) * x2, block_states); + sample_buf[(j2 + 1) + (j1 * stride)] = ((int32_t)*mu) * x2; + jpeg2000_modify_state(j1, j2 + 1, stride, (*sigma) * x2, block_states); sigma += 1; mu += 1; x3 = x1 | x2; - sample_buf[(j2 + 1) + (j1 + 1) * width] = ((int32_t)*mu) * x3; - jpeg2000_modify_state(j1 + 1, j2 + 1, width, (*sigma) * x3, block_states); + sample_buf[(j2 + 1) + (j1 + 1) * stride] = ((int32_t)*mu) * x3; + jpeg2000_modify_state(j1 + 1, j2 + 1, stride, (*sigma) * x3, block_states); sigma += 1; mu += 1; } @@ -992,39 +992,39 @@ free: static void jpeg2000_calc_mbr(uint8_t *mbr, const uint16_t i, const uint16_t j, const uint32_t mbr_info, uint8_t causal_cond, - uint8_t *block_states, int width) + uint8_t *block_states, int stride) { int local_mbr = 0; - local_mbr |= jpeg2000_get_state(i - 1, j - 1, width, HT_SHIFT_SIGMA, block_states); - local_mbr |= jpeg2000_get_state(i - 1, j + 0, width, HT_SHIFT_SIGMA, block_states); - local_mbr |= jpeg2000_get_state(i - 1, j + 1, width, HT_SHIFT_SIGMA, block_states); + local_mbr |= jpeg2000_get_state(i - 1, j - 1, stride, HT_SHIFT_SIGMA, block_states); + local_mbr |= jpeg2000_get_state(i - 1, j + 0, stride, HT_SHIFT_SIGMA, block_states); + local_mbr |= jpeg2000_get_state(i - 1, j + 1, stride, HT_SHIFT_SIGMA, block_states); - local_mbr |= jpeg2000_get_state(i + 0, j - 1, width, HT_SHIFT_SIGMA, block_states); - local_mbr |= jpeg2000_get_state(i + 0, j + 1, width, HT_SHIFT_SIGMA, block_states); + local_mbr |= jpeg2000_get_state(i + 0, j - 1, stride, HT_SHIFT_SIGMA, block_states); + local_mbr |= jpeg2000_get_state(i + 0, j + 1, stride, HT_SHIFT_SIGMA, block_states); - local_mbr |= jpeg2000_get_state(i + 1, j - 1, width, HT_SHIFT_SIGMA, block_states) * causal_cond; - local_mbr |= jpeg2000_get_state(i + 1, j + 0, width, HT_SHIFT_SIGMA, block_states) * causal_cond; - local_mbr |= jpeg2000_get_state(i + 1, j + 1, width, HT_SHIFT_SIGMA, block_states) * causal_cond; + local_mbr |= jpeg2000_get_state(i + 1, j - 1, stride, HT_SHIFT_SIGMA, block_states) * causal_cond; + local_mbr |= jpeg2000_get_state(i + 1, j + 0, stride, HT_SHIFT_SIGMA, block_states) * causal_cond; + local_mbr |= jpeg2000_get_state(i + 1, j + 1, stride, HT_SHIFT_SIGMA, block_states) * causal_cond; - local_mbr |= jpeg2000_get_state(i - 1, j - 1, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i - 1, j - 1, width, HT_SHIFT_SCAN, block_states); - local_mbr |= jpeg2000_get_state(i - 1, j + 0, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i - 1, j - 1, width, HT_SHIFT_SCAN, block_states); - local_mbr |= jpeg2000_get_state(i - 1, j + 1, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i - 1, j + 1, width, HT_SHIFT_SCAN, block_states); + local_mbr |= jpeg2000_get_state(i - 1, j - 1, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i - 1, j - 1, stride, HT_SHIFT_SCAN, block_states); + local_mbr |= jpeg2000_get_state(i - 1, j + 0, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i - 1, j - 1, stride, HT_SHIFT_SCAN, block_states); + local_mbr |= jpeg2000_get_state(i - 1, j + 1, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i - 1, j + 1, stride, HT_SHIFT_SCAN, block_states); - local_mbr |= jpeg2000_get_state(i + 0, j - 1, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i + 0, j - 1, width, HT_SHIFT_SCAN, block_states); - local_mbr |= jpeg2000_get_state(i + 0, j + 1, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i + 0, j + 1, width, HT_SHIFT_SCAN, block_states); + local_mbr |= jpeg2000_get_state(i + 0, j - 1, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i + 0, j - 1, stride, HT_SHIFT_SCAN, block_states); + local_mbr |= jpeg2000_get_state(i + 0, j + 1, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i + 0, j + 1, stride, HT_SHIFT_SCAN, block_states); - local_mbr |= jpeg2000_get_state(i + 1, j - 1, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i + 1, j - 1, width, HT_SHIFT_SCAN, block_states) * causal_cond; - local_mbr |= jpeg2000_get_state(i + 1, j + 0, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i + 1, j + 0, width, HT_SHIFT_SCAN, block_states) * causal_cond; - local_mbr |= jpeg2000_get_state(i + 1, j + 1, width, HT_SHIFT_REF, block_states) * - jpeg2000_get_state(i + 1, j + 1, width, HT_SHIFT_SCAN, block_states) * causal_cond; + local_mbr |= jpeg2000_get_state(i + 1, j - 1, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i + 1, j - 1, stride, HT_SHIFT_SCAN, block_states) * causal_cond; + local_mbr |= jpeg2000_get_state(i + 1, j + 0, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i + 1, j + 0, stride, HT_SHIFT_SCAN, block_states) * causal_cond; + local_mbr |= jpeg2000_get_state(i + 1, j + 1, stride, HT_SHIFT_REF, block_states) * + jpeg2000_get_state(i + 1, j + 1, stride, HT_SHIFT_SCAN, block_states) * causal_cond; *mbr |= local_mbr; } @@ -1040,18 +1040,18 @@ static void jpeg2000_process_stripes_block(StateVars *sig_prop, int i_s, int j_s int modify_state, cond; uint8_t bit; uint8_t causal_cond = i != (i_s + height - 1); - int32_t *sp = &sample_buf[j + (i * (stride - 2))]; + int32_t *sp = &sample_buf[j + (i * (stride))]; uint8_t mbr = 0; if (jpeg2000_get_state(i, j, stride - 2, HT_SHIFT_SIGMA, block_states) == 0) - jpeg2000_calc_mbr(&mbr, i, j, mbr_info & 0x1EF, causal_cond, block_states, stride - 2); + jpeg2000_calc_mbr(&mbr, i, j, mbr_info & 0x1EF, causal_cond, block_states, stride); mbr_info >>= 3; cond = mbr != 0; bit = jpeg2000_peek_bit(sig_prop, magref_segment, magref_length); *sp |= (bit * cond) << pLSB; sig_prop->bits -= cond; modify_state = (((1 << HT_SHIFT_REF_IND) | (1 << HT_SHIFT_REF)) * cond) | 1 << HT_SHIFT_SCAN; - jpeg2000_modify_state(i, j, stride - 2, modify_state, block_states); + jpeg2000_modify_state(i, j, stride, modify_state, block_states); } } } @@ -1060,8 +1060,8 @@ static void jpeg2000_process_stripes_block(StateVars *sig_prop, int i_s, int j_s * See procedure decodeSigPropMag at Rec. ITU-T T.814, 7.4. */ av_noinline -static void jpeg2000_decode_sigprop_segment(Jpeg2000Cblk *cblk, uint16_t width, - uint16_t height, uint8_t *magref_segment, +static void jpeg2000_decode_sigprop_segment(Jpeg2000Cblk *cblk, uint16_t width, uint16_t height, + const int stride, uint8_t *magref_segment, uint32_t magref_length, uint8_t pLSB, int32_t *sample_buf, uint8_t *block_states) { @@ -1071,7 +1071,6 @@ static void jpeg2000_decode_sigprop_segment(Jpeg2000Cblk *cblk, uint16_t width, const uint16_t num_h_stripe = width / 4; int b_width = 4; int b_height = 4; - int stride = width + 2; int last_width; uint16_t i = 0, j = 0; @@ -1114,7 +1113,7 @@ static void jpeg2000_decode_sigprop_segment(Jpeg2000Cblk *cblk, uint16_t width, * See procedure decodeSigPropMag at Rec. ITU-T T.814, 7.5. */ static int -jpeg2000_decode_magref_segment( uint16_t width, uint16_t block_height, +jpeg2000_decode_magref_segment( uint16_t width, uint16_t block_height, const int stride, uint8_t *magref_segment,uint32_t magref_length, uint8_t pLSB, int32_t *sample_buf, uint8_t *block_states) { @@ -1134,7 +1133,7 @@ jpeg2000_decode_magref_segment( uint16_t width, uint16_t block_height, * We move column wise, going from one quad to another. See * Rec. ITU-T T.814, Figure 7. */ - sp = &sample_buf[j + i * width]; + sp = &sample_buf[j + i * stride]; if (jpeg2000_get_state(i, j, width, HT_SHIFT_SIGMA, block_states) != 0) { jpeg2000_modify_state(i, j, width, 1 << HT_SHIFT_REF_IND, block_states); *sp |= jpeg2000_import_magref_bit(&mag_ref, magref_segment, magref_length) << pLSB; @@ -1146,7 +1145,7 @@ jpeg2000_decode_magref_segment( uint16_t width, uint16_t block_height, height = block_height % 4; for (int j = 0; j < width; j++) { for (int i = i_start; i < i_start + height; i++) { - sp = &sample_buf[j + i * width]; + sp = &sample_buf[j + i * stride]; if (jpeg2000_get_state(i, j, width, HT_SHIFT_SIGMA, block_states) != 0) { jpeg2000_modify_state(i, j, width, 1 << HT_SHIFT_REF_IND, block_states); *sp |= jpeg2000_import_magref_bit(&mag_ref, magref_segment, magref_length) << pLSB; @@ -1194,6 +1193,9 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c int32_t M_b = magp; + const int quad_buf_width = width + 4; + const int quad_buf_height = height + 4; + /* codeblock size as constrained by Rec. ITU-T T.800, Table A.18 */ av_assert0(width <= 1024U && height <= 1024U); av_assert0(width * height <= 4096); @@ -1261,23 +1263,23 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c jpeg2000_init_mel_decoder(&mel_state); - sample_buf = av_calloc((width + 4) * (height + 4), sizeof(int32_t)); - block_states = av_calloc((width + 4) * (height + 4), sizeof(uint8_t)); + sample_buf = av_calloc(quad_buf_width * quad_buf_height, sizeof(int32_t)); + block_states = av_calloc(quad_buf_width * quad_buf_height, sizeof(uint8_t)); if (!sample_buf || !block_states) { ret = AVERROR(ENOMEM); goto free; } if ((ret = jpeg2000_decode_ht_cleanup_segment(s, cblk, t1, &mel_state, &mel, &vlc, - &mag_sgn, Dcup, Lcup, Pcup, pLSB, width, - height, sample_buf, block_states)) < 0) { + &mag_sgn, Dcup, Lcup, Pcup, pLSB, width, + height, quad_buf_width, sample_buf, block_states)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "Bad HT cleanup segment\n"); goto free; } if (cblk->npasses > 1) - jpeg2000_decode_sigprop_segment(cblk, width, height, Dref, Lref, - pLSB - 1, sample_buf, block_states); + jpeg2000_decode_sigprop_segment(cblk, width, height, quad_buf_width, Dref, Lref, + pLSB - 1, sample_buf, block_states); if (cblk->npasses > 2) { @@ -1286,7 +1288,7 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c ret = AVERROR_INVALIDDATA; goto free; } - if ((ret = jpeg2000_decode_magref_segment(width, height, Dref, Lref, + if ((ret = jpeg2000_decode_magref_segment(width, height, quad_buf_width, Dref, Lref, pLSB - 1, sample_buf, block_states)) < 0) goto free; } @@ -1297,7 +1299,7 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { n = x + (y * t1->stride); - val = sample_buf[x + (y * width)]; + val = sample_buf[x + (y * quad_buf_width)]; /* Convert sign-magnitude to two's complement. */ val = val >> 31 ? 0x80000000 - val : val; val >>= (pLSB - 1); diff --git a/tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 b/tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 index af3eaa086d..d923cc2109 100644 --- a/tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 +++ b/tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 128x128 #sar 0: 0/1 -0, 0, 0, 1, 16384, 0x44426324 +0, 0, 0, 1, 16384, 0x04a3647e