diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-05-27 21:47:32 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-05-27 21:54:07 +0200 |
commit | d4a4661342640726d80dff0ac26656aac2a4e306 (patch) | |
tree | e6ccbc954fc2572c59d3bbab51b0a453f5d01632 /libavcodec/jpeg2000dwt.c | |
parent | 160ea26560c4e929b6b70937f032234c33fbe6c7 (diff) | |
download | ffmpeg-d4a4661342640726d80dff0ac26656aac2a4e306.tar.gz |
j2k/jpeg2000: merge j2k & jpeg2000 dwts, drop j2k dwt
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/jpeg2000dwt.c')
-rw-r--r-- | libavcodec/jpeg2000dwt.c | 151 |
1 files changed, 150 insertions, 1 deletions
diff --git a/libavcodec/jpeg2000dwt.c b/libavcodec/jpeg2000dwt.c index 080b0a045d..905ce1805b 100644 --- a/libavcodec/jpeg2000dwt.c +++ b/libavcodec/jpeg2000dwt.c @@ -51,7 +51,6 @@ #define I_LFTG_K 80621 #define I_LFTG_X 106544 - static inline void extend53(int *p, int i0, int i1) { p[i0 - 1] = p[i0 + 1]; @@ -80,6 +79,143 @@ static inline void extend97_int(int32_t *p, int i0, int i1) } } +static void sd_1d53(int *p, int i0, int i1) +{ + int i; + + if (i1 == i0 + 1) + return; + + extend53(p, i0, i1); + + for (i = (i0+1)/2 - 1; i < (i1+1)/2; i++) + p[2*i+1] -= (p[2*i] + p[2*i+2]) >> 1; + for (i = (i0+1)/2; i < (i1+1)/2; i++) + p[2*i] += (p[2*i-1] + p[2*i+1] + 2) >> 2; +} + +static void dwt_encode53(DWTContext *s, int *t) +{ + int lev, + w = s->linelen[s->ndeclevels-1][0]; + int *line = s->i_linebuf; + line += 3; + + for (lev = s->ndeclevels-1; lev >= 0; lev--){ + int lh = s->linelen[lev][0], + lv = s->linelen[lev][1], + mh = s->mod[lev][0], + mv = s->mod[lev][1], + lp; + int *l; + + // HOR_SD + l = line + mh; + for (lp = 0; lp < lv; lp++){ + int i, j = 0; + + for (i = 0; i < lh; i++) + l[i] = t[w*lp + i]; + + sd_1d53(line, mh, mh + lh); + + // copy back and deinterleave + for (i = mh; i < lh; i+=2, j++) + t[w*lp + j] = l[i]; + for (i = 1-mh; i < lh; i+=2, j++) + t[w*lp + j] = l[i]; + } + + // VER_SD + l = line + mv; + for (lp = 0; lp < lh; lp++) { + int i, j = 0; + + for (i = 0; i < lv; i++) + l[i] = t[w*i + lp]; + + sd_1d53(line, mv, mv + lv); + + // copy back and deinterleave + for (i = mv; i < lv; i+=2, j++) + t[w*j + lp] = l[i]; + for (i = 1-mv; i < lv; i+=2, j++) + t[w*j + lp] = l[i]; + } + } +} + +static void sd_1d97(float *p, int i0, int i1) +{ + int i; + + if (i1 == i0 + 1) + return; + + extend97_float(p, i0, i1); + i0++; i1++; + + for (i = i0/2 - 2; i < i1/2 + 1; i++) + p[2*i+1] -= 1.586134 * (p[2*i] + p[2*i+2]); + for (i = i0/2 - 1; i < i1/2 + 1; i++) + p[2*i] -= 0.052980 * (p[2*i-1] + p[2*i+1]); + for (i = i0/2 - 1; i < i1/2; i++) + p[2*i+1] += 0.882911 * (p[2*i] + p[2*i+2]); + for (i = i0/2; i < i1/2; i++) + p[2*i] += 0.443506 * (p[2*i-1] + p[2*i+1]); +} + +static void dwt_encode97_int(DWTContext *s, int *t) +{ + int lev, + w = s->linelen[s->ndeclevels-1][0]; + float *line = s->i_linebuf; + line += 5; + + for (lev = s->ndeclevels-1; lev >= 0; lev--){ + int lh = s->linelen[lev][0], + lv = s->linelen[lev][1], + mh = s->mod[lev][0], + mv = s->mod[lev][1], + lp; + float *l; + + // HOR_SD + l = line + mh; + for (lp = 0; lp < lv; lp++){ + int i, j = 0; + + for (i = 0; i < lh; i++) + l[i] = t[w*lp + i]; + + sd_1d97(line, mh, mh + lh); + + // copy back and deinterleave + for (i = mh; i < lh; i+=2, j++) + t[w*lp + j] = F_LFTG_X * l[i] / 2; + for (i = 1-mh; i < lh; i+=2, j++) + t[w*lp + j] = F_LFTG_K * l[i] / 2; + } + + // VER_SD + l = line + mv; + for (lp = 0; lp < lh; lp++) { + int i, j = 0; + + for (i = 0; i < lv; i++) + l[i] = t[w*i + lp]; + + sd_1d97(line, mv, mv + lv); + + // copy back and deinterleave + for (i = mv; i < lv; i+=2, j++) + t[w*j + lp] = F_LFTG_X * l[i] / 2; + for (i = 1-mv; i < lv; i+=2, j++) + t[w*j + lp] = F_LFTG_K * l[i] / 2; + } + } +} + static void sr_1d53(int *p, int i0, int i1) { int i; @@ -346,6 +482,19 @@ int ff_jpeg2000_dwt_init(DWTContext *s, uint16_t border[2][2], return 0; } +int ff_dwt_encode(DWTContext *s, int *t) +{ + switch(s->type){ + case FF_DWT97_INT: + dwt_encode97_int(s, t); break; + case FF_DWT53: + dwt_encode53(s, t); break; + default: + return -1; + } + return 0; +} + int ff_dwt_decode(DWTContext *s, void *t) { switch (s->type) { |