From: Michael Niedermayer <michael@niedermayer.cc> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/snow_dwt: Support correct rounding of dwt decomposition of non even sizes Date: Fri, 24 Mar 2023 23:10:24 +0100 Message-ID: <20230324221025.19447-1-michael@niedermayer.cc> (raw) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- 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".
next reply other threads:[~2023-03-24 22:10 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-24 22:10 Michael Niedermayer [this message] 2023-03-24 22:10 ` [FFmpeg-devel] [PATCH 2/2] avcodec/snowdec: support DWT with new size rounding Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230324221025.19447-1-michael@niedermayer.cc \ --to=michael@niedermayer.cc \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git