36 #define F_LFTG_ALPHA 1.586134342059924f 37 #define F_LFTG_BETA 0.052980118572961f 38 #define F_LFTG_GAMMA 0.882911075530934f 39 #define F_LFTG_DELTA 0.443506852043971f 43 #define I_LFTG_ALPHA 103949ll 44 #define I_LFTG_BETA 3472ll 45 #define I_LFTG_GAMMA 57862ll 46 #define I_LFTG_DELTA 29066ll 47 #define I_LFTG_K 80621ll 48 #define I_LFTG_X 53274ll 51 static inline void extend53(
int *p,
int i0,
int i1)
53 p[i0 - 1] = p[i0 + 1];
55 p[i0 - 2] = p[i0 + 2];
56 p[i1 + 1] = p[i1 - 3];
63 for (i = 1; i <= 4; i++) {
64 p[i0 - i] = p[i0 + i];
65 p[i1 + i - 1] = p[i1 - i - 1];
73 for (i = 1; i <= 4; i++) {
74 p[i0 - i] = p[i0 + i];
75 p[i1 + i - 1] = p[i1 - i - 1];
79 static void sd_1d53(
int *p,
int i0,
int i1)
91 for (i = ((i0+1)>>1) - 1; i < (i1+1)>>1; i++)
92 p[2*i+1] -= (p[2*i] + p[2*i+2]) >> 1;
93 for (i = ((i0+1)>>1); i < (i1+1)>>1; i++)
94 p[2*i] += (p[2*i-1] + p[2*i+1] + 2) >> 2;
114 for (lp = 0; lp < lh; lp++) {
117 for (i = 0; i < lv; i++)
123 for (i = mv; i < lv; i+=2, j++)
125 for (i = 1-mv; i < lv; i+=2, j++)
131 for (lp = 0; lp < lv; lp++){
134 for (i = 0; i < lh; i++)
140 for (i = mh; i < lh; i+=2, j++)
142 for (i = 1-mh; i < lh; i+=2, j++)
162 for (i = (i0>>1) - 2; i < (i1>>1) + 1; i++)
163 p[2*i+1] -= 1.586134 * (p[2*i] + p[2*i+2]);
164 for (i = (i0>>1) - 1; i < (i1>>1) + 1; i++)
165 p[2*i] -= 0.052980 * (p[2*i-1] + p[2*i+1]);
166 for (i = (i0>>1) - 1; i < (i1>>1); i++)
167 p[2*i+1] += 0.882911 * (p[2*i] + p[2*i+2]);
168 for (i = (i0>>1); i < (i1>>1); i++)
169 p[2*i] += 0.443506 * (p[2*i-1] + p[2*i+1]);
189 for (lp = 0; lp < lv; lp++){
192 for (i = 0; i < lh; i++)
198 for (i = mh; i < lh; i+=2, j++)
200 for (i = 1-mh; i < lh; i+=2, j++)
206 for (lp = 0; lp < lh; lp++) {
209 for (i = 0; i < lv; i++)
215 for (i = mv; i < lv; i+=2, j++)
217 for (i = 1-mv; i < lv; i+=2, j++)
229 p[1] = (p[1] *
I_LFTG_X + (1<<14)) >> 15;
231 p[0] = (p[0] *
I_LFTG_K + (1<<15)) >> 16;
238 for (i = (i0>>1) - 2; i < (i1>>1) + 1; i++)
239 p[2 * i + 1] -= (
I_LFTG_ALPHA * (p[2 * i] + p[2 * i + 2]) + (1 << 15)) >> 16;
240 for (i = (i0>>1) - 1; i < (i1>>1) + 1; i++)
241 p[2 * i] -= (
I_LFTG_BETA * (p[2 * i - 1] + p[2 * i + 1]) + (1 << 15)) >> 16;
242 for (i = (i0>>1) - 1; i < (i1>>1); i++)
243 p[2 * i + 1] += (
I_LFTG_GAMMA * (p[2 * i] + p[2 * i + 2]) + (1 << 15)) >> 16;
244 for (i = (i0>>1); i < (i1>>1); i++)
245 p[2 * i] += (
I_LFTG_DELTA * (p[2 * i - 1] + p[2 * i + 1]) + (1 << 15)) >> 16;
257 for (i = 0; i < w *
h; i++)
270 for (lp = 0; lp < lh; lp++) {
273 for (i = 0; i < lv; i++)
279 for (i = mv; i < lv; i+=2, j++)
280 t[w*j + lp] = ((l[i] *
I_LFTG_X) + (1 << 15)) >> 16;
281 for (i = 1-mv; i < lv; i+=2, j++)
287 for (lp = 0; lp < lv; lp++){
290 for (i = 0; i < lh; i++)
296 for (i = mh; i < lh; i+=2, j++)
297 t[w*lp + j] = ((l[i] *
I_LFTG_X) + (1 << 15)) >> 16;
298 for (i = 1-mh; i < lh; i+=2, j++)
304 for (i = 0; i < w *
h; i++)
308 static void sr_1d53(
unsigned *p,
int i0,
int i1)
314 p[1] = (
int)p[1] >> 1;
320 for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
321 p[2 * i] -= (
int)(p[2 * i - 1] + p[2 * i + 1] + 2) >> 2;
322 for (i = (i0 >> 1); i < (i1 >> 1); i++)
323 p[2 * i + 1] += (
int)(p[2 * i] + p[2 * i + 2]) >> 1;
343 for (lp = 0; lp < lv; lp++) {
346 for (i = mh; i < lh; i += 2, j++)
347 l[i] = t[w * lp + j];
348 for (i = 1 - mh; i < lh; i += 2, j++)
349 l[i] = t[w * lp + j];
353 for (i = 0; i < lh; i++)
354 t[w * lp + i] = l[i];
359 for (lp = 0; lp < lh; lp++) {
362 for (i = mv; i < lv; i += 2, j++)
363 l[i] = t[w * j + lp];
364 for (i = 1 - mv; i < lv; i += 2, j++)
365 l[i] = t[w * j + lp];
369 for (i = 0; i < lv; i++)
370 t[w * i + lp] = l[i];
389 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 2; i++)
390 p[2 * i] -=
F_LFTG_DELTA * (p[2 * i - 1] + p[2 * i + 1]);
392 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 1; i++)
393 p[2 * i + 1] -=
F_LFTG_GAMMA * (p[2 * i] + p[2 * i + 2]);
395 for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
396 p[2 * i] +=
F_LFTG_BETA * (p[2 * i - 1] + p[2 * i + 1]);
398 for (i = (i0 >> 1); i < (i1 >> 1); i++)
399 p[2 * i + 1] +=
F_LFTG_ALPHA * (p[2 * i] + p[2 * i + 2]);
420 for (lp = 0; lp < lv; lp++) {
423 for (i = mh; i < lh; i += 2, j++)
424 l[i] = data[w * lp + j];
425 for (i = 1 - mh; i < lh; i += 2, j++)
426 l[i] = data[w * lp + j];
430 for (i = 0; i < lh; i++)
431 data[w * lp + i] = l[i];
436 for (lp = 0; lp < lh; lp++) {
439 for (i = mv; i < lv; i += 2, j++)
440 l[i] = data[w * j + lp];
441 for (i = 1 - mv; i < lv; i += 2, j++)
442 l[i] = data[w * j + lp];
446 for (i = 0; i < lv; i++)
447 data[w * i + lp] = l[i];
458 p[1] = (p[1] *
I_LFTG_K + (1<<16)) >> 17;
460 p[0] = (p[0] *
I_LFTG_X + (1<<15)) >> 16;
466 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 2; i++)
467 p[2 * i] -= (
I_LFTG_DELTA * (p[2 * i - 1] + (int64_t)p[2 * i + 1]) + (1 << 15)) >> 16;
469 for (i = (i0 >> 1) - 1; i < (i1 >> 1) + 1; i++)
470 p[2 * i + 1] -= (
I_LFTG_GAMMA * (p[2 * i] + (int64_t)p[2 * i + 2]) + (1 << 15)) >> 16;
472 for (i = (i0 >> 1); i < (i1 >> 1) + 1; i++)
473 p[2 * i] += (
I_LFTG_BETA * (p[2 * i - 1] + (int64_t)p[2 * i + 1]) + (1 << 15)) >> 16;
475 for (i = (i0 >> 1); i < (i1 >> 1); i++)
476 p[2 * i + 1] += (
I_LFTG_ALPHA * (p[2 * i] + (int64_t)p[2 * i + 2]) + (1 << 15)) >> 16;
490 for (i = 0; i < w *
h; i++)
502 for (lp = 0; lp < lv; lp++) {
505 for (i = mh; i < lh; i += 2, j++)
506 l[i] = ((data[w * lp + j] *
I_LFTG_K) + (1 << 15)) >> 16;
507 for (i = 1 - mh; i < lh; i += 2, j++)
508 l[i] = data[w * lp + j];
512 for (i = 0; i < lh; i++)
513 data[w * lp + i] = l[i];
518 for (lp = 0; lp < lh; lp++) {
521 for (i = mv; i < lv; i += 2, j++)
522 l[i] = ((data[w * j + lp] *
I_LFTG_K) + (1 << 15)) >> 16;
523 for (i = 1 - mv; i < lv; i += 2, j++)
524 l[i] = data[w * j + lp];
528 for (i = 0; i < lv; i++)
529 data[w * i + lp] = l[i];
533 for (i = 0; i < w *
h; i++)
538 int decomp_levels,
int type)
540 int i, j, lev = decomp_levels, maxlen,
546 for (i = 0; i < 2; i++)
547 for (j = 0; j < 2; j++)
548 b[i][j] = border[i][j];
550 maxlen =
FFMAX(b[0][1] - b[0][0],
553 for (i = 0; i < 2; i++) {
554 s->
linelen[lev][i] = b[i][1] - b[i][0];
555 s->
mod[lev][i] = b[i][0] & 1;
556 for (j = 0; j < 2; j++)
557 b[i][j] = (b[i][j] + 1) >> 1;
Discrete wavelet transform.
static void sd_1d97_float(float *p, int i0, int i1)
uint8_t ndeclevels
number of decomposition levels
static void dwt_encode53(DWTContext *s, int *t)
Memory handling functions.
static void sr_1d97_int(int32_t *p, int i0, int i1)
static void sd_1d97_int(int *p, int i0, int i1)
static void extend97_float(float *p, int i0, int i1)
uint8_t type
0 for 9/7; 1 for 5/3
static void sr_1d97_float(float *p, int i0, int i1)
int32_t * i_linebuf
int buffer used by transform
int linelen[FF_DWT_MAX_DECLVLS][2]
line lengths { horizontal, vertical } in consecutive decomposition levels
static void dwt_encode97_int(DWTContext *s, int *t)
int ff_jpeg2000_dwt_init(DWTContext *s, int border[2][2], int decomp_levels, int type)
Initialize DWT.
static void dwt_encode97_float(DWTContext *s, float *t)
simple assert() macros that are a bit more flexible than ISO C assert().
static void dwt_decode97_int(DWTContext *s, int32_t *t)
static void sr_1d53(unsigned *p, int i0, int i1)
static void dwt_decode53(DWTContext *s, int *t)
void ff_dwt_destroy(DWTContext *s)
int ff_dwt_encode(DWTContext *s, void *t)
static void extend53(int *p, int i0, int i1)
static const int8_t mv[256][2]
float * f_linebuf
float buffer used by transform
common internal api header.
common internal and external API header
int ff_dwt_decode(DWTContext *s, void *t)
static void sd_1d53(int *p, int i0, int i1)
uint8_t mod[FF_DWT_MAX_DECLVLS][2]
coordinates (x0, y0) of decomp. levels mod 2
static void extend97_int(int32_t *p, int i0, int i1)
#define av_malloc_array(a, b)
static void dwt_decode97_float(DWTContext *s, float *t)