4 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2014, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
36 #include "opj_inttypes.h"
37 #include "index_manager.h"
38 #include "box_manager.h"
39 #include "manfbox_manager.h"
40 #include "mhixbox_manager.h"
41 #include "codestream_manager.h"
42 #include "marker_manager.h"
43 #include "faixbox_manager.h"
44 #include "boxheader_manager.h"
47 #include "fcgi_stdio.h"
48 #define logstream FCGI_stdout
50 #define FCGI_stdout stdout
51 #define FCGI_stderr stderr
52 #define logstream stderr
56 * check JP2 box indexing
58 * @param[in] toplev_boxlist top level box list
59 * @return if correct (true) or wrong (false)
61 OPJ_BOOL check_JP2boxidx(boxlist_param_t *toplev_boxlist);
64 * set code index parameters (parse cidx box)
67 * @param[in] cidx_box pointer to the reference cidx_box
68 * @param[out] codeidx pointer to index parameters
69 * @return if succeeded (true) or failed (false)
71 OPJ_BOOL set_cidxdata(box_param_t *cidx_box, index_param_t *codeidx);
73 index_param_t * parse_jp2file(int fd)
75 index_param_t *jp2idx;
77 metadatalist_param_t *metadatalist;
78 boxlist_param_t *toplev_boxlist;
81 if (!(filesize = (Byte8_t)get_filesize(fd))) {
85 if (!(toplev_boxlist = get_boxstructure(fd, 0, filesize))) {
86 fprintf(FCGI_stderr, "Error: Not correctl JP2 format\n");
90 if (!check_JP2boxidx(toplev_boxlist)) {
91 fprintf(FCGI_stderr, "Index format not supported\n");
92 delete_boxlist(&toplev_boxlist);
96 if (!(cidx = search_box("cidx", toplev_boxlist))) {
97 fprintf(FCGI_stderr, "Box cidx not found\n");
98 delete_boxlist(&toplev_boxlist);
102 jp2idx = (index_param_t *)opj_malloc(sizeof(index_param_t));
104 if (!set_cidxdata(cidx, jp2idx)) {
105 fprintf(FCGI_stderr, "Error: Not correctl format in cidx box\n");
107 delete_boxlist(&toplev_boxlist);
110 delete_boxlist(&toplev_boxlist);
112 metadatalist = const_metadatalist(fd);
113 jp2idx->metadatalist = metadatalist;
116 fprintf(logstream, "local log: code index created\n");
122 void print_index(index_param_t index)
126 fprintf(logstream, "index info:\n");
127 fprintf(logstream, "\tCodestream Offset: %#" PRIx64 "\n", index.offset);
128 fprintf(logstream, "\t Length: %#" PRIx64 "\n", index.length);
129 fprintf(logstream, "\tMain header Length: %#" PRIx64 "\n", index.mhead_length);
131 print_SIZ(index.SIZ);
132 print_COD(index.COD);
134 fprintf(logstream, "Tile part information: \n");
135 print_faixbox(index.tilepart);
137 fprintf(logstream, "Tile header information: \n");
138 for (i = 0; i < (int)(index.SIZ.XTnum * index.SIZ.YTnum); i++) {
139 print_mhixbox(index.tileheader[i]);
142 fprintf(logstream, "Precinct packet information: \n");
143 for (i = 0; i < index.SIZ.Csiz; i++) {
144 fprintf(logstream, "Component %d\n", i);
145 print_faixbox(index.precpacket[i]);
148 print_allmetadata(index.metadatalist);
151 void print_SIZ(SIZmarker_param_t SIZ)
155 fprintf(logstream, "\tImage and Tile SIZ parameters\n");
156 fprintf(logstream, "\t Rsiz: %#x\n", SIZ.Rsiz);
157 fprintf(logstream, "\t Xsiz, Ysiz: (%d,%d) = (%#x, %#x)\n", SIZ.Xsiz,
158 SIZ.Ysiz, SIZ.Xsiz, SIZ.Ysiz);
159 fprintf(logstream, "\t XOsiz, YOsiz: (%d,%d) = (%#x, %#x)\n", SIZ.XOsiz,
160 SIZ.YOsiz, SIZ.XOsiz, SIZ.YOsiz);
161 fprintf(logstream, "\t XTsiz, YTsiz: (%d,%d) = (%#x, %#x)\n", SIZ.XTsiz,
162 SIZ.YTsiz, SIZ.XTsiz, SIZ.YTsiz);
163 fprintf(logstream, "\t XTOsiz, YTOsiz: (%d,%d) = (%#x, %#x)\n", SIZ.XTOsiz,
164 SIZ.YTOsiz, SIZ.XTOsiz, SIZ.YTOsiz);
165 fprintf(logstream, "\t XTnum, YTnum: (%d,%d)\n", SIZ.XTnum, SIZ.YTnum);
166 fprintf(logstream, "\t Num of Components: %d\n", SIZ.Csiz);
168 for (i = 0; i < SIZ.Csiz; i++) {
170 "\t[%d] (Ssiz, XRsiz, YRsiz): (%d, %d, %d) = (%#x, %#x, %#x)\n", i, SIZ.Ssiz[i],
171 SIZ.XRsiz[i], SIZ.YRsiz[i], SIZ.Ssiz[i], SIZ.XRsiz[i], SIZ.YRsiz[i]);
175 void print_COD(CODmarker_param_t COD)
179 fprintf(logstream, "\tCoding style default COD parameters\n");
181 "\t Progression order: %d [ LRCP=0, RLCP=1, RPCL=2, PCRL=3, CPRL=4]\n",
183 fprintf(logstream, "\t Num of layers: %d\n", COD.numOflayers);
184 fprintf(logstream, "\t Decomposition lvl: %d\n", COD.numOfdecomp);
186 for (i = 0; i <= ((COD.Scod & 0x01) ? COD.numOfdecomp : 0); i++) {
187 fprintf(logstream, "\t [%d] XPsiz, YPsiz: (%d,%d) = (%#x, %#x)\n", i,
188 COD.XPsiz[i], COD.YPsiz[i], COD.XPsiz[i], COD.YPsiz[i]);
192 void delete_index(index_param_t **index)
196 delete_metadatalist(&((*index)->metadatalist));
198 delete_COD((*index)->COD);
200 delete_faixbox(&((*index)->tilepart));
202 for (i = 0; i < (int)((*index)->SIZ.XTnum * (*index)->SIZ.YTnum); i++) {
203 delete_mhixbox(&((*index)->tileheader[i]));
205 opj_free((*index)->tileheader);
207 for (i = 0; i < (*index)->SIZ.Csiz; i++) {
208 delete_faixbox(&((*index)->precpacket[i]));
210 opj_free((*index)->precpacket);
215 void delete_COD(CODmarker_param_t COD)
225 OPJ_BOOL check_JP2boxidx(boxlist_param_t *toplev_boxlist)
227 box_param_t *iptr, *fidx, *prxy;
228 box_param_t *cidx, *jp2c;
233 boxheader_param_t *obh;
236 boxheader_param_t *ibh;
238 iptr = search_box("iptr", toplev_boxlist);
239 fidx = search_box("fidx", toplev_boxlist);
240 cidx = search_box("cidx", toplev_boxlist);
241 jp2c = search_box("jp2c", toplev_boxlist);
242 prxy = gene_childboxbyType(fidx, 0, "prxy");
244 off = fetch_DBox8bytebigendian(iptr, 0);
245 if (off != (Byte8_t)fidx->offset) {
247 "Reference File Index box offset in Index Finder box not correct\n");
250 len = fetch_DBox8bytebigendian(iptr, 8);
251 if (len != fidx->length) {
253 "Reference File Index box length in Index Finder box not correct\n");
257 ooff = fetch_DBox8bytebigendian(prxy, pos);
258 if (ooff != (Byte8_t)jp2c->offset) {
259 fprintf(FCGI_stderr, "Reference jp2c offset in prxy box not correct\n");
263 obh = gene_childboxheader(prxy, pos);
264 if (obh->length != jp2c->length || strncmp(obh->type, "jp2c", 4) != 0) {
265 fprintf(FCGI_stderr, "Reference jp2c header in prxy box not correct\n");
270 ni = fetch_DBox1byte(prxy, pos);
272 fprintf(FCGI_stderr, "Multiple indexes not supported\n");
278 ioff = fetch_DBox8bytebigendian(prxy, pos);
279 if (ioff != (Byte8_t)cidx->offset) {
280 fprintf(FCGI_stderr, "Reference cidx offset in prxy box not correct\n");
284 ibh = gene_childboxheader(prxy, pos);
285 if (ibh->length != cidx->length || strncmp(ibh->type, "cidx", 4) != 0) {
286 fprintf(FCGI_stderr, "Reference cidx header in prxy box not correct\n");
297 * set code index parameters from cptr box
298 * I.3.2.2 Codestream Finder box
300 * @param[in] cidx_box pointer to the reference cidx_box
301 * @param[out] jp2idx pointer to index parameters
302 * @return if succeeded (true) or failed (false)
304 OPJ_BOOL set_cptrdata(box_param_t *cidx_box, index_param_t *jp2idx);
307 * set code index parameters from mhix box for main header
308 * I.3.2.4.3 Header Index Table box
310 * @param[in] cidx_box pointer to the reference cidx_box
311 * @param[in] codestream codestream parameters
312 * @param[out] jp2idx pointer to index parameters
313 * @return if succeeded (true) or failed (false)
315 OPJ_BOOL set_mainmhixdata(box_param_t *cidx_box, codestream_param_t codestream,
316 index_param_t *jp2idx);
319 * set code index parameters from tpix box
320 * I.3.2.4.4 Tile-part Index Table box
322 * @param[in] cidx_box pointer to the reference cidx_box
323 * @param[out] jp2idx pointer to index parameters
324 * @return if succeeded (true) or failed (false)
326 OPJ_BOOL set_tpixdata(box_param_t *cidx_box, index_param_t *jp2idx);
329 * set code index parameters from thix box
330 * I.3.2.4.5 Tile Header Index Table box
332 * @param[in] cidx_box pointer to the reference cidx_box
333 * @param[out] jp2idx pointer to index parameters
334 * @return if succeeded (true) or failed (false)
336 OPJ_BOOL set_thixdata(box_param_t *cidx_box, index_param_t *jp2idx);
339 * set code index parameters from ppix box
340 * I.3.2.4.6 Precinct Packet Index Table box
342 * @param[in] cidx_box pointer to the reference cidx_box
343 * @param[out] jp2idx pointer to index parameters
344 * @return if succeeded (true) or failed (false)
346 OPJ_BOOL set_ppixdata(box_param_t *cidx_box, index_param_t *jp2idx);
348 OPJ_BOOL set_cidxdata(box_param_t *cidx_box, index_param_t *jp2idx)
350 box_param_t *manf_box;
351 manfbox_param_t *manf;
352 codestream_param_t codestream;
354 set_cptrdata(cidx_box, jp2idx);
356 codestream = set_codestream(cidx_box->fd, jp2idx->offset, jp2idx->length);
358 manf_box = gene_boxbyType(cidx_box->fd, get_DBoxoff(cidx_box),
359 get_DBoxlen(cidx_box), "manf");
360 manf = gene_manfbox(manf_box);
362 if (!search_boxheader("mhix", manf)) {
363 fprintf(FCGI_stderr, "Error: mhix box not present in manfbox\n");
365 delete_manfbox(&manf);
368 set_mainmhixdata(cidx_box, codestream, jp2idx);
370 if (!search_boxheader("tpix", manf)) {
371 fprintf(FCGI_stderr, "Error: tpix box not present in manfbox\n");
373 delete_manfbox(&manf);
376 set_tpixdata(cidx_box, jp2idx);
378 if (!search_boxheader("thix", manf)) {
379 fprintf(FCGI_stderr, "Error: thix box not present in manfbox\n");
381 delete_manfbox(&manf);
384 set_thixdata(cidx_box, jp2idx);
386 if (!search_boxheader("ppix", manf)) {
387 fprintf(FCGI_stderr, "Error: ppix box not present in manfbox\n");
389 delete_manfbox(&manf);
392 set_ppixdata(cidx_box, jp2idx);
394 delete_manfbox(&manf);
400 OPJ_BOOL set_cptrdata(box_param_t *cidx_box, index_param_t *jp2idx)
402 box_param_t *box; /**< cptr box*/
405 if (!(box = gene_boxbyType(cidx_box->fd, get_DBoxoff(cidx_box),
406 get_DBoxlen(cidx_box), "cptr"))) {
410 /* DR: Data Reference. */
411 /* If 0, the codestream or its Fragment Table box exists in the current file*/
412 if ((dr = fetch_DBox2bytebigendian(box, 0))) {
413 fprintf(FCGI_stderr, "Error: Codestream not present in current file\n");
418 /* CONT: Container Type*/
419 /* If 0, the entire codestream appears as a contiguous range of*/
420 /* bytes within its file or resource.*/
421 if ((cont = fetch_DBox2bytebigendian(box, 2))) {
422 fprintf(FCGI_stderr, "Error: Can't cope with fragmented codestreams yet\n");
427 jp2idx->offset = (OPJ_OFF_T)fetch_DBox8bytebigendian(box, 4);
428 jp2idx->length = fetch_DBox8bytebigendian(box, 12);
437 * set SIZ marker information
438 * A.5 Fixed information marker segment
439 * A.5.1 Image and tile size (SIZ)
441 * @param[in] sizmkidx pointer to SIZ marker index in mhix box
442 * @param[in] codestream codestream parameters
443 * @param[out] SIZ SIZ marker parameters pointer
444 * @return if succeeded (true) or failed (false)
446 OPJ_BOOL set_SIZmkrdata(markeridx_param_t *sizmkidx,
447 codestream_param_t codestream, SIZmarker_param_t *SIZ);
450 * set code index parameters from COD marker in codestream
451 * A.6 Functional marker segments
452 * A.6.1 Coding style default (COD)
454 * @param[in] codmkidx pointer to COD marker index in mhix box
455 * @param[in] codestream codestream parameters
456 * @param[out] COD COD marker parameters pointer
457 * @return if succeeded (true) or failed (false)
459 OPJ_BOOL set_CODmkrdata(markeridx_param_t *codmkidx,
460 codestream_param_t codestream, CODmarker_param_t *COD);
462 OPJ_BOOL set_mainmhixdata(box_param_t *cidx_box, codestream_param_t codestream,
463 index_param_t *jp2idx)
465 box_param_t *mhix_box;
466 mhixbox_param_t *mhix;
467 markeridx_param_t *sizmkidx;
468 markeridx_param_t *codmkidx;
470 if (!(mhix_box = gene_boxbyType(cidx_box->fd, get_DBoxoff(cidx_box),
471 get_DBoxlen(cidx_box), "mhix"))) {
475 jp2idx->mhead_length = fetch_DBox8bytebigendian(mhix_box, 0);
477 mhix = gene_mhixbox(mhix_box);
480 sizmkidx = search_markeridx(0xff51, mhix);
481 set_SIZmkrdata(sizmkidx, codestream, &(jp2idx->SIZ));
483 codmkidx = search_markeridx(0xff52, mhix);
484 set_CODmkrdata(codmkidx, codestream, &(jp2idx->COD));
486 delete_mhixbox(&mhix);
491 OPJ_BOOL set_tpixdata(box_param_t *cidx_box, index_param_t *jp2idx)
493 box_param_t *tpix_box; /**< tpix box*/
494 box_param_t *faix_box; /**< faix box*/
496 if (!(tpix_box = gene_boxbyType(cidx_box->fd, get_DBoxoff(cidx_box),
497 get_DBoxlen(cidx_box), "tpix"))) {
498 fprintf(FCGI_stderr, "Error: tpix box not present in cidx box\n");
502 if (!(faix_box = gene_boxbyType(tpix_box->fd, get_DBoxoff(tpix_box),
503 get_DBoxlen(tpix_box), "faix"))) {
504 fprintf(FCGI_stderr, "Error: faix box not present in tpix box\n");
509 jp2idx->tilepart = gene_faixbox(faix_box);
517 OPJ_BOOL set_thixdata(box_param_t *cidx_box, index_param_t *jp2idx)
519 box_param_t *thix_box, *manf_box, *mhix_box;
520 manfbox_param_t *manf;
521 boxheader_param_t *ptr;
522 mhixbox_param_t *mhix;
524 OPJ_OFF_T mhixseqoff;
527 if (!(thix_box = gene_boxbyType(cidx_box->fd, get_DBoxoff(cidx_box),
528 get_DBoxlen(cidx_box), "thix"))) {
529 fprintf(FCGI_stderr, "Error: thix box not present in cidx box\n");
533 if (!(manf_box = gene_boxbyType(thix_box->fd, get_DBoxoff(thix_box),
534 get_DBoxlen(thix_box), "manf"))) {
535 fprintf(FCGI_stderr, "Error: manf box not present in thix box\n");
540 manf = gene_manfbox(manf_box);
542 mhixseqoff = manf_box->offset + (OPJ_OFF_T)manf_box->length;
545 jp2idx->tileheader = (mhixbox_param_t **)opj_malloc(jp2idx->SIZ.XTnum *
546 jp2idx->SIZ.YTnum * sizeof(mhixbox_param_t *));
549 if (!(mhix_box = gene_boxbyType(thix_box->fd, mhixseqoff + (OPJ_OFF_T)pos,
550 get_DBoxlen(thix_box) - manf_box->length - pos, "mhix"))) {
551 fprintf(FCGI_stderr, "Error: mhix box not present in thix box\n");
552 delete_manfbox(&manf);
557 mhix = gene_mhixbox(mhix_box);
559 pos += mhix_box->length;
563 jp2idx->tileheader[tile_no++] = mhix;
566 delete_manfbox(&manf);
573 OPJ_BOOL set_ppixdata(box_param_t *cidx_box, index_param_t *jp2idx)
575 box_param_t *ppix_box, *faix_box, *manf_box;
576 manfbox_param_t *manf; /**< manf*/
577 boxheader_param_t *bh; /**< box headers*/
578 faixbox_param_t *faix; /**< faix*/
579 OPJ_OFF_T inbox_offset;
582 if (!(ppix_box = gene_boxbyType(cidx_box->fd, get_DBoxoff(cidx_box),
583 get_DBoxlen(cidx_box), "ppix"))) {
584 fprintf(FCGI_stderr, "Error: ppix box not present in cidx box\n");
588 inbox_offset = get_DBoxoff(ppix_box);
589 if (!(manf_box = gene_boxbyType(ppix_box->fd, inbox_offset,
590 get_DBoxlen(ppix_box), "manf"))) {
591 fprintf(FCGI_stderr, "Error: manf box not present in ppix box\n");
598 manf = gene_manfbox(manf_box);
599 bh = search_boxheader("faix", manf);
600 inbox_offset = manf_box->offset + (OPJ_OFF_T)manf_box->length;
604 jp2idx->precpacket = (faixbox_param_t **)opj_malloc(jp2idx->SIZ.Csiz * sizeof(
607 for (comp_idx = 0; bh != NULL; bh = bh->next, comp_idx++) {
608 if (jp2idx->SIZ.Csiz <= comp_idx) {
610 "Error: num of faix boxes is not identical to num of components in ppix box\n");
611 delete_manfbox(&manf);
615 if (!(faix_box = gene_boxbyOffset(cidx_box->fd, inbox_offset))) {
616 fprintf(FCGI_stderr, "Error: faix box not present in ppix box\n");
617 delete_manfbox(&manf);
621 faix = gene_faixbox(faix_box);
622 jp2idx->precpacket[comp_idx] = faix;
624 inbox_offset = faix_box->offset + (OPJ_OFF_T)faix_box->length;
628 delete_manfbox(&manf);
633 OPJ_BOOL set_SIZmkrdata(markeridx_param_t *sizmkidx,
634 codestream_param_t codestream, SIZmarker_param_t *SIZ)
636 marker_param_t sizmkr;
639 sizmkr = set_marker(codestream, sizmkidx->code, sizmkidx->offset,
642 SIZ->Lsiz = fetch_marker2bytebigendian(sizmkr, 0);
644 if (sizmkidx->length != SIZ->Lsiz) {
645 fprintf(FCGI_stderr, "Error: marker %#x index is not correct\n",
650 SIZ->Rsiz = fetch_marker2bytebigendian(sizmkr, 2);
651 SIZ->Xsiz = fetch_marker4bytebigendian(sizmkr, 4);
652 SIZ->Ysiz = fetch_marker4bytebigendian(sizmkr, 8);
653 SIZ->XOsiz = fetch_marker4bytebigendian(sizmkr, 12);
654 SIZ->YOsiz = fetch_marker4bytebigendian(sizmkr, 16);
655 SIZ->XTsiz = fetch_marker4bytebigendian(sizmkr, 20);
656 SIZ->YTsiz = fetch_marker4bytebigendian(sizmkr, 24);
657 SIZ->XTOsiz = fetch_marker4bytebigendian(sizmkr, 28);
658 SIZ->YTOsiz = fetch_marker4bytebigendian(sizmkr, 32);
659 SIZ->Csiz = fetch_marker2bytebigendian(sizmkr, 36);
661 SIZ->XTnum = (SIZ->Xsiz - SIZ->XTOsiz + SIZ->XTsiz - 1) / SIZ->XTsiz;
662 SIZ->YTnum = (SIZ->Ysiz - SIZ->YTOsiz + SIZ->YTsiz - 1) / SIZ->YTsiz;
664 for (i = 0; i < (int)SIZ->Csiz; i++) {
665 SIZ->Ssiz[i] = fetch_marker1byte(sizmkr, 38 + i * 3);
666 SIZ->XRsiz[i] = fetch_marker1byte(sizmkr, 39 + i * 3);
667 SIZ->YRsiz[i] = fetch_marker1byte(sizmkr, 40 + i * 3);
672 OPJ_BOOL set_CODmkrdata(markeridx_param_t *codmkidx,
673 codestream_param_t codestream, CODmarker_param_t *COD)
675 marker_param_t codmkr;
678 codmkr = set_marker(codestream, codmkidx->code, codmkidx->offset,
681 COD->Lcod = fetch_marker2bytebigendian(codmkr, 0);
683 if (codmkidx->length != COD->Lcod) {
684 fprintf(FCGI_stderr, "Error: marker %#x index is not correct\n",
689 COD->Scod = fetch_marker1byte(codmkr, 2);
690 COD->prog_order = fetch_marker1byte(codmkr, 3);
691 COD->numOflayers = fetch_marker2bytebigendian(codmkr, 4);
692 COD->numOfdecomp = fetch_marker1byte(codmkr, 7);
694 if (COD->Scod & 0x01) {
695 COD->XPsiz = (Byte4_t *)opj_malloc((OPJ_SIZE_T)(COD->numOfdecomp + 1) * sizeof(
697 COD->YPsiz = (Byte4_t *)opj_malloc((OPJ_SIZE_T)(COD->numOfdecomp + 1) * sizeof(
700 for (i = 0; i <= COD->numOfdecomp; i++) {
702 COD->XPsiz[i] = (Byte2_t)pow(2, fetch_marker1byte(codmkr, 12 + i) & 0x0F);
703 COD->YPsiz[i] = (Byte2_t)pow(2, (fetch_marker1byte(codmkr,
704 12 + i) & 0xF0) >> 4);
707 COD->XPsiz = (Byte4_t *)opj_malloc(sizeof(Byte4_t));
708 COD->YPsiz = (Byte4_t *)opj_malloc(sizeof(Byte4_t));
710 COD->XPsiz[0] = COD->YPsiz[0] = 1 << 15; /* pow(2,15); */
716 /* very very generic name see NOMINMAX */
723 Byte4_t max(Byte4_t n1, Byte4_t n2);
724 Byte4_t min(Byte4_t n1, Byte4_t n2);
726 range_param_t get_tile_range(Byte4_t Osiz, Byte4_t siz, Byte4_t TOsiz,
727 Byte4_t Tsiz, Byte4_t tile_XYid, int level);
729 range_param_t get_tile_Xrange(SIZmarker_param_t SIZ, Byte4_t tile_id, int level)
731 return get_tile_range(SIZ.XOsiz, SIZ.Xsiz, SIZ.XTOsiz, SIZ.XTsiz,
732 tile_id % SIZ.XTnum, level);
735 range_param_t get_tile_Yrange(SIZmarker_param_t SIZ, Byte4_t tile_id, int level)
737 return get_tile_range(SIZ.YOsiz, SIZ.Ysiz, SIZ.YTOsiz, SIZ.YTsiz,
738 tile_id / SIZ.XTnum, level);
741 range_param_t get_tile_range(Byte4_t Osiz, Byte4_t siz, Byte4_t TOsiz,
742 Byte4_t Tsiz, Byte4_t tile_XYid, int level)
747 range.minvalue = max(Osiz, TOsiz + tile_XYid * Tsiz);
748 range.maxvalue = min(siz, TOsiz + (tile_XYid + 1) * Tsiz);
750 for (n = 0; n < level; n++) {
751 range.minvalue = (Byte4_t)ceil(range.minvalue / 2.0);
752 range.maxvalue = (Byte4_t)ceil(range.maxvalue / 2.0);
757 Byte4_t get_tile_XSiz(SIZmarker_param_t SIZ, Byte4_t tile_id, int level)
759 range_param_t tile_Xrange;
761 tile_Xrange = get_tile_Xrange(SIZ, tile_id, level);
762 return tile_Xrange.maxvalue - tile_Xrange.minvalue;
765 Byte4_t get_tile_YSiz(SIZmarker_param_t SIZ, Byte4_t tile_id, int level)
767 range_param_t tile_Yrange;
769 tile_Yrange = get_tile_Yrange(SIZ, tile_id, level);
770 return tile_Yrange.maxvalue - tile_Yrange.minvalue;
773 /* TODO: what is this code doing ? will all compiler be able to optimize the following ? */
774 Byte4_t max(Byte4_t n1, Byte4_t n2)
783 Byte4_t min(Byte4_t n1, Byte4_t n2)
792 OPJ_BOOL isJPTfeasible(index_param_t index)
794 if (1 < get_nmax(index.tilepart)) {