From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9A96145BCC for ; Fri, 24 Mar 2023 22:10:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ADCBD68C8D5; Sat, 25 Mar 2023 00:10:33 +0200 (EET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6474768C8CF for ; Sat, 25 Mar 2023 00:10:27 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 7EBC940004 for ; Fri, 24 Mar 2023 22:10:26 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 24 Mar 2023 23:10:24 +0100 Message-Id: <20230324221025.19447-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/snow_dwt: Support correct rounding of dwt decomposition of non even sizes 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 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: Michael Niedermayer --- libavcodec/snow_dwt.c | 61 ++++++++++++++++++++++++------------------- libavcodec/snow_dwt.h | 3 +++ 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/libavcodec/snow_dwt.c b/libavcodec/snow_dwt.c index 965f409002..b27b07f58a 100644 --- a/libavcodec/snow_dwt.c +++ b/libavcodec/snow_dwt.c @@ -322,15 +322,17 @@ void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height, int level; for (level = 0; level < decomposition_count; level++) { - switch (type) { + int w = DWT_RSHIFT(width , level); + int h = DWT_RSHIFT(height, level); + switch (type & 3) { case DWT_97: spatial_decompose97i(buffer, temp, - width >> level, height >> level, + w, h, stride << level); break; case DWT_53: spatial_decompose53i(buffer, temp, - width >> level, height >> level, + w, h, stride << level); break; } @@ -642,13 +644,14 @@ void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, { int level; for (level = decomposition_count - 1; level >= 0; level--) { - switch (type) { + int h = DWT_RSHIFT(height, level); + switch (type & 3) { case DWT_97: - spatial_compose97i_buffered_init(cs + level, sb, height >> level, + spatial_compose97i_buffered_init(cs + level, sb, h, stride_line << level); break; case DWT_53: - spatial_compose53i_buffered_init(cs + level, sb, height >> level, + spatial_compose53i_buffered_init(cs + level, sb, h, stride_line << level); break; } @@ -660,28 +663,29 @@ void ff_spatial_idwt_buffered_slice(SnowDWTContext *dsp, DWTCompose *cs, int width, int height, int stride_line, int type, int decomposition_count, int y) { - const int support = type == 1 ? 3 : 5; + const int support = (type & 3) == 1 ? 3 : 5; int level; - if (type == 2) + if ((type & 3) == 2) return; - for (level = decomposition_count - 1; level >= 0; level--) - while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) { - switch (type) { + for (level = decomposition_count - 1; level >= 0; level--) { + int w = DWT_RSHIFT(width , level); + int h = DWT_RSHIFT(height, level); + while (cs[level].y <= FFMIN((y >> level) + support, h)) { + switch (type & 3) { case DWT_97: spatial_compose97i_dy_buffered(dsp, cs + level, slice_buf, temp, - width >> level, - height >> level, + w, h, stride_line << level); break; case DWT_53: spatial_compose53i_dy_buffered(cs + level, slice_buf, temp, - width >> level, - height >> level, + w, h, stride_line << level); break; } } + } } static void spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, @@ -690,13 +694,14 @@ static void spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, { int level; for (level = decomposition_count - 1; level >= 0; level--) { - switch (type) { + int h = DWT_RSHIFT(height, level); + switch (type & 3) { case DWT_97: - spatial_compose97i_init(cs + level, buffer, height >> level, + spatial_compose97i_init(cs + level, buffer, h, stride << level); break; case DWT_53: - spatial_compose53i_init(cs + level, buffer, height >> level, + spatial_compose53i_init(cs + level, buffer, h, stride << level); break; } @@ -708,24 +713,25 @@ static void spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, int stride, int type, int decomposition_count, int y) { - const int support = type == 1 ? 3 : 5; + const int support = (type & 3) == 1 ? 3 : 5; int level; - if (type == 2) + if ((type & 3) == 2) return; - for (level = decomposition_count - 1; level >= 0; level--) - while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) { - switch (type) { + for (level = decomposition_count - 1; level >= 0; level--) { + int w = DWT_RSHIFT(width , level); + int h = DWT_RSHIFT(height, level); + while (cs[level].y <= FFMIN((y >> level) + support, h)) { + switch (type & 3) { case DWT_97: - spatial_compose97i_dy(cs + level, buffer, temp, width >> level, - height >> level, stride << level); + spatial_compose97i_dy(cs + level, buffer, temp, w, h, stride << level); break; case DWT_53: - spatial_compose53i_dy(cs + level, buffer, temp, width >> level, - height >> level, stride << level); + spatial_compose53i_dy(cs + level, buffer, temp, w, h, stride << level); break; } } + } } void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height, @@ -788,6 +794,7 @@ static inline int w_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8 } ff_spatial_dwt(tmp, tmp2, w, h, 32, type, dec_count); + type &= 3; s = 0; av_assert1(w == h); diff --git a/libavcodec/snow_dwt.h b/libavcodec/snow_dwt.h index 15b8a3007b..48acfd46c5 100644 --- a/libavcodec/snow_dwt.h +++ b/libavcodec/snow_dwt.h @@ -67,6 +67,9 @@ typedef struct SnowDWTContext { #define DWT_97 0 #define DWT_53 1 +#define DWT_NEW_ROUNDING_FLAG 4 + +#define DWT_RSHIFT(a, b) (((type) & DWT_NEW_ROUNDING_FLAG) ? -(-(a) >> (b)) : (a) >> (b)) #define liftS lift #define W_AM 3 -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".