Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4758 | right-hear | 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 | * Copyright (c) 2007, Callum Lerwick |
||
9 | * All rights reserved. |
||
10 | * |
||
11 | * Redistribution and use in source and binary forms, with or without |
||
12 | * modification, are permitted provided that the following conditions |
||
13 | * are met: |
||
14 | * 1. Redistributions of source code must retain the above copyright |
||
15 | * notice, this list of conditions and the following disclaimer. |
||
16 | * 2. Redistributions in binary form must reproduce the above copyright |
||
17 | * notice, this list of conditions and the following disclaimer in the |
||
18 | * documentation and/or other materials provided with the distribution. |
||
19 | * |
||
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' |
||
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
30 | * POSSIBILITY OF SUCH DAMAGE. |
||
31 | */ |
||
32 | |||
33 | #include "opj_includes.h" |
||
34 | #include "t1_luts.h" |
||
35 | |||
36 | /** @defgroup T1 T1 - Implementation of the tier-1 coding */ |
||
37 | /*@{*/ |
||
38 | |||
39 | /** @name Local static functions */ |
||
40 | /*@{*/ |
||
41 | |||
42 | static INLINE char t1_getctxno_zc(int f, int orient); |
||
43 | static char t1_getctxno_sc(int f); |
||
44 | static INLINE int t1_getctxno_mag(int f); |
||
45 | static char t1_getspb(int f); |
||
46 | static short t1_getnmsedec_sig(int x, int bitpos); |
||
47 | static short t1_getnmsedec_ref(int x, int bitpos); |
||
48 | static void t1_updateflags(flag_t *flagsp, int s, int stride); |
||
49 | /** |
||
50 | Encode significant pass |
||
51 | */ |
||
52 | static void t1_enc_sigpass_step( |
||
53 | opj_t1_t *t1, |
||
54 | flag_t *flagsp, |
||
55 | int *datap, |
||
56 | int orient, |
||
57 | int bpno, |
||
58 | int one, |
||
59 | int *nmsedec, |
||
60 | char type, |
||
61 | int vsc); |
||
62 | /** |
||
63 | Decode significant pass |
||
64 | */ |
||
65 | static INLINE void t1_dec_sigpass_step_raw( |
||
66 | opj_t1_t *t1, |
||
67 | flag_t *flagsp, |
||
68 | int *datap, |
||
69 | int orient, |
||
70 | int oneplushalf, |
||
71 | int vsc); |
||
72 | static INLINE void t1_dec_sigpass_step_mqc( |
||
73 | opj_t1_t *t1, |
||
74 | flag_t *flagsp, |
||
75 | int *datap, |
||
76 | int orient, |
||
77 | int oneplushalf); |
||
78 | static INLINE void t1_dec_sigpass_step_mqc_vsc( |
||
79 | opj_t1_t *t1, |
||
80 | flag_t *flagsp, |
||
81 | int *datap, |
||
82 | int orient, |
||
83 | int oneplushalf, |
||
84 | int vsc); |
||
85 | /** |
||
86 | Encode significant pass |
||
87 | */ |
||
88 | static void t1_enc_sigpass( |
||
89 | opj_t1_t *t1, |
||
90 | int bpno, |
||
91 | int orient, |
||
92 | int *nmsedec, |
||
93 | char type, |
||
94 | int cblksty); |
||
95 | /** |
||
96 | Decode significant pass |
||
97 | */ |
||
98 | static void t1_dec_sigpass_raw( |
||
99 | opj_t1_t *t1, |
||
100 | int bpno, |
||
101 | int orient, |
||
102 | int cblksty); |
||
103 | static void t1_dec_sigpass_mqc( |
||
104 | opj_t1_t *t1, |
||
105 | int bpno, |
||
106 | int orient); |
||
107 | static void t1_dec_sigpass_mqc_vsc( |
||
108 | opj_t1_t *t1, |
||
109 | int bpno, |
||
110 | int orient); |
||
111 | /** |
||
112 | Encode refinement pass |
||
113 | */ |
||
114 | static void t1_enc_refpass_step( |
||
115 | opj_t1_t *t1, |
||
116 | flag_t *flagsp, |
||
117 | int *datap, |
||
118 | int bpno, |
||
119 | int one, |
||
120 | int *nmsedec, |
||
121 | char type, |
||
122 | int vsc); |
||
123 | /** |
||
124 | Decode refinement pass |
||
125 | */ |
||
126 | static void INLINE t1_dec_refpass_step_raw( |
||
127 | opj_t1_t *t1, |
||
128 | flag_t *flagsp, |
||
129 | int *datap, |
||
130 | int poshalf, |
||
131 | int neghalf, |
||
132 | int vsc); |
||
133 | static void INLINE t1_dec_refpass_step_mqc( |
||
134 | opj_t1_t *t1, |
||
135 | flag_t *flagsp, |
||
136 | int *datap, |
||
137 | int poshalf, |
||
138 | int neghalf); |
||
139 | static void INLINE t1_dec_refpass_step_mqc_vsc( |
||
140 | opj_t1_t *t1, |
||
141 | flag_t *flagsp, |
||
142 | int *datap, |
||
143 | int poshalf, |
||
144 | int neghalf, |
||
145 | int vsc); |
||
146 | |||
147 | /** |
||
148 | Encode refinement pass |
||
149 | */ |
||
150 | static void t1_enc_refpass( |
||
151 | opj_t1_t *t1, |
||
152 | int bpno, |
||
153 | int *nmsedec, |
||
154 | char type, |
||
155 | int cblksty); |
||
156 | /** |
||
157 | Decode refinement pass |
||
158 | */ |
||
159 | static void t1_dec_refpass_raw( |
||
160 | opj_t1_t *t1, |
||
161 | int bpno, |
||
162 | int cblksty); |
||
163 | static void t1_dec_refpass_mqc( |
||
164 | opj_t1_t *t1, |
||
165 | int bpno); |
||
166 | static void t1_dec_refpass_mqc_vsc( |
||
167 | opj_t1_t *t1, |
||
168 | int bpno); |
||
169 | /** |
||
170 | Encode clean-up pass |
||
171 | */ |
||
172 | static void t1_enc_clnpass_step( |
||
173 | opj_t1_t *t1, |
||
174 | flag_t *flagsp, |
||
175 | int *datap, |
||
176 | int orient, |
||
177 | int bpno, |
||
178 | int one, |
||
179 | int *nmsedec, |
||
180 | int partial, |
||
181 | int vsc); |
||
182 | /** |
||
183 | Decode clean-up pass |
||
184 | */ |
||
185 | static void t1_dec_clnpass_step_partial( |
||
186 | opj_t1_t *t1, |
||
187 | flag_t *flagsp, |
||
188 | int *datap, |
||
189 | int orient, |
||
190 | int oneplushalf); |
||
191 | static void t1_dec_clnpass_step( |
||
192 | opj_t1_t *t1, |
||
193 | flag_t *flagsp, |
||
194 | int *datap, |
||
195 | int orient, |
||
196 | int oneplushalf); |
||
197 | static void t1_dec_clnpass_step_vsc( |
||
198 | opj_t1_t *t1, |
||
199 | flag_t *flagsp, |
||
200 | int *datap, |
||
201 | int orient, |
||
202 | int oneplushalf, |
||
203 | int partial, |
||
204 | int vsc); |
||
205 | /** |
||
206 | Encode clean-up pass |
||
207 | */ |
||
208 | static void t1_enc_clnpass( |
||
209 | opj_t1_t *t1, |
||
210 | int bpno, |
||
211 | int orient, |
||
212 | int *nmsedec, |
||
213 | int cblksty); |
||
214 | /** |
||
215 | Decode clean-up pass |
||
216 | */ |
||
217 | static void t1_dec_clnpass( |
||
218 | opj_t1_t *t1, |
||
219 | int bpno, |
||
220 | int orient, |
||
221 | int cblksty); |
||
222 | static double t1_getwmsedec( |
||
223 | int nmsedec, |
||
224 | int compno, |
||
225 | int level, |
||
226 | int orient, |
||
227 | int bpno, |
||
228 | int qmfbid, |
||
229 | double stepsize, |
||
230 | int numcomps, |
||
231 | int mct); |
||
232 | /** |
||
233 | Encode 1 code-block |
||
234 | @param t1 T1 handle |
||
235 | @param cblk Code-block coding parameters |
||
236 | @param orient |
||
237 | @param compno Component number |
||
238 | @param level |
||
239 | @param qmfbid |
||
240 | @param stepsize |
||
241 | @param cblksty Code-block style |
||
242 | @param numcomps |
||
243 | @param mct |
||
244 | @param tile |
||
245 | */ |
||
246 | static void t1_encode_cblk( |
||
247 | opj_t1_t *t1, |
||
248 | opj_tcd_cblk_enc_t* cblk, |
||
249 | int orient, |
||
250 | int compno, |
||
251 | int level, |
||
252 | int qmfbid, |
||
253 | double stepsize, |
||
254 | int cblksty, |
||
255 | int numcomps, |
||
256 | int mct, |
||
257 | opj_tcd_tile_t * tile); |
||
258 | /** |
||
259 | Decode 1 code-block |
||
260 | @param t1 T1 handle |
||
261 | @param cblk Code-block coding parameters |
||
262 | @param orient |
||
263 | @param roishift Region of interest shifting value |
||
264 | @param cblksty Code-block style |
||
265 | */ |
||
266 | static void t1_decode_cblk( |
||
267 | opj_t1_t *t1, |
||
268 | opj_tcd_cblk_dec_t* cblk, |
||
269 | int orient, |
||
270 | int roishift, |
||
271 | int cblksty); |
||
272 | |||
273 | /*@}*/ |
||
274 | |||
275 | /*@}*/ |
||
276 | |||
277 | /* ----------------------------------------------------------------------- */ |
||
278 | |||
279 | static char t1_getctxno_zc(int f, int orient) { |
||
280 | return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; |
||
281 | } |
||
282 | |||
283 | static char t1_getctxno_sc(int f) { |
||
284 | return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; |
||
285 | } |
||
286 | |||
287 | static int t1_getctxno_mag(int f) { |
||
288 | int tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG; |
||
289 | int tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1; |
||
290 | return (tmp2); |
||
291 | } |
||
292 | |||
293 | static char t1_getspb(int f) { |
||
294 | return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; |
||
295 | } |
||
296 | |||
297 | static short t1_getnmsedec_sig(int x, int bitpos) { |
||
298 | if (bitpos > T1_NMSEDEC_FRACBITS) { |
||
299 | return lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; |
||
300 | } |
||
301 | |||
302 | return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; |
||
303 | } |
||
304 | |||
305 | static short t1_getnmsedec_ref(int x, int bitpos) { |
||
306 | if (bitpos > T1_NMSEDEC_FRACBITS) { |
||
307 | return lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; |
||
308 | } |
||
309 | |||
310 | return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; |
||
311 | } |
||
312 | |||
313 | static void t1_updateflags(flag_t *flagsp, int s, int stride) { |
||
314 | flag_t *np = flagsp - stride; |
||
315 | flag_t *sp = flagsp + stride; |
||
316 | |||
317 | static const flag_t mod[] = { |
||
318 | T1_SIG_S, T1_SIG_S|T1_SGN_S, |
||
319 | T1_SIG_E, T1_SIG_E|T1_SGN_E, |
||
320 | T1_SIG_W, T1_SIG_W|T1_SGN_W, |
||
321 | T1_SIG_N, T1_SIG_N|T1_SGN_N |
||
322 | }; |
||
323 | |||
324 | np[-1] |= T1_SIG_SE; |
||
325 | np[0] |= mod[s]; |
||
326 | np[1] |= T1_SIG_SW; |
||
327 | |||
328 | flagsp[-1] |= mod[s+2]; |
||
329 | flagsp[0] |= T1_SIG; |
||
330 | flagsp[1] |= mod[s+4]; |
||
331 | |||
332 | sp[-1] |= T1_SIG_NE; |
||
333 | sp[0] |= mod[s+6]; |
||
334 | sp[1] |= T1_SIG_NW; |
||
335 | } |
||
336 | |||
337 | static void t1_enc_sigpass_step( |
||
338 | opj_t1_t *t1, |
||
339 | flag_t *flagsp, |
||
340 | int *datap, |
||
341 | int orient, |
||
342 | int bpno, |
||
343 | int one, |
||
344 | int *nmsedec, |
||
345 | char type, |
||
346 | int vsc) |
||
347 | { |
||
348 | int v, flag; |
||
349 | |||
350 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
351 | |||
352 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
353 | if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { |
||
354 | v = int_abs(*datap) & one ? 1 : 0; |
||
355 | mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); /* ESSAI */ |
||
356 | if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ |
||
357 | mqc_bypass_enc(mqc, v); |
||
358 | } else { |
||
359 | mqc_encode(mqc, v); |
||
360 | } |
||
361 | if (v) { |
||
362 | v = *datap < 0 ? 1 : 0; |
||
363 | *nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); |
||
364 | mqc_setcurctx(mqc, t1_getctxno_sc(flag)); /* ESSAI */ |
||
365 | if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ |
||
366 | mqc_bypass_enc(mqc, v); |
||
367 | } else { |
||
368 | mqc_encode(mqc, v ^ t1_getspb(flag)); |
||
369 | } |
||
370 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
371 | } |
||
372 | *flagsp |= T1_VISIT; |
||
373 | } |
||
374 | } |
||
375 | |||
376 | static INLINE void t1_dec_sigpass_step_raw( |
||
377 | opj_t1_t *t1, |
||
378 | flag_t *flagsp, |
||
379 | int *datap, |
||
380 | int orient, |
||
381 | int oneplushalf, |
||
382 | int vsc) |
||
383 | { |
||
384 | int v, flag; |
||
385 | |||
386 | opj_raw_t *raw = t1->raw; /* RAW component */ |
||
387 | |||
388 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
389 | if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { |
||
390 | if (raw_decode(raw)) { |
||
391 | v = raw_decode(raw); /* ESSAI */ |
||
392 | *datap = v ? -oneplushalf : oneplushalf; |
||
393 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
394 | } |
||
395 | *flagsp |= T1_VISIT; |
||
396 | } |
||
397 | } /* VSC and BYPASS by Antonin */ |
||
398 | |||
399 | static INLINE void t1_dec_sigpass_step_mqc( |
||
400 | opj_t1_t *t1, |
||
401 | flag_t *flagsp, |
||
402 | int *datap, |
||
403 | int orient, |
||
404 | int oneplushalf) |
||
405 | { |
||
406 | int v, flag; |
||
407 | |||
408 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
409 | |||
410 | flag = *flagsp; |
||
411 | if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { |
||
412 | mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); |
||
413 | if (mqc_decode(mqc)) { |
||
414 | mqc_setcurctx(mqc, t1_getctxno_sc(flag)); |
||
415 | v = mqc_decode(mqc) ^ t1_getspb(flag); |
||
416 | *datap = v ? -oneplushalf : oneplushalf; |
||
417 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
418 | } |
||
419 | *flagsp |= T1_VISIT; |
||
420 | } |
||
421 | } /* VSC and BYPASS by Antonin */ |
||
422 | |||
423 | static INLINE void t1_dec_sigpass_step_mqc_vsc( |
||
424 | opj_t1_t *t1, |
||
425 | flag_t *flagsp, |
||
426 | int *datap, |
||
427 | int orient, |
||
428 | int oneplushalf, |
||
429 | int vsc) |
||
430 | { |
||
431 | int v, flag; |
||
432 | |||
433 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
434 | |||
435 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
436 | if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { |
||
437 | mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); |
||
438 | if (mqc_decode(mqc)) { |
||
439 | mqc_setcurctx(mqc, t1_getctxno_sc(flag)); |
||
440 | v = mqc_decode(mqc) ^ t1_getspb(flag); |
||
441 | *datap = v ? -oneplushalf : oneplushalf; |
||
442 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
443 | } |
||
444 | *flagsp |= T1_VISIT; |
||
445 | } |
||
446 | } /* VSC and BYPASS by Antonin */ |
||
447 | |||
448 | static void t1_enc_sigpass( |
||
449 | opj_t1_t *t1, |
||
450 | int bpno, |
||
451 | int orient, |
||
452 | int *nmsedec, |
||
453 | char type, |
||
454 | int cblksty) |
||
455 | { |
||
456 | int i, j, k, one, vsc; |
||
457 | *nmsedec = 0; |
||
458 | one = 1 << (bpno + T1_NMSEDEC_FRACBITS); |
||
459 | for (k = 0; k < t1->h; k += 4) { |
||
460 | for (i = 0; i < t1->w; ++i) { |
||
461 | for (j = k; j < k + 4 && j < t1->h; ++j) { |
||
462 | vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; |
||
463 | t1_enc_sigpass_step( |
||
464 | t1, |
||
465 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
466 | &t1->data[(j * t1->w) + i], |
||
467 | orient, |
||
468 | bpno, |
||
469 | one, |
||
470 | nmsedec, |
||
471 | type, |
||
472 | vsc); |
||
473 | } |
||
474 | } |
||
475 | } |
||
476 | } |
||
477 | |||
478 | static void t1_dec_sigpass_raw( |
||
479 | opj_t1_t *t1, |
||
480 | int bpno, |
||
481 | int orient, |
||
482 | int cblksty) |
||
483 | { |
||
484 | int i, j, k, one, half, oneplushalf, vsc; |
||
485 | one = 1 << bpno; |
||
486 | half = one >> 1; |
||
487 | oneplushalf = one | half; |
||
488 | for (k = 0; k < t1->h; k += 4) { |
||
489 | for (i = 0; i < t1->w; ++i) { |
||
490 | for (j = k; j < k + 4 && j < t1->h; ++j) { |
||
491 | vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; |
||
492 | t1_dec_sigpass_step_raw( |
||
493 | t1, |
||
494 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
495 | &t1->data[(j * t1->w) + i], |
||
496 | orient, |
||
497 | oneplushalf, |
||
498 | vsc); |
||
499 | } |
||
500 | } |
||
501 | } |
||
502 | } /* VSC and BYPASS by Antonin */ |
||
503 | |||
504 | static void t1_dec_sigpass_mqc( |
||
505 | opj_t1_t *t1, |
||
506 | int bpno, |
||
507 | int orient) |
||
508 | { |
||
509 | int i, j, k, one, half, oneplushalf; |
||
510 | int *data1 = t1->data; |
||
511 | flag_t *flags1 = &t1->flags[1]; |
||
512 | one = 1 << bpno; |
||
513 | half = one >> 1; |
||
514 | oneplushalf = one | half; |
||
515 | for (k = 0; k < (t1->h & ~3); k += 4) { |
||
516 | for (i = 0; i < t1->w; ++i) { |
||
517 | int *data2 = data1 + i; |
||
518 | flag_t *flags2 = flags1 + i; |
||
519 | flags2 += t1->flags_stride; |
||
520 | t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); |
||
521 | data2 += t1->w; |
||
522 | flags2 += t1->flags_stride; |
||
523 | t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); |
||
524 | data2 += t1->w; |
||
525 | flags2 += t1->flags_stride; |
||
526 | t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); |
||
527 | data2 += t1->w; |
||
528 | flags2 += t1->flags_stride; |
||
529 | t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); |
||
530 | data2 += t1->w; |
||
531 | } |
||
532 | data1 += t1->w << 2; |
||
533 | flags1 += t1->flags_stride << 2; |
||
534 | } |
||
535 | for (i = 0; i < t1->w; ++i) { |
||
536 | int *data2 = data1 + i; |
||
537 | flag_t *flags2 = flags1 + i; |
||
538 | for (j = k; j < t1->h; ++j) { |
||
539 | flags2 += t1->flags_stride; |
||
540 | t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); |
||
541 | data2 += t1->w; |
||
542 | } |
||
543 | } |
||
544 | } /* VSC and BYPASS by Antonin */ |
||
545 | |||
546 | static void t1_dec_sigpass_mqc_vsc( |
||
547 | opj_t1_t *t1, |
||
548 | int bpno, |
||
549 | int orient) |
||
550 | { |
||
551 | int i, j, k, one, half, oneplushalf, vsc; |
||
552 | one = 1 << bpno; |
||
553 | half = one >> 1; |
||
554 | oneplushalf = one | half; |
||
555 | for (k = 0; k < t1->h; k += 4) { |
||
556 | for (i = 0; i < t1->w; ++i) { |
||
557 | for (j = k; j < k + 4 && j < t1->h; ++j) { |
||
558 | vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0; |
||
559 | t1_dec_sigpass_step_mqc_vsc( |
||
560 | t1, |
||
561 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
562 | &t1->data[(j * t1->w) + i], |
||
563 | orient, |
||
564 | oneplushalf, |
||
565 | vsc); |
||
566 | } |
||
567 | } |
||
568 | } |
||
569 | } /* VSC and BYPASS by Antonin */ |
||
570 | |||
571 | static void t1_enc_refpass_step( |
||
572 | opj_t1_t *t1, |
||
573 | flag_t *flagsp, |
||
574 | int *datap, |
||
575 | int bpno, |
||
576 | int one, |
||
577 | int *nmsedec, |
||
578 | char type, |
||
579 | int vsc) |
||
580 | { |
||
581 | int v, flag; |
||
582 | |||
583 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
584 | |||
585 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
586 | if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { |
||
587 | *nmsedec += t1_getnmsedec_ref(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); |
||
588 | v = int_abs(*datap) & one ? 1 : 0; |
||
589 | mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ |
||
590 | if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ |
||
591 | mqc_bypass_enc(mqc, v); |
||
592 | } else { |
||
593 | mqc_encode(mqc, v); |
||
594 | } |
||
595 | *flagsp |= T1_REFINE; |
||
596 | } |
||
597 | } |
||
598 | |||
599 | static INLINE void t1_dec_refpass_step_raw( |
||
600 | opj_t1_t *t1, |
||
601 | flag_t *flagsp, |
||
602 | int *datap, |
||
603 | int poshalf, |
||
604 | int neghalf, |
||
605 | int vsc) |
||
606 | { |
||
607 | int v, t, flag; |
||
608 | |||
609 | opj_raw_t *raw = t1->raw; /* RAW component */ |
||
610 | |||
611 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
612 | if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { |
||
613 | v = raw_decode(raw); |
||
614 | t = v ? poshalf : neghalf; |
||
615 | *datap += *datap < 0 ? -t : t; |
||
616 | *flagsp |= T1_REFINE; |
||
617 | } |
||
618 | } /* VSC and BYPASS by Antonin */ |
||
619 | |||
620 | static INLINE void t1_dec_refpass_step_mqc( |
||
621 | opj_t1_t *t1, |
||
622 | flag_t *flagsp, |
||
623 | int *datap, |
||
624 | int poshalf, |
||
625 | int neghalf) |
||
626 | { |
||
627 | int v, t, flag; |
||
628 | |||
629 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
630 | |||
631 | flag = *flagsp; |
||
632 | if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { |
||
633 | mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ |
||
634 | v = mqc_decode(mqc); |
||
635 | t = v ? poshalf : neghalf; |
||
636 | *datap += *datap < 0 ? -t : t; |
||
637 | *flagsp |= T1_REFINE; |
||
638 | } |
||
639 | } /* VSC and BYPASS by Antonin */ |
||
640 | |||
641 | static INLINE void t1_dec_refpass_step_mqc_vsc( |
||
642 | opj_t1_t *t1, |
||
643 | flag_t *flagsp, |
||
644 | int *datap, |
||
645 | int poshalf, |
||
646 | int neghalf, |
||
647 | int vsc) |
||
648 | { |
||
649 | int v, t, flag; |
||
650 | |||
651 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
652 | |||
653 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
654 | if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { |
||
655 | mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ |
||
656 | v = mqc_decode(mqc); |
||
657 | t = v ? poshalf : neghalf; |
||
658 | *datap += *datap < 0 ? -t : t; |
||
659 | *flagsp |= T1_REFINE; |
||
660 | } |
||
661 | } /* VSC and BYPASS by Antonin */ |
||
662 | |||
663 | static void t1_enc_refpass( |
||
664 | opj_t1_t *t1, |
||
665 | int bpno, |
||
666 | int *nmsedec, |
||
667 | char type, |
||
668 | int cblksty) |
||
669 | { |
||
670 | int i, j, k, one, vsc; |
||
671 | *nmsedec = 0; |
||
672 | one = 1 << (bpno + T1_NMSEDEC_FRACBITS); |
||
673 | for (k = 0; k < t1->h; k += 4) { |
||
674 | for (i = 0; i < t1->w; ++i) { |
||
675 | for (j = k; j < k + 4 && j < t1->h; ++j) { |
||
676 | vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; |
||
677 | t1_enc_refpass_step( |
||
678 | t1, |
||
679 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
680 | &t1->data[(j * t1->w) + i], |
||
681 | bpno, |
||
682 | one, |
||
683 | nmsedec, |
||
684 | type, |
||
685 | vsc); |
||
686 | } |
||
687 | } |
||
688 | } |
||
689 | } |
||
690 | |||
691 | static void t1_dec_refpass_raw( |
||
692 | opj_t1_t *t1, |
||
693 | int bpno, |
||
694 | int cblksty) |
||
695 | { |
||
696 | int i, j, k, one, poshalf, neghalf; |
||
697 | int vsc; |
||
698 | one = 1 << bpno; |
||
699 | poshalf = one >> 1; |
||
700 | neghalf = bpno > 0 ? -poshalf : -1; |
||
701 | for (k = 0; k < t1->h; k += 4) { |
||
702 | for (i = 0; i < t1->w; ++i) { |
||
703 | for (j = k; j < k + 4 && j < t1->h; ++j) { |
||
704 | vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; |
||
705 | t1_dec_refpass_step_raw( |
||
706 | t1, |
||
707 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
708 | &t1->data[(j * t1->w) + i], |
||
709 | poshalf, |
||
710 | neghalf, |
||
711 | vsc); |
||
712 | } |
||
713 | } |
||
714 | } |
||
715 | } /* VSC and BYPASS by Antonin */ |
||
716 | |||
717 | static void t1_dec_refpass_mqc( |
||
718 | opj_t1_t *t1, |
||
719 | int bpno) |
||
720 | { |
||
721 | int i, j, k, one, poshalf, neghalf; |
||
722 | int *data1 = t1->data; |
||
723 | flag_t *flags1 = &t1->flags[1]; |
||
724 | one = 1 << bpno; |
||
725 | poshalf = one >> 1; |
||
726 | neghalf = bpno > 0 ? -poshalf : -1; |
||
727 | for (k = 0; k < (t1->h & ~3); k += 4) { |
||
728 | for (i = 0; i < t1->w; ++i) { |
||
729 | int *data2 = data1 + i; |
||
730 | flag_t *flags2 = flags1 + i; |
||
731 | flags2 += t1->flags_stride; |
||
732 | t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); |
||
733 | data2 += t1->w; |
||
734 | flags2 += t1->flags_stride; |
||
735 | t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); |
||
736 | data2 += t1->w; |
||
737 | flags2 += t1->flags_stride; |
||
738 | t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); |
||
739 | data2 += t1->w; |
||
740 | flags2 += t1->flags_stride; |
||
741 | t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); |
||
742 | data2 += t1->w; |
||
743 | } |
||
744 | data1 += t1->w << 2; |
||
745 | flags1 += t1->flags_stride << 2; |
||
746 | } |
||
747 | for (i = 0; i < t1->w; ++i) { |
||
748 | int *data2 = data1 + i; |
||
749 | flag_t *flags2 = flags1 + i; |
||
750 | for (j = k; j < t1->h; ++j) { |
||
751 | flags2 += t1->flags_stride; |
||
752 | t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); |
||
753 | data2 += t1->w; |
||
754 | } |
||
755 | } |
||
756 | } /* VSC and BYPASS by Antonin */ |
||
757 | |||
758 | static void t1_dec_refpass_mqc_vsc( |
||
759 | opj_t1_t *t1, |
||
760 | int bpno) |
||
761 | { |
||
762 | int i, j, k, one, poshalf, neghalf; |
||
763 | int vsc; |
||
764 | one = 1 << bpno; |
||
765 | poshalf = one >> 1; |
||
766 | neghalf = bpno > 0 ? -poshalf : -1; |
||
767 | for (k = 0; k < t1->h; k += 4) { |
||
768 | for (i = 0; i < t1->w; ++i) { |
||
769 | for (j = k; j < k + 4 && j < t1->h; ++j) { |
||
770 | vsc = ((j == k + 3 || j == t1->h - 1)) ? 1 : 0; |
||
771 | t1_dec_refpass_step_mqc_vsc( |
||
772 | t1, |
||
773 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
774 | &t1->data[(j * t1->w) + i], |
||
775 | poshalf, |
||
776 | neghalf, |
||
777 | vsc); |
||
778 | } |
||
779 | } |
||
780 | } |
||
781 | } /* VSC and BYPASS by Antonin */ |
||
782 | |||
783 | static void t1_enc_clnpass_step( |
||
784 | opj_t1_t *t1, |
||
785 | flag_t *flagsp, |
||
786 | int *datap, |
||
787 | int orient, |
||
788 | int bpno, |
||
789 | int one, |
||
790 | int *nmsedec, |
||
791 | int partial, |
||
792 | int vsc) |
||
793 | { |
||
794 | int v, flag; |
||
795 | |||
796 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
797 | |||
798 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
799 | if (partial) { |
||
800 | goto LABEL_PARTIAL; |
||
801 | } |
||
802 | if (!(*flagsp & (T1_SIG | T1_VISIT))) { |
||
803 | mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); |
||
804 | v = int_abs(*datap) & one ? 1 : 0; |
||
805 | mqc_encode(mqc, v); |
||
806 | if (v) { |
||
807 | LABEL_PARTIAL: |
||
808 | *nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); |
||
809 | mqc_setcurctx(mqc, t1_getctxno_sc(flag)); |
||
810 | v = *datap < 0 ? 1 : 0; |
||
811 | mqc_encode(mqc, v ^ t1_getspb(flag)); |
||
812 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
813 | } |
||
814 | } |
||
815 | *flagsp &= ~T1_VISIT; |
||
816 | } |
||
817 | |||
818 | static void t1_dec_clnpass_step_partial( |
||
819 | opj_t1_t *t1, |
||
820 | flag_t *flagsp, |
||
821 | int *datap, |
||
822 | int orient, |
||
823 | int oneplushalf) |
||
824 | { |
||
825 | int v, flag; |
||
826 | |||
827 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
828 | |||
829 | flag = *flagsp; |
||
830 | mqc_setcurctx(mqc, t1_getctxno_sc(flag)); |
||
831 | v = mqc_decode(mqc) ^ t1_getspb(flag); |
||
832 | *datap = v ? -oneplushalf : oneplushalf; |
||
833 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
834 | *flagsp &= ~T1_VISIT; |
||
835 | } /* VSC and BYPASS by Antonin */ |
||
836 | |||
837 | static void t1_dec_clnpass_step( |
||
838 | opj_t1_t *t1, |
||
839 | flag_t *flagsp, |
||
840 | int *datap, |
||
841 | int orient, |
||
842 | int oneplushalf) |
||
843 | { |
||
844 | int v, flag; |
||
845 | |||
846 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
847 | |||
848 | flag = *flagsp; |
||
849 | if (!(flag & (T1_SIG | T1_VISIT))) { |
||
850 | mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); |
||
851 | if (mqc_decode(mqc)) { |
||
852 | mqc_setcurctx(mqc, t1_getctxno_sc(flag)); |
||
853 | v = mqc_decode(mqc) ^ t1_getspb(flag); |
||
854 | *datap = v ? -oneplushalf : oneplushalf; |
||
855 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
856 | } |
||
857 | } |
||
858 | *flagsp &= ~T1_VISIT; |
||
859 | } /* VSC and BYPASS by Antonin */ |
||
860 | |||
861 | static void t1_dec_clnpass_step_vsc( |
||
862 | opj_t1_t *t1, |
||
863 | flag_t *flagsp, |
||
864 | int *datap, |
||
865 | int orient, |
||
866 | int oneplushalf, |
||
867 | int partial, |
||
868 | int vsc) |
||
869 | { |
||
870 | int v, flag; |
||
871 | |||
872 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
873 | |||
874 | flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); |
||
875 | if (partial) { |
||
876 | goto LABEL_PARTIAL; |
||
877 | } |
||
878 | if (!(flag & (T1_SIG | T1_VISIT))) { |
||
879 | mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); |
||
880 | if (mqc_decode(mqc)) { |
||
881 | LABEL_PARTIAL: |
||
882 | mqc_setcurctx(mqc, t1_getctxno_sc(flag)); |
||
883 | v = mqc_decode(mqc) ^ t1_getspb(flag); |
||
884 | *datap = v ? -oneplushalf : oneplushalf; |
||
885 | t1_updateflags(flagsp, v, t1->flags_stride); |
||
886 | } |
||
887 | } |
||
888 | *flagsp &= ~T1_VISIT; |
||
889 | } |
||
890 | |||
891 | static void t1_enc_clnpass( |
||
892 | opj_t1_t *t1, |
||
893 | int bpno, |
||
894 | int orient, |
||
895 | int *nmsedec, |
||
896 | int cblksty) |
||
897 | { |
||
898 | int i, j, k, one, agg, runlen, vsc; |
||
899 | |||
900 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
901 | |||
902 | *nmsedec = 0; |
||
903 | one = 1 << (bpno + T1_NMSEDEC_FRACBITS); |
||
904 | for (k = 0; k < t1->h; k += 4) { |
||
905 | for (i = 0; i < t1->w; ++i) { |
||
906 | if (k + 3 < t1->h) { |
||
907 | if (cblksty & J2K_CCP_CBLKSTY_VSC) { |
||
908 | agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
909 | || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
910 | || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
911 | || (MACRO_t1_flags(1 + k + 3,1 + i) |
||
912 | & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); |
||
913 | } else { |
||
914 | agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
915 | || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
916 | || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
917 | || MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); |
||
918 | } |
||
919 | } else { |
||
920 | agg = 0; |
||
921 | } |
||
922 | if (agg) { |
||
923 | for (runlen = 0; runlen < 4; ++runlen) { |
||
924 | if (int_abs(t1->data[((k + runlen)*t1->w) + i]) & one) |
||
925 | break; |
||
926 | } |
||
927 | mqc_setcurctx(mqc, T1_CTXNO_AGG); |
||
928 | mqc_encode(mqc, runlen != 4); |
||
929 | if (runlen == 4) { |
||
930 | continue; |
||
931 | } |
||
932 | mqc_setcurctx(mqc, T1_CTXNO_UNI); |
||
933 | mqc_encode(mqc, runlen >> 1); |
||
934 | mqc_encode(mqc, runlen & 1); |
||
935 | } else { |
||
936 | runlen = 0; |
||
937 | } |
||
938 | for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { |
||
939 | vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; |
||
940 | t1_enc_clnpass_step( |
||
941 | t1, |
||
942 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
943 | &t1->data[(j * t1->w) + i], |
||
944 | orient, |
||
945 | bpno, |
||
946 | one, |
||
947 | nmsedec, |
||
948 | agg && (j == k + runlen), |
||
949 | vsc); |
||
950 | } |
||
951 | } |
||
952 | } |
||
953 | } |
||
954 | |||
955 | static void t1_dec_clnpass( |
||
956 | opj_t1_t *t1, |
||
957 | int bpno, |
||
958 | int orient, |
||
959 | int cblksty) |
||
960 | { |
||
961 | int i, j, k, one, half, oneplushalf, agg, runlen, vsc; |
||
962 | int segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; |
||
963 | |||
964 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
965 | |||
966 | one = 1 << bpno; |
||
967 | half = one >> 1; |
||
968 | oneplushalf = one | half; |
||
969 | if (cblksty & J2K_CCP_CBLKSTY_VSC) { |
||
970 | for (k = 0; k < t1->h; k += 4) { |
||
971 | for (i = 0; i < t1->w; ++i) { |
||
972 | if (k + 3 < t1->h) { |
||
973 | agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
974 | || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
975 | || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
976 | || (MACRO_t1_flags(1 + k + 3,1 + i) |
||
977 | & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); |
||
978 | } else { |
||
979 | agg = 0; |
||
980 | } |
||
981 | if (agg) { |
||
982 | mqc_setcurctx(mqc, T1_CTXNO_AGG); |
||
983 | if (!mqc_decode(mqc)) { |
||
984 | continue; |
||
985 | } |
||
986 | mqc_setcurctx(mqc, T1_CTXNO_UNI); |
||
987 | runlen = mqc_decode(mqc); |
||
988 | runlen = (runlen << 1) | mqc_decode(mqc); |
||
989 | } else { |
||
990 | runlen = 0; |
||
991 | } |
||
992 | for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { |
||
993 | vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0; |
||
994 | t1_dec_clnpass_step_vsc( |
||
995 | t1, |
||
996 | &t1->flags[((j+1) * t1->flags_stride) + i + 1], |
||
997 | &t1->data[(j * t1->w) + i], |
||
998 | orient, |
||
999 | oneplushalf, |
||
1000 | agg && (j == k + runlen), |
||
1001 | vsc); |
||
1002 | } |
||
1003 | } |
||
1004 | } |
||
1005 | } else { |
||
1006 | int *data1 = t1->data; |
||
1007 | flag_t *flags1 = &t1->flags[1]; |
||
1008 | for (k = 0; k < (t1->h & ~3); k += 4) { |
||
1009 | for (i = 0; i < t1->w; ++i) { |
||
1010 | int *data2 = data1 + i; |
||
1011 | flag_t *flags2 = flags1 + i; |
||
1012 | agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
1013 | || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
1014 | || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) |
||
1015 | || MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); |
||
1016 | if (agg) { |
||
1017 | mqc_setcurctx(mqc, T1_CTXNO_AGG); |
||
1018 | if (!mqc_decode(mqc)) { |
||
1019 | continue; |
||
1020 | } |
||
1021 | mqc_setcurctx(mqc, T1_CTXNO_UNI); |
||
1022 | runlen = mqc_decode(mqc); |
||
1023 | runlen = (runlen << 1) | mqc_decode(mqc); |
||
1024 | flags2 += runlen * t1->flags_stride; |
||
1025 | data2 += runlen * t1->w; |
||
1026 | for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { |
||
1027 | flags2 += t1->flags_stride; |
||
1028 | if (agg && (j == k + runlen)) { |
||
1029 | t1_dec_clnpass_step_partial(t1, flags2, data2, orient, oneplushalf); |
||
1030 | } else { |
||
1031 | t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); |
||
1032 | } |
||
1033 | data2 += t1->w; |
||
1034 | } |
||
1035 | } else { |
||
1036 | flags2 += t1->flags_stride; |
||
1037 | t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); |
||
1038 | data2 += t1->w; |
||
1039 | flags2 += t1->flags_stride; |
||
1040 | t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); |
||
1041 | data2 += t1->w; |
||
1042 | flags2 += t1->flags_stride; |
||
1043 | t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); |
||
1044 | data2 += t1->w; |
||
1045 | flags2 += t1->flags_stride; |
||
1046 | t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); |
||
1047 | data2 += t1->w; |
||
1048 | } |
||
1049 | } |
||
1050 | data1 += t1->w << 2; |
||
1051 | flags1 += t1->flags_stride << 2; |
||
1052 | } |
||
1053 | for (i = 0; i < t1->w; ++i) { |
||
1054 | int *data2 = data1 + i; |
||
1055 | flag_t *flags2 = flags1 + i; |
||
1056 | for (j = k; j < t1->h; ++j) { |
||
1057 | flags2 += t1->flags_stride; |
||
1058 | t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); |
||
1059 | data2 += t1->w; |
||
1060 | } |
||
1061 | } |
||
1062 | } |
||
1063 | |||
1064 | if (segsym) { |
||
1065 | int v = 0; |
||
1066 | mqc_setcurctx(mqc, T1_CTXNO_UNI); |
||
1067 | v = mqc_decode(mqc); |
||
1068 | v = (v << 1) | mqc_decode(mqc); |
||
1069 | v = (v << 1) | mqc_decode(mqc); |
||
1070 | v = (v << 1) | mqc_decode(mqc); |
||
1071 | /* |
||
1072 | if (v!=0xa) { |
||
1073 | opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); |
||
1074 | } |
||
1075 | */ |
||
1076 | } |
||
1077 | } /* VSC and BYPASS by Antonin */ |
||
1078 | |||
1079 | |||
1080 | /** mod fixed_quality */ |
||
1081 | static double t1_getwmsedec( |
||
1082 | int nmsedec, |
||
1083 | int compno, |
||
1084 | int level, |
||
1085 | int orient, |
||
1086 | int bpno, |
||
1087 | int qmfbid, |
||
1088 | double stepsize, |
||
1089 | int numcomps, |
||
1090 | int mct) |
||
1091 | { |
||
1092 | double w1, w2, wmsedec; |
||
1093 | if (qmfbid == 1) { |
||
1094 | w1 = (mct && numcomps==3) ? mct_getnorm(compno) : 1.0; |
||
1095 | w2 = dwt_getnorm(level, orient); |
||
1096 | } else { /* if (qmfbid == 0) */ |
||
1097 | w1 = (mct && numcomps==3) ? mct_getnorm_real(compno) : 1.0; |
||
1098 | w2 = dwt_getnorm_real(level, orient); |
||
1099 | } |
||
1100 | wmsedec = w1 * w2 * stepsize * (1 << bpno); |
||
1101 | wmsedec *= wmsedec * nmsedec / 8192.0; |
||
1102 | |||
1103 | return wmsedec; |
||
1104 | } |
||
1105 | |||
1106 | static bool allocate_buffers( |
||
1107 | opj_t1_t *t1, |
||
1108 | int w, |
||
1109 | int h) |
||
1110 | { |
||
1111 | int datasize=w * h; |
||
1112 | int flagssize; |
||
1113 | |||
1114 | if(datasize > t1->datasize){ |
||
1115 | opj_aligned_free(t1->data); |
||
1116 | t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int)); |
||
1117 | if(!t1->data){ |
||
1118 | return false; |
||
1119 | } |
||
1120 | t1->datasize=datasize; |
||
1121 | } |
||
1122 | memset(t1->data,0,datasize * sizeof(int)); |
||
1123 | |||
1124 | t1->flags_stride=w+2; |
||
1125 | flagssize=t1->flags_stride * (h+2); |
||
1126 | |||
1127 | if(flagssize > t1->flagssize){ |
||
1128 | opj_aligned_free(t1->flags); |
||
1129 | t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t)); |
||
1130 | if(!t1->flags){ |
||
1131 | return false; |
||
1132 | } |
||
1133 | t1->flagssize=flagssize; |
||
1134 | } |
||
1135 | memset(t1->flags,0,flagssize * sizeof(flag_t)); |
||
1136 | |||
1137 | t1->w=w; |
||
1138 | t1->h=h; |
||
1139 | |||
1140 | return true; |
||
1141 | } |
||
1142 | |||
1143 | /** mod fixed_quality */ |
||
1144 | static void t1_encode_cblk( |
||
1145 | opj_t1_t *t1, |
||
1146 | opj_tcd_cblk_enc_t* cblk, |
||
1147 | int orient, |
||
1148 | int compno, |
||
1149 | int level, |
||
1150 | int qmfbid, |
||
1151 | double stepsize, |
||
1152 | int cblksty, |
||
1153 | int numcomps, |
||
1154 | int mct, |
||
1155 | opj_tcd_tile_t * tile) |
||
1156 | { |
||
1157 | double cumwmsedec = 0.0; |
||
1158 | |||
1159 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
1160 | |||
1161 | int passno, bpno, passtype; |
||
1162 | int nmsedec = 0; |
||
1163 | int i, max; |
||
1164 | char type = T1_TYPE_MQ; |
||
1165 | double tempwmsedec; |
||
1166 | |||
1167 | max = 0; |
||
1168 | for (i = 0; i < t1->w * t1->h; ++i) { |
||
1169 | int tmp = abs(t1->data[i]); |
||
1170 | max = int_max(max, tmp); |
||
1171 | } |
||
1172 | |||
1173 | cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; |
||
1174 | |||
1175 | bpno = cblk->numbps - 1; |
||
1176 | passtype = 2; |
||
1177 | |||
1178 | mqc_resetstates(mqc); |
||
1179 | mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); |
||
1180 | mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); |
||
1181 | mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); |
||
1182 | mqc_init_enc(mqc, cblk->data); |
||
1183 | |||
1184 | for (passno = 0; bpno >= 0; ++passno) { |
||
1185 | opj_tcd_pass_t *pass = &cblk->passes[passno]; |
||
1186 | int correction = 3; |
||
1187 | type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; |
||
1188 | |||
1189 | switch (passtype) { |
||
1190 | case 0: |
||
1191 | t1_enc_sigpass(t1, bpno, orient, &nmsedec, type, cblksty); |
||
1192 | break; |
||
1193 | case 1: |
||
1194 | t1_enc_refpass(t1, bpno, &nmsedec, type, cblksty); |
||
1195 | break; |
||
1196 | case 2: |
||
1197 | t1_enc_clnpass(t1, bpno, orient, &nmsedec, cblksty); |
||
1198 | /* code switch SEGMARK (i.e. SEGSYM) */ |
||
1199 | if (cblksty & J2K_CCP_CBLKSTY_SEGSYM) |
||
1200 | mqc_segmark_enc(mqc); |
||
1201 | break; |
||
1202 | } |
||
1203 | |||
1204 | /* fixed_quality */ |
||
1205 | tempwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps, mct); |
||
1206 | cumwmsedec += tempwmsedec; |
||
1207 | tile->distotile += tempwmsedec; |
||
1208 | |||
1209 | /* Code switch "RESTART" (i.e. TERMALL) */ |
||
1210 | if ((cblksty & J2K_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { |
||
1211 | if (type == T1_TYPE_RAW) { |
||
1212 | mqc_flush(mqc); |
||
1213 | correction = 1; |
||
1214 | /* correction = mqc_bypass_flush_enc(); */ |
||
1215 | } else { /* correction = mqc_restart_enc(); */ |
||
1216 | mqc_flush(mqc); |
||
1217 | correction = 1; |
||
1218 | } |
||
1219 | pass->term = 1; |
||
1220 | } else { |
||
1221 | if (((bpno < (cblk->numbps - 4) && (passtype > 0)) |
||
1222 | || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) { |
||
1223 | if (type == T1_TYPE_RAW) { |
||
1224 | mqc_flush(mqc); |
||
1225 | correction = 1; |
||
1226 | /* correction = mqc_bypass_flush_enc(); */ |
||
1227 | } else { /* correction = mqc_restart_enc(); */ |
||
1228 | mqc_flush(mqc); |
||
1229 | correction = 1; |
||
1230 | } |
||
1231 | pass->term = 1; |
||
1232 | } else { |
||
1233 | pass->term = 0; |
||
1234 | } |
||
1235 | } |
||
1236 | |||
1237 | if (++passtype == 3) { |
||
1238 | passtype = 0; |
||
1239 | bpno--; |
||
1240 | } |
||
1241 | |||
1242 | if (pass->term && bpno > 0) { |
||
1243 | type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; |
||
1244 | if (type == T1_TYPE_RAW) |
||
1245 | mqc_bypass_init_enc(mqc); |
||
1246 | else |
||
1247 | mqc_restart_init_enc(mqc); |
||
1248 | } |
||
1249 | |||
1250 | pass->distortiondec = cumwmsedec; |
||
1251 | pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */ |
||
1252 | |||
1253 | /* Code-switch "RESET" */ |
||
1254 | if (cblksty & J2K_CCP_CBLKSTY_RESET) |
||
1255 | mqc_reset_enc(mqc); |
||
1256 | } |
||
1257 | |||
1258 | /* Code switch "ERTERM" (i.e. PTERM) */ |
||
1259 | if (cblksty & J2K_CCP_CBLKSTY_PTERM) |
||
1260 | mqc_erterm_enc(mqc); |
||
1261 | else /* Default coding */ if (!(cblksty & J2K_CCP_CBLKSTY_LAZY)) |
||
1262 | mqc_flush(mqc); |
||
1263 | |||
1264 | cblk->totalpasses = passno; |
||
1265 | |||
1266 | for (passno = 0; passno |
||
1267 | opj_tcd_pass_t *pass = &cblk->passes[passno]; |
||
1268 | if (pass->rate > mqc_numbytes(mqc)) |
||
1269 | pass->rate = mqc_numbytes(mqc); |
||
1270 | /*Preventing generation of FF as last data byte of a pass*/ |
||
1271 | if((pass->rate>1) && (cblk->data[pass->rate - 1] == 0xFF)){ |
||
1272 | pass->rate--; |
||
1273 | } |
||
1274 | pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); |
||
1275 | } |
||
1276 | } |
||
1277 | |||
1278 | static void t1_decode_cblk( |
||
1279 | opj_t1_t *t1, |
||
1280 | opj_tcd_cblk_dec_t* cblk, |
||
1281 | int orient, |
||
1282 | int roishift, |
||
1283 | int cblksty) |
||
1284 | { |
||
1285 | opj_raw_t *raw = t1->raw; /* RAW component */ |
||
1286 | opj_mqc_t *mqc = t1->mqc; /* MQC component */ |
||
1287 | |||
1288 | int bpno, passtype; |
||
1289 | int segno, passno; |
||
1290 | char type = T1_TYPE_MQ; /* BYPASS mode */ |
||
1291 | |||
1292 | if(!allocate_buffers( |
||
1293 | t1, |
||
1294 | cblk->x1 - cblk->x0, |
||
1295 | cblk->y1 - cblk->y0)) |
||
1296 | { |
||
1297 | return; |
||
1298 | } |
||
1299 | |||
1300 | bpno = roishift + cblk->numbps - 1; |
||
1301 | passtype = 2; |
||
1302 | |||
1303 | mqc_resetstates(mqc); |
||
1304 | mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); |
||
1305 | mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); |
||
1306 | mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); |
||
1307 | |||
1308 | for (segno = 0; segno < cblk->numsegs; ++segno) { |
||
1309 | opj_tcd_seg_t *seg = &cblk->segs[segno]; |
||
1310 | |||
1311 | /* BYPASS mode */ |
||
1312 | type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; |
||
1313 | /* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */ |
||
1314 | if(seg->data == NULL){ |
||
1315 | continue; |
||
1316 | } |
||
1317 | if (type == T1_TYPE_RAW) { |
||
1318 | raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len); |
||
1319 | } else { |
||
1320 | mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len); |
||
1321 | } |
||
1322 | |||
1323 | for (passno = 0; passno < seg->numpasses; ++passno) { |
||
1324 | switch (passtype) { |
||
1325 | case 0: |
||
1326 | if (type == T1_TYPE_RAW) { |
||
1327 | t1_dec_sigpass_raw(t1, bpno+1, orient, cblksty); |
||
1328 | } else { |
||
1329 | if (cblksty & J2K_CCP_CBLKSTY_VSC) { |
||
1330 | t1_dec_sigpass_mqc_vsc(t1, bpno+1, orient); |
||
1331 | } else { |
||
1332 | t1_dec_sigpass_mqc(t1, bpno+1, orient); |
||
1333 | } |
||
1334 | } |
||
1335 | break; |
||
1336 | case 1: |
||
1337 | if (type == T1_TYPE_RAW) { |
||
1338 | t1_dec_refpass_raw(t1, bpno+1, cblksty); |
||
1339 | } else { |
||
1340 | if (cblksty & J2K_CCP_CBLKSTY_VSC) { |
||
1341 | t1_dec_refpass_mqc_vsc(t1, bpno+1); |
||
1342 | } else { |
||
1343 | t1_dec_refpass_mqc(t1, bpno+1); |
||
1344 | } |
||
1345 | } |
||
1346 | break; |
||
1347 | case 2: |
||
1348 | t1_dec_clnpass(t1, bpno+1, orient, cblksty); |
||
1349 | break; |
||
1350 | } |
||
1351 | |||
1352 | if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { |
||
1353 | mqc_resetstates(mqc); |
||
1354 | mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); |
||
1355 | mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); |
||
1356 | mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); |
||
1357 | } |
||
1358 | if (++passtype == 3) { |
||
1359 | passtype = 0; |
||
1360 | bpno--; |
||
1361 | } |
||
1362 | } |
||
1363 | } |
||
1364 | } |
||
1365 | |||
1366 | /* ----------------------------------------------------------------------- */ |
||
1367 | |||
1368 | opj_t1_t* t1_create(opj_common_ptr cinfo) { |
||
1369 | opj_t1_t *t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t)); |
||
1370 | if(!t1) |
||
1371 | return NULL; |
||
1372 | |||
1373 | t1->cinfo = cinfo; |
||
1374 | /* create MQC and RAW handles */ |
||
1375 | t1->mqc = mqc_create(); |
||
1376 | t1->raw = raw_create(); |
||
1377 | |||
1378 | t1->data=NULL; |
||
1379 | t1->flags=NULL; |
||
1380 | t1->datasize=0; |
||
1381 | t1->flagssize=0; |
||
1382 | |||
1383 | return t1; |
||
1384 | } |
||
1385 | |||
1386 | void t1_destroy(opj_t1_t *t1) { |
||
1387 | if(t1) { |
||
1388 | /* destroy MQC and RAW handles */ |
||
1389 | mqc_destroy(t1->mqc); |
||
1390 | raw_destroy(t1->raw); |
||
1391 | opj_aligned_free(t1->data); |
||
1392 | opj_aligned_free(t1->flags); |
||
1393 | opj_free(t1); |
||
1394 | } |
||
1395 | } |
||
1396 | |||
1397 | void t1_encode_cblks( |
||
1398 | opj_t1_t *t1, |
||
1399 | opj_tcd_tile_t *tile, |
||
1400 | opj_tcp_t *tcp) |
||
1401 | { |
||
1402 | int compno, resno, bandno, precno, cblkno; |
||
1403 | |||
1404 | tile->distotile = 0; /* fixed_quality */ |
||
1405 | |||
1406 | for (compno = 0; compno < tile->numcomps; ++compno) { |
||
1407 | opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; |
||
1408 | opj_tccp_t* tccp = &tcp->tccps[compno]; |
||
1409 | int tile_w = tilec->x1 - tilec->x0; |
||
1410 | |||
1411 | for (resno = 0; resno < tilec->numresolutions; ++resno) { |
||
1412 | opj_tcd_resolution_t *res = &tilec->resolutions[resno]; |
||
1413 | |||
1414 | for (bandno = 0; bandno < res->numbands; ++bandno) { |
||
1415 | opj_tcd_band_t* restrict band = &res->bands[bandno]; |
||
1416 | |||
1417 | for (precno = 0; precno < res->pw * res->ph; ++precno) { |
||
1418 | opj_tcd_precinct_t *prc = &band->precincts[precno]; |
||
1419 | |||
1420 | for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) { |
||
1421 | opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; |
||
1422 | int* restrict datap; |
||
1423 | int* restrict tiledp; |
||
1424 | int cblk_w; |
||
1425 | int cblk_h; |
||
1426 | int i, j; |
||
1427 | |||
1428 | int x = cblk->x0 - band->x0; |
||
1429 | int y = cblk->y0 - band->y0; |
||
1430 | if (band->bandno & 1) { |
||
1431 | opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; |
||
1432 | x += pres->x1 - pres->x0; |
||
1433 | } |
||
1434 | if (band->bandno & 2) { |
||
1435 | opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; |
||
1436 | y += pres->y1 - pres->y0; |
||
1437 | } |
||
1438 | |||
1439 | if(!allocate_buffers( |
||
1440 | t1, |
||
1441 | cblk->x1 - cblk->x0, |
||
1442 | cblk->y1 - cblk->y0)) |
||
1443 | { |
||
1444 | return; |
||
1445 | } |
||
1446 | |||
1447 | datap=t1->data; |
||
1448 | cblk_w = t1->w; |
||
1449 | cblk_h = t1->h; |
||
1450 | |||
1451 | tiledp=&tilec->data[(y * tile_w) + x]; |
||
1452 | if (tccp->qmfbid == 1) { |
||
1453 | for (j = 0; j < cblk_h; ++j) { |
||
1454 | for (i = 0; i < cblk_w; ++i) { |
||
1455 | int tmp = tiledp[(j * tile_w) + i]; |
||
1456 | datap[(j * cblk_w) + i] = tmp << T1_NMSEDEC_FRACBITS; |
||
1457 | } |
||
1458 | } |
||
1459 | } else { /* if (tccp->qmfbid == 0) */ |
||
1460 | for (j = 0; j < cblk_h; ++j) { |
||
1461 | for (i = 0; i < cblk_w; ++i) { |
||
1462 | int tmp = tiledp[(j * tile_w) + i]; |
||
1463 | datap[(j * cblk_w) + i] = |
||
1464 | fix_mul( |
||
1465 | tmp, |
||
1466 | 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (11 - T1_NMSEDEC_FRACBITS); |
||
1467 | } |
||
1468 | } |
||
1469 | } |
||
1470 | |||
1471 | t1_encode_cblk( |
||
1472 | t1, |
||
1473 | cblk, |
||
1474 | band->bandno, |
||
1475 | compno, |
||
1476 | tilec->numresolutions - 1 - resno, |
||
1477 | tccp->qmfbid, |
||
1478 | band->stepsize, |
||
1479 | tccp->cblksty, |
||
1480 | tile->numcomps, |
||
1481 | tcp->mct, |
||
1482 | tile); |
||
1483 | |||
1484 | } /* cblkno */ |
||
1485 | } /* precno */ |
||
1486 | } /* bandno */ |
||
1487 | } /* resno */ |
||
1488 | } /* compno */ |
||
1489 | } |
||
1490 | |||
1491 | void t1_decode_cblks( |
||
1492 | opj_t1_t* t1, |
||
1493 | opj_tcd_tilecomp_t* tilec, |
||
1494 | opj_tccp_t* tccp) |
||
1495 | { |
||
1496 | int resno, bandno, precno, cblkno; |
||
1497 | |||
1498 | int tile_w = tilec->x1 - tilec->x0; |
||
1499 | |||
1500 | for (resno = 0; resno < tilec->numresolutions; ++resno) { |
||
1501 | opj_tcd_resolution_t* res = &tilec->resolutions[resno]; |
||
1502 | |||
1503 | for (bandno = 0; bandno < res->numbands; ++bandno) { |
||
1504 | opj_tcd_band_t* restrict band = &res->bands[bandno]; |
||
1505 | |||
1506 | for (precno = 0; precno < res->pw * res->ph; ++precno) { |
||
1507 | opj_tcd_precinct_t* precinct = &band->precincts[precno]; |
||
1508 | |||
1509 | for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) { |
||
1510 | opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno]; |
||
1511 | int* restrict datap; |
||
1512 | int cblk_w, cblk_h; |
||
1513 | int x, y; |
||
1514 | int i, j; |
||
1515 | |||
1516 | t1_decode_cblk( |
||
1517 | t1, |
||
1518 | cblk, |
||
1519 | band->bandno, |
||
1520 | tccp->roishift, |
||
1521 | tccp->cblksty); |
||
1522 | |||
1523 | x = cblk->x0 - band->x0; |
||
1524 | y = cblk->y0 - band->y0; |
||
1525 | if (band->bandno & 1) { |
||
1526 | opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; |
||
1527 | x += pres->x1 - pres->x0; |
||
1528 | } |
||
1529 | if (band->bandno & 2) { |
||
1530 | opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; |
||
1531 | y += pres->y1 - pres->y0; |
||
1532 | } |
||
1533 | |||
1534 | datap=t1->data; |
||
1535 | cblk_w = t1->w; |
||
1536 | cblk_h = t1->h; |
||
1537 | |||
1538 | if (tccp->roishift) { |
||
1539 | int thresh = 1 << tccp->roishift; |
||
1540 | for (j = 0; j < cblk_h; ++j) { |
||
1541 | for (i = 0; i < cblk_w; ++i) { |
||
1542 | int val = datap[(j * cblk_w) + i]; |
||
1543 | int mag = abs(val); |
||
1544 | if (mag >= thresh) { |
||
1545 | mag >>= tccp->roishift; |
||
1546 | datap[(j * cblk_w) + i] = val < 0 ? -mag : mag; |
||
1547 | } |
||
1548 | } |
||
1549 | } |
||
1550 | } |
||
1551 | |||
1552 | if (tccp->qmfbid == 1) { |
||
1553 | int* restrict tiledp = &tilec->data[(y * tile_w) + x]; |
||
1554 | for (j = 0; j < cblk_h; ++j) { |
||
1555 | for (i = 0; i < cblk_w; ++i) { |
||
1556 | int tmp = datap[(j * cblk_w) + i]; |
||
1557 | ((int*)tiledp)[(j * tile_w) + i] = tmp / 2; |
||
1558 | } |
||
1559 | } |
||
1560 | } else { /* if (tccp->qmfbid == 0) */ |
||
1561 | float* restrict tiledp = (float*) &tilec->data[(y * tile_w) + x]; |
||
1562 | for (j = 0; j < cblk_h; ++j) { |
||
1563 | float* restrict tiledp2 = tiledp; |
||
1564 | for (i = 0; i < cblk_w; ++i) { |
||
1565 | float tmp = *datap * band->stepsize; |
||
1566 | *tiledp2 = tmp; |
||
1567 | datap++; |
||
1568 | tiledp2++; |
||
1569 | } |
||
1570 | tiledp += tile_w; |
||
1571 | } |
||
1572 | } |
||
1573 | opj_free(cblk->data); |
||
1574 | opj_free(cblk->segs); |
||
1575 | } /* cblkno */ |
||
1576 | opj_free(precinct->cblks.dec); |
||
1577 | } /* precno */ |
||
1578 | } /* bandno */ |
||
1579 | } /* resno */ |
||
1580 | }>>>>>>>><>>>>>>>><>>>>>>>>>>=>>>>>>>>>><>><>><>><>>>><>><>>>><>>>>>><>>>>><>>>>>>>><>>>>>>><>>>><>><>>>><>>>>>><>>>>>><>>>>>>>>><>>>><>><>>>><>>>>>><>>>>>><>>><>><>><>><>><> |
||
1581 |