diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/openjpeg-libsl/libopenjpeg/dwt.c | 661 |
1 files changed, 0 insertions, 661 deletions
diff --git a/libraries/openjpeg-libsl/libopenjpeg/dwt.c b/libraries/openjpeg-libsl/libopenjpeg/dwt.c deleted file mode 100644 index d10de18..0000000 --- a/libraries/openjpeg-libsl/libopenjpeg/dwt.c +++ /dev/null | |||
@@ -1,661 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium | ||
3 | * Copyright (c) 2002-2007, Professor Benoit Macq | ||
4 | * Copyright (c) 2001-2003, David Janssens | ||
5 | * Copyright (c) 2002-2003, Yannick Verschueren | ||
6 | * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe | ||
7 | * Copyright (c) 2005, Herve Drolon, FreeImage Team | ||
8 | * All rights reserved. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in the | ||
17 | * documentation and/or other materials provided with the distribution. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' | ||
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | |||
33 | #include "opj_includes.h" | ||
34 | |||
35 | /** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ | ||
36 | /*@{*/ | ||
37 | |||
38 | #define WS(i) v->mem[(i)*2] | ||
39 | #define WD(i) v->mem[(1+(i)*2)] | ||
40 | |||
41 | /** @name Local data structures */ | ||
42 | /*@{*/ | ||
43 | |||
44 | typedef struct dwt_local{ | ||
45 | int * mem ; | ||
46 | int dn ; | ||
47 | int sn ; | ||
48 | int cas ; | ||
49 | } dwt_t ; | ||
50 | |||
51 | /*@}*/ | ||
52 | |||
53 | /** | ||
54 | Virtual function type for wavelet transform in 1-D | ||
55 | */ | ||
56 | typedef void (*DWT1DFN)(dwt_t* v); | ||
57 | |||
58 | /** @name Local static functions */ | ||
59 | /*@{*/ | ||
60 | |||
61 | /** | ||
62 | Forward lazy transform (horizontal) | ||
63 | */ | ||
64 | static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas); | ||
65 | /** | ||
66 | Forward lazy transform (vertical) | ||
67 | */ | ||
68 | static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas); | ||
69 | /** | ||
70 | Inverse lazy transform (horizontal) | ||
71 | */ | ||
72 | static void dwt_interleave_h(dwt_t* h, int *a); | ||
73 | /** | ||
74 | Inverse lazy transform (vertical) | ||
75 | */ | ||
76 | static void dwt_interleave_v(dwt_t* v, int *a, int x); | ||
77 | /** | ||
78 | Forward 5-3 wavelet tranform in 1-D | ||
79 | */ | ||
80 | static void dwt_encode_1(int *a, int dn, int sn, int cas); | ||
81 | /** | ||
82 | Inverse 5-3 wavelet tranform in 1-D | ||
83 | */ | ||
84 | static void dwt_decode_1(dwt_t *v); | ||
85 | /** | ||
86 | Forward 9-7 wavelet transform in 1-D | ||
87 | */ | ||
88 | static void dwt_encode_1_real(int *a, int dn, int sn, int cas); | ||
89 | /** | ||
90 | Inverse 9-7 wavelet transform in 1-D | ||
91 | */ | ||
92 | static void dwt_decode_1_real(dwt_t *v); | ||
93 | /** | ||
94 | FIXME : comment ??? | ||
95 | */ | ||
96 | static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize); | ||
97 | /** | ||
98 | Inverse wavelet tranform in 2-D. | ||
99 | */ | ||
100 | static void dwt_decode_tile(opj_tcd_tilecomp_t * tilec, int stop , DWT1DFN fn); | ||
101 | |||
102 | /*@}*/ | ||
103 | |||
104 | /*@}*/ | ||
105 | |||
106 | #define S(i) a[(i)*2] | ||
107 | #define D(i) a[(1+(i)*2)] | ||
108 | #define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i))) | ||
109 | #define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i))) | ||
110 | /* new */ | ||
111 | #define SS_(i) ((i)<0?S(0):((i)>=dn?S(dn-1):S(i))) | ||
112 | #define DD_(i) ((i)<0?D(0):((i)>=sn?D(sn-1):D(i))) | ||
113 | |||
114 | /* <summary> */ | ||
115 | /* This table contains the norms of the 5-3 wavelets for different bands. */ | ||
116 | /* </summary> */ | ||
117 | static const double dwt_norms[4][10] = { | ||
118 | {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3}, | ||
119 | {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, | ||
120 | {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, | ||
121 | {.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93} | ||
122 | }; | ||
123 | |||
124 | /* <summary> */ | ||
125 | /* This table contains the norms of the 9-7 wavelets for different bands. */ | ||
126 | /* </summary> */ | ||
127 | static const double dwt_norms_real[4][10] = { | ||
128 | {1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9}, | ||
129 | {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, | ||
130 | {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, | ||
131 | {2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2} | ||
132 | }; | ||
133 | |||
134 | /* | ||
135 | ========================================================== | ||
136 | local functions | ||
137 | ========================================================== | ||
138 | */ | ||
139 | |||
140 | /* <summary> */ | ||
141 | /* Forward lazy transform (horizontal). */ | ||
142 | /* </summary> */ | ||
143 | static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) { | ||
144 | int i; | ||
145 | for (i=0; i<sn; i++) b[i]=a[2*i+cas]; | ||
146 | for (i=0; i<dn; i++) b[sn+i]=a[(2*i+1-cas)]; | ||
147 | } | ||
148 | |||
149 | /* <summary> */ | ||
150 | /* Forward lazy transform (vertical). */ | ||
151 | /* </summary> */ | ||
152 | static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) { | ||
153 | int i; | ||
154 | for (i=0; i<sn; i++) b[i*x]=a[2*i+cas]; | ||
155 | for (i=0; i<dn; i++) b[(sn+i)*x]=a[(2*i+1-cas)]; | ||
156 | } | ||
157 | |||
158 | /* <summary> */ | ||
159 | /* Inverse lazy transform (horizontal). */ | ||
160 | /* </summary> */ | ||
161 | static void dwt_interleave_h(dwt_t* h, int *a) { | ||
162 | int *ai = a; | ||
163 | int *bi = h->mem + h->cas; | ||
164 | int i = h->sn; | ||
165 | while( i-- ) { | ||
166 | *bi = *(ai++); | ||
167 | bi += 2; | ||
168 | } | ||
169 | ai = a + h->sn; | ||
170 | bi = h->mem + 1 - h->cas; | ||
171 | i = h->dn ; | ||
172 | while( i-- ) { | ||
173 | *bi = *(ai++); | ||
174 | bi += 2; | ||
175 | } | ||
176 | } | ||
177 | |||
178 | /* <summary> */ | ||
179 | /* Inverse lazy transform (vertical). */ | ||
180 | /* </summary> */ | ||
181 | static void dwt_interleave_v(dwt_t* v, int *a, int x) { | ||
182 | int *ai = a; | ||
183 | int *bi = v->mem + v->cas; | ||
184 | int i = v->sn; | ||
185 | while( i-- ) { | ||
186 | *bi = *ai; | ||
187 | bi += 2; | ||
188 | ai += x; | ||
189 | } | ||
190 | ai = a + (v->sn * x); | ||
191 | bi = v->mem + 1 - v->cas; | ||
192 | i = v->dn ; | ||
193 | while( i-- ) { | ||
194 | *bi = *ai; | ||
195 | bi += 2; | ||
196 | ai += x; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | |||
201 | /* <summary> */ | ||
202 | /* Forward 5-3 wavelet tranform in 1-D. */ | ||
203 | /* </summary> */ | ||
204 | static void dwt_encode_1(int *a, int dn, int sn, int cas) { | ||
205 | int i; | ||
206 | |||
207 | if (!cas) { | ||
208 | if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ | ||
209 | for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1; | ||
210 | for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2; | ||
211 | } | ||
212 | } else { | ||
213 | if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ | ||
214 | S(0) *= 2; | ||
215 | else { | ||
216 | for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1; | ||
217 | for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2; | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | |||
222 | /* <summary> */ | ||
223 | /* Inverse 5-3 wavelet tranform in 1-D. */ | ||
224 | /* </summary> */ | ||
225 | static void dwt_decode_1_(int *a, int dn, int sn, int cas) { | ||
226 | int i; | ||
227 | |||
228 | if (!cas) { | ||
229 | if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ | ||
230 | for (i = 0; i < sn; i++) S(i) -= (D_(i - 1) + D_(i) + 2) >> 2; | ||
231 | for (i = 0; i < dn; i++) D(i) += (S_(i) + S_(i + 1)) >> 1; | ||
232 | } | ||
233 | } else { | ||
234 | if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ | ||
235 | S(0) /= 2; | ||
236 | else { | ||
237 | for (i = 0; i < sn; i++) D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2; | ||
238 | for (i = 0; i < dn; i++) S(i) += (DD_(i) + DD_(i - 1)) >> 1; | ||
239 | } | ||
240 | } | ||
241 | } | ||
242 | |||
243 | /* <summary> */ | ||
244 | /* Inverse 5-3 wavelet tranform in 1-D. */ | ||
245 | /* </summary> */ | ||
246 | static void dwt_decode_1(dwt_t *v) { | ||
247 | dwt_decode_1_(v->mem, v->dn, v->sn, v->cas); | ||
248 | } | ||
249 | |||
250 | /* <summary> */ | ||
251 | /* Forward 9-7 wavelet transform in 1-D. */ | ||
252 | /* </summary> */ | ||
253 | static void dwt_encode_1_real(int *a, int dn, int sn, int cas) { | ||
254 | int i; | ||
255 | if (!cas) { | ||
256 | if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ | ||
257 | for (i = 0; i < dn; i++) | ||
258 | D(i) -= fix_mul(S_(i) + S_(i + 1), 12993); | ||
259 | for (i = 0; i < sn; i++) | ||
260 | S(i) -= fix_mul(D_(i - 1) + D_(i), 434); | ||
261 | for (i = 0; i < dn; i++) | ||
262 | D(i) += fix_mul(S_(i) + S_(i + 1), 7233); | ||
263 | for (i = 0; i < sn; i++) | ||
264 | S(i) += fix_mul(D_(i - 1) + D_(i), 3633); | ||
265 | for (i = 0; i < dn; i++) | ||
266 | D(i) = fix_mul(D(i), 5038); /*5038 */ | ||
267 | for (i = 0; i < sn; i++) | ||
268 | S(i) = fix_mul(S(i), 6659); /*6660 */ | ||
269 | } | ||
270 | } else { | ||
271 | if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */ | ||
272 | for (i = 0; i < dn; i++) | ||
273 | S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993); | ||
274 | for (i = 0; i < sn; i++) | ||
275 | D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434); | ||
276 | for (i = 0; i < dn; i++) | ||
277 | S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233); | ||
278 | for (i = 0; i < sn; i++) | ||
279 | D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633); | ||
280 | for (i = 0; i < dn; i++) | ||
281 | S(i) = fix_mul(S(i), 5038); /*5038 */ | ||
282 | for (i = 0; i < sn; i++) | ||
283 | D(i) = fix_mul(D(i), 6659); /*6660 */ | ||
284 | } | ||
285 | } | ||
286 | } | ||
287 | |||
288 | static void dwt_decode_sm(dwt_t* v, int k, int n, int x) { | ||
289 | int m = k > n ? n : k; | ||
290 | int l = v->mem[1]; //D(0); | ||
291 | int j; | ||
292 | int i; | ||
293 | for (i = 0; i < m; i++) { | ||
294 | j = l; | ||
295 | WS(i) -= fix_mul( ( l = WD(i) ) + j , x); | ||
296 | } | ||
297 | if( i < k ) { | ||
298 | l = fix_mul( l + l , x ); | ||
299 | for (; i < k; i++) | ||
300 | WS(i) -= l; | ||
301 | } | ||
302 | } | ||
303 | |||
304 | static void dwt_decode_sp(dwt_t* v, int k, int n, int x) { | ||
305 | int m = k > n ? n : k; | ||
306 | int l = v->mem[1]; //D(0); | ||
307 | int j; | ||
308 | int i; | ||
309 | for (i = 0; i < m; i++) { | ||
310 | j = l; | ||
311 | WS(i) += fix_mul( ( l = WD(i) ) + j , x); | ||
312 | } | ||
313 | if( i < k ) { | ||
314 | l = fix_mul( l + l , x ); | ||
315 | for (; i < k; i++) | ||
316 | WS(i) += l; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | static void dwt_decode_dm(dwt_t* v, int k, int n, int x) { | ||
321 | int m = k >= n ? n-1 : k; | ||
322 | int l = v->mem[0]; //S(0); | ||
323 | int i; | ||
324 | int j; | ||
325 | for (i = 0; i < m; i++) { | ||
326 | j = l; | ||
327 | WD(i) -= fix_mul( ( l = WS(i+1) ) + j , x); | ||
328 | } | ||
329 | if( i < k ) { | ||
330 | l = fix_mul( l + l , x ); | ||
331 | for (; i < k; i++) | ||
332 | WD(i) -= l; | ||
333 | } | ||
334 | } | ||
335 | |||
336 | static void dwt_decode_dp(dwt_t* v, int k, int n, int x) { | ||
337 | int m = k >= n ? n-1 : k; | ||
338 | int l = v->mem[0]; //S(0); | ||
339 | int i; | ||
340 | int j; | ||
341 | for (i = 0; i < m; i++) { | ||
342 | j = l; | ||
343 | WD(i) += fix_mul( ( l = WS(i+1) ) + j , x); | ||
344 | } | ||
345 | |||
346 | if( i < k ) { | ||
347 | l = fix_mul( l + l , x ); | ||
348 | for (; i < k; i++) | ||
349 | WD(i) += l; | ||
350 | } | ||
351 | } | ||
352 | |||
353 | |||
354 | /* <summary> */ | ||
355 | /* Inverse 9-7 wavelet transform in 1-D. */ | ||
356 | /* </summary> */ | ||
357 | static void dwt_decode_1_real(dwt_t* v) { | ||
358 | int i; | ||
359 | if (!v->cas) { | ||
360 | if ((v->dn > 0) || (v->sn > 1)) { /* NEW : CASE ONE ELEMENT */ | ||
361 | for (i = 0; i < v->sn; i++) | ||
362 | WS(i) = fix_mul(WS(i), 10078); /* 10076 */ | ||
363 | for (i = 0; i < v->dn; i++) | ||
364 | WD(i) = fix_mul(WD(i), 13318); /* 13320 */ | ||
365 | dwt_decode_sm(v, v->sn, v->dn, 3633); | ||
366 | dwt_decode_dm(v, v->dn, v->sn, 7233); | ||
367 | dwt_decode_sp(v, v->sn, v->dn, 434); | ||
368 | dwt_decode_dp(v, v->dn, v->sn, 12994); | ||
369 | } | ||
370 | } else { | ||
371 | if ((v->sn > 0) || (v->dn > 1)) { /* NEW : CASE ONE ELEMENT */ | ||
372 | for (i = 0; i < v->sn; i++) | ||
373 | WD(i) = fix_mul(WD(i), 10078); /* 10076 */ | ||
374 | for (i = 0; i < v->dn; i++) | ||
375 | WS(i) = fix_mul(WS(i), 13318); /* 13320 */ | ||
376 | dwt_decode_dm(v, v->sn, v->dn, 3633); | ||
377 | dwt_decode_sm(v, v->dn, v->sn, 7233); | ||
378 | dwt_decode_dp(v, v->sn, v->dn, 434); | ||
379 | dwt_decode_sp(v, v->dn, v->sn, 12994); | ||
380 | } | ||
381 | } | ||
382 | } | ||
383 | |||
384 | static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) { | ||
385 | int p, n; | ||
386 | p = int_floorlog2(stepsize) - 13; | ||
387 | n = 11 - int_floorlog2(stepsize); | ||
388 | bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff; | ||
389 | bandno_stepsize->expn = numbps - p; | ||
390 | } | ||
391 | |||
392 | /* | ||
393 | ========================================================== | ||
394 | DWT interface | ||
395 | ========================================================== | ||
396 | */ | ||
397 | |||
398 | /* <summary> */ | ||
399 | /* Forward 5-3 wavelet tranform in 2-D. */ | ||
400 | /* </summary> */ | ||
401 | void dwt_encode(opj_tcd_tilecomp_t * tilec) { | ||
402 | int i, j, k; | ||
403 | int *a = NULL; | ||
404 | int *aj = NULL; | ||
405 | int *bj = NULL; | ||
406 | int w, l; | ||
407 | |||
408 | w = tilec->x1-tilec->x0; | ||
409 | l = tilec->numresolutions-1; | ||
410 | a = tilec->data; | ||
411 | |||
412 | for (i = 0; i < l; i++) { | ||
413 | int rw; /* width of the resolution level computed */ | ||
414 | int rh; /* heigth of the resolution level computed */ | ||
415 | int rw1; /* width of the resolution level once lower than computed one */ | ||
416 | int rh1; /* height of the resolution level once lower than computed one */ | ||
417 | int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ | ||
418 | int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */ | ||
419 | int dn, sn; | ||
420 | |||
421 | rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0; | ||
422 | rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0; | ||
423 | rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0; | ||
424 | rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0; | ||
425 | |||
426 | cas_row = tilec->resolutions[l - i].x0 % 2; | ||
427 | cas_col = tilec->resolutions[l - i].y0 % 2; | ||
428 | |||
429 | sn = rh1; | ||
430 | dn = rh - rh1; | ||
431 | bj = (int*)opj_malloc(rh * sizeof(int)); | ||
432 | for (j = 0; j < rw; j++) { | ||
433 | aj = a + j; | ||
434 | for (k = 0; k < rh; k++) bj[k] = aj[k*w]; | ||
435 | dwt_encode_1(bj, dn, sn, cas_col); | ||
436 | dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); | ||
437 | } | ||
438 | opj_free(bj); | ||
439 | |||
440 | sn = rw1; | ||
441 | dn = rw - rw1; | ||
442 | bj = (int*)opj_malloc(rw * sizeof(int)); | ||
443 | for (j = 0; j < rh; j++) { | ||
444 | aj = a + j * w; | ||
445 | for (k = 0; k < rw; k++) bj[k] = aj[k]; | ||
446 | dwt_encode_1(bj, dn, sn, cas_row); | ||
447 | dwt_deinterleave_h(bj, aj, dn, sn, cas_row); | ||
448 | } | ||
449 | opj_free(bj); | ||
450 | } | ||
451 | } | ||
452 | |||
453 | |||
454 | /* <summary> */ | ||
455 | /* Inverse 5-3 wavelet tranform in 2-D. */ | ||
456 | /* </summary> */ | ||
457 | void dwt_decode(opj_tcd_tilecomp_t * tilec, int stop) { | ||
458 | dwt_decode_tile(tilec, stop, &dwt_decode_1); | ||
459 | } | ||
460 | |||
461 | |||
462 | /* <summary> */ | ||
463 | /* Get gain of 5-3 wavelet transform. */ | ||
464 | /* </summary> */ | ||
465 | int dwt_getgain(int orient) { | ||
466 | if (orient == 0) | ||
467 | return 0; | ||
468 | if (orient == 1 || orient == 2) | ||
469 | return 1; | ||
470 | return 2; | ||
471 | } | ||
472 | |||
473 | /* <summary> */ | ||
474 | /* Get norm of 5-3 wavelet. */ | ||
475 | /* </summary> */ | ||
476 | double dwt_getnorm(int level, int orient) { | ||
477 | return dwt_norms[orient][level]; | ||
478 | } | ||
479 | |||
480 | /* <summary> */ | ||
481 | /* Forward 9-7 wavelet transform in 2-D. */ | ||
482 | /* </summary> */ | ||
483 | |||
484 | void dwt_encode_real(opj_tcd_tilecomp_t * tilec) { | ||
485 | int i, j, k; | ||
486 | int *a = NULL; | ||
487 | int *aj = NULL; | ||
488 | int *bj = NULL; | ||
489 | int w, l; | ||
490 | |||
491 | w = tilec->x1-tilec->x0; | ||
492 | l = tilec->numresolutions-1; | ||
493 | a = tilec->data; | ||
494 | |||
495 | for (i = 0; i < l; i++) { | ||
496 | int rw; /* width of the resolution level computed */ | ||
497 | int rh; /* heigth of the resolution level computed */ | ||
498 | int rw1; /* width of the resolution level once lower than computed one */ | ||
499 | int rh1; /* height of the resolution level once lower than computed one */ | ||
500 | int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ | ||
501 | int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */ | ||
502 | int dn, sn; | ||
503 | |||
504 | rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0; | ||
505 | rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0; | ||
506 | rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0; | ||
507 | rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0; | ||
508 | |||
509 | cas_row = tilec->resolutions[l - i].x0 % 2; | ||
510 | cas_col = tilec->resolutions[l - i].y0 % 2; | ||
511 | |||
512 | sn = rh1; | ||
513 | dn = rh - rh1; | ||
514 | bj = (int*)opj_malloc(rh * sizeof(int)); | ||
515 | for (j = 0; j < rw; j++) { | ||
516 | aj = a + j; | ||
517 | for (k = 0; k < rh; k++) bj[k] = aj[k*w]; | ||
518 | dwt_encode_1_real(bj, dn, sn, cas_col); | ||
519 | dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); | ||
520 | } | ||
521 | opj_free(bj); | ||
522 | |||
523 | sn = rw1; | ||
524 | dn = rw - rw1; | ||
525 | bj = (int*)opj_malloc(rw * sizeof(int)); | ||
526 | for (j = 0; j < rh; j++) { | ||
527 | aj = a + j * w; | ||
528 | for (k = 0; k < rw; k++) bj[k] = aj[k]; | ||
529 | dwt_encode_1_real(bj, dn, sn, cas_row); | ||
530 | dwt_deinterleave_h(bj, aj, dn, sn, cas_row); | ||
531 | } | ||
532 | opj_free(bj); | ||
533 | } | ||
534 | } | ||
535 | |||
536 | |||
537 | /* <summary> */ | ||
538 | /* Inverse 9-7 wavelet transform in 2-D. */ | ||
539 | /* </summary> */ | ||
540 | void dwt_decode_real(opj_tcd_tilecomp_t * tilec, int stop) { | ||
541 | dwt_decode_tile(tilec, stop, dwt_decode_1_real); | ||
542 | } | ||
543 | |||
544 | |||
545 | /* <summary> */ | ||
546 | /* Get gain of 9-7 wavelet transform. */ | ||
547 | /* </summary> */ | ||
548 | int dwt_getgain_real(int orient) { | ||
549 | (void)orient; | ||
550 | return 0; | ||
551 | } | ||
552 | |||
553 | /* <summary> */ | ||
554 | /* Get norm of 9-7 wavelet. */ | ||
555 | /* </summary> */ | ||
556 | double dwt_getnorm_real(int level, int orient) { | ||
557 | return dwt_norms_real[orient][level]; | ||
558 | } | ||
559 | |||
560 | void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) { | ||
561 | int numbands, bandno; | ||
562 | numbands = 3 * tccp->numresolutions - 2; | ||
563 | for (bandno = 0; bandno < numbands; bandno++) { | ||
564 | double stepsize; | ||
565 | int resno, level, orient, gain; | ||
566 | |||
567 | resno = (bandno == 0) ? 0 : ((bandno - 1) / 3 + 1); | ||
568 | orient = (bandno == 0) ? 0 : ((bandno - 1) % 3 + 1); | ||
569 | level = tccp->numresolutions - 1 - resno; | ||
570 | gain = (tccp->qmfbid == 0) ? 0 : ((orient == 0) ? 0 : (((orient == 1) || (orient == 2)) ? 1 : 2)); | ||
571 | if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { | ||
572 | stepsize = 1.0; | ||
573 | } else { | ||
574 | double norm = dwt_norms_real[orient][level]; | ||
575 | stepsize = (1 << (gain)) / norm; | ||
576 | } | ||
577 | dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]); | ||
578 | } | ||
579 | } | ||
580 | |||
581 | |||
582 | /* <summary> */ | ||
583 | /* Determine maximum computed resolution level for inverse wavelet transform */ | ||
584 | /* </summary> */ | ||
585 | static int dwt_decode_max_resolution(opj_tcd_resolution_t* r, int i) { | ||
586 | int mr = 1; | ||
587 | int w; | ||
588 | while( --i ) { | ||
589 | r++; | ||
590 | if( mr < ( w = r->x1 - r->x0 ) ) | ||
591 | mr = w ; | ||
592 | if( mr < ( w = r->y1 - r->y0 ) ) | ||
593 | mr = w ; | ||
594 | } | ||
595 | return mr ; | ||
596 | } | ||
597 | |||
598 | |||
599 | /* <summary> */ | ||
600 | /* Inverse wavelet tranform in 2-D. */ | ||
601 | /* </summary> */ | ||
602 | static void dwt_decode_tile(opj_tcd_tilecomp_t * tilec, int stop, DWT1DFN dwt_1D) { | ||
603 | opj_tcd_resolution_t* tr; | ||
604 | int i, j, k; | ||
605 | int *a = NULL; | ||
606 | int *aj = NULL; | ||
607 | int *m; | ||
608 | int w; //, l; | ||
609 | int rw; /* width of the resolution level computed */ | ||
610 | int rh; /* heigth of the resolution level computed */ | ||
611 | dwt_t h; | ||
612 | dwt_t v; | ||
613 | |||
614 | if( 1 > ( i = tilec->numresolutions - stop ) ) | ||
615 | return ; | ||
616 | |||
617 | tr = tilec->resolutions; | ||
618 | |||
619 | w = tilec->x1-tilec->x0; | ||
620 | a = tilec->data; | ||
621 | |||
622 | m = (int*)opj_malloc(sizeof(int) * (dwt_decode_max_resolution(tr, i)+5)); | ||
623 | h.mem = v.mem = (int*)( (unsigned)m + 16 - ( (unsigned)m % 16 ) ) ; | ||
624 | |||
625 | rw = tr->x1 - tr->x0; | ||
626 | rh = tr->y1 - tr->y0; | ||
627 | |||
628 | while( --i ) { | ||
629 | tr++; | ||
630 | h.sn = rw; | ||
631 | v.sn = rh; | ||
632 | h.dn = ( rw = tr->x1 - tr->x0 ) - h.sn; | ||
633 | v.dn = ( rh = tr->y1 - tr->y0 ) - v.sn; | ||
634 | |||
635 | h.cas = tr->x0 % 2; | ||
636 | v.cas = tr->y0 % 2; | ||
637 | |||
638 | aj = a; | ||
639 | j = rh; | ||
640 | while( j-- ) { | ||
641 | dwt_interleave_h(&h, aj); | ||
642 | (dwt_1D)(&h); | ||
643 | k = rw; | ||
644 | while( k-- ) | ||
645 | aj[k] = h.mem[k]; | ||
646 | aj += w; | ||
647 | } | ||
648 | |||
649 | aj = a; | ||
650 | j = rw; | ||
651 | while( j-- ) { | ||
652 | dwt_interleave_v(&v, aj, w); | ||
653 | (dwt_1D)(&v); | ||
654 | k = rh; | ||
655 | while( k-- ) | ||
656 | aj[k * w] = v.mem[k]; | ||
657 | aj++; | ||
658 | } | ||
659 | } | ||
660 | opj_free(m); | ||
661 | } | ||