diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2015-06-22 01:30:33 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-06-22 01:36:05 +0200 |
commit | 1c495b0bf690995c45f79f4f19500921e14ec78a (patch) | |
tree | d5ef046b1289363a74f1d54e8ee609ec8a6649a4 /libavcodec | |
parent | 6504047f82866fdc0e2a5422ad7fecb44740e9d6 (diff) | |
download | ffmpeg-1c495b0bf690995c45f79f4f19500921e14ec78a.tar.gz |
avcodec/jpeg2000: Move gainb handling into the quantization code
thats how the specification defines it, this also improves numerical
accuracy of the integer wavelet implementation. It otherwise should
be equivalent, in case of overflows this can be reverted.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/jpeg2000.c | 5 | ||||
-rw-r--r-- | libavcodec/jpeg2000dwt.c | 28 |
2 files changed, 16 insertions, 17 deletions
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c index 427f6f7423..3bb55786b7 100644 --- a/libavcodec/jpeg2000.c +++ b/libavcodec/jpeg2000.c @@ -305,9 +305,6 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp, * delta_b = 2 ^ (R_b - expn_b) * (1 + (mant_b / 2 ^ 11)) * R_b = R_I + log2 (gain_b ) * see ISO/IEC 15444-1:2002 E.1.1 eqn. E-3 and E-4 */ - /* TODO/WARN: value of log2 (gain_b ) not taken into account - * but it works (compared to OpenJPEG). Why? - * Further investigation needed. */ gain = cbps; band->f_stepsize = pow(2.0, gain - qntsty->expn[gbandno]); band->f_stepsize *= qntsty->mant[gbandno] / 2048.0 + 1.0; @@ -317,6 +314,8 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp, av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n"); break; } + band->f_stepsize *= 1<<lut_gain[codsty->transform != FF_DWT53][bandno + (reslevelno > 0)]; + /* FIXME: In openjepg code stespize = stepsize * 0.5. Why? * If not set output of entropic decoder is not correct. */ if (!av_codec_is_encoder(avctx->codec)) diff --git a/libavcodec/jpeg2000dwt.c b/libavcodec/jpeg2000dwt.c index 5c2ec679c8..9c887d2afd 100644 --- a/libavcodec/jpeg2000dwt.c +++ b/libavcodec/jpeg2000dwt.c @@ -38,7 +38,7 @@ #define F_LFTG_GAMMA 0.882911075530934f #define F_LFTG_DELTA 0.443506852043971f #define F_LFTG_K 1.230174104914001f -#define F_LFTG_X 1.625786132231922f +#define F_LFTG_X 0.812893066115961f /* Lifting parameters in integer format. * Computed as param = (float param) * (1 << 16) */ @@ -47,7 +47,7 @@ #define I_LFTG_GAMMA 57862 #define I_LFTG_DELTA 29066 #define I_LFTG_K 80621 -#define I_LFTG_X 106548 +#define I_LFTG_X 53274 static inline void extend53(int *p, int i0, int i1) { @@ -151,7 +151,7 @@ static void sd_1d97_float(float *p, int i0, int i1) if (i1 <= i0 + 1) { if (i0 == 1) - p[1] *= F_LFTG_X; + p[1] *= F_LFTG_X * 2; else p[0] *= F_LFTG_K; return; @@ -197,9 +197,9 @@ static void dwt_encode97_float(DWTContext *s, float *t) // copy back and deinterleave for (i = mh; i < lh; i+=2, j++) - t[w*lp + j] = F_LFTG_X * l[i] / 2; + t[w*lp + j] = F_LFTG_X * l[i]; for (i = 1-mh; i < lh; i+=2, j++) - t[w*lp + j] = F_LFTG_K * l[i] / 2; + t[w*lp + j] = F_LFTG_K * l[i]; } // VER_SD @@ -214,9 +214,9 @@ static void dwt_encode97_float(DWTContext *s, float *t) // copy back and deinterleave for (i = mv; i < lv; i+=2, j++) - t[w*j + lp] = F_LFTG_X * l[i] / 2; + t[w*j + lp] = F_LFTG_X * l[i]; for (i = 1-mv; i < lv; i+=2, j++) - t[w*j + lp] = F_LFTG_K * l[i] / 2; + t[w*j + lp] = F_LFTG_K * l[i]; } } } @@ -227,7 +227,7 @@ static void sd_1d97_int(int *p, int i0, int i1) if (i1 <= i0 + 1) { if (i0 == 1) - p[1] = (p[1] * I_LFTG_X + (1<<15)) >> 16; + p[1] = (p[1] * I_LFTG_X + (1<<14)) >> 15; else p[0] = (p[0] * I_LFTG_K + (1<<15)) >> 16; return; @@ -273,9 +273,9 @@ static void dwt_encode97_int(DWTContext *s, int *t) // copy back and deinterleave for (i = mv; i < lv; i+=2, j++) - t[w*j + lp] = ((l[i] * I_LFTG_X) + (1 << 16)) >> 17; + t[w*j + lp] = ((l[i] * I_LFTG_X) + (1 << 15)) >> 16; for (i = 1-mv; i < lv; i+=2, j++) - t[w*j + lp] = ((l[i] * I_LFTG_K) + (1 << 16)) >> 17; + t[w*j + lp] = ((l[i] * I_LFTG_K) + (1 << 15)) >> 16; } // HOR_SD @@ -290,9 +290,9 @@ static void dwt_encode97_int(DWTContext *s, int *t) // copy back and deinterleave for (i = mh; i < lh; i+=2, j++) - t[w*lp + j] = ((l[i] * I_LFTG_X) + (1 << 16)) >> 17; + t[w*lp + j] = ((l[i] * I_LFTG_X) + (1 << 15)) >> 16; for (i = 1-mh; i < lh; i+=2, j++) - t[w*lp + j] = ((l[i] * I_LFTG_K) + (1 << 16)) >> 17; + t[w*lp + j] = ((l[i] * I_LFTG_K) + (1 << 15)) >> 16; } } @@ -373,7 +373,7 @@ static void sr_1d97_float(float *p, int i0, int i1) if (i0 == 1) p[1] *= F_LFTG_K/2; else - p[0] *= F_LFTG_X/2; + p[0] *= F_LFTG_X; return; } @@ -450,7 +450,7 @@ static void sr_1d97_int(int32_t *p, int i0, int i1) if (i0 == 1) p[1] = (p[1] * I_LFTG_K + (1<<16)) >> 17; else - p[0] = (p[0] * I_LFTG_X + (1<<16)) >> 17; + p[0] = (p[0] * I_LFTG_X + (1<<15)) >> 16; return; } |