* [FFmpeg-devel] [PATCH 1/2] avcodec/snow_dwt: Support correct rounding of dwt decomposition of non even sizes
@ 2023-03-24 22:10 Michael Niedermayer
2023-03-24 22:10 ` [FFmpeg-devel] [PATCH 2/2] avcodec/snowdec: support DWT with new size rounding Michael Niedermayer
0 siblings, 1 reply; 2+ messages in thread
From: Michael Niedermayer @ 2023-03-24 22:10 UTC (permalink / raw)
To: FFmpeg development discussions and patches
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] avcodec/snowdec: support DWT with new size rounding
2023-03-24 22:10 [FFmpeg-devel] [PATCH 1/2] avcodec/snow_dwt: Support correct rounding of dwt decomposition of non even sizes Michael Niedermayer
@ 2023-03-24 22:10 ` Michael Niedermayer
0 siblings, 0 replies; 2+ messages in thread
From: Michael Niedermayer @ 2023-03-24 22:10 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavcodec/snowdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index bed29d3390..b7a5864f4c 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -385,7 +385,7 @@ static int decode_header(SnowContext *s){
}
s->spatial_decomposition_type+= (unsigned)get_symbol(&s->c, s->header_state, 1);
- if(s->spatial_decomposition_type > 1U){
+ if((s->spatial_decomposition_type & (~4)) > 1U){
av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported\n", s->spatial_decomposition_type);
return AVERROR_INVALIDDATA;
}
--
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-24 22:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 22:10 [FFmpeg-devel] [PATCH 1/2] avcodec/snow_dwt: Support correct rounding of dwt decomposition of non even sizes Michael Niedermayer
2023-03-24 22:10 ` [FFmpeg-devel] [PATCH 2/2] avcodec/snowdec: support DWT with new size rounding Michael Niedermayer
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