8 void fwd_analyze_1 (const TYPE
*x
, TYPE
*d
, int stride
, int n
)
13 d
[i
] = x
[(2*i
+1)*stride
] - x
[2*i
*stride
];
18 void fwd_synthesize_1 (const TYPE
*x
, TYPE
*s
, const TYPE
*d
, int stride
, int n
)
23 s
[i
*stride
] = x
[2*i
*stride
] + d
[i
] / 2;
25 s
[k
*stride
] = x
[2*k
*stride
] + d
[k
-1] / 2;
30 void inv_analyze_1 (TYPE
*x
, const TYPE
*d
, int stride
, int n
)
35 x
[(2*i
+1)*stride
] = d
[i
] + x
[2*i
*stride
];
40 void inv_synthesize_1 (TYPE
*x
, const TYPE
*s
, const TYPE
*d
, int stride
, int n
)
45 x
[2*i
*stride
] = s
[i
] - d
[i
] / 2;
47 x
[2*k
*stride
] = s
[k
] - d
[k
-1] / 2;
53 void fwd_analyze_2 (const TYPE
*x
, TYPE
*d
, int stride
, int n
)
59 d
[i
] = x
[(2*i
+1)*stride
] - (x
[2*i
*stride
] + x
[(2*i
+2)*stride
]) / 2;
62 d
[i
] = x
[(2*i
+1)*stride
] - (x
[2*i
*stride
] + x
[(2*i
+2)*stride
]) / 2;
63 d
[k
-1] = x
[(n
-1)*stride
] - x
[(n
-2)*stride
];
70 void fwd_synthesize_2 (const TYPE
*x
, TYPE
*s
, const TYPE
*d
, int stride
, int n
)
74 s
[0] = x
[0] + d
[1] / 2;
76 s
[i
*stride
] = x
[2*i
*stride
] + (d
[i
-1] + d
[i
]) / 4;
78 s
[k
*stride
] = x
[2*k
*stride
] + d
[k
-1] / 2;
83 void inv_analyze_2 (TYPE
*x
, const TYPE
*d
, int stride
, int n
)
89 x
[(2*i
+1)*stride
] = d
[i
] + (x
[2*i
*stride
] + x
[(2*i
+2)*stride
]) / 2;
92 x
[(2*i
+1)*stride
] = d
[i
] + (x
[2*i
*stride
] + x
[(2*i
+2)*stride
]) / 2;
93 x
[(n
-1)*stride
] = d
[k
-1] + x
[(n
-2)*stride
];
99 void inv_synthesize_2 (TYPE
*x
, const TYPE
*s
, const TYPE
*d
, int stride
, int n
)
103 x
[0] = s
[0] - d
[1] / 2;
105 x
[2*i
*stride
] = s
[i
] - (d
[i
-1] + d
[i
]) / 4;
107 x
[2*k
*stride
] = s
[k
] - d
[k
-1] / 2;
113 void fwd_analyze_4 (const TYPE
*x
, TYPE
*d
, int stride
, int n
)
117 d
[0] = x
[stride
] - (x
[0] + x
[2*stride
]) / 2;
120 for (i
=1; i
<k
-1; i
++)
121 d
[i
] = x
[(2*i
+1)*stride
]
122 - ((uint32_t) 9 * (x
[2*i
*stride
] + x
[(2*i
+2)*stride
])
123 - (x
[(2*i
-2)*stride
] + x
[(2*i
+4)*stride
])) / 16;
125 d
[k
-1] = x
[(2*k
-1)*stride
] - (x
[(2*k
-2)*stride
] + x
[2*k
*stride
]) / 2;
127 for (i
=1; i
<k
-2; i
++)
128 d
[i
] = x
[(2*i
+1)*stride
]
129 - ((uint32_t) 9 * (x
[2*i
*stride
] + x
[(2*i
+2)*stride
])
130 - (x
[(2*i
-2)*stride
] + x
[(2*i
+4)*stride
])) / 16;
132 d
[k
-2] = x
[(2*k
-3)*stride
] - (x
[(2*k
-4)*stride
]
133 + x
[(2*k
-2)*stride
]) / 2;
135 d
[k
-1] = x
[(n
-1)*stride
] - x
[(n
-2)*stride
];
141 void fwd_synthesize_4 (const TYPE
*x
, TYPE
*s
, const TYPE
*d
, int stride
, int n
)
145 s
[0] = x
[0] + d
[1] / 2;
147 s
[stride
] = x
[2*stride
] + (d
[0] + d
[1]) / 4;
148 for (i
=2; i
<k
-1; i
++)
149 s
[i
*stride
] = x
[2*i
*stride
]
150 + ((uint32_t) 9 * (d
[i
-1] + d
[i
]) - (d
[i
-2] + d
[i
+1])) / 32;
152 s
[(k
-1)*stride
] = x
[(2*k
-2)*stride
] + (d
[k
-2] + d
[k
-1]) / 4;
154 s
[k
*stride
] = x
[2*k
*stride
] + d
[k
-1] / 2;
159 void inv_analyze_4 (TYPE
*x
, const TYPE
*d
, int stride
, int n
)
163 x
[stride
] = d
[0] + (x
[0] + x
[2*stride
]) / 2;
166 for (i
=1; i
<k
-1; i
++)
167 x
[(2*i
+1)*stride
] = d
[i
]
168 + ((uint32_t) 9 * (x
[2*i
*stride
] + x
[(2*i
+2)*stride
])
169 - (x
[(2*i
-2)*stride
] + x
[(2*i
+4)*stride
])) / 16;
171 x
[(2*k
-1)*stride
] = d
[k
-1] + (x
[(2*k
-2)*stride
] + x
[2*k
*stride
]) / 2;
173 for (i
=1; i
<k
-2; i
++)
174 x
[(2*i
+1)*stride
] = d
[i
]
175 + (9 * (x
[2*i
*stride
] + x
[(2*i
+2)*stride
])
176 - (x
[(2*i
-2)*stride
] + x
[(2*i
+4)*stride
])) / 16;
178 x
[(2*k
-3)*stride
] = d
[k
-2] + (x
[(2*k
-4)*stride
]
179 + x
[(2*k
-2)*stride
]) / 2;
181 x
[(n
-1)*stride
] = d
[k
-1] + x
[(n
-2)*stride
];
187 void inv_synthesize_4 (TYPE
*x
, const TYPE
*s
, const TYPE
*d
, int stride
, int n
)
191 x
[0] = s
[0] - d
[1] / 2;
193 x
[2*stride
] = s
[1] - (d
[0] + d
[1]) / 4;
194 for (i
=2; i
<k
-1; i
++)
195 x
[2*i
*stride
] = s
[i
] - ((uint32_t) 9 * (d
[i
-1] + d
[i
])
196 - (d
[i
-2] + d
[i
+1])) / 32;
198 x
[(2*k
-2)*stride
] = s
[k
-1] - (d
[k
-2] + d
[k
-1]) / 4;
200 x
[2*k
*stride
] = s
[k
] - d
[k
-1] / 2;
205 void copyback_d (TYPE
*x
, const TYPE
*d
, int stride
, int n
)
209 for (i
=n
-k
, j
=0; i
<n
; i
++, j
++)
215 void copy_s_d (const TYPE
*x
, TYPE
*s_d
, int stride
, int n
)
220 s_d
[i
] = x
[i
*stride
];
226 void (*FwdSFnc
) (const TYPE
*x
, TYPE
*s
, const TYPE
*d
, int stride
, int n
);
229 void (*FwdAFnc
) (const TYPE
*x
, TYPE
*d
, int stride
, int n
);
232 void (*InvSFnc
) (TYPE
*x
, const TYPE
*s
, const TYPE
*d
, int stride
, int n
);
235 void (*InvAFnc
) (TYPE
*x
, const TYPE
*d
, int stride
, int n
);
239 static FwdSFnc fwd_synthesize
[] = { NULL
, fwd_synthesize_1
, fwd_synthesize_2
,
240 NULL
, fwd_synthesize_4
};
242 static FwdAFnc fwd_analyze
[] = { NULL
, fwd_analyze_1
, fwd_analyze_2
,
243 NULL
, fwd_analyze_4
};
245 static InvSFnc inv_synthesize
[] = { NULL
, inv_synthesize_1
, inv_synthesize_2
,
246 NULL
, inv_synthesize_4
};
248 static InvAFnc inv_analyze
[] = { NULL
, inv_analyze_1
, inv_analyze_2
,
249 NULL
, inv_analyze_4
};
254 void fwd_xform (TYPE
*scratchbuf
, TYPE
*data
, int stride
, int n
,
255 int a_moments
, int s_moments
)
258 TYPE
*d
= scratchbuf
;
261 assert (a_moments
== 1 || a_moments
== 2 || a_moments
== 4);
262 assert (s_moments
== 1 || s_moments
== 2 || s_moments
== 4);
264 /* XXX FIXME: Ugly hack to work around */
265 /* the short-row bug in high */
266 /* order xform functions */
268 a_moments
= s_moments
= 2;
270 a_moments
= s_moments
= 1;
272 fwd_analyze
[a_moments
] (x
, d
, stride
, n
);
273 fwd_synthesize
[s_moments
] (x
, s
, d
, stride
, n
);
274 copyback_d (x
, d
, stride
, n
);
279 void inv_xform (TYPE
*scratchbuf
, TYPE
*data
, int stride
, int n
,
280 int a_moments
, int s_moments
)
284 TYPE
*s
= scratchbuf
;
285 TYPE
*d
= scratchbuf
+ n
- k
;
287 assert (a_moments
== 1 || a_moments
== 2 || a_moments
== 4);
288 assert (s_moments
== 1 || s_moments
== 2 || s_moments
== 4);
290 /* XXX FIXME: Ugly hack to work around */
291 /* the short-row bug in high */
292 /* order xform functions */
294 a_moments
= s_moments
= 2;
296 a_moments
= s_moments
= 1;
298 copy_s_d (data
, scratchbuf
, stride
, n
);
299 inv_synthesize
[s_moments
] (x
, s
, d
, stride
, n
);
300 inv_analyze
[a_moments
] (x
, d
, stride
, n
);
305 void wavelet_3d_buf_fwd_xform (Wavelet3DBuf
* buf
, int a_moments
, int s_moments
)
309 for (level
=buf
->scales
-1; level
>0; level
--) {
310 uint32_t w
= buf
->w
[level
];
311 uint32_t h
= buf
->h
[level
];
312 uint32_t f
= buf
->f
[level
];
316 for (frame
=0; frame
<f
; frame
++) {
317 for (row
=0; row
<h
; row
++) {
318 TYPE
*data
= buf
->data
+ (frame
* buf
->height
+ row
) * buf
->width
;
319 fwd_xform (buf
->scratchbuf
, data
, 1, w
, a_moments
, s_moments
);
326 for (frame
=0; frame
<f
; frame
++) {
327 for (col
=0; col
<w
; col
++) {
328 TYPE
*data
= buf
->data
+ frame
* buf
->width
* buf
->height
+ col
;
329 fwd_xform (buf
->scratchbuf
, data
, buf
->width
, h
,
330 a_moments
, s_moments
);
337 for (j
=0; j
<h
; j
++) {
338 for (i
=0; i
<w
; i
++) {
339 TYPE
*data
= buf
->data
+ j
*buf
->width
+ i
;
340 fwd_xform (buf
->scratchbuf
, data
, buf
->width
* buf
->height
, f
,
341 a_moments
, s_moments
);
349 void wavelet_3d_buf_inv_xform (Wavelet3DBuf
* buf
, int a_moments
, int s_moments
)
353 for (level
=1; level
<buf
->scales
; level
++) {
354 uint32_t w
= buf
->w
[level
];
355 uint32_t h
= buf
->h
[level
];
356 uint32_t f
= buf
->f
[level
];
360 for (j
=0; j
<h
; j
++) {
361 for (i
=0; i
<w
; i
++) {
362 TYPE
*data
= buf
->data
+ j
*buf
->width
+ i
;
363 inv_xform (buf
->scratchbuf
, data
, buf
->width
* buf
->height
, f
,
364 a_moments
, s_moments
);
371 for (frame
=0; frame
<f
; frame
++) {
372 for (col
=0; col
<w
; col
++) {
373 TYPE
*data
= buf
->data
+ frame
* buf
->width
* buf
->height
+ col
;
374 inv_xform (buf
->scratchbuf
, data
, buf
->width
, h
,
375 a_moments
, s_moments
);
382 for (frame
=0; frame
<f
; frame
++) {
383 for (row
=0; row
<h
; row
++) {
384 TYPE
*data
= buf
->data
+ (frame
* buf
->height
+ row
) * buf
->width
;
385 inv_xform (buf
->scratchbuf
, data
, 1, w
, a_moments
, s_moments
);