2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren
11 * Copyright (c) 2003-2007, Francois-Olivier Devaux
12 * Copyright (c) 2003-2014, Antonin Descampe
13 * Copyright (c) 2005, Herve Drolon, FreeImage Team
14 * Copyright (c) 2006-2007, Parvatha Elangovan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
39 #define OPJ_UINT32_SEMANTICALLY_BUT_INT32 OPJ_UINT32
41 #include "opj_includes.h"
43 /** @defgroup PI PI - Implementation of a packet iterator */
46 /** @name Local static functions */
50 Get next packet in layer-resolution-component-precinct order.
51 @param pi packet iterator to modify
52 @return returns false if pi pointed to the last packet or else returns true
54 static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi);
56 Get next packet in resolution-layer-component-precinct order.
57 @param pi packet iterator to modify
58 @return returns false if pi pointed to the last packet or else returns true
60 static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi);
62 Get next packet in resolution-precinct-component-layer order.
63 @param pi packet iterator to modify
64 @return returns false if pi pointed to the last packet or else returns true
66 static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi);
68 Get next packet in precinct-component-resolution-layer order.
69 @param pi packet iterator to modify
70 @return returns false if pi pointed to the last packet or else returns true
72 static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi);
74 Get next packet in component-precinct-resolution-layer order.
75 @param pi packet iterator to modify
76 @return returns false if pi pointed to the last packet or else returns true
78 static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi);
81 * Updates the coding parameters if the encoding is used with Progression order changes and final (or cinema parameters are used).
83 * @param p_cp the coding parameters to modify
84 * @param p_tileno the tile index being concerned.
85 * @param p_tx0 X0 parameter for the tile
86 * @param p_tx1 X1 parameter for the tile
87 * @param p_ty0 Y0 parameter for the tile
88 * @param p_ty1 Y1 parameter for the tile
89 * @param p_max_prec the maximum precision for all the bands of the tile
90 * @param p_max_res the maximum number of resolutions for all the poc inside the tile.
91 * @param p_dx_min the minimum dx of all the components of all the resolutions for the tile.
92 * @param p_dy_min the minimum dy of all the components of all the resolutions for the tile.
94 static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp,
100 OPJ_UINT32 p_max_prec,
101 OPJ_UINT32 p_max_res,
103 OPJ_UINT32 p_dy_min);
106 * Updates the coding parameters if the encoding is not used with Progression order changes and final (and cinema parameters are used).
108 * @param p_cp the coding parameters to modify
109 * @param p_num_comps the number of components
110 * @param p_tileno the tile index being concerned.
111 * @param p_tx0 X0 parameter for the tile
112 * @param p_tx1 X1 parameter for the tile
113 * @param p_ty0 Y0 parameter for the tile
114 * @param p_ty1 Y1 parameter for the tile
115 * @param p_max_prec the maximum precision for all the bands of the tile
116 * @param p_max_res the maximum number of resolutions for all the poc inside the tile.
117 * @param p_dx_min the minimum dx of all the components of all the resolutions for the tile.
118 * @param p_dy_min the minimum dy of all the components of all the resolutions for the tile.
120 static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp,
121 OPJ_UINT32 p_num_comps,
127 OPJ_UINT32 p_max_prec,
128 OPJ_UINT32 p_max_res,
130 OPJ_UINT32 p_dy_min);
132 * Gets the encoding parameters needed to update the coding parameters and all the pocs.
134 * @param p_image the image being encoded.
135 * @param p_cp the coding parameters.
136 * @param tileno the tile index of the tile being encoded.
137 * @param p_tx0 pointer that will hold the X0 parameter for the tile
138 * @param p_tx1 pointer that will hold the X1 parameter for the tile
139 * @param p_ty0 pointer that will hold the Y0 parameter for the tile
140 * @param p_ty1 pointer that will hold the Y1 parameter for the tile
141 * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
142 * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
143 * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
144 * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
146 static void opj_get_encoding_parameters(const opj_image_t *p_image,
147 const opj_cp_t *p_cp,
153 OPJ_UINT32 * p_dx_min,
154 OPJ_UINT32 * p_dy_min,
155 OPJ_UINT32 * p_max_prec,
156 OPJ_UINT32 * p_max_res);
159 * Gets the encoding parameters needed to update the coding parameters and all the pocs.
160 * The precinct widths, heights, dx and dy for each component at each resolution will be stored as well.
161 * the last parameter of the function should be an array of pointers of size nb components, each pointer leading
162 * to an area of size 4 * max_res. The data is stored inside this area with the following pattern :
163 * dx_compi_res0 , dy_compi_res0 , w_compi_res0, h_compi_res0 , dx_compi_res1 , dy_compi_res1 , w_compi_res1, h_compi_res1 , ...
165 * @param p_image the image being encoded.
166 * @param p_cp the coding parameters.
167 * @param tileno the tile index of the tile being encoded.
168 * @param p_tx0 pointer that will hold the X0 parameter for the tile
169 * @param p_tx1 pointer that will hold the X1 parameter for the tile
170 * @param p_ty0 pointer that will hold the Y0 parameter for the tile
171 * @param p_ty1 pointer that will hold the Y1 parameter for the tile
172 * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
173 * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
174 * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
175 * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
176 * @param p_resolutions pointer to an area corresponding to the one described above.
178 static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
179 const opj_cp_t *p_cp,
185 OPJ_UINT32 * p_dx_min,
186 OPJ_UINT32 * p_dy_min,
187 OPJ_UINT32 * p_max_prec,
188 OPJ_UINT32 * p_max_res,
189 OPJ_UINT32 ** p_resolutions);
191 * Allocates memory for a packet iterator. Data and data sizes are set by this operation.
192 * No other data is set. The include section of the packet iterator is not allocated.
194 * @param p_image the image used to initialize the packet iterator (in fact only the number of components is relevant.
195 * @param p_cp the coding parameters.
196 * @param tileno the index of the tile from which creating the packet iterator.
198 static opj_pi_iterator_t * opj_pi_create(const opj_image_t *p_image,
199 const opj_cp_t *p_cp,
204 static void opj_pi_update_decode_not_poc(opj_pi_iterator_t * p_pi,
206 OPJ_UINT32 p_max_precision,
207 OPJ_UINT32 p_max_res);
211 static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi,
213 OPJ_UINT32 p_max_precision,
214 OPJ_UINT32 p_max_res);
219 static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos,
223 const OPJ_CHAR *prog);
230 ==========================================================
232 ==========================================================
235 static void opj_pi_emit_error(opj_pi_iterator_t * pi, const char* msg)
241 static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi)
243 opj_pi_comp_t *comp = NULL;
244 opj_pi_resolution_t *res = NULL;
245 OPJ_UINT32 index = 0;
248 comp = &pi->comps[pi->compno];
249 res = &comp->resolutions[pi->resno];
255 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
256 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
258 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
259 comp = &pi->comps[pi->compno];
260 if (pi->resno >= comp->numresolutions) {
263 res = &comp->resolutions[pi->resno];
265 pi->poc.precno1 = res->pw * res->ph;
267 for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
268 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
269 pi->step_c + pi->precno * pi->step_p;
270 /* Avoids index out of bounds access with */
271 /* id_000098,sig_11,src_005411,op_havoc,rep_2 of */
272 /* https://github.com/uclouvain/openjpeg/issues/938 */
273 /* Not sure if this is the most clever fix. Perhaps */
274 /* include should be resized when a POC arises, or */
275 /* the POC should be rejected */
276 if (index >= pi->include_size) {
277 opj_pi_emit_error(pi, "Invalid access to pi->include");
280 if (!pi->include[index]) {
281 pi->include[index] = 1;
294 static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi)
296 opj_pi_comp_t *comp = NULL;
297 opj_pi_resolution_t *res = NULL;
298 OPJ_UINT32 index = 0;
301 comp = &pi->comps[pi->compno];
302 res = &comp->resolutions[pi->resno];
308 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
309 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
310 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
311 comp = &pi->comps[pi->compno];
312 if (pi->resno >= comp->numresolutions) {
315 res = &comp->resolutions[pi->resno];
317 pi->poc.precno1 = res->pw * res->ph;
319 for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
320 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
321 pi->step_c + pi->precno * pi->step_p;
322 if (index >= pi->include_size) {
323 opj_pi_emit_error(pi, "Invalid access to pi->include");
326 if (!pi->include[index]) {
327 pi->include[index] = 1;
340 static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi)
342 opj_pi_comp_t *comp = NULL;
343 opj_pi_resolution_t *res = NULL;
344 OPJ_UINT32 index = 0;
349 OPJ_UINT32 compno, resno;
353 for (compno = 0; compno < pi->numcomps; compno++) {
354 comp = &pi->comps[compno];
355 for (resno = 0; resno < comp->numresolutions; resno++) {
357 res = &comp->resolutions[resno];
358 if (res->pdx + comp->numresolutions - 1 - resno < 32 &&
359 comp->dx <= UINT_MAX / (1u << (res->pdx + comp->numresolutions - 1 - resno))) {
360 dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
361 pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
363 if (res->pdy + comp->numresolutions - 1 - resno < 32 &&
364 comp->dy <= UINT_MAX / (1u << (res->pdy + comp->numresolutions - 1 - resno))) {
365 dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
366 pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
370 if (pi->dx == 0 || pi->dy == 0) {
375 pi->poc.ty0 = pi->ty0;
376 pi->poc.tx0 = pi->tx0;
377 pi->poc.ty1 = pi->ty1;
378 pi->poc.tx1 = pi->tx1;
380 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
381 for (pi->y = (OPJ_UINT32)pi->poc.ty0; pi->y < (OPJ_UINT32)pi->poc.ty1;
382 pi->y += (pi->dy - (pi->y % pi->dy))) {
383 for (pi->x = (OPJ_UINT32)pi->poc.tx0; pi->x < (OPJ_UINT32)pi->poc.tx1;
384 pi->x += (pi->dx - (pi->x % pi->dx))) {
385 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
387 OPJ_UINT32 trx0, try0;
388 OPJ_UINT32 trx1, try1;
390 OPJ_UINT32 prci, prcj;
391 comp = &pi->comps[pi->compno];
392 if (pi->resno >= comp->numresolutions) {
395 res = &comp->resolutions[pi->resno];
396 levelno = comp->numresolutions - 1 - pi->resno;
397 /* Avoids division by zero */
398 /* Relates to id_000004,sig_06,src_000679,op_arith8,pos_49,val_-17 */
399 /* of https://github.com/uclouvain/openjpeg/issues/938 */
401 ((comp->dx << levelno) >> levelno) != comp->dx ||
402 ((comp->dy << levelno) >> levelno) != comp->dy) {
405 if ((comp->dx << levelno) > INT_MAX ||
406 (comp->dy << levelno) > INT_MAX) {
409 trx0 = opj_uint_ceildiv(pi->tx0, (comp->dx << levelno));
410 try0 = opj_uint_ceildiv(pi->ty0, (comp->dy << levelno));
411 trx1 = opj_uint_ceildiv(pi->tx1, (comp->dx << levelno));
412 try1 = opj_uint_ceildiv(pi->ty1, (comp->dy << levelno));
413 rpx = res->pdx + levelno;
414 rpy = res->pdy + levelno;
416 /* To avoid divisions by zero / undefined behaviour on shift */
418 /* Fixes reading id:000026,sig:08,src:002419,op:int32,pos:60,val:+32 */
419 /* of https://github.com/uclouvain/openjpeg/issues/938 */
420 if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
421 rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) {
425 /* See ISO-15441. B.12.1.3 Resolution level-position-component-layer progression */
426 if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) &&
427 ((try0 << levelno) % (1U << rpy))))) {
430 if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) &&
431 ((trx0 << levelno) % (1U << rpx))))) {
435 if ((res->pw == 0) || (res->ph == 0)) {
439 if ((trx0 == trx1) || (try0 == try1)) {
443 prci = opj_uint_floordivpow2(opj_uint_ceildiv(pi->x,
444 (comp->dx << levelno)), res->pdx)
445 - opj_uint_floordivpow2(trx0, res->pdx);
446 prcj = opj_uint_floordivpow2(opj_uint_ceildiv(pi->y,
447 (comp->dy << levelno)), res->pdy)
448 - opj_uint_floordivpow2(try0, res->pdy);
449 pi->precno = prci + prcj * res->pw;
450 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
451 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
452 pi->step_c + pi->precno * pi->step_p;
453 if (index >= pi->include_size) {
454 opj_pi_emit_error(pi, "Invalid access to pi->include");
457 if (!pi->include[index]) {
458 pi->include[index] = 1;
472 static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi)
474 opj_pi_comp_t *comp = NULL;
475 opj_pi_resolution_t *res = NULL;
476 OPJ_UINT32 index = 0;
479 comp = &pi->comps[pi->compno];
482 OPJ_UINT32 compno, resno;
486 for (compno = 0; compno < pi->numcomps; compno++) {
487 comp = &pi->comps[compno];
488 for (resno = 0; resno < comp->numresolutions; resno++) {
490 res = &comp->resolutions[resno];
491 if (res->pdx + comp->numresolutions - 1 - resno < 32 &&
492 comp->dx <= UINT_MAX / (1u << (res->pdx + comp->numresolutions - 1 - resno))) {
493 dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
494 pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
496 if (res->pdy + comp->numresolutions - 1 - resno < 32 &&
497 comp->dy <= UINT_MAX / (1u << (res->pdy + comp->numresolutions - 1 - resno))) {
498 dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
499 pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
503 if (pi->dx == 0 || pi->dy == 0) {
508 pi->poc.ty0 = pi->ty0;
509 pi->poc.tx0 = pi->tx0;
510 pi->poc.ty1 = pi->ty1;
511 pi->poc.tx1 = pi->tx1;
513 for (pi->y = (OPJ_UINT32)pi->poc.ty0; pi->y < (OPJ_UINT32)pi->poc.ty1;
514 pi->y += (pi->dy - (pi->y % pi->dy))) {
515 for (pi->x = (OPJ_UINT32)pi->poc.tx0; pi->x < (OPJ_UINT32)pi->poc.tx1;
516 pi->x += (pi->dx - (pi->x % pi->dx))) {
517 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
518 comp = &pi->comps[pi->compno];
519 for (pi->resno = pi->poc.resno0;
520 pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
522 OPJ_UINT32 trx0, try0;
523 OPJ_UINT32 trx1, try1;
525 OPJ_UINT32 prci, prcj;
526 res = &comp->resolutions[pi->resno];
527 levelno = comp->numresolutions - 1 - pi->resno;
528 /* Avoids division by zero */
529 /* Relates to id_000004,sig_06,src_000679,op_arith8,pos_49,val_-17 */
530 /* of https://github.com/uclouvain/openjpeg/issues/938 */
532 ((comp->dx << levelno) >> levelno) != comp->dx ||
533 ((comp->dy << levelno) >> levelno) != comp->dy) {
536 if ((comp->dx << levelno) > INT_MAX ||
537 (comp->dy << levelno) > INT_MAX) {
540 trx0 = opj_uint_ceildiv(pi->tx0, (comp->dx << levelno));
541 try0 = opj_uint_ceildiv(pi->ty0, (comp->dy << levelno));
542 trx1 = opj_uint_ceildiv(pi->tx1, (comp->dx << levelno));
543 try1 = opj_uint_ceildiv(pi->ty1, (comp->dy << levelno));
544 rpx = res->pdx + levelno;
545 rpy = res->pdy + levelno;
547 /* To avoid divisions by zero / undefined behaviour on shift */
549 /* Relates to id:000019,sig:08,src:001098,op:flip1,pos:49 */
550 /* of https://github.com/uclouvain/openjpeg/issues/938 */
551 if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
552 rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) {
556 /* See ISO-15441. B.12.1.4 Position-component-resolution level-layer progression */
557 if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) &&
558 ((try0 << levelno) % (1U << rpy))))) {
561 if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) &&
562 ((trx0 << levelno) % (1U << rpx))))) {
566 if ((res->pw == 0) || (res->ph == 0)) {
570 if ((trx0 == trx1) || (try0 == try1)) {
574 prci = opj_uint_floordivpow2(opj_uint_ceildiv(pi->x,
575 (comp->dx << levelno)), res->pdx)
576 - opj_uint_floordivpow2(trx0, res->pdx);
577 prcj = opj_uint_floordivpow2(opj_uint_ceildiv(pi->y,
578 (comp->dy << levelno)), res->pdy)
579 - opj_uint_floordivpow2(try0, res->pdy);
580 pi->precno = prci + prcj * res->pw;
581 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
582 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
583 pi->step_c + pi->precno * pi->step_p;
584 if (index >= pi->include_size) {
585 opj_pi_emit_error(pi, "Invalid access to pi->include");
588 if (!pi->include[index]) {
589 pi->include[index] = 1;
603 static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi)
605 opj_pi_comp_t *comp = NULL;
606 opj_pi_resolution_t *res = NULL;
607 OPJ_UINT32 index = 0;
610 comp = &pi->comps[pi->compno];
616 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
618 comp = &pi->comps[pi->compno];
621 for (resno = 0; resno < comp->numresolutions; resno++) {
623 res = &comp->resolutions[resno];
624 if (res->pdx + comp->numresolutions - 1 - resno < 32 &&
625 comp->dx <= UINT_MAX / (1u << (res->pdx + comp->numresolutions - 1 - resno))) {
626 dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
627 pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
629 if (res->pdy + comp->numresolutions - 1 - resno < 32 &&
630 comp->dy <= UINT_MAX / (1u << (res->pdy + comp->numresolutions - 1 - resno))) {
631 dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
632 pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
635 if (pi->dx == 0 || pi->dy == 0) {
639 pi->poc.ty0 = pi->ty0;
640 pi->poc.tx0 = pi->tx0;
641 pi->poc.ty1 = pi->ty1;
642 pi->poc.tx1 = pi->tx1;
644 for (pi->y = (OPJ_UINT32)pi->poc.ty0; pi->y < (OPJ_UINT32)pi->poc.ty1;
645 pi->y += (pi->dy - (pi->y % pi->dy))) {
646 for (pi->x = (OPJ_UINT32)pi->poc.tx0; pi->x < (OPJ_UINT32)pi->poc.tx1;
647 pi->x += (pi->dx - (pi->x % pi->dx))) {
648 for (pi->resno = pi->poc.resno0;
649 pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
651 OPJ_UINT32 trx0, try0;
652 OPJ_UINT32 trx1, try1;
654 OPJ_UINT32 prci, prcj;
655 res = &comp->resolutions[pi->resno];
656 levelno = comp->numresolutions - 1 - pi->resno;
657 /* Avoids division by zero on id_000004,sig_06,src_000679,op_arith8,pos_49,val_-17 */
658 /* of https://github.com/uclouvain/openjpeg/issues/938 */
660 ((comp->dx << levelno) >> levelno) != comp->dx ||
661 ((comp->dy << levelno) >> levelno) != comp->dy) {
664 if ((comp->dx << levelno) > INT_MAX ||
665 (comp->dy << levelno) > INT_MAX) {
668 trx0 = opj_uint_ceildiv(pi->tx0, (comp->dx << levelno));
669 try0 = opj_uint_ceildiv(pi->ty0, (comp->dy << levelno));
670 trx1 = opj_uint_ceildiv(pi->tx1, (comp->dx << levelno));
671 try1 = opj_uint_ceildiv(pi->ty1, (comp->dy << levelno));
672 rpx = res->pdx + levelno;
673 rpy = res->pdy + levelno;
675 /* To avoid divisions by zero / undefined behaviour on shift */
677 /* Fixes reading id:000019,sig:08,src:001098,op:flip1,pos:49 */
678 /* of https://github.com/uclouvain/openjpeg/issues/938 */
679 if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
680 rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) {
684 /* See ISO-15441. B.12.1.5 Component-position-resolution level-layer progression */
685 if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) &&
686 ((try0 << levelno) % (1U << rpy))))) {
689 if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) &&
690 ((trx0 << levelno) % (1U << rpx))))) {
694 if ((res->pw == 0) || (res->ph == 0)) {
698 if ((trx0 == trx1) || (try0 == try1)) {
702 prci = opj_uint_floordivpow2(opj_uint_ceildiv(pi->x,
703 (comp->dx << levelno)), res->pdx)
704 - opj_uint_floordivpow2(trx0, res->pdx);
705 prcj = opj_uint_floordivpow2(opj_uint_ceildiv(pi->y,
706 (comp->dy << levelno)), res->pdy)
707 - opj_uint_floordivpow2(try0, res->pdy);
708 pi->precno = (OPJ_UINT32)(prci + prcj * res->pw);
709 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
710 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
711 pi->step_c + pi->precno * pi->step_p;
712 if (index >= pi->include_size) {
713 opj_pi_emit_error(pi, "Invalid access to pi->include");
716 if (!pi->include[index]) {
717 pi->include[index] = 1;
731 static void opj_get_encoding_parameters(const opj_image_t *p_image,
732 const opj_cp_t *p_cp,
738 OPJ_UINT32 * p_dx_min,
739 OPJ_UINT32 * p_dy_min,
740 OPJ_UINT32 * p_max_prec,
741 OPJ_UINT32 * p_max_res)
744 OPJ_UINT32 compno, resno;
746 const opj_tcp_t *l_tcp = 00;
747 const opj_tccp_t * l_tccp = 00;
748 const opj_image_comp_t * l_img_comp = 00;
750 /* position in x and y of tile */
753 /* non-corrected (in regard to image offset) tile offset */
754 OPJ_UINT32 l_tx0, l_ty0;
758 assert(p_image != 00);
759 assert(p_tileno < p_cp->tw * p_cp->th);
761 /* initializations */
762 l_tcp = &p_cp->tcps [p_tileno];
763 l_img_comp = p_image->comps;
764 l_tccp = l_tcp->tccps;
766 /* here calculation of tx0, tx1, ty0, ty1, maxprec, dx and dy */
767 p = p_tileno % p_cp->tw;
768 q = p_tileno / p_cp->tw;
770 /* find extent of tile */
771 l_tx0 = p_cp->tx0 + p *
772 p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */
773 *p_tx0 = opj_uint_max(l_tx0, p_image->x0);
774 *p_tx1 = opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1);
775 l_ty0 = p_cp->ty0 + q *
776 p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */
777 *p_ty0 = opj_uint_max(l_ty0, p_image->y0);
778 *p_ty1 = opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1);
780 /* max precision is 0 (can only grow) */
784 /* take the largest value for dx_min and dy_min */
785 *p_dx_min = 0x7fffffff;
786 *p_dy_min = 0x7fffffff;
788 for (compno = 0; compno < p_image->numcomps; ++compno) {
789 /* arithmetic variables to calculate */
790 OPJ_UINT32 l_level_no;
791 OPJ_UINT32 l_rx0, l_ry0, l_rx1, l_ry1;
792 OPJ_UINT32 l_px0, l_py0, l_px1, py1;
793 OPJ_UINT32 l_pdx, l_pdy;
794 OPJ_UINT32 l_pw, l_ph;
795 OPJ_UINT32 l_product;
796 OPJ_UINT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
798 l_tcx0 = opj_uint_ceildiv(*p_tx0, l_img_comp->dx);
799 l_tcy0 = opj_uint_ceildiv(*p_ty0, l_img_comp->dy);
800 l_tcx1 = opj_uint_ceildiv(*p_tx1, l_img_comp->dx);
801 l_tcy1 = opj_uint_ceildiv(*p_ty1, l_img_comp->dy);
803 if (l_tccp->numresolutions > *p_max_res) {
804 *p_max_res = l_tccp->numresolutions;
807 /* use custom size for precincts */
808 for (resno = 0; resno < l_tccp->numresolutions; ++resno) {
809 OPJ_UINT32 l_dx, l_dy;
811 /* precinct width and height */
812 l_pdx = l_tccp->prcw[resno];
813 l_pdy = l_tccp->prch[resno];
815 l_dx = l_img_comp->dx * (1u << (l_pdx + l_tccp->numresolutions - 1 - resno));
816 l_dy = l_img_comp->dy * (1u << (l_pdy + l_tccp->numresolutions - 1 - resno));
818 /* take the minimum size for dx for each comp and resolution */
819 *p_dx_min = opj_uint_min(*p_dx_min, l_dx);
820 *p_dy_min = opj_uint_min(*p_dy_min, l_dy);
822 /* various calculations of extents */
823 l_level_no = l_tccp->numresolutions - 1 - resno;
825 l_rx0 = opj_uint_ceildivpow2(l_tcx0, l_level_no);
826 l_ry0 = opj_uint_ceildivpow2(l_tcy0, l_level_no);
827 l_rx1 = opj_uint_ceildivpow2(l_tcx1, l_level_no);
828 l_ry1 = opj_uint_ceildivpow2(l_tcy1, l_level_no);
830 l_px0 = opj_uint_floordivpow2(l_rx0, l_pdx) << l_pdx;
831 l_py0 = opj_uint_floordivpow2(l_ry0, l_pdy) << l_pdy;
832 l_px1 = opj_uint_ceildivpow2(l_rx1, l_pdx) << l_pdx;
834 py1 = opj_uint_ceildivpow2(l_ry1, l_pdy) << l_pdy;
836 l_pw = (l_rx0 == l_rx1) ? 0 : ((l_px1 - l_px0) >> l_pdx);
837 l_ph = (l_ry0 == l_ry1) ? 0 : ((py1 - l_py0) >> l_pdy);
839 l_product = l_pw * l_ph;
841 /* update precision */
842 if (l_product > *p_max_prec) {
843 *p_max_prec = l_product;
852 static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
853 const opj_cp_t *p_cp,
859 OPJ_UINT32 * p_dx_min,
860 OPJ_UINT32 * p_dy_min,
861 OPJ_UINT32 * p_max_prec,
862 OPJ_UINT32 * p_max_res,
863 OPJ_UINT32 ** p_resolutions)
866 OPJ_UINT32 compno, resno;
869 const opj_tcp_t *tcp = 00;
870 const opj_tccp_t * l_tccp = 00;
871 const opj_image_comp_t * l_img_comp = 00;
873 /* to store l_dx, l_dy, w and h for each resolution and component.*/
874 OPJ_UINT32 * lResolutionPtr;
876 /* position in x and y of tile*/
879 /* non-corrected (in regard to image offset) tile offset */
880 OPJ_UINT32 l_tx0, l_ty0;
882 /* preconditions in debug*/
884 assert(p_image != 00);
885 assert(tileno < p_cp->tw * p_cp->th);
888 tcp = &p_cp->tcps [tileno];
890 l_img_comp = p_image->comps;
892 /* position in x and y of tile*/
893 p = tileno % p_cp->tw;
894 q = tileno / p_cp->tw;
896 /* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */
897 l_tx0 = p_cp->tx0 + p *
898 p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */
899 *p_tx0 = opj_uint_max(l_tx0, p_image->x0);
900 *p_tx1 = opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1);
901 l_ty0 = p_cp->ty0 + q *
902 p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */
903 *p_ty0 = opj_uint_max(l_ty0, p_image->y0);
904 *p_ty1 = opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1);
906 /* max precision and resolution is 0 (can only grow)*/
910 /* take the largest value for dx_min and dy_min*/
911 *p_dx_min = 0x7fffffff;
912 *p_dy_min = 0x7fffffff;
914 for (compno = 0; compno < p_image->numcomps; ++compno) {
915 /* aritmetic variables to calculate*/
916 OPJ_UINT32 l_level_no;
917 OPJ_UINT32 l_rx0, l_ry0, l_rx1, l_ry1;
918 OPJ_UINT32 l_px0, l_py0, l_px1, py1;
919 OPJ_UINT32 l_product;
920 OPJ_UINT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
921 OPJ_UINT32 l_pdx, l_pdy, l_pw, l_ph;
923 lResolutionPtr = p_resolutions[compno];
925 l_tcx0 = opj_uint_ceildiv(*p_tx0, l_img_comp->dx);
926 l_tcy0 = opj_uint_ceildiv(*p_ty0, l_img_comp->dy);
927 l_tcx1 = opj_uint_ceildiv(*p_tx1, l_img_comp->dx);
928 l_tcy1 = opj_uint_ceildiv(*p_ty1, l_img_comp->dy);
930 if (l_tccp->numresolutions > *p_max_res) {
931 *p_max_res = l_tccp->numresolutions;
934 /* use custom size for precincts*/
935 l_level_no = l_tccp->numresolutions;
936 for (resno = 0; resno < l_tccp->numresolutions; ++resno) {
937 OPJ_UINT32 l_dx, l_dy;
941 /* precinct width and height*/
942 l_pdx = l_tccp->prcw[resno];
943 l_pdy = l_tccp->prch[resno];
944 *lResolutionPtr++ = l_pdx;
945 *lResolutionPtr++ = l_pdy;
946 if (l_pdx + l_level_no < 32 &&
947 l_img_comp->dx <= UINT_MAX / (1u << (l_pdx + l_level_no))) {
948 l_dx = l_img_comp->dx * (1u << (l_pdx + l_level_no));
949 /* take the minimum size for l_dx for each comp and resolution*/
950 *p_dx_min = opj_uint_min(*p_dx_min, l_dx);
952 if (l_pdy + l_level_no < 32 &&
953 l_img_comp->dy <= UINT_MAX / (1u << (l_pdy + l_level_no))) {
954 l_dy = l_img_comp->dy * (1u << (l_pdy + l_level_no));
955 *p_dy_min = opj_uint_min(*p_dy_min, l_dy);
958 /* various calculations of extents*/
959 l_rx0 = opj_uint_ceildivpow2(l_tcx0, l_level_no);
960 l_ry0 = opj_uint_ceildivpow2(l_tcy0, l_level_no);
961 l_rx1 = opj_uint_ceildivpow2(l_tcx1, l_level_no);
962 l_ry1 = opj_uint_ceildivpow2(l_tcy1, l_level_no);
963 l_px0 = opj_uint_floordivpow2(l_rx0, l_pdx) << l_pdx;
964 l_py0 = opj_uint_floordivpow2(l_ry0, l_pdy) << l_pdy;
965 l_px1 = opj_uint_ceildivpow2(l_rx1, l_pdx) << l_pdx;
966 py1 = opj_uint_ceildivpow2(l_ry1, l_pdy) << l_pdy;
967 l_pw = (l_rx0 == l_rx1) ? 0 : ((l_px1 - l_px0) >> l_pdx);
968 l_ph = (l_ry0 == l_ry1) ? 0 : ((py1 - l_py0) >> l_pdy);
969 *lResolutionPtr++ = l_pw;
970 *lResolutionPtr++ = l_ph;
971 l_product = l_pw * l_ph;
973 /* update precision*/
974 if (l_product > *p_max_prec) {
975 *p_max_prec = l_product;
984 static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image,
989 OPJ_UINT32 pino, compno;
990 /* number of poc in the p_pi*/
991 OPJ_UINT32 l_poc_bound;
993 /* pointers to tile coding parameters and components.*/
994 opj_pi_iterator_t *l_pi = 00;
996 const opj_tccp_t *tccp = 00;
998 /* current packet iterator being allocated*/
999 opj_pi_iterator_t *l_current_pi = 00;
1001 /* preconditions in debug*/
1003 assert(image != 00);
1004 assert(tileno < cp->tw * cp->th);
1006 /* initializations*/
1007 tcp = &cp->tcps[tileno];
1008 l_poc_bound = tcp->numpocs + 1;
1010 /* memory allocations*/
1011 l_pi = (opj_pi_iterator_t*) opj_calloc((l_poc_bound),
1012 sizeof(opj_pi_iterator_t));
1017 l_current_pi = l_pi;
1018 for (pino = 0; pino < l_poc_bound ; ++pino) {
1020 l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps,
1021 sizeof(opj_pi_comp_t));
1022 if (! l_current_pi->comps) {
1023 opj_pi_destroy(l_pi, l_poc_bound);
1027 l_current_pi->numcomps = image->numcomps;
1029 for (compno = 0; compno < image->numcomps; ++compno) {
1030 opj_pi_comp_t *comp = &l_current_pi->comps[compno];
1032 tccp = &tcp->tccps[compno];
1034 comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions,
1035 sizeof(opj_pi_resolution_t));
1036 if (!comp->resolutions) {
1037 opj_pi_destroy(l_pi, l_poc_bound);
1041 comp->numresolutions = tccp->numresolutions;
1048 static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp,
1049 OPJ_UINT32 p_tileno,
1054 OPJ_UINT32 p_max_prec,
1055 OPJ_UINT32 p_max_res,
1056 OPJ_UINT32 p_dx_min,
1057 OPJ_UINT32 p_dy_min)
1061 /* tile coding parameter*/
1062 opj_tcp_t *l_tcp = 00;
1063 /* current poc being updated*/
1064 opj_poc_t * l_current_poc = 00;
1067 OPJ_UINT32 l_poc_bound;
1069 OPJ_ARG_NOT_USED(p_max_res);
1071 /* preconditions in debug*/
1073 assert(p_tileno < p_cp->tw * p_cp->th);
1075 /* initializations*/
1076 l_tcp = &p_cp->tcps [p_tileno];
1077 /* number of iterations in the loop */
1078 l_poc_bound = l_tcp->numpocs + 1;
1080 /* start at first element, and to make sure the compiler will not make a calculation each time in the loop
1081 store a pointer to the current element to modify rather than l_tcp->pocs[i]*/
1082 l_current_poc = l_tcp->pocs;
1084 l_current_poc->compS = l_current_poc->compno0;
1085 l_current_poc->compE = l_current_poc->compno1;
1086 l_current_poc->resS = l_current_poc->resno0;
1087 l_current_poc->resE = l_current_poc->resno1;
1088 l_current_poc->layE = l_current_poc->layno1;
1090 /* special treatment for the first element*/
1091 l_current_poc->layS = 0;
1092 l_current_poc->prg = l_current_poc->prg1;
1093 l_current_poc->prcS = 0;
1095 l_current_poc->prcE = p_max_prec;
1096 l_current_poc->txS = (OPJ_UINT32)p_tx0;
1097 l_current_poc->txE = (OPJ_UINT32)p_tx1;
1098 l_current_poc->tyS = (OPJ_UINT32)p_ty0;
1099 l_current_poc->tyE = (OPJ_UINT32)p_ty1;
1100 l_current_poc->dx = p_dx_min;
1101 l_current_poc->dy = p_dy_min;
1104 for (pino = 1; pino < l_poc_bound ; ++pino) {
1105 l_current_poc->compS = l_current_poc->compno0;
1106 l_current_poc->compE = l_current_poc->compno1;
1107 l_current_poc->resS = l_current_poc->resno0;
1108 l_current_poc->resE = l_current_poc->resno1;
1109 l_current_poc->layE = l_current_poc->layno1;
1110 l_current_poc->prg = l_current_poc->prg1;
1111 l_current_poc->prcS = 0;
1112 /* special treatment here different from the first element*/
1113 l_current_poc->layS = (l_current_poc->layE > (l_current_poc - 1)->layE) ?
1114 l_current_poc->layE : 0;
1116 l_current_poc->prcE = p_max_prec;
1117 l_current_poc->txS = (OPJ_UINT32)p_tx0;
1118 l_current_poc->txE = (OPJ_UINT32)p_tx1;
1119 l_current_poc->tyS = (OPJ_UINT32)p_ty0;
1120 l_current_poc->tyE = (OPJ_UINT32)p_ty1;
1121 l_current_poc->dx = p_dx_min;
1122 l_current_poc->dy = p_dy_min;
1127 static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp,
1128 OPJ_UINT32 p_num_comps,
1129 OPJ_UINT32 p_tileno,
1134 OPJ_UINT32 p_max_prec,
1135 OPJ_UINT32 p_max_res,
1136 OPJ_UINT32 p_dx_min,
1137 OPJ_UINT32 p_dy_min)
1141 /* tile coding parameter*/
1142 opj_tcp_t *l_tcp = 00;
1143 /* current poc being updated*/
1144 opj_poc_t * l_current_poc = 00;
1146 OPJ_UINT32 l_poc_bound;
1148 /* preconditions in debug*/
1150 assert(p_tileno < p_cp->tw * p_cp->th);
1152 /* initializations*/
1153 l_tcp = &p_cp->tcps [p_tileno];
1155 /* number of iterations in the loop */
1156 l_poc_bound = l_tcp->numpocs + 1;
1158 /* start at first element, and to make sure the compiler will not make a calculation each time in the loop
1159 store a pointer to the current element to modify rather than l_tcp->pocs[i]*/
1160 l_current_poc = l_tcp->pocs;
1162 for (pino = 0; pino < l_poc_bound ; ++pino) {
1163 l_current_poc->compS = 0;
1164 l_current_poc->compE = p_num_comps;/*p_image->numcomps;*/
1165 l_current_poc->resS = 0;
1166 l_current_poc->resE = p_max_res;
1167 l_current_poc->layS = 0;
1168 l_current_poc->layE = l_tcp->numlayers;
1169 l_current_poc->prg = l_tcp->prg;
1170 l_current_poc->prcS = 0;
1171 l_current_poc->prcE = p_max_prec;
1172 l_current_poc->txS = p_tx0;
1173 l_current_poc->txE = p_tx1;
1174 l_current_poc->tyS = p_ty0;
1175 l_current_poc->tyE = p_ty1;
1176 l_current_poc->dx = p_dx_min;
1177 l_current_poc->dy = p_dy_min;
1182 static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi,
1184 OPJ_UINT32 p_max_precision,
1185 OPJ_UINT32 p_max_res)
1190 /* encoding prameters to set*/
1193 opj_pi_iterator_t * l_current_pi = 00;
1194 opj_poc_t* l_current_poc = 0;
1196 OPJ_ARG_NOT_USED(p_max_res);
1198 /* preconditions in debug*/
1200 assert(p_tcp != 00);
1202 /* initializations*/
1203 l_bound = p_tcp->numpocs + 1;
1204 l_current_pi = p_pi;
1205 l_current_poc = p_tcp->pocs;
1207 for (pino = 0; pino < l_bound; ++pino) {
1208 l_current_pi->poc.prg = l_current_poc->prg; /* Progression Order #0 */
1209 l_current_pi->first = 1;
1211 l_current_pi->poc.resno0 =
1212 l_current_poc->resno0; /* Resolution Level Index #0 (Start) */
1213 l_current_pi->poc.compno0 =
1214 l_current_poc->compno0; /* Component Index #0 (Start) */
1215 l_current_pi->poc.layno0 = 0;
1216 l_current_pi->poc.precno0 = 0;
1217 l_current_pi->poc.resno1 =
1218 l_current_poc->resno1; /* Resolution Level Index #0 (End) */
1219 l_current_pi->poc.compno1 =
1220 l_current_poc->compno1; /* Component Index #0 (End) */
1221 l_current_pi->poc.layno1 = opj_uint_min(l_current_poc->layno1,
1222 p_tcp->numlayers); /* Layer Index #0 (End) */
1223 l_current_pi->poc.precno1 = p_max_precision;
1229 static void opj_pi_update_decode_not_poc(opj_pi_iterator_t * p_pi,
1231 OPJ_UINT32 p_max_precision,
1232 OPJ_UINT32 p_max_res)
1237 /* encoding prameters to set*/
1240 opj_pi_iterator_t * l_current_pi = 00;
1241 /* preconditions in debug*/
1242 assert(p_tcp != 00);
1245 /* initializations*/
1246 l_bound = p_tcp->numpocs + 1;
1247 l_current_pi = p_pi;
1249 for (pino = 0; pino < l_bound; ++pino) {
1250 l_current_pi->poc.prg = p_tcp->prg;
1251 l_current_pi->first = 1;
1252 l_current_pi->poc.resno0 = 0;
1253 l_current_pi->poc.compno0 = 0;
1254 l_current_pi->poc.layno0 = 0;
1255 l_current_pi->poc.precno0 = 0;
1256 l_current_pi->poc.resno1 = p_max_res;
1257 l_current_pi->poc.compno1 = l_current_pi->numcomps;
1258 l_current_pi->poc.layno1 = p_tcp->numlayers;
1259 l_current_pi->poc.precno1 = p_max_precision;
1266 static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos,
1270 const OPJ_CHAR *prog)
1273 opj_tcp_t *tcps = &cp->tcps[tileno];
1274 opj_poc_t *tcp = &tcps->pocs[pino];
1277 for (i = pos; pos >= 0; i--) {
1280 if (tcp->res_t == tcp->resE) {
1281 if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) {
1291 if (tcp->comp_t == tcp->compE) {
1292 if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) {
1302 if (tcp->lay_t == tcp->layE) {
1303 if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) {
1314 case OPJ_LRCP: /* fall through */
1316 if (tcp->prc_t == tcp->prcE) {
1317 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1327 if (tcp->tx0_t == tcp->txE) {
1329 if (tcp->ty0_t == tcp->tyE) {
1330 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1351 ==========================================================
1352 Packet iterator interface
1353 ==========================================================
1355 opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
1357 OPJ_UINT32 p_tile_no)
1359 OPJ_UINT32 numcomps = p_image->numcomps;
1363 OPJ_UINT32 compno, resno;
1365 /* to store w, h, dx and dy fro all components and resolutions */
1366 OPJ_UINT32 * l_tmp_data;
1367 OPJ_UINT32 ** l_tmp_ptr;
1369 /* encoding prameters to set */
1370 OPJ_UINT32 l_max_res;
1371 OPJ_UINT32 l_max_prec;
1372 OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1;
1373 OPJ_UINT32 l_dx_min, l_dy_min;
1375 OPJ_UINT32 l_step_p, l_step_c, l_step_r, l_step_l ;
1376 OPJ_UINT32 l_data_stride;
1379 opj_pi_iterator_t *l_pi = 00;
1380 opj_tcp_t *l_tcp = 00;
1381 const opj_tccp_t *l_tccp = 00;
1382 opj_pi_comp_t *l_current_comp = 00;
1383 opj_image_comp_t * l_img_comp = 00;
1384 opj_pi_iterator_t * l_current_pi = 00;
1385 OPJ_UINT32 * l_encoding_value_ptr = 00;
1387 /* preconditions in debug */
1389 assert(p_image != 00);
1390 assert(p_tile_no < p_cp->tw * p_cp->th);
1392 /* initializations */
1393 l_tcp = &p_cp->tcps[p_tile_no];
1394 l_bound = l_tcp->numpocs + 1;
1396 l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
1397 l_tmp_data = (OPJ_UINT32*)opj_malloc(
1398 l_data_stride * numcomps * sizeof(OPJ_UINT32));
1403 l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
1404 numcomps * sizeof(OPJ_UINT32 *));
1407 opj_free(l_tmp_data);
1411 /* memory allocation for pi */
1412 l_pi = opj_pi_create(p_image, p_cp, p_tile_no);
1414 opj_free(l_tmp_data);
1415 opj_free(l_tmp_ptr);
1419 l_encoding_value_ptr = l_tmp_data;
1420 /* update pointer array */
1422 (compno = 0; compno < numcomps; ++compno) {
1423 l_tmp_ptr[compno] = l_encoding_value_ptr;
1424 l_encoding_value_ptr += l_data_stride;
1426 /* get encoding parameters */
1427 opj_get_all_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1,
1428 &l_ty0, &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res, l_tmp_ptr);
1430 /* step calculations */
1432 l_step_c = l_max_prec * l_step_p;
1433 l_step_r = numcomps * l_step_c;
1434 l_step_l = l_max_res * l_step_r;
1436 /* set values for first packet iterator */
1437 l_current_pi = l_pi;
1439 /* memory allocation for include */
1440 /* prevent an integer overflow issue */
1441 /* 0 < l_tcp->numlayers < 65536 c.f. opj_j2k_read_cod in j2k.c */
1442 l_current_pi->include = 00;
1443 if (l_step_l <= (UINT_MAX / (l_tcp->numlayers + 1U))) {
1444 l_current_pi->include_size = (l_tcp->numlayers + 1U) * l_step_l;
1445 l_current_pi->include = (OPJ_INT16*) opj_calloc(
1446 l_current_pi->include_size, sizeof(OPJ_INT16));
1449 if (!l_current_pi->include) {
1450 opj_free(l_tmp_data);
1451 opj_free(l_tmp_ptr);
1452 opj_pi_destroy(l_pi, l_bound);
1456 /* special treatment for the first packet iterator */
1457 l_current_comp = l_current_pi->comps;
1458 l_img_comp = p_image->comps;
1459 l_tccp = l_tcp->tccps;
1461 l_current_pi->tx0 = l_tx0;
1462 l_current_pi->ty0 = l_ty0;
1463 l_current_pi->tx1 = l_tx1;
1464 l_current_pi->ty1 = l_ty1;
1466 /*l_current_pi->dx = l_img_comp->dx;*/
1467 /*l_current_pi->dy = l_img_comp->dy;*/
1469 l_current_pi->step_p = l_step_p;
1470 l_current_pi->step_c = l_step_c;
1471 l_current_pi->step_r = l_step_r;
1472 l_current_pi->step_l = l_step_l;
1474 /* allocation for components and number of components has already been calculated by opj_pi_create */
1476 (compno = 0; compno < numcomps; ++compno) {
1477 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1478 l_encoding_value_ptr = l_tmp_ptr[compno];
1480 l_current_comp->dx = l_img_comp->dx;
1481 l_current_comp->dy = l_img_comp->dy;
1482 /* resolutions have already been initialized */
1484 (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1485 l_res->pdx = *(l_encoding_value_ptr++);
1486 l_res->pdy = *(l_encoding_value_ptr++);
1487 l_res->pw = *(l_encoding_value_ptr++);
1488 l_res->ph = *(l_encoding_value_ptr++);
1497 for (pino = 1 ; pino < l_bound ; ++pino) {
1498 l_current_comp = l_current_pi->comps;
1499 l_img_comp = p_image->comps;
1500 l_tccp = l_tcp->tccps;
1502 l_current_pi->tx0 = l_tx0;
1503 l_current_pi->ty0 = l_ty0;
1504 l_current_pi->tx1 = l_tx1;
1505 l_current_pi->ty1 = l_ty1;
1506 /*l_current_pi->dx = l_dx_min;*/
1507 /*l_current_pi->dy = l_dy_min;*/
1508 l_current_pi->step_p = l_step_p;
1509 l_current_pi->step_c = l_step_c;
1510 l_current_pi->step_r = l_step_r;
1511 l_current_pi->step_l = l_step_l;
1513 /* allocation for components and number of components has already been calculated by opj_pi_create */
1515 (compno = 0; compno < numcomps; ++compno) {
1516 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1517 l_encoding_value_ptr = l_tmp_ptr[compno];
1519 l_current_comp->dx = l_img_comp->dx;
1520 l_current_comp->dy = l_img_comp->dy;
1521 /* resolutions have already been initialized */
1523 (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1524 l_res->pdx = *(l_encoding_value_ptr++);
1525 l_res->pdy = *(l_encoding_value_ptr++);
1526 l_res->pw = *(l_encoding_value_ptr++);
1527 l_res->ph = *(l_encoding_value_ptr++);
1534 /* special treatment*/
1535 l_current_pi->include = (l_current_pi - 1)->include;
1536 l_current_pi->include_size = (l_current_pi - 1)->include_size;
1539 opj_free(l_tmp_data);
1541 opj_free(l_tmp_ptr);
1545 opj_pi_update_decode_poc(l_pi, l_tcp, l_max_prec, l_max_res);
1547 opj_pi_update_decode_not_poc(l_pi, l_tcp, l_max_prec, l_max_res);
1554 opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
1556 OPJ_UINT32 p_tile_no,
1557 J2K_T2_MODE p_t2_mode)
1559 OPJ_UINT32 numcomps = p_image->numcomps;
1563 OPJ_UINT32 compno, resno;
1565 /* to store w, h, dx and dy fro all components and resolutions*/
1566 OPJ_UINT32 * l_tmp_data;
1567 OPJ_UINT32 ** l_tmp_ptr;
1569 /* encoding prameters to set*/
1570 OPJ_UINT32 l_max_res;
1571 OPJ_UINT32 l_max_prec;
1572 OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1;
1573 OPJ_UINT32 l_dx_min, l_dy_min;
1575 OPJ_UINT32 l_step_p, l_step_c, l_step_r, l_step_l ;
1576 OPJ_UINT32 l_data_stride;
1579 opj_pi_iterator_t *l_pi = 00;
1580 opj_tcp_t *l_tcp = 00;
1581 const opj_tccp_t *l_tccp = 00;
1582 opj_pi_comp_t *l_current_comp = 00;
1583 opj_image_comp_t * l_img_comp = 00;
1584 opj_pi_iterator_t * l_current_pi = 00;
1585 OPJ_UINT32 * l_encoding_value_ptr = 00;
1587 /* preconditions in debug*/
1589 assert(p_image != 00);
1590 assert(p_tile_no < p_cp->tw * p_cp->th);
1592 /* initializations*/
1593 l_tcp = &p_cp->tcps[p_tile_no];
1594 l_bound = l_tcp->numpocs + 1;
1596 l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
1597 l_tmp_data = (OPJ_UINT32*)opj_malloc(
1598 l_data_stride * numcomps * sizeof(OPJ_UINT32));
1603 l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
1604 numcomps * sizeof(OPJ_UINT32 *));
1606 opj_free(l_tmp_data);
1610 /* memory allocation for pi*/
1611 l_pi = opj_pi_create(p_image, p_cp, p_tile_no);
1613 opj_free(l_tmp_data);
1614 opj_free(l_tmp_ptr);
1618 l_encoding_value_ptr = l_tmp_data;
1619 /* update pointer array*/
1620 for (compno = 0; compno < numcomps; ++compno) {
1621 l_tmp_ptr[compno] = l_encoding_value_ptr;
1622 l_encoding_value_ptr += l_data_stride;
1625 /* get encoding parameters*/
1626 opj_get_all_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1,
1627 &l_ty0, &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res, l_tmp_ptr);
1629 /* step calculations*/
1631 l_step_c = l_max_prec * l_step_p;
1632 l_step_r = numcomps * l_step_c;
1633 l_step_l = l_max_res * l_step_r;
1635 /* set values for first packet iterator*/
1636 l_pi->tp_on = (OPJ_BYTE)p_cp->m_specific_param.m_enc.m_tp_on;
1637 l_current_pi = l_pi;
1639 /* memory allocation for include*/
1640 l_current_pi->include_size = l_tcp->numlayers * l_step_l;
1641 l_current_pi->include = (OPJ_INT16*) opj_calloc(l_current_pi->include_size,
1643 if (!l_current_pi->include) {
1644 opj_free(l_tmp_data);
1645 opj_free(l_tmp_ptr);
1646 opj_pi_destroy(l_pi, l_bound);
1650 /* special treatment for the first packet iterator*/
1651 l_current_comp = l_current_pi->comps;
1652 l_img_comp = p_image->comps;
1653 l_tccp = l_tcp->tccps;
1654 l_current_pi->tx0 = l_tx0;
1655 l_current_pi->ty0 = l_ty0;
1656 l_current_pi->tx1 = l_tx1;
1657 l_current_pi->ty1 = l_ty1;
1658 l_current_pi->dx = l_dx_min;
1659 l_current_pi->dy = l_dy_min;
1660 l_current_pi->step_p = l_step_p;
1661 l_current_pi->step_c = l_step_c;
1662 l_current_pi->step_r = l_step_r;
1663 l_current_pi->step_l = l_step_l;
1665 /* allocation for components and number of components has already been calculated by opj_pi_create */
1666 for (compno = 0; compno < numcomps; ++compno) {
1667 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1668 l_encoding_value_ptr = l_tmp_ptr[compno];
1670 l_current_comp->dx = l_img_comp->dx;
1671 l_current_comp->dy = l_img_comp->dy;
1673 /* resolutions have already been initialized */
1674 for (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1675 l_res->pdx = *(l_encoding_value_ptr++);
1676 l_res->pdy = *(l_encoding_value_ptr++);
1677 l_res->pw = *(l_encoding_value_ptr++);
1678 l_res->ph = *(l_encoding_value_ptr++);
1688 for (pino = 1 ; pino < l_bound ; ++pino) {
1689 l_current_comp = l_current_pi->comps;
1690 l_img_comp = p_image->comps;
1691 l_tccp = l_tcp->tccps;
1693 l_current_pi->tx0 = l_tx0;
1694 l_current_pi->ty0 = l_ty0;
1695 l_current_pi->tx1 = l_tx1;
1696 l_current_pi->ty1 = l_ty1;
1697 l_current_pi->dx = l_dx_min;
1698 l_current_pi->dy = l_dy_min;
1699 l_current_pi->step_p = l_step_p;
1700 l_current_pi->step_c = l_step_c;
1701 l_current_pi->step_r = l_step_r;
1702 l_current_pi->step_l = l_step_l;
1704 /* allocation for components and number of components has already been calculated by opj_pi_create */
1705 for (compno = 0; compno < numcomps; ++compno) {
1706 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1707 l_encoding_value_ptr = l_tmp_ptr[compno];
1709 l_current_comp->dx = l_img_comp->dx;
1710 l_current_comp->dy = l_img_comp->dy;
1711 /* resolutions have already been initialized */
1712 for (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1713 l_res->pdx = *(l_encoding_value_ptr++);
1714 l_res->pdy = *(l_encoding_value_ptr++);
1715 l_res->pw = *(l_encoding_value_ptr++);
1716 l_res->ph = *(l_encoding_value_ptr++);
1724 /* special treatment*/
1725 l_current_pi->include = (l_current_pi - 1)->include;
1726 l_current_pi->include_size = (l_current_pi - 1)->include_size;
1730 opj_free(l_tmp_data);
1732 opj_free(l_tmp_ptr);
1735 if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) {
1736 opj_pi_update_encode_poc_and_final(p_cp, p_tile_no, l_tx0, l_tx1, l_ty0, l_ty1,
1737 l_max_prec, l_max_res, l_dx_min, l_dy_min);
1739 opj_pi_update_encode_not_poc(p_cp, numcomps, p_tile_no, l_tx0, l_tx1,
1740 l_ty0, l_ty1, l_max_prec, l_max_res, l_dx_min, l_dy_min);
1746 void opj_pi_create_encode(opj_pi_iterator_t *pi,
1752 J2K_T2_MODE t2_mode)
1754 const OPJ_CHAR *prog;
1756 OPJ_UINT32 incr_top = 1, resetX = 0;
1757 opj_tcp_t *tcps = &cp->tcps[tileno];
1758 opj_poc_t *tcp = &tcps->pocs[pino];
1760 prog = opj_j2k_convert_progression_order(tcp->prg);
1763 pi[pino].poc.prg = tcp->prg;
1765 if (!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) &&
1766 !OPJ_IS_IMF(cp->rsiz) &&
1767 (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz) || OPJ_IS_IMF(cp->rsiz)))) {
1768 pi[pino].poc.resno0 = tcp->resS;
1769 pi[pino].poc.resno1 = tcp->resE;
1770 pi[pino].poc.compno0 = tcp->compS;
1771 pi[pino].poc.compno1 = tcp->compE;
1772 pi[pino].poc.layno0 = tcp->layS;
1773 pi[pino].poc.layno1 = tcp->layE;
1774 pi[pino].poc.precno0 = tcp->prcS;
1775 pi[pino].poc.precno1 = tcp->prcE;
1776 pi[pino].poc.tx0 = tcp->txS;
1777 pi[pino].poc.ty0 = tcp->tyS;
1778 pi[pino].poc.tx1 = tcp->txE;
1779 pi[pino].poc.ty1 = tcp->tyE;
1781 for (i = tppos + 1; i < 4; i++) {
1784 pi[pino].poc.resno0 = tcp->resS;
1785 pi[pino].poc.resno1 = tcp->resE;
1788 pi[pino].poc.compno0 = tcp->compS;
1789 pi[pino].poc.compno1 = tcp->compE;
1792 pi[pino].poc.layno0 = tcp->layS;
1793 pi[pino].poc.layno1 = tcp->layE;
1799 pi[pino].poc.precno0 = tcp->prcS;
1800 pi[pino].poc.precno1 = tcp->prcE;
1803 pi[pino].poc.tx0 = tcp->txS;
1804 pi[pino].poc.ty0 = tcp->tyS;
1805 pi[pino].poc.tx1 = tcp->txE;
1806 pi[pino].poc.ty1 = tcp->tyE;
1814 for (i = tppos; i >= 0; i--) {
1817 tcp->comp_t = tcp->compS;
1818 pi[pino].poc.compno0 = tcp->comp_t;
1819 pi[pino].poc.compno1 = tcp->comp_t + 1;
1823 tcp->res_t = tcp->resS;
1824 pi[pino].poc.resno0 = tcp->res_t;
1825 pi[pino].poc.resno1 = tcp->res_t + 1;
1829 tcp->lay_t = tcp->layS;
1830 pi[pino].poc.layno0 = tcp->lay_t;
1831 pi[pino].poc.layno1 = tcp->lay_t + 1;
1838 tcp->prc_t = tcp->prcS;
1839 pi[pino].poc.precno0 = tcp->prc_t;
1840 pi[pino].poc.precno1 = tcp->prc_t + 1;
1844 tcp->tx0_t = tcp->txS;
1845 tcp->ty0_t = tcp->tyS;
1846 pi[pino].poc.tx0 = tcp->tx0_t;
1847 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx);
1848 pi[pino].poc.ty0 = tcp->ty0_t;
1849 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
1850 tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
1851 tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
1859 for (i = tppos; i >= 0; i--) {
1862 pi[pino].poc.compno0 = tcp->comp_t - 1;
1863 pi[pino].poc.compno1 = tcp->comp_t;
1866 pi[pino].poc.resno0 = tcp->res_t - 1;
1867 pi[pino].poc.resno1 = tcp->res_t;
1870 pi[pino].poc.layno0 = tcp->lay_t - 1;
1871 pi[pino].poc.layno1 = tcp->lay_t;
1877 pi[pino].poc.precno0 = tcp->prc_t - 1;
1878 pi[pino].poc.precno1 = tcp->prc_t;
1881 pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx);
1882 pi[pino].poc.tx1 = tcp->tx0_t ;
1883 pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
1884 pi[pino].poc.ty1 = tcp->ty0_t ;
1889 if (incr_top == 1) {
1892 if (tcp->res_t == tcp->resE) {
1893 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1894 tcp->res_t = tcp->resS;
1895 pi[pino].poc.resno0 = tcp->res_t;
1896 pi[pino].poc.resno1 = tcp->res_t + 1;
1903 pi[pino].poc.resno0 = tcp->res_t;
1904 pi[pino].poc.resno1 = tcp->res_t + 1;
1910 if (tcp->comp_t == tcp->compE) {
1911 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1912 tcp->comp_t = tcp->compS;
1913 pi[pino].poc.compno0 = tcp->comp_t;
1914 pi[pino].poc.compno1 = tcp->comp_t + 1;
1921 pi[pino].poc.compno0 = tcp->comp_t;
1922 pi[pino].poc.compno1 = tcp->comp_t + 1;
1928 if (tcp->lay_t == tcp->layE) {
1929 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1930 tcp->lay_t = tcp->layS;
1931 pi[pino].poc.layno0 = tcp->lay_t;
1932 pi[pino].poc.layno1 = tcp->lay_t + 1;
1939 pi[pino].poc.layno0 = tcp->lay_t;
1940 pi[pino].poc.layno1 = tcp->lay_t + 1;
1949 if (tcp->prc_t == tcp->prcE) {
1950 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1951 tcp->prc_t = tcp->prcS;
1952 pi[pino].poc.precno0 = tcp->prc_t;
1953 pi[pino].poc.precno1 = tcp->prc_t + 1;
1960 pi[pino].poc.precno0 = tcp->prc_t;
1961 pi[pino].poc.precno1 = tcp->prc_t + 1;
1967 if (tcp->tx0_t >= tcp->txE) {
1968 if (tcp->ty0_t >= tcp->tyE) {
1969 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1970 tcp->ty0_t = tcp->tyS;
1971 pi[pino].poc.ty0 = tcp->ty0_t;
1972 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
1973 tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
1981 pi[pino].poc.ty0 = tcp->ty0_t;
1982 pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
1983 tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
1988 tcp->tx0_t = tcp->txS;
1989 pi[pino].poc.tx0 = tcp->tx0_t;
1990 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx);
1991 tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
1994 pi[pino].poc.tx0 = tcp->tx0_t;
1995 pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx);
1996 tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
2009 void opj_pi_destroy(opj_pi_iterator_t *p_pi,
2010 OPJ_UINT32 p_nb_elements)
2012 OPJ_UINT32 compno, pino;
2013 opj_pi_iterator_t *l_current_pi = p_pi;
2015 if (p_pi->include) {
2016 opj_free(p_pi->include);
2019 for (pino = 0; pino < p_nb_elements; ++pino) {
2020 if (l_current_pi->comps) {
2021 opj_pi_comp_t *l_current_component = l_current_pi->comps;
2022 for (compno = 0; compno < l_current_pi->numcomps; compno++) {
2023 if (l_current_component->resolutions) {
2024 opj_free(l_current_component->resolutions);
2025 l_current_component->resolutions = 00;
2028 ++l_current_component;
2030 opj_free(l_current_pi->comps);
2031 l_current_pi->comps = 0;
2041 void opj_pi_update_encoding_parameters(const opj_image_t *p_image,
2043 OPJ_UINT32 p_tile_no)
2045 /* encoding parameters to set */
2046 OPJ_UINT32 l_max_res;
2047 OPJ_UINT32 l_max_prec;
2048 OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1;
2049 OPJ_UINT32 l_dx_min, l_dy_min;
2052 opj_tcp_t *l_tcp = 00;
2056 assert(p_image != 00);
2057 assert(p_tile_no < p_cp->tw * p_cp->th);
2059 l_tcp = &(p_cp->tcps[p_tile_no]);
2061 /* get encoding parameters */
2062 opj_get_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1, &l_ty0,
2063 &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res);
2066 opj_pi_update_encode_poc_and_final(p_cp, p_tile_no, l_tx0, l_tx1, l_ty0, l_ty1,
2067 l_max_prec, l_max_res, l_dx_min, l_dy_min);
2069 opj_pi_update_encode_not_poc(p_cp, p_image->numcomps, p_tile_no, l_tx0, l_tx1,
2070 l_ty0, l_ty1, l_max_prec, l_max_res, l_dx_min, l_dy_min);
2074 OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi)
2076 switch (pi->poc.prg) {
2078 return opj_pi_next_lrcp(pi);
2080 return opj_pi_next_rlcp(pi);
2082 return opj_pi_next_rpcl(pi);
2084 return opj_pi_next_pcrl(pi);
2086 return opj_pi_next_cprl(pi);
2087 case OPJ_PROG_UNKNOWN: