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) 2006-2007, Parvatha Elangovan
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
33 #include "opj_includes.h"
35 /** @defgroup PI PI - Implementation of a packet iterator */
38 /** @name Local static functions */
42 Get next packet in layer-resolution-component-precinct order.
43 @param pi packet iterator to modify
44 @return returns false if pi pointed to the last packet or else returns true
46 static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi);
48 Get next packet in resolution-layer-component-precinct order.
49 @param pi packet iterator to modify
50 @return returns false if pi pointed to the last packet or else returns true
52 static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi);
54 Get next packet in resolution-precinct-component-layer order.
55 @param pi packet iterator to modify
56 @return returns false if pi pointed to the last packet or else returns true
58 static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi);
60 Get next packet in precinct-component-resolution-layer order.
61 @param pi packet iterator to modify
62 @return returns false if pi pointed to the last packet or else returns true
64 static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi);
66 Get next packet in component-precinct-resolution-layer order.
67 @param pi packet iterator to modify
68 @return returns false if pi pointed to the last packet or else returns true
70 static opj_bool pi_next_cprl(opj_pi_iterator_t * pi);
73 * Updates the coding parameters if the encoding is used with Progression order changes and final (or cinema parameters are used).
75 * @param p_cp the coding parameters to modify
76 * @param p_tileno the tile index being concerned.
77 * @param p_tx0 X0 parameter for the tile
78 * @param p_tx1 X1 parameter for the tile
79 * @param p_ty0 Y0 parameter for the tile
80 * @param p_ty1 Y1 parameter for the tile
81 * @param p_max_prec the maximum precision for all the bands of the tile
82 * @param p_max_res the maximum number of resolutions for all the poc inside the tile.
83 * @param p_dx_min the minimum dx of all the components of all the resolutions for the tile.
84 * @param p_dy_min the minimum dy of all the components of all the resolutions for the tile.
86 static void pi_update_encode_poc_and_final (opj_cp_v2_t *p_cp,
92 OPJ_UINT32 p_max_prec,
97 void pi_update_encode_not_poc ( opj_cp_v2_t *p_cp,
98 OPJ_UINT32 p_num_comps,
104 OPJ_UINT32 p_max_prec,
105 OPJ_UINT32 p_max_res,
107 OPJ_UINT32 p_dy_min);
109 void get_encoding_parameters( const opj_image_t *p_image,
110 const opj_cp_v2_t *p_cp,
116 OPJ_UINT32 * p_dx_min,
117 OPJ_UINT32 * p_dy_min,
118 OPJ_UINT32 * p_max_prec,
119 OPJ_UINT32 * p_max_res );
121 void get_all_encoding_parameters(
122 const opj_image_t *p_image,
123 const opj_cp_v2_t *p_cp,
129 OPJ_UINT32 * p_dx_min,
130 OPJ_UINT32 * p_dy_min,
131 OPJ_UINT32 * p_max_prec,
132 OPJ_UINT32 * p_max_res,
133 OPJ_UINT32 ** p_resolutions
136 opj_pi_iterator_t * pi_create( const opj_image_t *image,
137 const opj_cp_v2_t *cp,
140 void pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res);
141 void pi_update_decode_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res);
143 OPJ_INT32 pi_check_next_level( OPJ_INT32 pos,
147 const OPJ_CHAR *prog);
154 ==========================================================
156 ==========================================================
159 static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi) {
160 opj_pi_comp_t *comp = NULL;
161 opj_pi_resolution_t *res = NULL;
165 comp = &pi->comps[pi->compno];
166 res = &comp->resolutions[pi->resno];
172 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
173 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
175 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
176 comp = &pi->comps[pi->compno];
177 if (pi->resno >= comp->numresolutions) {
180 res = &comp->resolutions[pi->resno];
182 pi->poc.precno1 = res->pw * res->ph;
184 for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
185 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
186 if (!pi->include[index]) {
187 pi->include[index] = 1;
199 static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi) {
200 opj_pi_comp_t *comp = NULL;
201 opj_pi_resolution_t *res = NULL;
205 comp = &pi->comps[pi->compno];
206 res = &comp->resolutions[pi->resno];
212 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
213 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
214 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
215 comp = &pi->comps[pi->compno];
216 if (pi->resno >= comp->numresolutions) {
219 res = &comp->resolutions[pi->resno];
221 pi->poc.precno1 = res->pw * res->ph;
223 for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
224 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
225 if (!pi->include[index]) {
226 pi->include[index] = 1;
238 static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi) {
239 opj_pi_comp_t *comp = NULL;
240 opj_pi_resolution_t *res = NULL;
250 for (compno = 0; compno < pi->numcomps; compno++) {
251 comp = &pi->comps[compno];
252 for (resno = 0; resno < comp->numresolutions; resno++) {
254 res = &comp->resolutions[resno];
255 dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
256 dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
257 pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
258 pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
263 pi->poc.ty0 = pi->ty0;
264 pi->poc.tx0 = pi->tx0;
265 pi->poc.ty1 = pi->ty1;
266 pi->poc.tx1 = pi->tx1;
268 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
269 for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
270 for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
271 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
277 comp = &pi->comps[pi->compno];
278 if (pi->resno >= comp->numresolutions) {
281 res = &comp->resolutions[pi->resno];
282 levelno = comp->numresolutions - 1 - pi->resno;
283 trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
284 try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
285 trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
286 try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
287 rpx = res->pdx + levelno;
288 rpy = res->pdy + levelno;
289 if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
292 if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
296 if ((res->pw==0)||(res->ph==0)) continue;
298 if ((trx0==trx1)||(try0==try1)) continue;
300 prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
301 - int_floordivpow2(trx0, res->pdx);
302 prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
303 - int_floordivpow2(try0, res->pdy);
304 pi->precno = prci + prcj * res->pw;
305 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
306 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
307 if (!pi->include[index]) {
308 pi->include[index] = 1;
321 static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi) {
322 opj_pi_comp_t *comp = NULL;
323 opj_pi_resolution_t *res = NULL;
327 comp = &pi->comps[pi->compno];
334 for (compno = 0; compno < pi->numcomps; compno++) {
335 comp = &pi->comps[compno];
336 for (resno = 0; resno < comp->numresolutions; resno++) {
338 res = &comp->resolutions[resno];
339 dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
340 dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
341 pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
342 pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
347 pi->poc.ty0 = pi->ty0;
348 pi->poc.tx0 = pi->tx0;
349 pi->poc.ty1 = pi->ty1;
350 pi->poc.tx1 = pi->tx1;
352 for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
353 for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
354 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
355 comp = &pi->comps[pi->compno];
356 for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
362 res = &comp->resolutions[pi->resno];
363 levelno = comp->numresolutions - 1 - pi->resno;
364 trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
365 try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
366 trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
367 try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
368 rpx = res->pdx + levelno;
369 rpy = res->pdy + levelno;
370 if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
373 if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
377 if ((res->pw==0)||(res->ph==0)) continue;
379 if ((trx0==trx1)||(try0==try1)) continue;
381 prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
382 - int_floordivpow2(trx0, res->pdx);
383 prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
384 - int_floordivpow2(try0, res->pdy);
385 pi->precno = prci + prcj * res->pw;
386 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
387 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
388 if (!pi->include[index]) {
389 pi->include[index] = 1;
402 static opj_bool pi_next_cprl(opj_pi_iterator_t * pi) {
403 opj_pi_comp_t *comp = NULL;
404 opj_pi_resolution_t *res = NULL;
408 comp = &pi->comps[pi->compno];
414 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
416 comp = &pi->comps[pi->compno];
419 for (resno = 0; resno < comp->numresolutions; resno++) {
421 res = &comp->resolutions[resno];
422 dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
423 dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
424 pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
425 pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
428 pi->poc.ty0 = pi->ty0;
429 pi->poc.tx0 = pi->tx0;
430 pi->poc.ty1 = pi->ty1;
431 pi->poc.tx1 = pi->tx1;
433 for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
434 for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
435 for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
441 res = &comp->resolutions[pi->resno];
442 levelno = comp->numresolutions - 1 - pi->resno;
443 trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
444 try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
445 trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
446 try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
447 rpx = res->pdx + levelno;
448 rpy = res->pdy + levelno;
449 if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
452 if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
456 if ((res->pw==0)||(res->ph==0)) continue;
458 if ((trx0==trx1)||(try0==try1)) continue;
460 prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
461 - int_floordivpow2(trx0, res->pdx);
462 prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
463 - int_floordivpow2(try0, res->pdy);
464 pi->precno = prci + prcj * res->pw;
465 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
466 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
467 if (!pi->include[index]) {
468 pi->include[index] = 1;
482 ==========================================================
483 Packet iterator interface
484 ==========================================================
487 opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno) {
489 int compno, resno, pino;
490 opj_pi_iterator_t *pi = NULL;
491 opj_tcp_t *tcp = NULL;
492 opj_tccp_t *tccp = NULL;
494 tcp = &cp->tcps[tileno];
496 pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
498 /* TODO: throw an error */
502 for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */
508 pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
509 pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
510 pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
511 pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
512 pi[pino].numcomps = image->numcomps;
514 pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
515 if(!pi[pino].comps) {
516 /* TODO: throw an error */
517 pi_destroy(pi, cp, tileno);
521 for (compno = 0; compno < pi->numcomps; compno++) {
522 int tcx0, tcy0, tcx1, tcy1;
523 opj_pi_comp_t *comp = &pi[pino].comps[compno];
524 tccp = &tcp->tccps[compno];
525 comp->dx = image->comps[compno].dx;
526 comp->dy = image->comps[compno].dy;
527 comp->numresolutions = tccp->numresolutions;
529 comp->resolutions = (opj_pi_resolution_t*) opj_calloc(comp->numresolutions, sizeof(opj_pi_resolution_t));
530 if(!comp->resolutions) {
531 /* TODO: throw an error */
532 pi_destroy(pi, cp, tileno);
536 tcx0 = int_ceildiv(pi->tx0, comp->dx);
537 tcy0 = int_ceildiv(pi->ty0, comp->dy);
538 tcx1 = int_ceildiv(pi->tx1, comp->dx);
539 tcy1 = int_ceildiv(pi->ty1, comp->dy);
540 if (comp->numresolutions > maxres) {
541 maxres = comp->numresolutions;
544 for (resno = 0; resno < comp->numresolutions; resno++) {
546 int rx0, ry0, rx1, ry1;
547 int px0, py0, px1, py1;
548 opj_pi_resolution_t *res = &comp->resolutions[resno];
549 if (tccp->csty & J2K_CCP_CSTY_PRT) {
550 res->pdx = tccp->prcw[resno];
551 res->pdy = tccp->prch[resno];
556 levelno = comp->numresolutions - 1 - resno;
557 rx0 = int_ceildivpow2(tcx0, levelno);
558 ry0 = int_ceildivpow2(tcy0, levelno);
559 rx1 = int_ceildivpow2(tcx1, levelno);
560 ry1 = int_ceildivpow2(tcy1, levelno);
561 px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
562 py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
563 px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
564 py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
565 res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx);
566 res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy);
568 if (res->pw*res->ph > maxprec) {
569 maxprec = res->pw*res->ph;
575 tccp = &tcp->tccps[0];
577 pi[pino].step_c = maxprec * pi[pino].step_p;
578 pi[pino].step_r = image->numcomps * pi[pino].step_c;
579 pi[pino].step_l = maxres * pi[pino].step_r;
582 pi[pino].include = (short int*) opj_calloc(image->numcomps * maxres * tcp->numlayers * maxprec, sizeof(short int));
583 if(!pi[pino].include) {
584 /* TODO: throw an error */
585 pi_destroy(pi, cp, tileno);
590 pi[pino].include = pi[pino - 1].include;
595 pi[pino].poc.resno0 = 0;
596 pi[pino].poc.compno0 = 0;
597 pi[pino].poc.layno1 = tcp->numlayers;
598 pi[pino].poc.resno1 = maxres;
599 pi[pino].poc.compno1 = image->numcomps;
600 pi[pino].poc.prg = tcp->prg;
603 pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
604 pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
605 pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
606 pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
607 pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
608 pi[pino].poc.prg = tcp->pocs[pino].prg;
610 pi[pino].poc.layno0 = 0;
611 pi[pino].poc.precno0 = 0;
612 pi[pino].poc.precno1 = maxprec;
619 opj_pi_iterator_t *pi_create_decode_v2( opj_image_t *p_image,
626 OPJ_UINT32 compno, resno;
628 /* to store w, h, dx and dy fro all components and resolutions */
629 OPJ_UINT32 * l_tmp_data;
630 OPJ_UINT32 ** l_tmp_ptr;
632 /* encoding prameters to set */
633 OPJ_UINT32 l_max_res;
634 OPJ_UINT32 l_max_prec;
635 OPJ_INT32 l_tx0,l_tx1,l_ty0,l_ty1;
636 OPJ_UINT32 l_dx_min,l_dy_min;
638 OPJ_UINT32 l_step_p , l_step_c , l_step_r , l_step_l ;
639 OPJ_UINT32 l_data_stride;
642 opj_pi_iterator_t *l_pi = 00;
643 opj_tcp_v2_t *l_tcp = 00;
644 const opj_tccp_t *l_tccp = 00;
645 opj_pi_comp_t *l_current_comp = 00;
646 opj_image_comp_t * l_img_comp = 00;
647 opj_pi_iterator_t * l_current_pi = 00;
648 OPJ_UINT32 * l_encoding_value_ptr = 00;
650 /* preconditions in debug */
652 assert(p_image != 00);
653 assert(p_tile_no < p_cp->tw * p_cp->th);
655 /* initializations */
656 l_tcp = &p_cp->tcps[p_tile_no];
657 l_bound = l_tcp->numpocs+1;
659 l_data_stride = 4 * J2K_MAXRLVLS;
660 l_tmp_data = (OPJ_UINT32*)opj_malloc(
661 l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
667 l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
668 p_image->numcomps * sizeof(OPJ_UINT32 *));
672 opj_free(l_tmp_data);
676 /* memory allocation for pi */
677 l_pi = pi_create(p_image, p_cp, p_tile_no);
679 opj_free(l_tmp_data);
684 l_encoding_value_ptr = l_tmp_data;
685 /* update pointer array */
687 (compno = 0; compno < p_image->numcomps; ++compno)
689 l_tmp_ptr[compno] = l_encoding_value_ptr;
690 l_encoding_value_ptr += l_data_stride;
692 /* get encoding parameters */
693 get_all_encoding_parameters(p_image,p_cp,p_tile_no,&l_tx0,&l_tx1,&l_ty0,&l_ty1,&l_dx_min,&l_dy_min,&l_max_prec,&l_max_res,l_tmp_ptr);
695 /* step calculations */
697 l_step_c = l_max_prec * l_step_p;
698 l_step_r = p_image->numcomps * l_step_c;
699 l_step_l = l_max_res * l_step_r;
701 /* set values for first packet iterator */
704 /* memory allocation for include */
705 l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
707 (!l_current_pi->include)
709 opj_free(l_tmp_data);
711 pi_destroy_v2(l_pi, l_bound);
714 memset(l_current_pi->include,0, (l_tcp->numlayers + 1) * l_step_l* sizeof(OPJ_INT16));
716 /* special treatment for the first packet iterator */
717 l_current_comp = l_current_pi->comps;
718 l_img_comp = p_image->comps;
719 l_tccp = l_tcp->tccps;
721 l_current_pi->tx0 = l_tx0;
722 l_current_pi->ty0 = l_ty0;
723 l_current_pi->tx1 = l_tx1;
724 l_current_pi->ty1 = l_ty1;
726 /*l_current_pi->dx = l_img_comp->dx;*/
727 /*l_current_pi->dy = l_img_comp->dy;*/
729 l_current_pi->step_p = l_step_p;
730 l_current_pi->step_c = l_step_c;
731 l_current_pi->step_r = l_step_r;
732 l_current_pi->step_l = l_step_l;
734 /* allocation for components and number of components has already been calculated by pi_create */
736 (compno = 0; compno < l_current_pi->numcomps; ++compno)
738 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
739 l_encoding_value_ptr = l_tmp_ptr[compno];
741 l_current_comp->dx = l_img_comp->dx;
742 l_current_comp->dy = l_img_comp->dy;
743 /* resolutions have already been initialized */
745 (resno = 0; resno < l_current_comp->numresolutions; resno++)
747 l_res->pdx = *(l_encoding_value_ptr++);
748 l_res->pdy = *(l_encoding_value_ptr++);
749 l_res->pw = *(l_encoding_value_ptr++);
750 l_res->ph = *(l_encoding_value_ptr++);
760 (pino = 1 ; pino<l_bound ; ++pino )
762 opj_pi_comp_t *l_current_comp = l_current_pi->comps;
763 opj_image_comp_t * l_img_comp = p_image->comps;
764 l_tccp = l_tcp->tccps;
766 l_current_pi->tx0 = l_tx0;
767 l_current_pi->ty0 = l_ty0;
768 l_current_pi->tx1 = l_tx1;
769 l_current_pi->ty1 = l_ty1;
770 /*l_current_pi->dx = l_dx_min;*/
771 /*l_current_pi->dy = l_dy_min;*/
772 l_current_pi->step_p = l_step_p;
773 l_current_pi->step_c = l_step_c;
774 l_current_pi->step_r = l_step_r;
775 l_current_pi->step_l = l_step_l;
777 /* allocation for components and number of components has already been calculated by pi_create */
779 (compno = 0; compno < l_current_pi->numcomps; ++compno)
781 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
782 l_encoding_value_ptr = l_tmp_ptr[compno];
784 l_current_comp->dx = l_img_comp->dx;
785 l_current_comp->dy = l_img_comp->dy;
786 /* resolutions have already been initialized */
788 (resno = 0; resno < l_current_comp->numresolutions; resno++)
790 l_res->pdx = *(l_encoding_value_ptr++);
791 l_res->pdy = *(l_encoding_value_ptr++);
792 l_res->pw = *(l_encoding_value_ptr++);
793 l_res->ph = *(l_encoding_value_ptr++);
800 /* special treatment*/
801 l_current_pi->include = (l_current_pi-1)->include;
804 opj_free(l_tmp_data);
811 pi_update_decode_poc (l_pi,l_tcp,l_max_prec,l_max_res);
815 pi_update_decode_not_poc(l_pi,l_tcp,l_max_prec,l_max_res);
820 opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, J2K_T2_MODE t2_mode){
825 opj_pi_iterator_t *pi = NULL;
826 opj_tcp_t *tcp = NULL;
827 opj_tccp_t *tccp = NULL;
829 tcp = &cp->tcps[tileno];
831 pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
832 if(!pi) { return NULL;}
833 pi->tp_on = cp->tp_on;
835 for(pino = 0;pino < tcp->numpocs+1 ; pino ++){
839 pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
840 pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
841 pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
842 pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
843 pi[pino].numcomps = image->numcomps;
845 pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
846 if(!pi[pino].comps) {
847 pi_destroy(pi, cp, tileno);
851 for (compno = 0; compno < pi[pino].numcomps; compno++) {
852 int tcx0, tcy0, tcx1, tcy1;
853 opj_pi_comp_t *comp = &pi[pino].comps[compno];
854 tccp = &tcp->tccps[compno];
855 comp->dx = image->comps[compno].dx;
856 comp->dy = image->comps[compno].dy;
857 comp->numresolutions = tccp->numresolutions;
859 comp->resolutions = (opj_pi_resolution_t*) opj_malloc(comp->numresolutions * sizeof(opj_pi_resolution_t));
860 if(!comp->resolutions) {
861 pi_destroy(pi, cp, tileno);
865 tcx0 = int_ceildiv(pi[pino].tx0, comp->dx);
866 tcy0 = int_ceildiv(pi[pino].ty0, comp->dy);
867 tcx1 = int_ceildiv(pi[pino].tx1, comp->dx);
868 tcy1 = int_ceildiv(pi[pino].ty1, comp->dy);
869 if (comp->numresolutions > maxres) {
870 maxres = comp->numresolutions;
873 for (resno = 0; resno < comp->numresolutions; resno++) {
875 int rx0, ry0, rx1, ry1;
876 int px0, py0, px1, py1;
877 opj_pi_resolution_t *res = &comp->resolutions[resno];
878 if (tccp->csty & J2K_CCP_CSTY_PRT) {
879 res->pdx = tccp->prcw[resno];
880 res->pdy = tccp->prch[resno];
885 levelno = comp->numresolutions - 1 - resno;
886 rx0 = int_ceildivpow2(tcx0, levelno);
887 ry0 = int_ceildivpow2(tcy0, levelno);
888 rx1 = int_ceildivpow2(tcx1, levelno);
889 ry1 = int_ceildivpow2(tcy1, levelno);
890 px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
891 py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
892 px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
893 py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
894 res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx);
895 res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy);
897 if (res->pw*res->ph > maxprec) {
898 maxprec = res->pw * res->ph;
903 tccp = &tcp->tccps[0];
905 pi[pino].step_c = maxprec * pi[pino].step_p;
906 pi[pino].step_r = image->numcomps * pi[pino].step_c;
907 pi[pino].step_l = maxres * pi[pino].step_r;
909 for (compno = 0; compno < pi->numcomps; compno++) {
910 opj_pi_comp_t *comp = &pi->comps[compno];
911 for (resno = 0; resno < comp->numresolutions; resno++) {
913 opj_pi_resolution_t *res = &comp->resolutions[resno];
914 dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
915 dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
916 pi[pino].dx = !pi->dx ? dx : int_min(pi->dx, dx);
917 pi[pino].dy = !pi->dy ? dy : int_min(pi->dy, dy);
922 pi[pino].include = (short int*) opj_calloc(tcp->numlayers * pi[pino].step_l, sizeof(short int));
923 if(!pi[pino].include) {
924 pi_destroy(pi, cp, tileno);
929 pi[pino].include = pi[pino - 1].include;
932 /* Generation of boundaries for each prog flag*/
933 if(tcp->POC && ( cp->cinema || ((!cp->cinema) && (t2_mode == FINAL_PASS)))){
934 tcp->pocs[pino].compS= tcp->pocs[pino].compno0;
935 tcp->pocs[pino].compE= tcp->pocs[pino].compno1;
936 tcp->pocs[pino].resS = tcp->pocs[pino].resno0;
937 tcp->pocs[pino].resE = tcp->pocs[pino].resno1;
938 tcp->pocs[pino].layE = tcp->pocs[pino].layno1;
939 tcp->pocs[pino].prg = tcp->pocs[pino].prg1;
941 tcp->pocs[pino].layS = (tcp->pocs[pino].layE > tcp->pocs[pino - 1].layE) ? tcp->pocs[pino - 1].layE : 0;
943 tcp->pocs[pino].compS= 0;
944 tcp->pocs[pino].compE= image->numcomps;
945 tcp->pocs[pino].resS = 0;
946 tcp->pocs[pino].resE = maxres;
947 tcp->pocs[pino].layS = 0;
948 tcp->pocs[pino].layE = tcp->numlayers;
949 tcp->pocs[pino].prg = tcp->prg;
951 tcp->pocs[pino].prcS = 0;
952 tcp->pocs[pino].prcE = maxprec;;
953 tcp->pocs[pino].txS = pi[pino].tx0;
954 tcp->pocs[pino].txE = pi[pino].tx1;
955 tcp->pocs[pino].tyS = pi[pino].ty0;
956 tcp->pocs[pino].tyE = pi[pino].ty1;
957 tcp->pocs[pino].dx = pi[pino].dx;
958 tcp->pocs[pino].dy = pi[pino].dy;
963 opj_pi_iterator_t *pi_initialise_encode_v2(
964 const opj_image_t *p_image,
966 OPJ_UINT32 p_tile_no,
967 J2K_T2_MODE p_t2_mode
972 OPJ_UINT32 compno, resno;
974 /* to store w, h, dx and dy fro all components and resolutions*/
975 OPJ_UINT32 * l_tmp_data;
976 OPJ_UINT32 ** l_tmp_ptr;
978 /* encoding prameters to set*/
979 OPJ_UINT32 l_max_res;
980 OPJ_UINT32 l_max_prec;
981 OPJ_INT32 l_tx0,l_tx1,l_ty0,l_ty1;
982 OPJ_UINT32 l_dx_min,l_dy_min;
984 OPJ_UINT32 l_step_p , l_step_c , l_step_r , l_step_l ;
985 OPJ_UINT32 l_data_stride;
988 opj_pi_iterator_t *l_pi = 00;
989 opj_tcp_v2_t *l_tcp = 00;
990 const opj_tccp_t *l_tccp = 00;
991 opj_pi_comp_t *l_current_comp = 00;
992 opj_image_comp_t * l_img_comp = 00;
993 opj_pi_iterator_t * l_current_pi = 00;
994 OPJ_UINT32 * l_encoding_value_ptr = 00;
996 /* preconditions in debug*/
998 assert(p_image != 00);
999 assert(p_tile_no < p_cp->tw * p_cp->th);
1001 /* initializations*/
1002 l_tcp = &p_cp->tcps[p_tile_no];
1003 l_bound = l_tcp->numpocs+1;
1005 l_data_stride = 4 * J2K_MAXRLVLS;
1006 l_tmp_data = (OPJ_UINT32*)opj_malloc(
1007 l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
1012 l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
1013 p_image->numcomps * sizeof(OPJ_UINT32 *));
1015 opj_free(l_tmp_data);
1019 /* memory allocation for pi*/
1020 l_pi = pi_create(p_image,p_cp,p_tile_no);
1022 opj_free(l_tmp_data);
1023 opj_free(l_tmp_ptr);
1027 l_encoding_value_ptr = l_tmp_data;
1028 /* update pointer array*/
1029 for (compno = 0; compno < p_image->numcomps; ++compno) {
1030 l_tmp_ptr[compno] = l_encoding_value_ptr;
1031 l_encoding_value_ptr += l_data_stride;
1034 /* get encoding parameters*/
1035 get_all_encoding_parameters(p_image,p_cp,p_tile_no,&l_tx0,&l_tx1,&l_ty0,&l_ty1,&l_dx_min,&l_dy_min,&l_max_prec,&l_max_res,l_tmp_ptr);
1037 /* step calculations*/
1039 l_step_c = l_max_prec * l_step_p;
1040 l_step_r = p_image->numcomps * l_step_c;
1041 l_step_l = l_max_res * l_step_r;
1043 /* set values for first packet iterator*/
1044 l_pi->tp_on = p_cp->m_specific_param.m_enc.m_tp_on;
1045 l_current_pi = l_pi;
1047 /* memory allocation for include*/
1048 l_current_pi->include = (OPJ_INT16*) opj_calloc(l_tcp->numlayers * l_step_l, sizeof(OPJ_INT16));
1049 if (!l_current_pi->include) {
1050 opj_free(l_tmp_data);
1051 opj_free(l_tmp_ptr);
1052 pi_destroy_v2(l_pi, l_bound);
1055 memset(l_current_pi->include,0,l_tcp->numlayers * l_step_l* sizeof(OPJ_INT16));
1057 /* special treatment for the first packet iterator*/
1058 l_current_comp = l_current_pi->comps;
1059 l_img_comp = p_image->comps;
1060 l_tccp = l_tcp->tccps;
1061 l_current_pi->tx0 = l_tx0;
1062 l_current_pi->ty0 = l_ty0;
1063 l_current_pi->tx1 = l_tx1;
1064 l_current_pi->ty1 = l_ty1;
1065 l_current_pi->dx = l_dx_min;
1066 l_current_pi->dy = l_dy_min;
1067 l_current_pi->step_p = l_step_p;
1068 l_current_pi->step_c = l_step_c;
1069 l_current_pi->step_r = l_step_r;
1070 l_current_pi->step_l = l_step_l;
1072 /* allocation for components and number of components has already been calculated by pi_create */
1073 for (compno = 0; compno < l_current_pi->numcomps; ++compno) {
1074 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1075 l_encoding_value_ptr = l_tmp_ptr[compno];
1077 l_current_comp->dx = l_img_comp->dx;
1078 l_current_comp->dy = l_img_comp->dy;
1080 /* resolutions have already been initialized */
1081 for (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1082 l_res->pdx = *(l_encoding_value_ptr++);
1083 l_res->pdy = *(l_encoding_value_ptr++);
1084 l_res->pw = *(l_encoding_value_ptr++);
1085 l_res->ph = *(l_encoding_value_ptr++);
1095 for (pino = 1 ; pino<l_bound ; ++pino ) {
1096 opj_pi_comp_t *l_current_comp = l_current_pi->comps;
1097 opj_image_comp_t * l_img_comp = p_image->comps;
1098 l_tccp = l_tcp->tccps;
1100 l_current_pi->tx0 = l_tx0;
1101 l_current_pi->ty0 = l_ty0;
1102 l_current_pi->tx1 = l_tx1;
1103 l_current_pi->ty1 = l_ty1;
1104 l_current_pi->dx = l_dx_min;
1105 l_current_pi->dy = l_dy_min;
1106 l_current_pi->step_p = l_step_p;
1107 l_current_pi->step_c = l_step_c;
1108 l_current_pi->step_r = l_step_r;
1109 l_current_pi->step_l = l_step_l;
1111 /* allocation for components and number of components has already been calculated by pi_create */
1112 for (compno = 0; compno < l_current_pi->numcomps; ++compno) {
1113 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1114 l_encoding_value_ptr = l_tmp_ptr[compno];
1116 l_current_comp->dx = l_img_comp->dx;
1117 l_current_comp->dy = l_img_comp->dy;
1118 /* resolutions have already been initialized */
1119 for (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1120 l_res->pdx = *(l_encoding_value_ptr++);
1121 l_res->pdy = *(l_encoding_value_ptr++);
1122 l_res->pw = *(l_encoding_value_ptr++);
1123 l_res->ph = *(l_encoding_value_ptr++);
1131 /* special treatment*/
1132 l_current_pi->include = (l_current_pi-1)->include;
1136 opj_free(l_tmp_data);
1138 opj_free(l_tmp_ptr);
1141 if (l_tcp->POC && ( p_cp->m_specific_param.m_enc.m_cinema || p_t2_mode == FINAL_PASS)) {
1142 pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
1145 pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
1151 void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) {
1153 opj_tcp_t *tcp = &cp->tcps[tileno];
1155 for (pino = 0; pino < tcp->numpocs + 1; pino++) {
1156 if(pi[pino].comps) {
1157 for (compno = 0; compno < pi->numcomps; compno++) {
1158 opj_pi_comp_t *comp = &pi[pino].comps[compno];
1159 if(comp->resolutions) {
1160 opj_free(comp->resolutions);
1163 opj_free(pi[pino].comps);
1167 opj_free(pi->include);
1173 opj_bool pi_next(opj_pi_iterator_t * pi) {
1174 switch (pi->poc.prg) {
1176 return pi_next_lrcp(pi);
1178 return pi_next_rlcp(pi);
1180 return pi_next_rpcl(pi);
1182 return pi_next_pcrl(pi);
1184 return pi_next_cprl(pi);
1192 opj_bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp){
1195 int incr_top=1,resetX=0;
1196 opj_tcp_t *tcps =&cp->tcps[tileno];
1197 opj_poc_t *tcp= &tcps->pocs[pino];
1200 pi[pino].poc.prg = tcp->prg;
1203 case CPRL: strncpy(prog, "CPRL",4);
1205 case LRCP: strncpy(prog, "LRCP",4);
1207 case PCRL: strncpy(prog, "PCRL",4);
1209 case RLCP: strncpy(prog, "RLCP",4);
1211 case RPCL: strncpy(prog, "RPCL",4);
1217 if(!(cp->tp_on && ((!cp->cinema && (t2_mode == FINAL_PASS)) || cp->cinema))){
1218 pi[pino].poc.resno0 = tcp->resS;
1219 pi[pino].poc.resno1 = tcp->resE;
1220 pi[pino].poc.compno0 = tcp->compS;
1221 pi[pino].poc.compno1 = tcp->compE;
1222 pi[pino].poc.layno0 = tcp->layS;
1223 pi[pino].poc.layno1 = tcp->layE;
1224 pi[pino].poc.precno0 = tcp->prcS;
1225 pi[pino].poc.precno1 = tcp->prcE;
1226 pi[pino].poc.tx0 = tcp->txS;
1227 pi[pino].poc.ty0 = tcp->tyS;
1228 pi[pino].poc.tx1 = tcp->txE;
1229 pi[pino].poc.ty1 = tcp->tyE;
1231 if( tpnum < cur_totnum_tp){
1236 pi[pino].poc.compno0 = tcp->compS;
1237 pi[pino].poc.compno1 = tcp->compE;
1240 tcp->comp_t = tcp->compS;
1241 pi[pino].poc.compno0 = tcp->comp_t;
1242 pi[pino].poc.compno1 = tcp->comp_t+1;
1246 if(tcp->comp_t ==tcp->compE){
1247 tcp->comp_t = tcp->compS;
1248 pi[pino].poc.compno0 = tcp->comp_t;
1249 pi[pino].poc.compno1 = tcp->comp_t+1;
1253 pi[pino].poc.compno0 = tcp->comp_t;
1254 pi[pino].poc.compno1 = tcp->comp_t+1;
1259 pi[pino].poc.compno0 = tcp->comp_t-1;
1260 pi[pino].poc.compno1 = tcp->comp_t;
1268 pi[pino].poc.resno0 = tcp->resS;
1269 pi[pino].poc.resno1 = tcp->resE;
1272 tcp->res_t = tcp->resS;
1273 pi[pino].poc.resno0 = tcp->res_t;
1274 pi[pino].poc.resno1 = tcp->res_t+1;
1278 if(tcp->res_t==tcp->resE){
1279 tcp->res_t = tcp->resS;
1280 pi[pino].poc.resno0 = tcp->res_t;
1281 pi[pino].poc.resno1 = tcp->res_t+1;
1285 pi[pino].poc.resno0 = tcp->res_t;
1286 pi[pino].poc.resno1 = tcp->res_t+1;
1291 pi[pino].poc.resno0 = tcp->res_t - 1;
1292 pi[pino].poc.resno1 = tcp->res_t;
1300 pi[pino].poc.layno0 = tcp->layS;
1301 pi[pino].poc.layno1 = tcp->layE;
1304 tcp->lay_t = tcp->layS;
1305 pi[pino].poc.layno0 = tcp->lay_t;
1306 pi[pino].poc.layno1 = tcp->lay_t+1;
1310 if(tcp->lay_t == tcp->layE){
1311 tcp->lay_t = tcp->layS;
1312 pi[pino].poc.layno0 = tcp->lay_t;
1313 pi[pino].poc.layno1 = tcp->lay_t+1;
1317 pi[pino].poc.layno0 = tcp->lay_t;
1318 pi[pino].poc.layno1 = tcp->lay_t+1;
1323 pi[pino].poc.layno0 = tcp->lay_t - 1;
1324 pi[pino].poc.layno1 = tcp->lay_t;
1335 pi[pino].poc.precno0 = tcp->prcS;
1336 pi[pino].poc.precno1 = tcp->prcE;
1339 tcp->prc_t = tcp->prcS;
1340 pi[pino].poc.precno0 = tcp->prc_t;
1341 pi[pino].poc.precno1 = tcp->prc_t+1;
1345 if(tcp->prc_t == tcp->prcE){
1346 tcp->prc_t = tcp->prcS;
1347 pi[pino].poc.precno0 = tcp->prc_t;
1348 pi[pino].poc.precno1 = tcp->prc_t+1;
1352 pi[pino].poc.precno0 = tcp->prc_t;
1353 pi[pino].poc.precno1 = tcp->prc_t+1;
1358 pi[pino].poc.precno0 = tcp->prc_t - 1;
1359 pi[pino].poc.precno1 = tcp->prc_t;
1366 pi[pino].poc.tx0 = tcp->txS;
1367 pi[pino].poc.ty0 = tcp->tyS;
1368 pi[pino].poc.tx1 = tcp->txE;
1369 pi[pino].poc.ty1 = tcp->tyE;
1372 tcp->tx0_t = tcp->txS;
1373 tcp->ty0_t = tcp->tyS;
1374 pi[pino].poc.tx0 = tcp->tx0_t;
1375 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx);
1376 pi[pino].poc.ty0 = tcp->ty0_t;
1377 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
1378 tcp->tx0_t = pi[pino].poc.tx1;
1379 tcp->ty0_t = pi[pino].poc.ty1;
1382 if(tcp->tx0_t >= tcp->txE){
1383 if(tcp->ty0_t >= tcp->tyE){
1384 tcp->ty0_t = tcp->tyS;
1385 pi[pino].poc.ty0 = tcp->ty0_t;
1386 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
1387 tcp->ty0_t = pi[pino].poc.ty1;
1388 incr_top=1;resetX=1;
1390 pi[pino].poc.ty0 = tcp->ty0_t;
1391 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
1392 tcp->ty0_t = pi[pino].poc.ty1;
1393 incr_top=0;resetX=1;
1396 tcp->tx0_t = tcp->txS;
1397 pi[pino].poc.tx0 = tcp->tx0_t;
1398 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
1399 tcp->tx0_t = pi[pino].poc.tx1;
1402 pi[pino].poc.tx0 = tcp->tx0_t;
1403 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
1404 tcp->tx0_t = pi[pino].poc.tx1;
1405 pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
1406 pi[pino].poc.ty1 = tcp->ty0_t ;
1410 pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx);
1411 pi[pino].poc.tx1 = tcp->tx0_t ;
1412 pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
1413 pi[pino].poc.ty1 = tcp->ty0_t ;
1427 void pi_update_encoding_parameters( const opj_image_t *p_image,
1429 OPJ_UINT32 p_tile_no )
1431 /* encoding parameters to set */
1432 OPJ_UINT32 l_max_res;
1433 OPJ_UINT32 l_max_prec;
1434 OPJ_INT32 l_tx0,l_tx1,l_ty0,l_ty1;
1435 OPJ_UINT32 l_dx_min,l_dy_min;
1438 opj_tcp_v2_t *l_tcp = 00;
1442 assert(p_image != 00);
1443 assert(p_tile_no < p_cp->tw * p_cp->th);
1445 l_tcp = &(p_cp->tcps[p_tile_no]);
1447 /* get encoding parameters */
1448 get_encoding_parameters(p_image,p_cp,p_tile_no,&l_tx0,&l_tx1,&l_ty0,&l_ty1,&l_dx_min,&l_dy_min,&l_max_prec,&l_max_res);
1451 pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
1454 pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
1459 void get_encoding_parameters( const opj_image_t *p_image,
1460 const opj_cp_v2_t *p_cp,
1461 OPJ_UINT32 p_tileno,
1466 OPJ_UINT32 * p_dx_min,
1467 OPJ_UINT32 * p_dy_min,
1468 OPJ_UINT32 * p_max_prec,
1469 OPJ_UINT32 * p_max_res )
1472 OPJ_UINT32 compno, resno;
1474 const opj_tcp_v2_t *l_tcp = 00;
1475 const opj_tccp_t * l_tccp = 00;
1476 const opj_image_comp_t * l_img_comp = 00;
1478 /* position in x and y of tile */
1483 assert(p_image != 00);
1484 assert(p_tileno < p_cp->tw * p_cp->th);
1486 /* initializations */
1487 l_tcp = &p_cp->tcps [p_tileno];
1488 l_img_comp = p_image->comps;
1489 l_tccp = l_tcp->tccps;
1491 /* here calculation of tx0, tx1, ty0, ty1, maxprec, dx and dy */
1492 p = p_tileno % p_cp->tw;
1493 q = p_tileno / p_cp->tw;
1495 /* find extent of tile */
1496 *p_tx0 = int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
1497 *p_tx1 = int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
1498 *p_ty0 = int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
1499 *p_ty1 = int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
1501 /* max precision is 0 (can only grow) */
1505 /* take the largest value for dx_min and dy_min */
1506 *p_dx_min = 0x7fffffff;
1507 *p_dy_min = 0x7fffffff;
1509 for (compno = 0; compno < p_image->numcomps; ++compno) {
1510 /* arithmetic variables to calculate */
1511 OPJ_UINT32 l_level_no;
1512 OPJ_INT32 l_rx0, l_ry0, l_rx1, l_ry1;
1513 OPJ_INT32 l_px0, l_py0, l_px1, py1;
1514 OPJ_UINT32 l_pdx, l_pdy;
1515 OPJ_UINT32 l_pw, l_ph;
1516 OPJ_UINT32 l_product;
1517 OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
1519 l_tcx0 = int_ceildiv(*p_tx0, l_img_comp->dx);
1520 l_tcy0 = int_ceildiv(*p_ty0, l_img_comp->dy);
1521 l_tcx1 = int_ceildiv(*p_tx1, l_img_comp->dx);
1522 l_tcy1 = int_ceildiv(*p_ty1, l_img_comp->dy);
1524 if (l_tccp->numresolutions > *p_max_res) {
1525 *p_max_res = l_tccp->numresolutions;
1528 /* use custom size for precincts */
1529 for (resno = 0; resno < l_tccp->numresolutions; ++resno) {
1530 OPJ_UINT32 l_dx, l_dy;
1532 /* precinct width and height */
1533 l_pdx = l_tccp->prcw[resno];
1534 l_pdy = l_tccp->prch[resno];
1536 l_dx = l_img_comp->dx * (1 << (l_pdx + l_tccp->numresolutions - 1 - resno));
1537 l_dy = l_img_comp->dy * (1 << (l_pdy + l_tccp->numresolutions - 1 - resno));
1539 /* take the minimum size for dx for each comp and resolution */
1540 *p_dx_min = uint_min(*p_dx_min, l_dx);
1541 *p_dy_min = uint_min(*p_dy_min, l_dy);
1543 /* various calculations of extents */
1544 l_level_no = l_tccp->numresolutions - 1 - resno;
1546 l_rx0 = int_ceildivpow2(l_tcx0, l_level_no);
1547 l_ry0 = int_ceildivpow2(l_tcy0, l_level_no);
1548 l_rx1 = int_ceildivpow2(l_tcx1, l_level_no);
1549 l_ry1 = int_ceildivpow2(l_tcy1, l_level_no);
1551 l_px0 = int_floordivpow2(l_rx0, l_pdx) << l_pdx;
1552 l_py0 = int_floordivpow2(l_ry0, l_pdy) << l_pdy;
1553 l_px1 = int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
1555 py1 = int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
1557 l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx);
1558 l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy);
1560 l_product = l_pw * l_ph;
1562 /* update precision */
1563 if (l_product > *p_max_prec) {
1564 *p_max_prec = l_product;
1573 * Gets the encoding parameters needed to update the coding parameters and all the pocs.
1574 * The precinct widths, heights, dx and dy for each component at each resolution will be stored as well.
1575 * the last parameter of the function should be an array of pointers of size nb components, each pointer leading
1576 * to an area of size 4 * max_res. The data is stored inside this area with the following pattern :
1577 * dx_compi_res0 , dy_compi_res0 , w_compi_res0, h_compi_res0 , dx_compi_res1 , dy_compi_res1 , w_compi_res1, h_compi_res1 , ...
1579 * @param p_image the image being encoded.
1580 * @param p_cp the coding parameters.
1581 * @param tileno the tile index of the tile being encoded.
1582 * @param p_tx0 pointer that will hold the X0 parameter for the tile
1583 * @param p_tx1 pointer that will hold the X1 parameter for the tile
1584 * @param p_ty0 pointer that will hold the Y0 parameter for the tile
1585 * @param p_ty1 pointer that will hold the Y1 parameter for the tile
1586 * @param p_max_prec pointer that will hold the the maximum precision for all the bands of the tile
1587 * @param p_max_res pointer that will hold the the maximum number of resolutions for all the poc inside the tile.
1588 * @param p_dx_min pointer that will hold the the minimum dx of all the components of all the resolutions for the tile.
1589 * @param p_dy_min pointer that will hold the the minimum dy of all the components of all the resolutions for the tile.
1590 * @param p_resolutions pointer to an area corresponding to the one described above.
1592 void get_all_encoding_parameters(
1593 const opj_image_t *p_image,
1594 const opj_cp_v2_t *p_cp,
1600 OPJ_UINT32 * p_dx_min,
1601 OPJ_UINT32 * p_dy_min,
1602 OPJ_UINT32 * p_max_prec,
1603 OPJ_UINT32 * p_max_res,
1604 OPJ_UINT32 ** p_resolutions
1608 OPJ_UINT32 compno, resno;
1611 const opj_tcp_v2_t *tcp = 00;
1612 const opj_tccp_t * l_tccp = 00;
1613 const opj_image_comp_t * l_img_comp = 00;
1615 /* to store l_dx, l_dy, w and h for each resolution and component.*/
1616 OPJ_UINT32 * lResolutionPtr;
1618 /* position in x and y of tile*/
1621 /* preconditions in debug*/
1623 assert(p_image != 00);
1624 assert(tileno < p_cp->tw * p_cp->th);
1626 /* initializations*/
1627 tcp = &p_cp->tcps [tileno];
1628 l_tccp = tcp->tccps;
1629 l_img_comp = p_image->comps;
1631 /* position in x and y of tile*/
1633 p = tileno % p_cp->tw;
1634 q = tileno / p_cp->tw;
1636 /* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */
1637 *p_tx0 = int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
1638 *p_tx1 = int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
1639 *p_ty0 = int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
1640 *p_ty1 = int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
1642 /* max precision and resolution is 0 (can only grow)*/
1646 /* take the largest value for dx_min and dy_min*/
1647 *p_dx_min = 0x7fffffff;
1648 *p_dy_min = 0x7fffffff;
1651 (compno = 0; compno < p_image->numcomps; ++compno)
1653 /* aritmetic variables to calculate*/
1654 OPJ_UINT32 l_level_no;
1655 OPJ_INT32 l_rx0, l_ry0, l_rx1, l_ry1;
1656 OPJ_INT32 l_px0, l_py0, l_px1, py1;
1657 OPJ_UINT32 l_product;
1658 OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
1659 OPJ_UINT32 l_pdx, l_pdy , l_pw , l_ph;
1661 lResolutionPtr = p_resolutions[compno];
1663 l_tcx0 = int_ceildiv(*p_tx0, l_img_comp->dx);
1664 l_tcy0 = int_ceildiv(*p_ty0, l_img_comp->dy);
1665 l_tcx1 = int_ceildiv(*p_tx1, l_img_comp->dx);
1666 l_tcy1 = int_ceildiv(*p_ty1, l_img_comp->dy);
1668 (l_tccp->numresolutions > *p_max_res)
1670 *p_max_res = l_tccp->numresolutions;
1673 /* use custom size for precincts*/
1674 l_level_no = l_tccp->numresolutions - 1;
1676 (resno = 0; resno < l_tccp->numresolutions; ++resno)
1678 OPJ_UINT32 l_dx, l_dy;
1679 /* precinct width and height*/
1680 l_pdx = l_tccp->prcw[resno];
1681 l_pdy = l_tccp->prch[resno];
1682 *lResolutionPtr++ = l_pdx;
1683 *lResolutionPtr++ = l_pdy;
1684 l_dx = l_img_comp->dx * (1 << (l_pdx + l_level_no));
1685 l_dy = l_img_comp->dy * (1 << (l_pdy + l_level_no));
1686 /* take the minimum size for l_dx for each comp and resolution*/
1687 *p_dx_min = int_min(*p_dx_min, l_dx);
1688 *p_dy_min = int_min(*p_dy_min, l_dy);
1689 /* various calculations of extents*/
1691 l_rx0 = int_ceildivpow2(l_tcx0, l_level_no);
1692 l_ry0 = int_ceildivpow2(l_tcy0, l_level_no);
1693 l_rx1 = int_ceildivpow2(l_tcx1, l_level_no);
1694 l_ry1 = int_ceildivpow2(l_tcy1, l_level_no);
1695 l_px0 = int_floordivpow2(l_rx0, l_pdx) << l_pdx;
1696 l_py0 = int_floordivpow2(l_ry0, l_pdy) << l_pdy;
1697 l_px1 = int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
1698 py1 = int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
1699 l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx);
1700 l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy);
1701 *lResolutionPtr++ = l_pw;
1702 *lResolutionPtr++ = l_ph;
1703 l_product = l_pw * l_ph;
1704 /* update precision*/
1706 (l_product > *p_max_prec)
1708 *p_max_prec = l_product;
1717 opj_pi_iterator_t * pi_create( const opj_image_t *image,
1718 const opj_cp_v2_t *cp,
1722 OPJ_UINT32 pino, compno;
1723 /* number of poc in the p_pi*/
1724 OPJ_UINT32 l_poc_bound;
1726 /* pointers to tile coding parameters and components.*/
1727 opj_pi_iterator_t *l_pi = 00;
1728 opj_tcp_v2_t *tcp = 00;
1729 const opj_tccp_t *tccp = 00;
1731 /* current packet iterator being allocated*/
1732 opj_pi_iterator_t *l_current_pi = 00;
1734 /* preconditions in debug*/
1736 assert(image != 00);
1737 assert(tileno < cp->tw * cp->th);
1739 /* initializations*/
1740 tcp = &cp->tcps[tileno];
1741 l_poc_bound = tcp->numpocs+1;
1743 /* memory allocations*/
1744 l_pi = (opj_pi_iterator_t*) opj_calloc((l_poc_bound), sizeof(opj_pi_iterator_t));
1748 memset(l_pi,0,l_poc_bound * sizeof(opj_pi_iterator_t));
1750 l_current_pi = l_pi;
1751 for (pino = 0; pino < l_poc_bound ; ++pino) {
1753 l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
1754 if (! l_current_pi->comps) {
1755 pi_destroy_v2(l_pi, l_poc_bound);
1759 l_current_pi->numcomps = image->numcomps;
1760 memset(l_current_pi->comps,0,image->numcomps * sizeof(opj_pi_comp_t));
1762 for (compno = 0; compno < image->numcomps; ++compno) {
1763 opj_pi_comp_t *comp = &l_current_pi->comps[compno];
1765 tccp = &tcp->tccps[compno];
1767 comp->resolutions = (opj_pi_resolution_t*) opj_malloc(tccp->numresolutions * sizeof(opj_pi_resolution_t));
1768 if (!comp->resolutions) {
1769 pi_destroy_v2(l_pi, l_poc_bound);
1773 comp->numresolutions = tccp->numresolutions;
1774 memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t));
1781 void pi_update_encode_poc_and_final (opj_cp_v2_t *p_cp,
1782 OPJ_UINT32 p_tileno,
1787 OPJ_UINT32 p_max_prec,
1788 OPJ_UINT32 p_max_res,
1789 OPJ_UINT32 p_dx_min,
1790 OPJ_UINT32 p_dy_min)
1794 /* tile coding parameter*/
1795 opj_tcp_v2_t *l_tcp = 00;
1796 /* current poc being updated*/
1797 opj_poc_t * l_current_poc = 00;
1800 OPJ_UINT32 l_poc_bound;
1802 /* preconditions in debug*/
1804 assert(p_tileno < p_cp->tw * p_cp->th);
1806 /* initializations*/
1807 l_tcp = &p_cp->tcps [p_tileno];
1808 /* number of iterations in the loop */
1809 l_poc_bound = l_tcp->numpocs+1;
1811 /* start at first element, and to make sure the compiler will not make a calculation each time in the loop
1812 store a pointer to the current element to modify rather than l_tcp->pocs[i]*/
1813 l_current_poc = l_tcp->pocs;
1815 l_current_poc->compS = l_current_poc->compno0;
1816 l_current_poc->compE = l_current_poc->compno1;
1817 l_current_poc->resS = l_current_poc->resno0;
1818 l_current_poc->resE = l_current_poc->resno1;
1819 l_current_poc->layE = l_current_poc->layno1;
1821 /* special treatment for the first element*/
1822 l_current_poc->layS = 0;
1823 l_current_poc->prg = l_current_poc->prg1;
1824 l_current_poc->prcS = 0;
1826 l_current_poc->prcE = p_max_prec;
1827 l_current_poc->txS = p_tx0;
1828 l_current_poc->txE = p_tx1;
1829 l_current_poc->tyS = p_ty0;
1830 l_current_poc->tyE = p_ty1;
1831 l_current_poc->dx = p_dx_min;
1832 l_current_poc->dy = p_dy_min;
1835 for (pino = 1;pino < l_poc_bound ; ++pino) {
1836 l_current_poc->compS = l_current_poc->compno0;
1837 l_current_poc->compE= l_current_poc->compno1;
1838 l_current_poc->resS = l_current_poc->resno0;
1839 l_current_poc->resE = l_current_poc->resno1;
1840 l_current_poc->layE = l_current_poc->layno1;
1841 l_current_poc->prg = l_current_poc->prg1;
1842 l_current_poc->prcS = 0;
1843 /* special treatment here different from the first element*/
1844 l_current_poc->layS = (l_current_poc->layE > (l_current_poc-1)->layE) ? l_current_poc->layE : 0;
1846 l_current_poc->prcE = p_max_prec;
1847 l_current_poc->txS = p_tx0;
1848 l_current_poc->txE = p_tx1;
1849 l_current_poc->tyS = p_ty0;
1850 l_current_poc->tyE = p_ty1;
1851 l_current_poc->dx = p_dx_min;
1852 l_current_poc->dy = p_dy_min;
1857 void pi_update_encode_not_poc ( opj_cp_v2_t *p_cp,
1858 OPJ_UINT32 p_num_comps,
1859 OPJ_UINT32 p_tileno,
1864 OPJ_UINT32 p_max_prec,
1865 OPJ_UINT32 p_max_res,
1866 OPJ_UINT32 p_dx_min,
1867 OPJ_UINT32 p_dy_min)
1871 /* tile coding parameter*/
1872 opj_tcp_v2_t *l_tcp = 00;
1873 /* current poc being updated*/
1874 opj_poc_t * l_current_poc = 00;
1876 OPJ_UINT32 l_poc_bound;
1878 /* preconditions in debug*/
1880 assert(p_tileno < p_cp->tw * p_cp->th);
1882 /* initializations*/
1883 l_tcp = &p_cp->tcps [p_tileno];
1885 /* number of iterations in the loop */
1886 l_poc_bound = l_tcp->numpocs+1;
1888 /* start at first element, and to make sure the compiler will not make a calculation each time in the loop
1889 store a pointer to the current element to modify rather than l_tcp->pocs[i]*/
1890 l_current_poc = l_tcp->pocs;
1892 for (pino = 0; pino < l_poc_bound ; ++pino) {
1893 l_current_poc->compS = 0;
1894 l_current_poc->compE = p_num_comps;/*p_image->numcomps;*/
1895 l_current_poc->resS = 0;
1896 l_current_poc->resE = p_max_res;
1897 l_current_poc->layS = 0;
1898 l_current_poc->layE = l_tcp->numlayers;
1899 l_current_poc->prg = l_tcp->prg;
1900 l_current_poc->prcS = 0;
1901 l_current_poc->prcE = p_max_prec;
1902 l_current_poc->txS = p_tx0;
1903 l_current_poc->txE = p_tx1;
1904 l_current_poc->tyS = p_ty0;
1905 l_current_poc->tyE = p_ty1;
1906 l_current_poc->dx = p_dx_min;
1907 l_current_poc->dy = p_dy_min;
1913 opj_pi_iterator_t *p_pi,
1914 OPJ_UINT32 p_nb_elements)
1916 OPJ_UINT32 compno, pino;
1917 opj_pi_iterator_t *l_current_pi = p_pi;
1924 opj_free(p_pi->include);
1929 (pino = 0; pino < p_nb_elements; ++pino)
1932 (l_current_pi->comps)
1934 opj_pi_comp_t *l_current_component = l_current_pi->comps;
1936 (compno = 0; compno < l_current_pi->numcomps; compno++)
1939 (l_current_component->resolutions)
1941 opj_free(l_current_component->resolutions);
1942 l_current_component->resolutions = 00;
1944 ++l_current_component;
1946 opj_free(l_current_pi->comps);
1947 l_current_pi->comps = 0;
1955 void pi_update_decode_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res)
1960 /* encoding prameters to set*/
1963 opj_pi_iterator_t * l_current_pi = 00;
1964 opj_poc_t* l_current_poc = 0;
1966 /* preconditions in debug*/
1968 assert(p_tcp != 00);
1970 /* initializations*/
1971 l_bound = p_tcp->numpocs+1;
1972 l_current_pi = p_pi;
1973 l_current_poc = p_tcp->pocs;
1976 (pino = 0;pino<l_bound;++pino)
1978 l_current_pi->poc.prg = l_current_poc->prg;
1979 l_current_pi->first = 1;
1981 l_current_pi->poc.resno0 = l_current_poc->resno0;
1982 l_current_pi->poc.compno0 = l_current_poc->compno0;
1983 l_current_pi->poc.layno0 = 0;
1984 l_current_pi->poc.precno0 = 0;
1985 l_current_pi->poc.resno1 = l_current_poc->resno1;
1986 l_current_pi->poc.compno1 = l_current_poc->compno1;
1987 l_current_pi->poc.layno1 = l_current_poc->layno1;
1988 l_current_pi->poc.precno1 = p_max_precision;
1994 void pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res)
1999 /* encoding prameters to set*/
2002 opj_pi_iterator_t * l_current_pi = 00;
2003 /* preconditions in debug*/
2004 assert(p_tcp != 00);
2007 /* initializations*/
2008 l_bound = p_tcp->numpocs+1;
2009 l_current_pi = p_pi;
2012 (pino = 0;pino<l_bound;++pino)
2014 l_current_pi->poc.prg = p_tcp->prg;
2015 l_current_pi->first = 1;
2016 l_current_pi->poc.resno0 = 0;
2017 l_current_pi->poc.compno0 = 0;
2018 l_current_pi->poc.layno0 = 0;
2019 l_current_pi->poc.precno0 = 0;
2020 l_current_pi->poc.resno1 = p_max_res;
2021 l_current_pi->poc.compno1 = l_current_pi->numcomps;
2022 l_current_pi->poc.layno1 = p_tcp->numlayers;
2023 l_current_pi->poc.precno1 = p_max_precision;
2028 void pi_create_encode_v2( opj_pi_iterator_t *pi,
2034 J2K_T2_MODE t2_mode)
2036 const OPJ_CHAR *prog;
2038 OPJ_UINT32 incr_top=1,resetX=0;
2039 opj_tcp_v2_t *tcps =&cp->tcps[tileno];
2040 opj_poc_t *tcp= &tcps->pocs[pino];
2042 prog = opj_j2k_convert_progression_order(tcp->prg);
2045 pi[pino].poc.prg = tcp->prg;
2047 if(!(cp->m_specific_param.m_enc.m_tp_on&& ((!cp->m_specific_param.m_enc.m_cinema && (t2_mode == FINAL_PASS)) || cp->m_specific_param.m_enc.m_cinema))){
2048 pi[pino].poc.resno0 = tcp->resS;
2049 pi[pino].poc.resno1 = tcp->resE;
2050 pi[pino].poc.compno0 = tcp->compS;
2051 pi[pino].poc.compno1 = tcp->compE;
2052 pi[pino].poc.layno0 = tcp->layS;
2053 pi[pino].poc.layno1 = tcp->layE;
2054 pi[pino].poc.precno0 = tcp->prcS;
2055 pi[pino].poc.precno1 = tcp->prcE;
2056 pi[pino].poc.tx0 = tcp->txS;
2057 pi[pino].poc.ty0 = tcp->tyS;
2058 pi[pino].poc.tx1 = tcp->txE;
2059 pi[pino].poc.ty1 = tcp->tyE;
2061 for(i=tppos+1;i<4;i++){
2064 pi[pino].poc.resno0 = tcp->resS;
2065 pi[pino].poc.resno1 = tcp->resE;
2068 pi[pino].poc.compno0 = tcp->compS;
2069 pi[pino].poc.compno1 = tcp->compE;
2072 pi[pino].poc.layno0 = tcp->layS;
2073 pi[pino].poc.layno1 = tcp->layE;
2079 pi[pino].poc.precno0 = tcp->prcS;
2080 pi[pino].poc.precno1 = tcp->prcE;
2083 pi[pino].poc.tx0 = tcp->txS;
2084 pi[pino].poc.ty0 = tcp->tyS;
2085 pi[pino].poc.tx1 = tcp->txE;
2086 pi[pino].poc.ty1 = tcp->tyE;
2094 for(i=tppos;i>=0;i--){
2097 tcp->comp_t = tcp->compS;
2098 pi[pino].poc.compno0 = tcp->comp_t;
2099 pi[pino].poc.compno1 = tcp->comp_t+1;
2103 tcp->res_t = tcp->resS;
2104 pi[pino].poc.resno0 = tcp->res_t;
2105 pi[pino].poc.resno1 = tcp->res_t+1;
2109 tcp->lay_t = tcp->layS;
2110 pi[pino].poc.layno0 = tcp->lay_t;
2111 pi[pino].poc.layno1 = tcp->lay_t+1;
2118 tcp->prc_t = tcp->prcS;
2119 pi[pino].poc.precno0 = tcp->prc_t;
2120 pi[pino].poc.precno1 = tcp->prc_t+1;
2124 tcp->tx0_t = tcp->txS;
2125 tcp->ty0_t = tcp->tyS;
2126 pi[pino].poc.tx0 = tcp->tx0_t;
2127 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx);
2128 pi[pino].poc.ty0 = tcp->ty0_t;
2129 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
2130 tcp->tx0_t = pi[pino].poc.tx1;
2131 tcp->ty0_t = pi[pino].poc.ty1;
2139 for(i=tppos;i>=0;i--){
2142 pi[pino].poc.compno0 = tcp->comp_t-1;
2143 pi[pino].poc.compno1 = tcp->comp_t;
2146 pi[pino].poc.resno0 = tcp->res_t-1;
2147 pi[pino].poc.resno1 = tcp->res_t;
2150 pi[pino].poc.layno0 = tcp->lay_t-1;
2151 pi[pino].poc.layno1 = tcp->lay_t;
2157 pi[pino].poc.precno0 = tcp->prc_t-1;
2158 pi[pino].poc.precno1 = tcp->prc_t;
2161 pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx);
2162 pi[pino].poc.tx1 = tcp->tx0_t ;
2163 pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
2164 pi[pino].poc.ty1 = tcp->ty0_t ;
2172 if(tcp->res_t==tcp->resE){
2173 l=pi_check_next_level(i-1,cp,tileno,pino,prog);
2175 tcp->res_t = tcp->resS;
2176 pi[pino].poc.resno0 = tcp->res_t;
2177 pi[pino].poc.resno1 = tcp->res_t+1;
2184 pi[pino].poc.resno0 = tcp->res_t;
2185 pi[pino].poc.resno1 = tcp->res_t+1;
2191 if(tcp->comp_t ==tcp->compE){
2192 l=pi_check_next_level(i-1,cp,tileno,pino,prog);
2194 tcp->comp_t = tcp->compS;
2195 pi[pino].poc.compno0 = tcp->comp_t;
2196 pi[pino].poc.compno1 = tcp->comp_t+1;
2203 pi[pino].poc.compno0 = tcp->comp_t;
2204 pi[pino].poc.compno1 = tcp->comp_t+1;
2210 if(tcp->lay_t == tcp->layE){
2211 l=pi_check_next_level(i-1,cp,tileno,pino,prog);
2213 tcp->lay_t = tcp->layS;
2214 pi[pino].poc.layno0 = tcp->lay_t;
2215 pi[pino].poc.layno1 = tcp->lay_t+1;
2222 pi[pino].poc.layno0 = tcp->lay_t;
2223 pi[pino].poc.layno1 = tcp->lay_t+1;
2232 if(tcp->prc_t == tcp->prcE){
2233 l=pi_check_next_level(i-1,cp,tileno,pino,prog);
2235 tcp->prc_t = tcp->prcS;
2236 pi[pino].poc.precno0 = tcp->prc_t;
2237 pi[pino].poc.precno1 = tcp->prc_t+1;
2244 pi[pino].poc.precno0 = tcp->prc_t;
2245 pi[pino].poc.precno1 = tcp->prc_t+1;
2251 if(tcp->tx0_t >= tcp->txE){
2252 if(tcp->ty0_t >= tcp->tyE){
2253 l=pi_check_next_level(i-1,cp,tileno,pino,prog);
2255 tcp->ty0_t = tcp->tyS;
2256 pi[pino].poc.ty0 = tcp->ty0_t;
2257 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
2258 tcp->ty0_t = pi[pino].poc.ty1;
2259 incr_top=1;resetX=1;
2261 incr_top=0;resetX=0;
2264 pi[pino].poc.ty0 = tcp->ty0_t;
2265 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
2266 tcp->ty0_t = pi[pino].poc.ty1;
2267 incr_top=0;resetX=1;
2270 tcp->tx0_t = tcp->txS;
2271 pi[pino].poc.tx0 = tcp->tx0_t;
2272 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
2273 tcp->tx0_t = pi[pino].poc.tx1;
2276 pi[pino].poc.tx0 = tcp->tx0_t;
2277 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
2278 tcp->tx0_t = pi[pino].poc.tx1;
2291 OPJ_INT32 pi_check_next_level( OPJ_INT32 pos,
2295 const OPJ_CHAR *prog)
2298 opj_tcp_v2_t *tcps =&cp->tcps[tileno];
2299 opj_poc_t *tcp = &tcps->pocs[pino];
2302 for(i=pos;pos>=0;i--){
2305 if(tcp->res_t==tcp->resE){
2306 l=pi_check_next_level(pos-1,cp,tileno,pino,prog);
2317 if(tcp->comp_t==tcp->compE){
2318 l=pi_check_next_level(pos-1,cp,tileno,pino,prog);
2329 if(tcp->lay_t==tcp->layE){
2330 l=pi_check_next_level(pos-1,cp,tileno,pino,prog);
2343 if(tcp->prc_t == tcp->prcE){
2344 l=pi_check_next_level(i-1,cp,tileno,pino,prog);
2355 if(tcp->tx0_t == tcp->txE){
2357 if(tcp->ty0_t == tcp->tyE){
2358 l=pi_check_next_level(i-1,cp,tileno,pino,prog);