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 #include "opj_includes.h"
41 /** @defgroup PI PI - Implementation of a packet iterator */
44 /** @name Local static functions */
48 Get next packet in layer-resolution-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 opj_pi_next_lrcp(opj_pi_iterator_t * pi);
54 Get next packet in resolution-layer-component-precinct 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 opj_pi_next_rlcp(opj_pi_iterator_t * pi);
60 Get next packet in resolution-precinct-component-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 opj_pi_next_rpcl(opj_pi_iterator_t * pi);
66 Get next packet in precinct-component-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 opj_pi_next_pcrl(opj_pi_iterator_t * pi);
72 Get next packet in component-precinct-resolution-layer order.
73 @param pi packet iterator to modify
74 @return returns false if pi pointed to the last packet or else returns true
76 static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi);
79 * Updates the coding parameters if the encoding is used with Progression order changes and final (or cinema parameters are used).
81 * @param p_cp the coding parameters to modify
82 * @param p_tileno the tile index being concerned.
83 * @param p_tx0 X0 parameter for the tile
84 * @param p_tx1 X1 parameter for the tile
85 * @param p_ty0 Y0 parameter for the tile
86 * @param p_ty1 Y1 parameter for the tile
87 * @param p_max_prec the maximum precision for all the bands of the tile
88 * @param p_max_res the maximum number of resolutions for all the poc inside the tile.
89 * @param p_dx_min the minimum dx of all the components of all the resolutions for the tile.
90 * @param p_dy_min the minimum dy of all the components of all the resolutions for the tile.
92 static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp,
98 OPJ_UINT32 p_max_prec,
101 OPJ_UINT32 p_dy_min);
104 * Updates the coding parameters if the encoding is not used with Progression order changes and final (and cinema parameters are used).
106 * @param p_cp the coding parameters to modify
107 * @param p_num_comps the number of components
108 * @param p_tileno the tile index being concerned.
109 * @param p_tx0 X0 parameter for the tile
110 * @param p_tx1 X1 parameter for the tile
111 * @param p_ty0 Y0 parameter for the tile
112 * @param p_ty1 Y1 parameter for the tile
113 * @param p_max_prec the maximum precision for all the bands of the tile
114 * @param p_max_res the maximum number of resolutions for all the poc inside the tile.
115 * @param p_dx_min the minimum dx of all the components of all the resolutions for the tile.
116 * @param p_dy_min the minimum dy of all the components of all the resolutions for the tile.
118 static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp,
119 OPJ_UINT32 p_num_comps,
125 OPJ_UINT32 p_max_prec,
126 OPJ_UINT32 p_max_res,
128 OPJ_UINT32 p_dy_min);
130 * Gets the encoding parameters needed to update the coding parameters and all the pocs.
132 * @param p_image the image being encoded.
133 * @param p_cp the coding parameters.
134 * @param tileno the tile index of the tile being encoded.
135 * @param p_tx0 pointer that will hold the X0 parameter for the tile
136 * @param p_tx1 pointer that will hold the X1 parameter for the tile
137 * @param p_ty0 pointer that will hold the Y0 parameter for the tile
138 * @param p_ty1 pointer that will hold the Y1 parameter for the tile
139 * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
140 * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
141 * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
142 * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
144 static void opj_get_encoding_parameters(const opj_image_t *p_image,
145 const opj_cp_t *p_cp,
151 OPJ_UINT32 * p_dx_min,
152 OPJ_UINT32 * p_dy_min,
153 OPJ_UINT32 * p_max_prec,
154 OPJ_UINT32 * p_max_res);
157 * Gets the encoding parameters needed to update the coding parameters and all the pocs.
158 * The precinct widths, heights, dx and dy for each component at each resolution will be stored as well.
159 * the last parameter of the function should be an array of pointers of size nb components, each pointer leading
160 * to an area of size 4 * max_res. The data is stored inside this area with the following pattern :
161 * dx_compi_res0 , dy_compi_res0 , w_compi_res0, h_compi_res0 , dx_compi_res1 , dy_compi_res1 , w_compi_res1, h_compi_res1 , ...
163 * @param p_image the image being encoded.
164 * @param p_cp the coding parameters.
165 * @param tileno the tile index of the tile being encoded.
166 * @param p_tx0 pointer that will hold the X0 parameter for the tile
167 * @param p_tx1 pointer that will hold the X1 parameter for the tile
168 * @param p_ty0 pointer that will hold the Y0 parameter for the tile
169 * @param p_ty1 pointer that will hold the Y1 parameter for the tile
170 * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
171 * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
172 * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
173 * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
174 * @param p_resolutions pointer to an area corresponding to the one described above.
176 static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
177 const opj_cp_t *p_cp,
183 OPJ_UINT32 * p_dx_min,
184 OPJ_UINT32 * p_dy_min,
185 OPJ_UINT32 * p_max_prec,
186 OPJ_UINT32 * p_max_res,
187 OPJ_UINT32 ** p_resolutions);
189 * Allocates memory for a packet iterator. Data and data sizes are set by this operation.
190 * No other data is set. The include section of the packet iterator is not allocated.
192 * @param p_image the image used to initialize the packet iterator (in fact only the number of components is relevant.
193 * @param p_cp the coding parameters.
194 * @param tileno the index of the tile from which creating the packet iterator.
196 static opj_pi_iterator_t * opj_pi_create(const opj_image_t *p_image,
197 const opj_cp_t *p_cp,
202 static void opj_pi_update_decode_not_poc(opj_pi_iterator_t * p_pi,
204 OPJ_UINT32 p_max_precision,
205 OPJ_UINT32 p_max_res);
209 static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi,
211 OPJ_UINT32 p_max_precision,
212 OPJ_UINT32 p_max_res);
217 static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos,
221 const OPJ_CHAR *prog);
228 ==========================================================
230 ==========================================================
233 static void opj_pi_emit_error(opj_pi_iterator_t * pi, const char* msg)
239 static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi)
241 opj_pi_comp_t *comp = NULL;
242 opj_pi_resolution_t *res = NULL;
243 OPJ_UINT32 index = 0;
246 comp = &pi->comps[pi->compno];
247 res = &comp->resolutions[pi->resno];
253 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
254 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
256 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
257 comp = &pi->comps[pi->compno];
258 if (pi->resno >= comp->numresolutions) {
261 res = &comp->resolutions[pi->resno];
263 pi->poc.precno1 = res->pw * res->ph;
265 for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
266 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
267 pi->step_c + pi->precno * pi->step_p;
268 /* Avoids index out of bounds access with */
269 /* id_000098,sig_11,src_005411,op_havoc,rep_2 of */
270 /* https://github.com/uclouvain/openjpeg/issues/938 */
271 /* Not sure if this is the most clever fix. Perhaps */
272 /* include should be resized when a POC arises, or */
273 /* the POC should be rejected */
274 if (index >= pi->include_size) {
275 opj_pi_emit_error(pi, "Invalid access to pi->include");
278 if (!pi->include[index]) {
279 pi->include[index] = 1;
292 static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi)
294 opj_pi_comp_t *comp = NULL;
295 opj_pi_resolution_t *res = NULL;
296 OPJ_UINT32 index = 0;
299 comp = &pi->comps[pi->compno];
300 res = &comp->resolutions[pi->resno];
306 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
307 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
308 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
309 comp = &pi->comps[pi->compno];
310 if (pi->resno >= comp->numresolutions) {
313 res = &comp->resolutions[pi->resno];
315 pi->poc.precno1 = res->pw * res->ph;
317 for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
318 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
319 pi->step_c + pi->precno * pi->step_p;
320 if (index >= pi->include_size) {
321 opj_pi_emit_error(pi, "Invalid access to pi->include");
324 if (!pi->include[index]) {
325 pi->include[index] = 1;
338 static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi)
340 opj_pi_comp_t *comp = NULL;
341 opj_pi_resolution_t *res = NULL;
342 OPJ_UINT32 index = 0;
347 OPJ_UINT32 compno, resno;
351 for (compno = 0; compno < pi->numcomps; compno++) {
352 comp = &pi->comps[compno];
353 for (resno = 0; resno < comp->numresolutions; resno++) {
355 res = &comp->resolutions[resno];
356 dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
357 dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
358 pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
359 pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
364 pi->poc.ty0 = pi->ty0;
365 pi->poc.tx0 = pi->tx0;
366 pi->poc.ty1 = pi->ty1;
367 pi->poc.tx1 = pi->tx1;
369 for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
370 for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1;
371 pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) {
372 for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1;
373 pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) {
374 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
376 OPJ_INT32 trx0, try0;
377 OPJ_INT32 trx1, try1;
379 OPJ_INT32 prci, prcj;
380 comp = &pi->comps[pi->compno];
381 if (pi->resno >= comp->numresolutions) {
384 res = &comp->resolutions[pi->resno];
385 levelno = comp->numresolutions - 1 - pi->resno;
386 trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno));
387 try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno));
388 trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno));
389 try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
390 rpx = res->pdx + levelno;
391 rpy = res->pdy + levelno;
393 /* To avoid divisions by zero / undefined behaviour on shift */
395 /* Fixes reading id:000026,sig:08,src:002419,op:int32,pos:60,val:+32 */
396 /* of https://github.com/uclouvain/openjpeg/issues/938 */
397 if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
398 rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) {
402 /* See ISO-15441. B.12.1.3 Resolution level-position-component-layer progression */
403 if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) &&
404 ((try0 << levelno) % (1 << rpy))))) {
407 if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) &&
408 ((trx0 << levelno) % (1 << rpx))))) {
412 if ((res->pw == 0) || (res->ph == 0)) {
416 if ((trx0 == trx1) || (try0 == try1)) {
420 prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x,
421 (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx)
422 - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx);
423 prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y,
424 (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy)
425 - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy);
426 pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw);
427 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
428 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
429 pi->step_c + pi->precno * pi->step_p;
430 if (index >= pi->include_size) {
431 opj_pi_emit_error(pi, "Invalid access to pi->include");
434 if (!pi->include[index]) {
435 pi->include[index] = 1;
449 static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi)
451 opj_pi_comp_t *comp = NULL;
452 opj_pi_resolution_t *res = NULL;
453 OPJ_UINT32 index = 0;
456 comp = &pi->comps[pi->compno];
459 OPJ_UINT32 compno, resno;
463 for (compno = 0; compno < pi->numcomps; compno++) {
464 comp = &pi->comps[compno];
465 for (resno = 0; resno < comp->numresolutions; resno++) {
467 res = &comp->resolutions[resno];
468 dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
469 dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
470 pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
471 pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
476 pi->poc.ty0 = pi->ty0;
477 pi->poc.tx0 = pi->tx0;
478 pi->poc.ty1 = pi->ty1;
479 pi->poc.tx1 = pi->tx1;
481 for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1;
482 pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) {
483 for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1;
484 pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) {
485 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
486 comp = &pi->comps[pi->compno];
487 for (pi->resno = pi->poc.resno0;
488 pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
490 OPJ_INT32 trx0, try0;
491 OPJ_INT32 trx1, try1;
493 OPJ_INT32 prci, prcj;
494 res = &comp->resolutions[pi->resno];
495 levelno = comp->numresolutions - 1 - pi->resno;
496 trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno));
497 try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno));
498 trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno));
499 try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
500 rpx = res->pdx + levelno;
501 rpy = res->pdy + levelno;
503 /* To avoid divisions by zero / undefined behaviour on shift */
505 /* Relates to id:000019,sig:08,src:001098,op:flip1,pos:49 */
506 /* of https://github.com/uclouvain/openjpeg/issues/938 */
507 if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
508 rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) {
512 /* See ISO-15441. B.12.1.4 Position-component-resolution level-layer progression */
513 if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) &&
514 ((try0 << levelno) % (1 << rpy))))) {
517 if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) &&
518 ((trx0 << levelno) % (1 << rpx))))) {
522 if ((res->pw == 0) || (res->ph == 0)) {
526 if ((trx0 == trx1) || (try0 == try1)) {
530 prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x,
531 (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx)
532 - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx);
533 prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y,
534 (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy)
535 - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy);
536 pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw);
537 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
538 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
539 pi->step_c + pi->precno * pi->step_p;
540 if (index >= pi->include_size) {
541 opj_pi_emit_error(pi, "Invalid access to pi->include");
544 if (!pi->include[index]) {
545 pi->include[index] = 1;
559 static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi)
561 opj_pi_comp_t *comp = NULL;
562 opj_pi_resolution_t *res = NULL;
563 OPJ_UINT32 index = 0;
566 comp = &pi->comps[pi->compno];
572 for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
574 comp = &pi->comps[pi->compno];
577 for (resno = 0; resno < comp->numresolutions; resno++) {
579 res = &comp->resolutions[resno];
580 dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
581 dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
582 pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
583 pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
586 pi->poc.ty0 = pi->ty0;
587 pi->poc.tx0 = pi->tx0;
588 pi->poc.ty1 = pi->ty1;
589 pi->poc.tx1 = pi->tx1;
591 for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1;
592 pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) {
593 for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1;
594 pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) {
595 for (pi->resno = pi->poc.resno0;
596 pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
598 OPJ_INT32 trx0, try0;
599 OPJ_INT32 trx1, try1;
601 OPJ_INT32 prci, prcj;
602 res = &comp->resolutions[pi->resno];
603 levelno = comp->numresolutions - 1 - pi->resno;
604 trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno));
605 try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno));
606 trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno));
607 try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
608 rpx = res->pdx + levelno;
609 rpy = res->pdy + levelno;
611 /* To avoid divisions by zero / undefined behaviour on shift */
613 /* Fixes reading id:000019,sig:08,src:001098,op:flip1,pos:49 */
614 /* of https://github.com/uclouvain/openjpeg/issues/938 */
615 if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
616 rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) {
620 /* See ISO-15441. B.12.1.5 Component-position-resolution level-layer progression */
621 if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) &&
622 ((try0 << levelno) % (1 << rpy))))) {
625 if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) &&
626 ((trx0 << levelno) % (1 << rpx))))) {
630 if ((res->pw == 0) || (res->ph == 0)) {
634 if ((trx0 == trx1) || (try0 == try1)) {
638 prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x,
639 (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx)
640 - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx);
641 prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y,
642 (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy)
643 - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy);
644 pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw);
645 for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
646 index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno *
647 pi->step_c + pi->precno * pi->step_p;
648 if (index >= pi->include_size) {
649 opj_pi_emit_error(pi, "Invalid access to pi->include");
652 if (!pi->include[index]) {
653 pi->include[index] = 1;
667 static void opj_get_encoding_parameters(const opj_image_t *p_image,
668 const opj_cp_t *p_cp,
674 OPJ_UINT32 * p_dx_min,
675 OPJ_UINT32 * p_dy_min,
676 OPJ_UINT32 * p_max_prec,
677 OPJ_UINT32 * p_max_res)
680 OPJ_UINT32 compno, resno;
682 const opj_tcp_t *l_tcp = 00;
683 const opj_tccp_t * l_tccp = 00;
684 const opj_image_comp_t * l_img_comp = 00;
686 /* position in x and y of tile */
691 assert(p_image != 00);
692 assert(p_tileno < p_cp->tw * p_cp->th);
694 /* initializations */
695 l_tcp = &p_cp->tcps [p_tileno];
696 l_img_comp = p_image->comps;
697 l_tccp = l_tcp->tccps;
699 /* here calculation of tx0, tx1, ty0, ty1, maxprec, dx and dy */
700 p = p_tileno % p_cp->tw;
701 q = p_tileno / p_cp->tw;
703 /* find extent of tile */
704 *p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx),
705 (OPJ_INT32)p_image->x0);
706 *p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx),
707 (OPJ_INT32)p_image->x1);
708 *p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy),
709 (OPJ_INT32)p_image->y0);
710 *p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy),
711 (OPJ_INT32)p_image->y1);
713 /* max precision is 0 (can only grow) */
717 /* take the largest value for dx_min and dy_min */
718 *p_dx_min = 0x7fffffff;
719 *p_dy_min = 0x7fffffff;
721 for (compno = 0; compno < p_image->numcomps; ++compno) {
722 /* arithmetic variables to calculate */
723 OPJ_UINT32 l_level_no;
724 OPJ_INT32 l_rx0, l_ry0, l_rx1, l_ry1;
725 OPJ_INT32 l_px0, l_py0, l_px1, py1;
726 OPJ_UINT32 l_pdx, l_pdy;
727 OPJ_UINT32 l_pw, l_ph;
728 OPJ_UINT32 l_product;
729 OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
731 l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx);
732 l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy);
733 l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx);
734 l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy);
736 if (l_tccp->numresolutions > *p_max_res) {
737 *p_max_res = l_tccp->numresolutions;
740 /* use custom size for precincts */
741 for (resno = 0; resno < l_tccp->numresolutions; ++resno) {
742 OPJ_UINT32 l_dx, l_dy;
744 /* precinct width and height */
745 l_pdx = l_tccp->prcw[resno];
746 l_pdy = l_tccp->prch[resno];
748 l_dx = l_img_comp->dx * (1u << (l_pdx + l_tccp->numresolutions - 1 - resno));
749 l_dy = l_img_comp->dy * (1u << (l_pdy + l_tccp->numresolutions - 1 - resno));
751 /* take the minimum size for dx for each comp and resolution */
752 *p_dx_min = opj_uint_min(*p_dx_min, l_dx);
753 *p_dy_min = opj_uint_min(*p_dy_min, l_dy);
755 /* various calculations of extents */
756 l_level_no = l_tccp->numresolutions - 1 - resno;
758 l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no);
759 l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no);
760 l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no);
761 l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no);
763 l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx;
764 l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy;
765 l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx;
767 py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy;
769 l_pw = (l_rx0 == l_rx1) ? 0 : (OPJ_UINT32)((l_px1 - l_px0) >> l_pdx);
770 l_ph = (l_ry0 == l_ry1) ? 0 : (OPJ_UINT32)((py1 - l_py0) >> l_pdy);
772 l_product = l_pw * l_ph;
774 /* update precision */
775 if (l_product > *p_max_prec) {
776 *p_max_prec = l_product;
785 static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
786 const opj_cp_t *p_cp,
792 OPJ_UINT32 * p_dx_min,
793 OPJ_UINT32 * p_dy_min,
794 OPJ_UINT32 * p_max_prec,
795 OPJ_UINT32 * p_max_res,
796 OPJ_UINT32 ** p_resolutions)
799 OPJ_UINT32 compno, resno;
802 const opj_tcp_t *tcp = 00;
803 const opj_tccp_t * l_tccp = 00;
804 const opj_image_comp_t * l_img_comp = 00;
806 /* to store l_dx, l_dy, w and h for each resolution and component.*/
807 OPJ_UINT32 * lResolutionPtr;
809 /* position in x and y of tile*/
812 /* non-corrected (in regard to image offset) tile offset */
813 OPJ_UINT32 l_tx0, l_ty0;
815 /* preconditions in debug*/
817 assert(p_image != 00);
818 assert(tileno < p_cp->tw * p_cp->th);
821 tcp = &p_cp->tcps [tileno];
823 l_img_comp = p_image->comps;
825 /* position in x and y of tile*/
826 p = tileno % p_cp->tw;
827 q = tileno / p_cp->tw;
829 /* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */
830 l_tx0 = p_cp->tx0 + p *
831 p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */
832 *p_tx0 = (OPJ_INT32)opj_uint_max(l_tx0, p_image->x0);
833 *p_tx1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1);
834 l_ty0 = p_cp->ty0 + q *
835 p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */
836 *p_ty0 = (OPJ_INT32)opj_uint_max(l_ty0, p_image->y0);
837 *p_ty1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1);
839 /* max precision and resolution is 0 (can only grow)*/
843 /* take the largest value for dx_min and dy_min*/
844 *p_dx_min = 0x7fffffff;
845 *p_dy_min = 0x7fffffff;
847 for (compno = 0; compno < p_image->numcomps; ++compno) {
848 /* aritmetic variables to calculate*/
849 OPJ_UINT32 l_level_no;
850 OPJ_INT32 l_rx0, l_ry0, l_rx1, l_ry1;
851 OPJ_INT32 l_px0, l_py0, l_px1, py1;
852 OPJ_UINT32 l_product;
853 OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
854 OPJ_UINT32 l_pdx, l_pdy, l_pw, l_ph;
856 lResolutionPtr = p_resolutions[compno];
858 l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx);
859 l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy);
860 l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx);
861 l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy);
863 if (l_tccp->numresolutions > *p_max_res) {
864 *p_max_res = l_tccp->numresolutions;
867 /* use custom size for precincts*/
868 l_level_no = l_tccp->numresolutions;
869 for (resno = 0; resno < l_tccp->numresolutions; ++resno) {
870 OPJ_UINT32 l_dx, l_dy;
874 /* precinct width and height*/
875 l_pdx = l_tccp->prcw[resno];
876 l_pdy = l_tccp->prch[resno];
877 *lResolutionPtr++ = l_pdx;
878 *lResolutionPtr++ = l_pdy;
879 l_dx = l_img_comp->dx * (1u << (l_pdx + l_level_no));
880 l_dy = l_img_comp->dy * (1u << (l_pdy + l_level_no));
881 /* take the minimum size for l_dx for each comp and resolution*/
882 *p_dx_min = (OPJ_UINT32)opj_int_min((OPJ_INT32) * p_dx_min, (OPJ_INT32)l_dx);
883 *p_dy_min = (OPJ_UINT32)opj_int_min((OPJ_INT32) * p_dy_min, (OPJ_INT32)l_dy);
885 /* various calculations of extents*/
886 l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no);
887 l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no);
888 l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no);
889 l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no);
890 l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx;
891 l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy;
892 l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx;
893 py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy;
894 l_pw = (l_rx0 == l_rx1) ? 0 : (OPJ_UINT32)((l_px1 - l_px0) >> l_pdx);
895 l_ph = (l_ry0 == l_ry1) ? 0 : (OPJ_UINT32)((py1 - l_py0) >> l_pdy);
896 *lResolutionPtr++ = l_pw;
897 *lResolutionPtr++ = l_ph;
898 l_product = l_pw * l_ph;
900 /* update precision*/
901 if (l_product > *p_max_prec) {
902 *p_max_prec = l_product;
911 static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image,
916 OPJ_UINT32 pino, compno;
917 /* number of poc in the p_pi*/
918 OPJ_UINT32 l_poc_bound;
920 /* pointers to tile coding parameters and components.*/
921 opj_pi_iterator_t *l_pi = 00;
923 const opj_tccp_t *tccp = 00;
925 /* current packet iterator being allocated*/
926 opj_pi_iterator_t *l_current_pi = 00;
928 /* preconditions in debug*/
931 assert(tileno < cp->tw * cp->th);
934 tcp = &cp->tcps[tileno];
935 l_poc_bound = tcp->numpocs + 1;
937 /* memory allocations*/
938 l_pi = (opj_pi_iterator_t*) opj_calloc((l_poc_bound),
939 sizeof(opj_pi_iterator_t));
945 for (pino = 0; pino < l_poc_bound ; ++pino) {
947 l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps,
948 sizeof(opj_pi_comp_t));
949 if (! l_current_pi->comps) {
950 opj_pi_destroy(l_pi, l_poc_bound);
954 l_current_pi->numcomps = image->numcomps;
956 for (compno = 0; compno < image->numcomps; ++compno) {
957 opj_pi_comp_t *comp = &l_current_pi->comps[compno];
959 tccp = &tcp->tccps[compno];
961 comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions,
962 sizeof(opj_pi_resolution_t));
963 if (!comp->resolutions) {
964 opj_pi_destroy(l_pi, l_poc_bound);
968 comp->numresolutions = tccp->numresolutions;
975 static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp,
981 OPJ_UINT32 p_max_prec,
982 OPJ_UINT32 p_max_res,
988 /* tile coding parameter*/
989 opj_tcp_t *l_tcp = 00;
990 /* current poc being updated*/
991 opj_poc_t * l_current_poc = 00;
994 OPJ_UINT32 l_poc_bound;
996 OPJ_ARG_NOT_USED(p_max_res);
998 /* preconditions in debug*/
1000 assert(p_tileno < p_cp->tw * p_cp->th);
1002 /* initializations*/
1003 l_tcp = &p_cp->tcps [p_tileno];
1004 /* number of iterations in the loop */
1005 l_poc_bound = l_tcp->numpocs + 1;
1007 /* start at first element, and to make sure the compiler will not make a calculation each time in the loop
1008 store a pointer to the current element to modify rather than l_tcp->pocs[i]*/
1009 l_current_poc = l_tcp->pocs;
1011 l_current_poc->compS = l_current_poc->compno0;
1012 l_current_poc->compE = l_current_poc->compno1;
1013 l_current_poc->resS = l_current_poc->resno0;
1014 l_current_poc->resE = l_current_poc->resno1;
1015 l_current_poc->layE = l_current_poc->layno1;
1017 /* special treatment for the first element*/
1018 l_current_poc->layS = 0;
1019 l_current_poc->prg = l_current_poc->prg1;
1020 l_current_poc->prcS = 0;
1022 l_current_poc->prcE = p_max_prec;
1023 l_current_poc->txS = (OPJ_UINT32)p_tx0;
1024 l_current_poc->txE = (OPJ_UINT32)p_tx1;
1025 l_current_poc->tyS = (OPJ_UINT32)p_ty0;
1026 l_current_poc->tyE = (OPJ_UINT32)p_ty1;
1027 l_current_poc->dx = p_dx_min;
1028 l_current_poc->dy = p_dy_min;
1031 for (pino = 1; pino < l_poc_bound ; ++pino) {
1032 l_current_poc->compS = l_current_poc->compno0;
1033 l_current_poc->compE = l_current_poc->compno1;
1034 l_current_poc->resS = l_current_poc->resno0;
1035 l_current_poc->resE = l_current_poc->resno1;
1036 l_current_poc->layE = l_current_poc->layno1;
1037 l_current_poc->prg = l_current_poc->prg1;
1038 l_current_poc->prcS = 0;
1039 /* special treatment here different from the first element*/
1040 l_current_poc->layS = (l_current_poc->layE > (l_current_poc - 1)->layE) ?
1041 l_current_poc->layE : 0;
1043 l_current_poc->prcE = p_max_prec;
1044 l_current_poc->txS = (OPJ_UINT32)p_tx0;
1045 l_current_poc->txE = (OPJ_UINT32)p_tx1;
1046 l_current_poc->tyS = (OPJ_UINT32)p_ty0;
1047 l_current_poc->tyE = (OPJ_UINT32)p_ty1;
1048 l_current_poc->dx = p_dx_min;
1049 l_current_poc->dy = p_dy_min;
1054 static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp,
1055 OPJ_UINT32 p_num_comps,
1056 OPJ_UINT32 p_tileno,
1061 OPJ_UINT32 p_max_prec,
1062 OPJ_UINT32 p_max_res,
1063 OPJ_UINT32 p_dx_min,
1064 OPJ_UINT32 p_dy_min)
1068 /* tile coding parameter*/
1069 opj_tcp_t *l_tcp = 00;
1070 /* current poc being updated*/
1071 opj_poc_t * l_current_poc = 00;
1073 OPJ_UINT32 l_poc_bound;
1075 /* preconditions in debug*/
1077 assert(p_tileno < p_cp->tw * p_cp->th);
1079 /* initializations*/
1080 l_tcp = &p_cp->tcps [p_tileno];
1082 /* number of iterations in the loop */
1083 l_poc_bound = l_tcp->numpocs + 1;
1085 /* start at first element, and to make sure the compiler will not make a calculation each time in the loop
1086 store a pointer to the current element to modify rather than l_tcp->pocs[i]*/
1087 l_current_poc = l_tcp->pocs;
1089 for (pino = 0; pino < l_poc_bound ; ++pino) {
1090 l_current_poc->compS = 0;
1091 l_current_poc->compE = p_num_comps;/*p_image->numcomps;*/
1092 l_current_poc->resS = 0;
1093 l_current_poc->resE = p_max_res;
1094 l_current_poc->layS = 0;
1095 l_current_poc->layE = l_tcp->numlayers;
1096 l_current_poc->prg = l_tcp->prg;
1097 l_current_poc->prcS = 0;
1098 l_current_poc->prcE = p_max_prec;
1099 l_current_poc->txS = (OPJ_UINT32)p_tx0;
1100 l_current_poc->txE = (OPJ_UINT32)p_tx1;
1101 l_current_poc->tyS = (OPJ_UINT32)p_ty0;
1102 l_current_poc->tyE = (OPJ_UINT32)p_ty1;
1103 l_current_poc->dx = p_dx_min;
1104 l_current_poc->dy = p_dy_min;
1109 static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi,
1111 OPJ_UINT32 p_max_precision,
1112 OPJ_UINT32 p_max_res)
1117 /* encoding prameters to set*/
1120 opj_pi_iterator_t * l_current_pi = 00;
1121 opj_poc_t* l_current_poc = 0;
1123 OPJ_ARG_NOT_USED(p_max_res);
1125 /* preconditions in debug*/
1127 assert(p_tcp != 00);
1129 /* initializations*/
1130 l_bound = p_tcp->numpocs + 1;
1131 l_current_pi = p_pi;
1132 l_current_poc = p_tcp->pocs;
1134 for (pino = 0; pino < l_bound; ++pino) {
1135 l_current_pi->poc.prg = l_current_poc->prg; /* Progression Order #0 */
1136 l_current_pi->first = 1;
1138 l_current_pi->poc.resno0 =
1139 l_current_poc->resno0; /* Resolution Level Index #0 (Start) */
1140 l_current_pi->poc.compno0 =
1141 l_current_poc->compno0; /* Component Index #0 (Start) */
1142 l_current_pi->poc.layno0 = 0;
1143 l_current_pi->poc.precno0 = 0;
1144 l_current_pi->poc.resno1 =
1145 l_current_poc->resno1; /* Resolution Level Index #0 (End) */
1146 l_current_pi->poc.compno1 =
1147 l_current_poc->compno1; /* Component Index #0 (End) */
1148 l_current_pi->poc.layno1 = l_current_poc->layno1; /* Layer Index #0 (End) */
1149 l_current_pi->poc.precno1 = p_max_precision;
1155 static void opj_pi_update_decode_not_poc(opj_pi_iterator_t * p_pi,
1157 OPJ_UINT32 p_max_precision,
1158 OPJ_UINT32 p_max_res)
1163 /* encoding prameters to set*/
1166 opj_pi_iterator_t * l_current_pi = 00;
1167 /* preconditions in debug*/
1168 assert(p_tcp != 00);
1171 /* initializations*/
1172 l_bound = p_tcp->numpocs + 1;
1173 l_current_pi = p_pi;
1175 for (pino = 0; pino < l_bound; ++pino) {
1176 l_current_pi->poc.prg = p_tcp->prg;
1177 l_current_pi->first = 1;
1178 l_current_pi->poc.resno0 = 0;
1179 l_current_pi->poc.compno0 = 0;
1180 l_current_pi->poc.layno0 = 0;
1181 l_current_pi->poc.precno0 = 0;
1182 l_current_pi->poc.resno1 = p_max_res;
1183 l_current_pi->poc.compno1 = l_current_pi->numcomps;
1184 l_current_pi->poc.layno1 = p_tcp->numlayers;
1185 l_current_pi->poc.precno1 = p_max_precision;
1192 static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos,
1196 const OPJ_CHAR *prog)
1199 opj_tcp_t *tcps = &cp->tcps[tileno];
1200 opj_poc_t *tcp = &tcps->pocs[pino];
1203 for (i = pos; pos >= 0; i--) {
1206 if (tcp->res_t == tcp->resE) {
1207 if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) {
1217 if (tcp->comp_t == tcp->compE) {
1218 if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) {
1228 if (tcp->lay_t == tcp->layE) {
1229 if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) {
1240 case OPJ_LRCP: /* fall through */
1242 if (tcp->prc_t == tcp->prcE) {
1243 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1253 if (tcp->tx0_t == tcp->txE) {
1255 if (tcp->ty0_t == tcp->tyE) {
1256 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1277 ==========================================================
1278 Packet iterator interface
1279 ==========================================================
1281 opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
1283 OPJ_UINT32 p_tile_no)
1287 OPJ_UINT32 compno, resno;
1289 /* to store w, h, dx and dy fro all components and resolutions */
1290 OPJ_UINT32 * l_tmp_data;
1291 OPJ_UINT32 ** l_tmp_ptr;
1293 /* encoding prameters to set */
1294 OPJ_UINT32 l_max_res;
1295 OPJ_UINT32 l_max_prec;
1296 OPJ_INT32 l_tx0, l_tx1, l_ty0, l_ty1;
1297 OPJ_UINT32 l_dx_min, l_dy_min;
1299 OPJ_UINT32 l_step_p, l_step_c, l_step_r, l_step_l ;
1300 OPJ_UINT32 l_data_stride;
1303 opj_pi_iterator_t *l_pi = 00;
1304 opj_tcp_t *l_tcp = 00;
1305 const opj_tccp_t *l_tccp = 00;
1306 opj_pi_comp_t *l_current_comp = 00;
1307 opj_image_comp_t * l_img_comp = 00;
1308 opj_pi_iterator_t * l_current_pi = 00;
1309 OPJ_UINT32 * l_encoding_value_ptr = 00;
1311 /* preconditions in debug */
1313 assert(p_image != 00);
1314 assert(p_tile_no < p_cp->tw * p_cp->th);
1316 /* initializations */
1317 l_tcp = &p_cp->tcps[p_tile_no];
1318 l_bound = l_tcp->numpocs + 1;
1320 l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
1321 l_tmp_data = (OPJ_UINT32*)opj_malloc(
1322 l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
1327 l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
1328 p_image->numcomps * sizeof(OPJ_UINT32 *));
1331 opj_free(l_tmp_data);
1335 /* memory allocation for pi */
1336 l_pi = opj_pi_create(p_image, p_cp, p_tile_no);
1338 opj_free(l_tmp_data);
1339 opj_free(l_tmp_ptr);
1343 l_encoding_value_ptr = l_tmp_data;
1344 /* update pointer array */
1346 (compno = 0; compno < p_image->numcomps; ++compno) {
1347 l_tmp_ptr[compno] = l_encoding_value_ptr;
1348 l_encoding_value_ptr += l_data_stride;
1350 /* get encoding parameters */
1351 opj_get_all_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1,
1352 &l_ty0, &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res, l_tmp_ptr);
1354 /* step calculations */
1356 l_step_c = l_max_prec * l_step_p;
1357 l_step_r = p_image->numcomps * l_step_c;
1358 l_step_l = l_max_res * l_step_r;
1360 /* set values for first packet iterator */
1361 l_current_pi = l_pi;
1363 /* memory allocation for include */
1364 /* prevent an integer overflow issue */
1365 /* 0 < l_tcp->numlayers < 65536 c.f. opj_j2k_read_cod in j2k.c */
1366 l_current_pi->include = 00;
1367 if (l_step_l <= (UINT_MAX / (l_tcp->numlayers + 1U))) {
1368 l_current_pi->include_size = (l_tcp->numlayers + 1U) * l_step_l;
1369 l_current_pi->include = (OPJ_INT16*) opj_calloc(
1370 l_current_pi->include_size, sizeof(OPJ_INT16));
1373 if (!l_current_pi->include) {
1374 opj_free(l_tmp_data);
1375 opj_free(l_tmp_ptr);
1376 opj_pi_destroy(l_pi, l_bound);
1380 /* special treatment for the first packet iterator */
1381 l_current_comp = l_current_pi->comps;
1382 l_img_comp = p_image->comps;
1383 l_tccp = l_tcp->tccps;
1385 l_current_pi->tx0 = l_tx0;
1386 l_current_pi->ty0 = l_ty0;
1387 l_current_pi->tx1 = l_tx1;
1388 l_current_pi->ty1 = l_ty1;
1390 /*l_current_pi->dx = l_img_comp->dx;*/
1391 /*l_current_pi->dy = l_img_comp->dy;*/
1393 l_current_pi->step_p = l_step_p;
1394 l_current_pi->step_c = l_step_c;
1395 l_current_pi->step_r = l_step_r;
1396 l_current_pi->step_l = l_step_l;
1398 /* allocation for components and number of components has already been calculated by opj_pi_create */
1400 (compno = 0; compno < l_current_pi->numcomps; ++compno) {
1401 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1402 l_encoding_value_ptr = l_tmp_ptr[compno];
1404 l_current_comp->dx = l_img_comp->dx;
1405 l_current_comp->dy = l_img_comp->dy;
1406 /* resolutions have already been initialized */
1408 (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1409 l_res->pdx = *(l_encoding_value_ptr++);
1410 l_res->pdy = *(l_encoding_value_ptr++);
1411 l_res->pw = *(l_encoding_value_ptr++);
1412 l_res->ph = *(l_encoding_value_ptr++);
1421 for (pino = 1 ; pino < l_bound ; ++pino) {
1422 l_current_comp = l_current_pi->comps;
1423 l_img_comp = p_image->comps;
1424 l_tccp = l_tcp->tccps;
1426 l_current_pi->tx0 = l_tx0;
1427 l_current_pi->ty0 = l_ty0;
1428 l_current_pi->tx1 = l_tx1;
1429 l_current_pi->ty1 = l_ty1;
1430 /*l_current_pi->dx = l_dx_min;*/
1431 /*l_current_pi->dy = l_dy_min;*/
1432 l_current_pi->step_p = l_step_p;
1433 l_current_pi->step_c = l_step_c;
1434 l_current_pi->step_r = l_step_r;
1435 l_current_pi->step_l = l_step_l;
1437 /* allocation for components and number of components has already been calculated by opj_pi_create */
1439 (compno = 0; compno < l_current_pi->numcomps; ++compno) {
1440 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1441 l_encoding_value_ptr = l_tmp_ptr[compno];
1443 l_current_comp->dx = l_img_comp->dx;
1444 l_current_comp->dy = l_img_comp->dy;
1445 /* resolutions have already been initialized */
1447 (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1448 l_res->pdx = *(l_encoding_value_ptr++);
1449 l_res->pdy = *(l_encoding_value_ptr++);
1450 l_res->pw = *(l_encoding_value_ptr++);
1451 l_res->ph = *(l_encoding_value_ptr++);
1458 /* special treatment*/
1459 l_current_pi->include = (l_current_pi - 1)->include;
1460 l_current_pi->include_size = (l_current_pi - 1)->include_size;
1463 opj_free(l_tmp_data);
1465 opj_free(l_tmp_ptr);
1469 opj_pi_update_decode_poc(l_pi, l_tcp, l_max_prec, l_max_res);
1471 opj_pi_update_decode_not_poc(l_pi, l_tcp, l_max_prec, l_max_res);
1478 opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
1480 OPJ_UINT32 p_tile_no,
1481 J2K_T2_MODE p_t2_mode)
1485 OPJ_UINT32 compno, resno;
1487 /* to store w, h, dx and dy fro all components and resolutions*/
1488 OPJ_UINT32 * l_tmp_data;
1489 OPJ_UINT32 ** l_tmp_ptr;
1491 /* encoding prameters to set*/
1492 OPJ_UINT32 l_max_res;
1493 OPJ_UINT32 l_max_prec;
1494 OPJ_INT32 l_tx0, l_tx1, l_ty0, l_ty1;
1495 OPJ_UINT32 l_dx_min, l_dy_min;
1497 OPJ_UINT32 l_step_p, l_step_c, l_step_r, l_step_l ;
1498 OPJ_UINT32 l_data_stride;
1501 opj_pi_iterator_t *l_pi = 00;
1502 opj_tcp_t *l_tcp = 00;
1503 const opj_tccp_t *l_tccp = 00;
1504 opj_pi_comp_t *l_current_comp = 00;
1505 opj_image_comp_t * l_img_comp = 00;
1506 opj_pi_iterator_t * l_current_pi = 00;
1507 OPJ_UINT32 * l_encoding_value_ptr = 00;
1509 /* preconditions in debug*/
1511 assert(p_image != 00);
1512 assert(p_tile_no < p_cp->tw * p_cp->th);
1514 /* initializations*/
1515 l_tcp = &p_cp->tcps[p_tile_no];
1516 l_bound = l_tcp->numpocs + 1;
1518 l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
1519 l_tmp_data = (OPJ_UINT32*)opj_malloc(
1520 l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
1525 l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
1526 p_image->numcomps * sizeof(OPJ_UINT32 *));
1528 opj_free(l_tmp_data);
1532 /* memory allocation for pi*/
1533 l_pi = opj_pi_create(p_image, p_cp, p_tile_no);
1535 opj_free(l_tmp_data);
1536 opj_free(l_tmp_ptr);
1540 l_encoding_value_ptr = l_tmp_data;
1541 /* update pointer array*/
1542 for (compno = 0; compno < p_image->numcomps; ++compno) {
1543 l_tmp_ptr[compno] = l_encoding_value_ptr;
1544 l_encoding_value_ptr += l_data_stride;
1547 /* get encoding parameters*/
1548 opj_get_all_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1,
1549 &l_ty0, &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res, l_tmp_ptr);
1551 /* step calculations*/
1553 l_step_c = l_max_prec * l_step_p;
1554 l_step_r = p_image->numcomps * l_step_c;
1555 l_step_l = l_max_res * l_step_r;
1557 /* set values for first packet iterator*/
1558 l_pi->tp_on = (OPJ_BYTE)p_cp->m_specific_param.m_enc.m_tp_on;
1559 l_current_pi = l_pi;
1561 /* memory allocation for include*/
1562 l_current_pi->include_size = l_tcp->numlayers * l_step_l;
1563 l_current_pi->include = (OPJ_INT16*) opj_calloc(l_current_pi->include_size,
1565 if (!l_current_pi->include) {
1566 opj_free(l_tmp_data);
1567 opj_free(l_tmp_ptr);
1568 opj_pi_destroy(l_pi, l_bound);
1572 /* special treatment for the first packet iterator*/
1573 l_current_comp = l_current_pi->comps;
1574 l_img_comp = p_image->comps;
1575 l_tccp = l_tcp->tccps;
1576 l_current_pi->tx0 = l_tx0;
1577 l_current_pi->ty0 = l_ty0;
1578 l_current_pi->tx1 = l_tx1;
1579 l_current_pi->ty1 = l_ty1;
1580 l_current_pi->dx = l_dx_min;
1581 l_current_pi->dy = l_dy_min;
1582 l_current_pi->step_p = l_step_p;
1583 l_current_pi->step_c = l_step_c;
1584 l_current_pi->step_r = l_step_r;
1585 l_current_pi->step_l = l_step_l;
1587 /* allocation for components and number of components has already been calculated by opj_pi_create */
1588 for (compno = 0; compno < l_current_pi->numcomps; ++compno) {
1589 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1590 l_encoding_value_ptr = l_tmp_ptr[compno];
1592 l_current_comp->dx = l_img_comp->dx;
1593 l_current_comp->dy = l_img_comp->dy;
1595 /* resolutions have already been initialized */
1596 for (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1597 l_res->pdx = *(l_encoding_value_ptr++);
1598 l_res->pdy = *(l_encoding_value_ptr++);
1599 l_res->pw = *(l_encoding_value_ptr++);
1600 l_res->ph = *(l_encoding_value_ptr++);
1610 for (pino = 1 ; pino < l_bound ; ++pino) {
1611 l_current_comp = l_current_pi->comps;
1612 l_img_comp = p_image->comps;
1613 l_tccp = l_tcp->tccps;
1615 l_current_pi->tx0 = l_tx0;
1616 l_current_pi->ty0 = l_ty0;
1617 l_current_pi->tx1 = l_tx1;
1618 l_current_pi->ty1 = l_ty1;
1619 l_current_pi->dx = l_dx_min;
1620 l_current_pi->dy = l_dy_min;
1621 l_current_pi->step_p = l_step_p;
1622 l_current_pi->step_c = l_step_c;
1623 l_current_pi->step_r = l_step_r;
1624 l_current_pi->step_l = l_step_l;
1626 /* allocation for components and number of components has already been calculated by opj_pi_create */
1627 for (compno = 0; compno < l_current_pi->numcomps; ++compno) {
1628 opj_pi_resolution_t *l_res = l_current_comp->resolutions;
1629 l_encoding_value_ptr = l_tmp_ptr[compno];
1631 l_current_comp->dx = l_img_comp->dx;
1632 l_current_comp->dy = l_img_comp->dy;
1633 /* resolutions have already been initialized */
1634 for (resno = 0; resno < l_current_comp->numresolutions; resno++) {
1635 l_res->pdx = *(l_encoding_value_ptr++);
1636 l_res->pdy = *(l_encoding_value_ptr++);
1637 l_res->pw = *(l_encoding_value_ptr++);
1638 l_res->ph = *(l_encoding_value_ptr++);
1646 /* special treatment*/
1647 l_current_pi->include = (l_current_pi - 1)->include;
1648 l_current_pi->include_size = (l_current_pi - 1)->include_size;
1652 opj_free(l_tmp_data);
1654 opj_free(l_tmp_ptr);
1657 if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) {
1658 opj_pi_update_encode_poc_and_final(p_cp, p_tile_no, l_tx0, l_tx1, l_ty0, l_ty1,
1659 l_max_prec, l_max_res, l_dx_min, l_dy_min);
1661 opj_pi_update_encode_not_poc(p_cp, p_image->numcomps, p_tile_no, l_tx0, l_tx1,
1662 l_ty0, l_ty1, l_max_prec, l_max_res, l_dx_min, l_dy_min);
1668 void opj_pi_create_encode(opj_pi_iterator_t *pi,
1674 J2K_T2_MODE t2_mode)
1676 const OPJ_CHAR *prog;
1678 OPJ_UINT32 incr_top = 1, resetX = 0;
1679 opj_tcp_t *tcps = &cp->tcps[tileno];
1680 opj_poc_t *tcp = &tcps->pocs[pino];
1682 prog = opj_j2k_convert_progression_order(tcp->prg);
1685 pi[pino].poc.prg = tcp->prg;
1687 if (!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) &&
1688 (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz)))) {
1689 pi[pino].poc.resno0 = tcp->resS;
1690 pi[pino].poc.resno1 = tcp->resE;
1691 pi[pino].poc.compno0 = tcp->compS;
1692 pi[pino].poc.compno1 = tcp->compE;
1693 pi[pino].poc.layno0 = tcp->layS;
1694 pi[pino].poc.layno1 = tcp->layE;
1695 pi[pino].poc.precno0 = tcp->prcS;
1696 pi[pino].poc.precno1 = tcp->prcE;
1697 pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS;
1698 pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS;
1699 pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE;
1700 pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE;
1702 for (i = tppos + 1; i < 4; i++) {
1705 pi[pino].poc.resno0 = tcp->resS;
1706 pi[pino].poc.resno1 = tcp->resE;
1709 pi[pino].poc.compno0 = tcp->compS;
1710 pi[pino].poc.compno1 = tcp->compE;
1713 pi[pino].poc.layno0 = tcp->layS;
1714 pi[pino].poc.layno1 = tcp->layE;
1720 pi[pino].poc.precno0 = tcp->prcS;
1721 pi[pino].poc.precno1 = tcp->prcE;
1724 pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS;
1725 pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS;
1726 pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE;
1727 pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE;
1735 for (i = tppos; i >= 0; i--) {
1738 tcp->comp_t = tcp->compS;
1739 pi[pino].poc.compno0 = tcp->comp_t;
1740 pi[pino].poc.compno1 = tcp->comp_t + 1;
1744 tcp->res_t = tcp->resS;
1745 pi[pino].poc.resno0 = tcp->res_t;
1746 pi[pino].poc.resno1 = tcp->res_t + 1;
1750 tcp->lay_t = tcp->layS;
1751 pi[pino].poc.layno0 = tcp->lay_t;
1752 pi[pino].poc.layno1 = tcp->lay_t + 1;
1759 tcp->prc_t = tcp->prcS;
1760 pi[pino].poc.precno0 = tcp->prc_t;
1761 pi[pino].poc.precno1 = tcp->prc_t + 1;
1765 tcp->tx0_t = tcp->txS;
1766 tcp->ty0_t = tcp->tyS;
1767 pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
1768 pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx));
1769 pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
1770 pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
1771 tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
1772 tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
1780 for (i = tppos; i >= 0; i--) {
1783 pi[pino].poc.compno0 = tcp->comp_t - 1;
1784 pi[pino].poc.compno1 = tcp->comp_t;
1787 pi[pino].poc.resno0 = tcp->res_t - 1;
1788 pi[pino].poc.resno1 = tcp->res_t;
1791 pi[pino].poc.layno0 = tcp->lay_t - 1;
1792 pi[pino].poc.layno1 = tcp->lay_t;
1798 pi[pino].poc.precno0 = tcp->prc_t - 1;
1799 pi[pino].poc.precno1 = tcp->prc_t;
1802 pi[pino].poc.tx0 = (OPJ_INT32)(tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx));
1803 pi[pino].poc.tx1 = (OPJ_INT32)tcp->tx0_t ;
1804 pi[pino].poc.ty0 = (OPJ_INT32)(tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy));
1805 pi[pino].poc.ty1 = (OPJ_INT32)tcp->ty0_t ;
1810 if (incr_top == 1) {
1813 if (tcp->res_t == tcp->resE) {
1814 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1815 tcp->res_t = tcp->resS;
1816 pi[pino].poc.resno0 = tcp->res_t;
1817 pi[pino].poc.resno1 = tcp->res_t + 1;
1824 pi[pino].poc.resno0 = tcp->res_t;
1825 pi[pino].poc.resno1 = tcp->res_t + 1;
1831 if (tcp->comp_t == tcp->compE) {
1832 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1833 tcp->comp_t = tcp->compS;
1834 pi[pino].poc.compno0 = tcp->comp_t;
1835 pi[pino].poc.compno1 = tcp->comp_t + 1;
1842 pi[pino].poc.compno0 = tcp->comp_t;
1843 pi[pino].poc.compno1 = tcp->comp_t + 1;
1849 if (tcp->lay_t == tcp->layE) {
1850 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1851 tcp->lay_t = tcp->layS;
1852 pi[pino].poc.layno0 = tcp->lay_t;
1853 pi[pino].poc.layno1 = tcp->lay_t + 1;
1860 pi[pino].poc.layno0 = tcp->lay_t;
1861 pi[pino].poc.layno1 = tcp->lay_t + 1;
1870 if (tcp->prc_t == tcp->prcE) {
1871 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1872 tcp->prc_t = tcp->prcS;
1873 pi[pino].poc.precno0 = tcp->prc_t;
1874 pi[pino].poc.precno1 = tcp->prc_t + 1;
1881 pi[pino].poc.precno0 = tcp->prc_t;
1882 pi[pino].poc.precno1 = tcp->prc_t + 1;
1888 if (tcp->tx0_t >= tcp->txE) {
1889 if (tcp->ty0_t >= tcp->tyE) {
1890 if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) {
1891 tcp->ty0_t = tcp->tyS;
1892 pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
1893 pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
1894 tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
1902 pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
1903 pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
1904 tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
1909 tcp->tx0_t = tcp->txS;
1910 pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
1911 pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx));
1912 tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
1915 pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
1916 pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx));
1917 tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
1930 void opj_pi_destroy(opj_pi_iterator_t *p_pi,
1931 OPJ_UINT32 p_nb_elements)
1933 OPJ_UINT32 compno, pino;
1934 opj_pi_iterator_t *l_current_pi = p_pi;
1936 if (p_pi->include) {
1937 opj_free(p_pi->include);
1940 for (pino = 0; pino < p_nb_elements; ++pino) {
1941 if (l_current_pi->comps) {
1942 opj_pi_comp_t *l_current_component = l_current_pi->comps;
1943 for (compno = 0; compno < l_current_pi->numcomps; compno++) {
1944 if (l_current_component->resolutions) {
1945 opj_free(l_current_component->resolutions);
1946 l_current_component->resolutions = 00;
1949 ++l_current_component;
1951 opj_free(l_current_pi->comps);
1952 l_current_pi->comps = 0;
1962 void opj_pi_update_encoding_parameters(const opj_image_t *p_image,
1964 OPJ_UINT32 p_tile_no)
1966 /* encoding parameters to set */
1967 OPJ_UINT32 l_max_res;
1968 OPJ_UINT32 l_max_prec;
1969 OPJ_INT32 l_tx0, l_tx1, l_ty0, l_ty1;
1970 OPJ_UINT32 l_dx_min, l_dy_min;
1973 opj_tcp_t *l_tcp = 00;
1977 assert(p_image != 00);
1978 assert(p_tile_no < p_cp->tw * p_cp->th);
1980 l_tcp = &(p_cp->tcps[p_tile_no]);
1982 /* get encoding parameters */
1983 opj_get_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1, &l_ty0,
1984 &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res);
1987 opj_pi_update_encode_poc_and_final(p_cp, p_tile_no, l_tx0, l_tx1, l_ty0, l_ty1,
1988 l_max_prec, l_max_res, l_dx_min, l_dy_min);
1990 opj_pi_update_encode_not_poc(p_cp, p_image->numcomps, p_tile_no, l_tx0, l_tx1,
1991 l_ty0, l_ty1, l_max_prec, l_max_res, l_dx_min, l_dy_min);
1995 OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi)
1997 switch (pi->poc.prg) {
1999 return opj_pi_next_lrcp(pi);
2001 return opj_pi_next_rlcp(pi);
2003 return opj_pi_next_rpcl(pi);
2005 return opj_pi_next_pcrl(pi);
2007 return opj_pi_next_cprl(pi);
2008 case OPJ_PROG_UNKNOWN: