2 * Copyright (c) 2001-2003, David Janssens
3 * Copyright (c) 2002-2003, Yannick Verschueren
4 * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
5 * Copyright (c) 2005, Herv� Drolon, FreeImage Team
6 * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
7 * Copyright (c) 2005-2006, Dept. of Electronic and Information Engineering, Universita' degli Studi di Perugia, Italy
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
34 #include "../libopenjpeg/opj_includes.h"
36 /** Minimum and maximum values for the double->pfp conversion */
38 #define MAX_V1 17293822569102704640.0
39 #define MIN_V2 0.000030517578125
40 #define MAX_V2 131040.0
42 /** conversion between a double precision floating point
43 number and the corresponding pseudo-floating point used
44 to represent sensitivity values
45 @param V the double precision value
46 @param bytes the number of bytes of the representation
47 @return the pseudo-floating point value (cast accordingly)
49 unsigned short int jpwl_double_to_pfp(double V, int bytes);
51 /** conversion between a pseudo-floating point used
52 to represent sensitivity values and the corresponding
53 double precision floating point number
54 @param em the pseudo-floating point value (cast accordingly)
55 @param bytes the number of bytes of the representation
56 @return the double precision value
58 double jpwl_pfp_to_double(unsigned short int em, int bytes);
60 /*-------------------------------------------------------------*/
62 int jpwl_markcomp(const void *arg1, const void *arg2)
64 /* Compare the two markers' positions */
65 double diff = (((jpwl_marker_t *) arg1)->dpos - ((jpwl_marker_t *) arg2)->dpos);
75 int jpwl_epbs_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num,
76 bool latest, bool packed, bool insideMH, int *idx, int hprot,
77 double place_pos, int tileno,
78 unsigned long int pre_len, unsigned long int post_len) {
80 jpwl_epb_ms_t *epb_mark = NULL;
82 int k_pre, k_post, n_pre, n_post;
84 unsigned long int L1, L2, dL4, max_postlen, epbs_len = 0;
86 /* We find RS(n,k) for EPB parms and pre-data, if any */
87 if (insideMH && (*idx == 0)) {
91 } else if (!insideMH && (*idx == 0)) {
96 /* Following EPBs in MH or TH */
101 /* Find lengths, Figs. B3 and B4 */
102 /* size of pre data: pre_buf(pre_len) + EPB(2) + Lepb(2) + Depb(1) + LDPepb(4) + Pepb(4) */
105 /* size of pre-data redundancy */
106 /* (redundancy per codeword) * (number of codewords, rounded up) */
107 L2 = (n_pre - k_pre) * (unsigned long int) ceil((double) L1 / (double) k_pre);
109 /* Find protection type for post data and its associated redundancy field length*/
110 if ((hprot == 16) || (hprot == 32)) {
111 /* there is a CRC for post-data */
113 n_post = post_len + (hprot >> 3);
114 /*L3 = hprot >> 3;*/ /* 2 (CRC-16) or 4 (CRC-32) bytes */
116 } else if ((hprot >= 37) && (hprot <= 128)) {
117 /* there is a RS for post-data */
122 /* Use predefined codes */
127 /* Create the EPB(s) */
128 while (post_len > 0) {
130 /* maximum postlen in order to respect EPB size
131 (we use 65450 instead of 65535 for keeping room for EPB parms)*/
132 /* (message word size) * (number of containable parity words) */
133 max_postlen = k_post * (unsigned long int) floor(65450.0 / (double) (n_post - k_post));
135 /* maximum postlen in order to respect EPB size */
137 /* (we use (65500 - L2) instead of 65535 for keeping room for EPB parms + pre-data) */
138 /* (message word size) * (number of containable parity words) */
139 max_postlen = k_post * (unsigned long int) floor((double) (65500 - L2) / (double) (n_post - k_post));
142 /* (we use 65500 instead of 65535 for keeping room for EPB parms) */
143 /* (message word size) * (number of containable parity words) */
144 max_postlen = k_post * (unsigned long int) floor(65500.0 / (double) (n_post - k_post));
147 dL4 = min(max_postlen, post_len);
149 if (epb_mark = jpwl_epb_create(
150 j2k, /* this encoder handle */
151 latest ? (dL4 < max_postlen) : false, /* is it the latest? */
152 packed, /* is it packed? */
153 tileno, /* we are in TPH */
154 *idx, /* its index */
155 hprot, /* protection type parameters of following data */
156 0, /* pre-data: nothing for now */
157 dL4 /* post-data: the stub computed previously */
160 /* Add this marker to the 'insertanda' list */
161 if (*jwmarker_num < JPWL_MAX_NO_MARKERS) {
162 jwmarker[*jwmarker_num].id = J2K_MS_EPB; /* its type */
163 jwmarker[*jwmarker_num].epbmark = epb_mark; /* the EPB */
164 jwmarker[*jwmarker_num].pos = (int) place_pos; /* after SOT */
165 jwmarker[*jwmarker_num].dpos = place_pos + 0.0000001 * (double)(*idx); /* not very first! */
166 jwmarker[*jwmarker_num].len = epb_mark->Lepb; /* its length */
167 jwmarker[*jwmarker_num].len_ready = true; /* ready */
168 jwmarker[*jwmarker_num].pos_ready = true; /* ready */
169 jwmarker[*jwmarker_num].parms_ready = true; /* ready */
170 jwmarker[*jwmarker_num].data_ready = false; /* not ready */
174 /* increment epb index */
177 /* decrease postlen */
180 /* increase the total length of EPBs */
181 epbs_len += epb_mark->Lepb + 2;
184 /* ooops, problems */
185 opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH EPB for UEP in tile %d\n", tileno);
193 jpwl_epb_ms_t *jpwl_epb_create(opj_j2k_t *j2k, bool latest, bool packed, int tileno, int idx, int hprot,
194 unsigned long int pre_len, unsigned long int post_len) {
196 jpwl_epb_ms_t *epb = NULL;
197 unsigned short int data_len = 0;
198 unsigned short int L2, L3;
199 unsigned long int L1, L4;
200 unsigned char *predata_in = NULL;
202 bool insideMH = (tileno == -1);
205 if (!(epb = (jpwl_epb_ms_t *) opj_malloc((size_t) 1 * sizeof (jpwl_epb_ms_t)))) {
206 opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for one EPB MS\n");
210 /* We set RS(n,k) for EPB parms and pre-data, if any */
211 if (insideMH && (idx == 0)) {
212 /* First EPB in MH */
215 } else if (!insideMH && (idx == 0)) {
216 /* First EPB in TH */
220 /* Following EPBs in MH or TH */
225 /* Find lengths, Figs. B3 and B4 */
226 /* size of pre data: pre_buf(pre_len) + EPB(2) + Lepb(2) + Depb(1) + LDPepb(4) + Pepb(4) */
228 epb->pre_len = pre_len;
230 /* size of pre-data redundancy */
231 /* (redundancy per codeword) * (number of codewords, rounded up) */
232 L2 = (epb->n_pre - epb->k_pre) * (unsigned short int) ceil((double) L1 / (double) epb->k_pre);
234 /* length of post-data */
236 epb->post_len = post_len;
238 /* Find protection type for post data and its associated redundancy field length*/
239 if ((hprot == 16) || (hprot == 32)) {
240 /* there is a CRC for post-data */
241 epb->Pepb = 0x10000000 | ((unsigned long int) hprot >> 5); /* 0=CRC-16, 1=CRC-32 */
242 epb->k_post = post_len;
243 epb->n_post = post_len + (hprot >> 3);
244 /*L3 = hprot >> 3;*/ /* 2 (CRC-16) or 4 (CRC-32) bytes */
246 } else if ((hprot >= 37) && (hprot <= 128)) {
247 /* there is a RS for post-data */
248 epb->Pepb = 0x20000020 | (((unsigned long int) hprot & 0x000000FF) << 8);
252 } else if (hprot == 1) {
253 /* Use predefined codes */
254 epb->Pepb = (unsigned long int) 0x00000000;
255 epb->n_post = epb->n_pre;
256 epb->k_post = epb->k_pre;
258 } else if (hprot == 0) {
259 /* Placeholder EPB: only protects its parameters, no protection method */
260 epb->Pepb = (unsigned long int) 0xFFFFFFFF;
265 opj_event_msg(j2k->cinfo, EVT_ERROR, "Invalid protection value for EPB h = %d\n", hprot);
271 /* (redundancy per codeword) * (number of codewords, rounded up) */
272 L3 = (epb->n_post - epb->k_post) * (unsigned short int) ceil((double) L4 / (double) epb->k_post);
275 epb->tileno = tileno;
277 /* Fill some fields of the EPB */
279 /* total length of the EPB MS (less the EPB marker itself): */
280 /* Lepb(2) + Depb(1) + LDPepb(4) + Pepb(4) + pre_redundancy + post-redundancy */
281 epb->Lepb = 11 + L2 + L3;
284 epb->Depb = ((packed & 0x0001) << 7) | ((latest & 0x0001) << 6) | (idx & 0x003F);
286 /* length of data protected by EPB: */
287 epb->LDPepb = L1 + L4;
292 void jpwl_epb_write(jpwl_epb_ms_t *epb, unsigned char *buf) {
295 *(buf++) = (unsigned char) (J2K_MS_EPB >> 8);
296 *(buf++) = (unsigned char) (J2K_MS_EPB >> 0);
299 *(buf++) = (unsigned char) (epb->Lepb >> 8);
300 *(buf++) = (unsigned char) (epb->Lepb >> 0);
303 *(buf++) = (unsigned char) (epb->Depb >> 0);
306 *(buf++) = (unsigned char) (epb->LDPepb >> 24);
307 *(buf++) = (unsigned char) (epb->LDPepb >> 16);
308 *(buf++) = (unsigned char) (epb->LDPepb >> 8);
309 *(buf++) = (unsigned char) (epb->LDPepb >> 0);
312 *(buf++) = (unsigned char) (epb->Pepb >> 24);
313 *(buf++) = (unsigned char) (epb->Pepb >> 16);
314 *(buf++) = (unsigned char) (epb->Pepb >> 8);
315 *(buf++) = (unsigned char) (epb->Pepb >> 0);
318 /*memcpy(buf, epb->data, (size_t) epb->Lepb - 11);*/
319 memset(buf, 0, (size_t) epb->Lepb - 11);
323 jpwl_epc_ms_t *jpwl_epc_create(opj_j2k_t *j2k, bool esd_on, bool red_on, bool epb_on, bool info_on) {
325 jpwl_epc_ms_t *epc = NULL;
328 if (!(epc = (jpwl_epc_ms_t *) malloc((size_t) 1 * sizeof (jpwl_epc_ms_t)))) {
329 opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for EPC MS\n");
333 /* Set the EPC parameters */
334 epc->esd_on = esd_on;
335 epc->epb_on = epb_on;
336 epc->red_on = red_on;
337 epc->info_on = info_on;
339 /* Fill the EPC fields with default values */
342 epc->DL = 0x00000000;
343 epc->Pepc = ((j2k->cp->esd_on & 0x0001) << 4) | ((j2k->cp->red_on & 0x0001) << 5) |
344 ((j2k->cp->epb_on & 0x0001) << 6) | ((j2k->cp->info_on & 0x0001) << 7);
349 bool jpwl_epb_fill(opj_j2k_t *j2k, jpwl_epb_ms_t *epb, unsigned char *buf, unsigned char *post_buf) {
351 unsigned long int L1, L2, L3, L4;
353 unsigned long int P, NN_P;
355 /* Operating buffer */
356 static unsigned char codeword[NN], *parityword;
358 unsigned char *L1_buf, *L2_buf;
359 /* these ones are static, since we need to keep memory of
360 the exact place from one call to the other */
361 static unsigned char *L3_buf, *L4_buf;
363 /* some consistency check */
365 opj_event_msg(j2k->cinfo, EVT_ERROR, "There is no operating buffer for EPBs\n");
369 if (!post_buf && !L4_buf) {
370 opj_event_msg(j2k->cinfo, EVT_ERROR, "There is no operating buffer for EPBs data\n");
375 * Compute parity bytes on pre-data, ALWAYS present (at least only for EPB parms)
378 /* Initialize RS structures */
379 P = epb->n_pre - epb->k_pre;
381 memset(codeword, 0, NN);
382 parityword = codeword + NN_P;
385 /* pre-data begins pre_len bytes before of EPB buf */
386 L1_buf = buf - epb->pre_len;
387 L1 = epb->pre_len + 13;
389 /* redundancy for pre-data begins immediately after EPB parms */
391 L2 = (epb->n_pre - epb->k_pre) * (unsigned short int) ceil((double) L1 / (double) epb->k_pre);
394 the position of L4 buffer can be:
395 1) passed as a parameter: in that case use it
396 2) null: in that case use the previous (static) one
402 /* post-data redundancy begins immediately after pre-data redundancy */
403 L3_buf = L2_buf + L2;
404 L3 = (epb->n_post - epb->k_post) * (unsigned short int) ceil((double) L4 / (double) epb->k_post);
406 /* let's check whether EPB length is sufficient to contain all these data */
407 if (epb->Lepb < (11 + L2 + L3))
408 opj_event_msg(j2k->cinfo, EVT_ERROR, "There is no room in EPB data field for writing redundancy data\n");
409 /*printf("Env. %d, nec. %d (%d + %d)\n", epb->Lepb - 11, L2 + L3, L2, L3);*/
411 /* Compute redundancy of pre-data message words */
415 /* copy message data into codeword buffer */
416 if (remaining < epb->k_pre) {
417 /* the last message word is zero-padded */
418 memset(codeword, 0, NN);
419 memcpy(codeword, L1_buf, remaining);
424 memcpy(codeword, L1_buf, epb->k_pre);
425 L1_buf += epb->k_pre;
426 remaining -= epb->k_pre;
430 /* Encode the buffer and obtain parity bytes */
431 if (encode_rs(codeword, parityword))
432 opj_event_msg(j2k->cinfo, EVT_WARNING,
433 "Possible encoding error in codeword @ position #%d\n", (L1_buf - buf) / epb->k_pre);
435 /* copy parity bytes only in redundancy buffer */
436 memcpy(L2_buf, parityword, P);
438 /* advance parity buffer */
443 * Compute parity bytes on post-data, may be absent if there are no data
445 /*printf("Hprot is %d (tileno=%d, k_pre=%d, n_pre=%d, k_post=%d, n_post=%d, pre_len=%d, post_len=%d)\n",
446 epb->hprot, epb->tileno, epb->k_pre, epb->n_pre, epb->k_post, epb->n_post, epb->pre_len,
448 if (epb->hprot < 0) {
450 /* there should be no EPB */
452 } else if (epb->hprot == 0) {
454 /* no protection for the data */
456 L4_buf += epb->post_len;
458 } else if (epb->hprot == 16) {
461 unsigned short int mycrc = 0x0000;
463 /* compute the CRC field (excluding itself) */
466 jpwl_updateCRC16(&mycrc, *(L4_buf++));
468 /* write the CRC field */
469 *(L3_buf++) = (unsigned char) (mycrc >> 8);
470 *(L3_buf++) = (unsigned char) (mycrc >> 0);
472 } else if (epb->hprot == 32) {
475 unsigned long int mycrc = 0x00000000;
477 /* compute the CRC field (excluding itself) */
480 jpwl_updateCRC32(&mycrc, *(L4_buf++));
482 /* write the CRC field */
483 *(L3_buf++) = (unsigned char) (mycrc >> 24);
484 *(L3_buf++) = (unsigned char) (mycrc >> 16);
485 *(L3_buf++) = (unsigned char) (mycrc >> 8);
486 *(L3_buf++) = (unsigned char) (mycrc >> 0);
492 /* Initialize RS structures */
493 P = epb->n_post - epb->k_post;
495 memset(codeword, 0, NN);
496 parityword = codeword + NN_P;
499 /* Compute redundancy of post-data message words */
503 /* copy message data into codeword buffer */
504 if (remaining < epb->k_post) {
505 /* the last message word is zero-padded */
506 memset(codeword, 0, NN);
507 memcpy(codeword, L4_buf, remaining);
512 memcpy(codeword, L4_buf, epb->k_post);
513 L4_buf += epb->k_post;
514 remaining -= epb->k_post;
518 /* Encode the buffer and obtain parity bytes */
519 if (encode_rs(codeword, parityword))
520 opj_event_msg(j2k->cinfo, EVT_WARNING,
521 "Possible encoding error in codeword @ position #%d\n", (L4_buf - buf) / epb->k_post);
523 /* copy parity bytes only in redundancy buffer */
524 memcpy(L3_buf, parityword, P);
526 /* advance parity buffer */
536 bool jpwl_correct(opj_j2k_t *j2k) {
538 opj_cio_t *cio = j2k->cio;
540 static bool mh_done = false;
541 int mark_pos, id, len, skips, sot_pos;
542 unsigned long int Psot = 0;
544 /* go back to marker position */
545 mark_pos = cio_tell(cio) - 2;
546 cio_seek(cio, mark_pos);
548 if ((j2k->state == J2K_STATE_MHSOC) && !mh_done) {
550 int mark_val = 0, skipnum = 0;
554 first thing to do, if we are here, is to look whether
555 51 (skipnum) positions ahead there is an EPB, in case of MH
559 first thing to do, if we are here, is to look whether
560 45 (skipnum) positions ahead there is an EPB, in case of MH
562 /* SIZ SIZ_FIELDS SIZ_COMPS FOLLOWING_MARKER */
563 skipnum = 2 + 38 + 3 * j2k->cp->exp_comps + 2;
564 if ((cio->bp + skipnum) < cio->end) {
566 cio_skip(cio, skipnum);
568 /* check that you are not going beyond the end of codestream */
570 /* call EPB corrector */
571 status = jpwl_epb_correct(j2k, /* J2K decompressor handle */
572 cio->bp, /* pointer to EPB in codestream buffer */
573 0, /* EPB type: MH */
574 skipnum, /* length of pre-data */
575 -1, /* length of post-data: -1 means auto */
580 /* read the marker value */
581 mark_val = (*(cio->bp) << 8) | *(cio->bp + 1);
583 if (status && (mark_val == J2K_MS_EPB)) {
593 if (true /*(j2k->state == J2K_STATE_TPHSOT) || (j2k->state == J2K_STATE_TPH)*/) {
594 /* else, look if 12 positions ahead there is an EPB, in case of TPH */
595 cio_seek(cio, mark_pos);
596 if ((cio->bp + 12) < cio->end) {
600 /* call EPB corrector */
601 status = jpwl_epb_correct(j2k, /* J2K decompressor handle */
602 cio->bp, /* pointer to EPB in codestream buffer */
603 1, /* EPB type: TPH */
604 12, /* length of pre-data */
605 -1, /* length of post-data: -1 means auto */
617 /* for now, don't use this code */
619 /* else, look if here is an EPB, in case of other */
621 /* it cannot stay before the first MH EPB */
622 cio_seek(cio, mark_pos);
625 /* call EPB corrector */
626 status = jpwl_epb_correct(j2k, /* J2K decompressor handle */
627 cio->bp, /* pointer to EPB in codestream buffer */
628 2, /* EPB type: TPH */
629 0, /* length of pre-data */
630 -1, /* length of post-data: -1 means auto */
639 /* nope, no EPBs probably, or they are so damaged that we can give up */
644 /* AN ATTEMPT OF PARSER */
645 /* NOT USED ACTUALLY */
647 /* go to the beginning of the file */
651 j2k->state = J2K_STATE_MHSOC;
653 /* cycle all over the markers */
654 while (cio_tell(cio) < cio->length) {
656 /* read the marker */
657 mark_pos = cio_tell(cio);
658 id = cio_read(cio, 2);
661 printf("Marker@%d: %X\n", cio_tell(cio) - 2, id);
663 /* do an action in response to the read marker */
670 j2k->state = J2K_STATE_MHSIZ;
677 j2k->state = J2K_STATE_MT;
682 /* particular case of SOD */
684 len = Psot - (mark_pos - sot_pos) - 2;
692 j2k->state = J2K_STATE_TPH;
693 sot_pos = mark_pos; /* position of SOT */
694 len = cio_read(cio, 2); /* read the length field */
695 cio_skip(cio, 2); /* this field is unnecessary */
696 Psot = cio_read(cio, 4); /* tile length */
702 j2k->state = J2K_STATE_MH;
703 /* read the length field */
704 len = cio_read(cio, 2);
710 /* read the length field */
711 len = cio_read(cio, 2);
717 /* skip to marker's end */
718 cio_skip(cio, skips);
725 bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_len, int post_len, int *conn,
726 unsigned char **L4_bufp) {
728 /* Operating buffer */
729 unsigned char codeword[NN], *parityword;
731 unsigned long int P, NN_P;
732 unsigned long int L1, L4;
733 int remaining, n_pre, k_pre, n_post, k_post;
737 int orig_pos = cio_tell(j2k->cio);
739 unsigned char *L1_buf, *L2_buf;
740 unsigned char *L3_buf, *L4_buf;
742 unsigned long int LDPepb, Pepb;
743 unsigned short int Lepb;
746 int myconn, errnum = 0;
747 bool errflag = false;
749 opj_cio_t *cio = j2k->cio;
751 /* check for common errors */
753 opj_event_msg(j2k->cinfo, EVT_ERROR, "The EPB pointer is a NULL buffer\n");
760 /* pre-data correction */
782 /* automatic setup */
787 opj_event_msg(j2k->cinfo, EVT_ERROR, "Unknown expected EPB type\n");
793 /* Initialize RS structures */
796 tt = (int) floor((float) P / 2.0F);
797 memset(codeword, 0, NN);
798 parityword = codeword + NN_P;
801 /* Correct pre-data message words */
802 L1_buf = buffer - pre_len;
803 L2_buf = buffer + 13;
807 /* always zero-pad codewords */
808 /* (this is required, since after decoding the zeros in the long codeword
809 could change, and keep unchanged in subsequent calls) */
810 memset(codeword, 0, NN);
812 /* copy codeword buffer into message bytes */
813 if (remaining < k_pre)
814 memcpy(codeword, L1_buf, remaining);
816 memcpy(codeword, L1_buf, k_pre);
818 /* copy redundancy buffer in parity bytes */
819 memcpy(parityword, L2_buf, P);
821 /* Decode the buffer and possibly obtain corrected bytes */
822 status = eras_dec_rs(codeword, NULL, 0);
825 opj_event_msg(j2k->cinfo, EVT_WARNING,
826 "Possible decoding error in codeword @ position #%d\n", (L1_buf - buffer) / k_pre);*/
828 /* we can try to safely get out from the function:
829 if we are here, either this is not an EPB or the first codeword
830 is too damaged to be helpful */
833 } else if (status == 0) {
835 opj_event_msg(j2k->cinfo, EVT_INFO, "codeword is correctly decoded\n");*/
837 } else if (status < tt) {
839 opj_event_msg(j2k->cinfo, EVT_WARNING, "%d errors corrected in codeword\n", status);*/
844 opj_event_msg(j2k->cinfo, EVT_WARNING, "EPB correction capability exceeded\n");
850 /* advance parity buffer */
851 if ((status >= 0) && (status < tt))
852 /* copy back corrected parity only if all is OK */
853 memcpy(L2_buf, parityword, P);
856 /* advance message buffer */
857 if (remaining < k_pre) {
858 if ((status >= 0) && (status < tt))
859 /* copy back corrected data only if all is OK */
860 memcpy(L1_buf, codeword, remaining);
865 if ((status >= 0) && (status < tt))
866 /* copy back corrected data only if all is OK */
867 memcpy(L1_buf, codeword, k_pre);
878 opj_event_msg(j2k->cinfo, EVT_INFO, "+ %d symbol errors corrected (Ps=%.1e)\n", errnum,
879 (float) errnum / ((float) n_pre * (float) L1 / (float) k_pre));*/
881 /*opj_event_msg(j2k->cinfo, EVT_INFO, "+ there were unrecoverable errors\n");*/
887 /* presumably, now, EPB parameters are correct */
890 /* Simply read the EPB parameters */
893 cio_skip(cio, 2); /* the marker */
894 Lepb = cio_read(cio, 2);
895 Depb = cio_read(cio, 1);
896 LDPepb = cio_read(cio, 4);
897 Pepb = cio_read(cio, 4);
899 /* What does Pepb tells us about the protection method? */
900 if (((Pepb & 0xF0000000) >> 28) == 0)
901 sprintf(str1, "pred"); /* predefined */
902 else if (((Pepb & 0xF0000000) >> 28) == 1)
903 sprintf(str1, "crc-%d", 16 * ((Pepb & 0x00000001) + 1)); /* CRC mode */
904 else if (((Pepb & 0xF0000000) >> 28) == 2)
905 sprintf(str1, "rs(%d,32)", (Pepb & 0x0000FF00) >> 8); /* RS mode */
906 else if (Pepb == 0xFFFFFFFF)
907 sprintf(str1, "nometh"); /* RS mode */
909 sprintf(str1, "unknown"); /* unknown */
911 /* Now we write them to screen */
912 if (!conn && post_len)
913 opj_event_msg(j2k->cinfo, EVT_INFO,
914 "EPB(%d): (%sl, %sp, %u), %lu, %s\n",
916 (Depb & 0x40) ? "" : "n", /* latest EPB or not? */
917 (Depb & 0x80) ? "" : "n", /* packed or unpacked EPB? */
918 (Depb & 0x3F), /* EPB index value */
919 LDPepb, /*length of the data protected by the EPB */
920 str1); /* protection method */
923 /* well, we need to investigate how long is the connected length of packed EPBs */
925 if ((Depb & 0x40) == 0) /* not latest in header */
926 jpwl_epb_correct(j2k, /* J2K decompressor handle */
927 buffer + Lepb + 2, /* pointer to next EPB in codestream buffer */
928 2, /* EPB type: should be of other type */
929 0, /* only EPB fields */
930 0, /* do not look after */
938 printf("connected = %d\n", myconn);*/
940 /*cio_seek(j2k->cio, orig_pos);
944 the position of L4 buffer is at the end of currently connected EPBs
947 L4_buf = buffer + myconn;
948 else if (!(*L4_bufp))
949 L4_buf = buffer + myconn;
953 L4 = LDPepb - pre_len - 13;
954 else if (post_len == 0)
961 /* Do a further check here on the read parameters */
962 if (L4 > (unsigned long) cio_numbytesleft(j2k->cio))
966 /* we are ready for decoding the remaining data */
967 if (((Pepb & 0xF0000000) >> 28) == 1) {
969 if ((16 * ((Pepb & 0x00000001) + 1)) == 16) {
972 unsigned short int mycrc = 0x0000, filecrc = 0x0000;
974 /* compute the CRC field */
977 jpwl_updateCRC16(&mycrc, *(L4_buf++));
979 /* read the CRC field */
980 filecrc = *(L3_buf++) << 8;
981 filecrc |= *(L3_buf++);
983 /* check the CRC field */
984 if (mycrc == filecrc) {
986 opj_event_msg(j2k->cinfo, EVT_INFO, "- CRC is OK\n");
989 opj_event_msg(j2k->cinfo, EVT_WARNING, "- CRC is KO (r=%d, c=%d)\n", filecrc, mycrc);
994 if ((16 * ((Pepb & 0x00000001) + 1)) == 32) {
997 unsigned long int mycrc = 0x00000000, filecrc = 0x00000000;
999 /* compute the CRC field */
1002 jpwl_updateCRC32(&mycrc, *(L4_buf++));
1004 /* read the CRC field */
1005 filecrc = *(L3_buf++) << 24;
1006 filecrc |= *(L3_buf++) << 16;
1007 filecrc |= *(L3_buf++) << 8;
1008 filecrc |= *(L3_buf++);
1010 /* check the CRC field */
1011 if (mycrc == filecrc) {
1013 opj_event_msg(j2k->cinfo, EVT_INFO, "- CRC is OK\n");
1016 opj_event_msg(j2k->cinfo, EVT_WARNING, "- CRC is KO (r=%d, c=%d)\n", filecrc, mycrc);
1021 } else if (Pepb == 0xFFFFFFFF) {
1024 /* advance without doing anything */
1029 } else if ((((Pepb & 0xF0000000) >> 28) == 2) || (((Pepb & 0xF0000000) >> 28) == 0)) {
1030 /* RS coding here */
1032 if (((Pepb & 0xF0000000) >> 28) == 0) {
1040 n_post = (Pepb & 0x0000FF00) >> 8;
1043 /* Initialize RS structures */
1044 P = n_post - k_post;
1046 tt = (int) floor((float) P / 2.0F);
1047 memset(codeword, 0, NN);
1048 parityword = codeword + NN_P;
1051 /* Correct post-data message words */
1052 /*L4_buf = buffer + Lepb + 2;*/
1057 /* always zero-pad codewords */
1058 /* (this is required, since after decoding the zeros in the long codeword
1059 could change, and keep unchanged in subsequent calls) */
1060 memset(codeword, 0, NN);
1062 /* copy codeword buffer into message bytes */
1063 if (remaining < k_post)
1064 memcpy(codeword, L4_buf, remaining);
1066 memcpy(codeword, L4_buf, k_post);
1068 /* copy redundancy buffer in parity bytes */
1069 memcpy(parityword, L3_buf, P);
1071 /* Decode the buffer and possibly obtain corrected bytes */
1072 status = eras_dec_rs(codeword, NULL, 0);
1075 opj_event_msg(j2k->cinfo, EVT_WARNING,
1076 "Possible decoding error in codeword @ position #%d\n", (L4_buf - (buffer + Lepb + 2)) / k_post);*/
1079 } else if (status == 0) {
1081 opj_event_msg(j2k->cinfo, EVT_INFO, "codeword is correctly decoded\n");*/
1083 } else if (status < tt) {
1085 opj_event_msg(j2k->cinfo, EVT_WARNING, "%d errors corrected in codeword\n", status);*/
1090 opj_event_msg(j2k->cinfo, EVT_WARNING, "EPB correction capability exceeded\n");
1096 /* advance parity buffer */
1097 if ((status >= 0) && (status < tt))
1098 /* copy back corrected data only if all is OK */
1099 memcpy(L3_buf, parityword, P);
1102 /* advance message buffer */
1103 if (remaining < k_post) {
1104 if ((status >= 0) && (status < tt))
1105 /* copy back corrected data only if all is OK */
1106 memcpy(L4_buf, codeword, remaining);
1107 L4_buf += remaining;
1111 if ((status >= 0) && (status < tt))
1112 /* copy back corrected data only if all is OK */
1113 memcpy(L4_buf, codeword, k_post);
1115 remaining -= k_post;
1121 /* give back the L4_buf address */
1129 opj_event_msg(j2k->cinfo, EVT_INFO, "- %d symbol errors corrected (Ps=%.1e)\n", errnum,
1130 (float) errnum / (float) LDPepb);
1132 opj_event_msg(j2k->cinfo, EVT_INFO, "- there were unrecoverable errors\n");
1136 cio_seek(j2k->cio, orig_pos);
1141 void jpwl_epc_write(jpwl_epc_ms_t *epc, unsigned char *buf) {
1144 *(buf++) = (unsigned char) (J2K_MS_EPC >> 8);
1145 *(buf++) = (unsigned char) (J2K_MS_EPC >> 0);
1148 *(buf++) = (unsigned char) (epc->Lepc >> 8);
1149 *(buf++) = (unsigned char) (epc->Lepc >> 0);
1152 *(buf++) = (unsigned char) (epc->Pcrc >> 8);
1153 *(buf++) = (unsigned char) (epc->Pcrc >> 0);
1156 *(buf++) = (unsigned char) (epc->DL >> 24);
1157 *(buf++) = (unsigned char) (epc->DL >> 16);
1158 *(buf++) = (unsigned char) (epc->DL >> 8);
1159 *(buf++) = (unsigned char) (epc->DL >> 0);
1162 *(buf++) = (unsigned char) (epc->Pepc >> 0);
1165 /*memcpy(buf, epc->data, (size_t) epc->Lepc - 9);*/
1166 memset(buf, 0, (size_t) epc->Lepc - 9);
1169 int jpwl_esds_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num,
1170 int comps, unsigned char addrm, unsigned char ad_size,
1171 unsigned char senst, unsigned char se_size,
1172 double place_pos, int tileno) {
1177 jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, unsigned char ad_size,
1178 unsigned char senst, unsigned char se_size, int tileno,
1179 unsigned long int svalnum, void *sensval) {
1181 jpwl_esd_ms_t *esd = NULL;
1184 if (!(esd = (jpwl_esd_ms_t *) malloc((size_t) 1 * sizeof (jpwl_esd_ms_t)))) {
1185 opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for ESD MS\n");
1189 /* if relative sensitivity, activate byte range mode */
1193 /* size of sensval's ... */
1194 if ((ad_size != 0) && (ad_size != 2) && (ad_size != 4)) {
1195 opj_event_msg(j2k->cinfo, EVT_ERROR, "Address size %d for ESD MS is forbidden\n", ad_size);
1198 if ((se_size != 1) && (se_size != 2)) {
1199 opj_event_msg(j2k->cinfo, EVT_ERROR, "Sensitivity size %d for ESD MS is forbidden\n", se_size);
1203 /* ... depends on the addressing mode */
1208 ad_size = 0; /* as per the standard */
1209 esd->sensval_size = se_size;
1214 /* auto sense address size */
1216 /* if there are more than 66% of (2^16 - 1) bytes, switch to 4 bytes
1217 (we keep space for possible EPBs being inserted) */
1218 ad_size = (j2k->image_info->codestream_size > (1 * 65535 / 3)) ? 4 : 2;
1219 esd->sensval_size = ad_size + ad_size + se_size;
1224 /* auto sense address size */
1226 /* if there are more than 2^16 - 1 packets, switch to 4 bytes */
1227 ad_size = (j2k->image_info->num > 65535) ? 4 : 2;
1228 esd->sensval_size = ad_size + ad_size + se_size;
1232 opj_event_msg(j2k->cinfo, EVT_ERROR, "Address mode %d for ESD MS is unimplemented\n", addrm);
1236 opj_event_msg(j2k->cinfo, EVT_ERROR, "Address mode %d for ESD MS is forbidden\n", addrm);
1240 /* set or unset sensitivity values */
1245 /* just based on the portions of a codestream */
1247 /* MH + no. of THs + no. of packets */
1248 svalnum = 1 + (j2k->image_info->tw * j2k->image_info->th) * (1 + j2k->image_info->num);
1251 /* all the ones that are based on the packets */
1254 /* MH: all the packets and all the tiles info is written */
1255 svalnum = j2k->image_info->tw * j2k->image_info->th * j2k->image_info->num;
1257 /* TPH: only that tile info is written */
1258 svalnum = j2k->image_info->num;
1264 /* fill private fields */
1266 esd->ad_size = ad_size;
1267 esd->se_size = se_size;
1269 esd->svalnum = svalnum;
1270 esd->numcomps = j2k->image->numcomps;
1271 esd->tileno = tileno;
1273 /* Set the ESD parameters */
1274 /* length, excluding data field */
1275 if (esd->numcomps < 257)
1276 esd->Lesd = 4 + (unsigned short int) (esd->svalnum * esd->sensval_size);
1278 esd->Lesd = 5 + (unsigned short int) (esd->svalnum * esd->sensval_size);
1280 /* component data field */
1284 /* we are averaging */
1289 esd->Pesd |= (esd->addrm & 0x03) << 6; /* addressing mode */
1290 esd->Pesd |= (esd->senst & 0x07) << 3; /* sensitivity type */
1291 esd->Pesd |= ((esd->se_size >> 1) & 0x01) << 2; /* sensitivity size */
1292 esd->Pesd |= ((esd->ad_size >> 2) & 0x01) << 1; /* addressing size */
1293 esd->Pesd |= (comp < 0) ? 0x01 : 0x00; /* averaging components */
1295 /* if pointer to sensval is NULL, we can fill data field by ourselves */
1298 /* old code moved to jpwl_esd_fill() */
1302 /* we set the data field as the sensitivity values poinnter passed to the function */
1303 esd->data = (unsigned char *) sensval;
1309 bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
1312 unsigned long int vv;
1313 unsigned long int addr1, addr2;
1314 double dvalue, Omax2, tmp, TSE, MSE, oldMSE, PSNR, oldPSNR;
1315 unsigned short int pfpvalue;
1316 unsigned long int addrmask = 0x00000000;
1317 bool doneMH = false, doneTPH = false;
1319 /* sensitivity values in image info are as follows:
1320 - for each tile, distotile is the starting distortion for that tile, sum of all components
1321 - for each packet in a tile, disto is the distortion reduction caused by that packet to that tile
1322 - the TSE for a single tile should be given by distotile - sum(disto) , for all components
1323 - the MSE for a single tile is given by TSE / nbpix , for all components
1324 - the PSNR for a single tile is given by 10*log10( Omax^2 / MSE) , for all components
1325 (Omax is given by 2^bpp - 1 for unsigned images and by 2^(bpp - 1) - 1 for signed images
1328 /* browse all components and find Omax */
1330 for (i = 0; i < j2k->image->numcomps; i++) {
1331 tmp = pow(2.0, (double) (j2k->image->comps[i].sgnd ?
1332 (j2k->image->comps[i].bpp - 1) : (j2k->image->comps[i].bpp))) - 1;
1336 Omax2 = Omax2 * Omax2;
1338 /* if pointer of esd->data is not null, simply write down all the values byte by byte */
1340 for (i = 0; i < (int) esd->svalnum; i++)
1341 *(buf++) = esd->data[i];
1345 /* addressing mask */
1346 if (esd->ad_size == 2)
1347 addrmask = 0x0000FFFF; /* two bytes */
1349 addrmask = 0xFFFFFFFF; /* four bytes */
1351 /* set on precise point where sensitivity starts */
1352 if (esd->numcomps < 257)
1357 /* let's fill the data fields */
1358 for (vv = (esd->tileno < 0) ? 0 : (j2k->image_info->num * esd->tileno); vv < esd->svalnum; vv++) {
1360 int thistile = vv / j2k->image_info->num, thispacket = vv % j2k->image_info->num;
1362 /* skip for the hack some lines below */
1363 if (thistile == j2k->image_info->tw * j2k->image_info->th)
1366 /* starting tile distortion */
1367 if (thispacket == 0) {
1368 TSE = j2k->image_info->tile[thistile].distotile;
1369 oldMSE = TSE / j2k->image_info->tile[thistile].nbpix;
1370 oldPSNR = 10.0 * log10(Omax2 / oldMSE);
1374 TSE -= j2k->image_info->tile[thistile].packet[thispacket].disto;
1377 MSE = TSE / j2k->image_info->tile[thistile].nbpix;
1380 PSNR = 10.0 * log10(Omax2 / MSE);
1382 /* fill the address range */
1383 switch (esd->addrm) {
1387 /* nothing, there is none */
1392 /* start address of packet */
1393 addr1 = (j2k->image_info->tile[thistile].packet[thispacket].start_pos) & addrmask;
1394 /* end address of packet */
1395 addr2 = (j2k->image_info->tile[thistile].packet[thispacket].end_pos) & addrmask;
1400 /* not implemented here */
1401 opj_event_msg(j2k->cinfo, EVT_WARNING, "Addressing mode packet_range is not implemented\n");
1404 /* unknown addressing method */
1406 /* not implemented here */
1407 opj_event_msg(j2k->cinfo, EVT_WARNING, "Unknown addressing mode\n");
1412 /* hack for writing relative sensitivity of MH and TPHs */
1413 if ((esd->senst == 0) && (thispacket == 0)) {
1416 if ((thistile == 0) && !doneMH) {
1417 /* we have to manage MH addresses */
1418 addr1 = 0; /* start of MH */
1419 addr2 = j2k->image_info->main_head_end; /* end of MH */
1420 /* set special dvalue for this MH */
1422 doneMH = true; /* don't come here anymore */
1423 vv--; /* wrap back loop counter */
1425 } else if (!doneTPH) {
1426 /* we have to manage TPH addresses */
1427 addr1 = j2k->image_info->tile[thistile].start_pos;
1428 addr2 = j2k->image_info->tile[thistile].end_header;
1429 /* set special dvalue for this TPH */
1431 doneTPH = true; /* don't come here till the next tile */
1432 vv--; /* wrap back loop counter */
1436 doneTPH = false; /* reset TPH counter */
1438 /* write the addresses to the buffer */
1439 switch (esd->ad_size) {
1447 *(buf++) = (unsigned char) (addr1 >> 8);
1448 *(buf++) = (unsigned char) (addr1 >> 0);
1449 *(buf++) = (unsigned char) (addr2 >> 8);
1450 *(buf++) = (unsigned char) (addr2 >> 0);
1455 *(buf++) = (unsigned char) (addr1 >> 24);
1456 *(buf++) = (unsigned char) (addr1 >> 16);
1457 *(buf++) = (unsigned char) (addr1 >> 8);
1458 *(buf++) = (unsigned char) (addr1 >> 0);
1459 *(buf++) = (unsigned char) (addr2 >> 24);
1460 *(buf++) = (unsigned char) (addr2 >> 16);
1461 *(buf++) = (unsigned char) (addr2 >> 8);
1462 *(buf++) = (unsigned char) (addr2 >> 0);
1471 /* let's fill the value field */
1472 switch (esd->senst) {
1474 /* relative sensitivity */
1476 /* we just write down the packet ordering */
1479 dvalue = MAX_V1 + 1000.0; /* this will cause pfpvalue set to 0xFFFF */
1480 else if (dvalue == -1)
1482 dvalue = MAX_V1 + 1000.0; /* this will cause pfpvalue set to 0xFFFF */
1484 /* packet: first is most important, and then in decreasing order
1485 down to the last, which counts for 1 */
1486 dvalue = jpwl_pfp_to_double(j2k->image_info->num - thispacket, esd->se_size);
1491 /* !!! WRONG: let's put here disto field of packets !!! */
1497 dvalue = oldMSE - MSE;
1508 dvalue = PSNR - oldPSNR;
1515 opj_event_msg(j2k->cinfo, EVT_WARNING, "MAXERR sensitivity mode is not implemented\n");
1526 opj_event_msg(j2k->cinfo, EVT_WARNING, "Reserved sensitivity mode is not implemented\n");
1534 /* compute the pseudo-floating point value */
1535 pfpvalue = jpwl_double_to_pfp(dvalue, esd->se_size);
1537 /* write the pfp value to the buffer */
1538 switch (esd->se_size) {
1542 *(buf++) = (unsigned char) (pfpvalue >> 0);
1547 *(buf++) = (unsigned char) (pfpvalue >> 8);
1548 *(buf++) = (unsigned char) (pfpvalue >> 0);
1557 void jpwl_esd_write(jpwl_esd_ms_t *esd, unsigned char *buf) {
1560 *(buf++) = (unsigned char) (J2K_MS_ESD >> 8);
1561 *(buf++) = (unsigned char) (J2K_MS_ESD >> 0);
1564 *(buf++) = (unsigned char) (esd->Lesd >> 8);
1565 *(buf++) = (unsigned char) (esd->Lesd >> 0);
1568 if (esd->numcomps >= 257)
1569 *(buf++) = (unsigned char) (esd->Cesd >> 8);
1570 *(buf++) = (unsigned char) (esd->Cesd >> 0);
1573 *(buf++) = (unsigned char) (esd->Pesd >> 0);
1576 if (esd->numcomps < 257)
1577 memset(buf, 0xAA, (size_t) esd->Lesd - 4);
1578 /*memcpy(buf, esd->data, (size_t) esd->Lesd - 4);*/
1580 memset(buf, 0xAA, (size_t) esd->Lesd - 5);
1581 /*memcpy(buf, esd->data, (size_t) esd->Lesd - 5);*/
1584 unsigned short int jpwl_double_to_pfp(double V, int bytes) {
1586 unsigned short int em, e, m;
1595 } else if (V > MAX_V1) {
1599 e = (unsigned short int) (floor(log(V) * 1.44269504088896) / 4.0);
1600 m = (unsigned short int) (0.5 + (V / (pow(2.0, (double) (4 * e)))));
1602 em = ((e & 0x000F) << 4) + (m & 0x000F);
1610 } else if (V > MAX_V2) {
1614 e = (unsigned short int) floor(log(V) * 1.44269504088896) + 15;
1615 m = (unsigned short int) (0.5 + 2048.0 * ((V / (pow(2.0, (double) e - 15.0))) - 1.0));
1617 em = ((e & 0x001F) << 11) + (m & 0x07FF);
1629 double jpwl_pfp_to_double(unsigned short int em, int bytes) {
1636 V = (double) (em & 0x0F) * pow(2.0, (double) (em & 0xF0));
1641 V = pow(2.0, (double) ((em & 0xF800) >> 11) - 15.0) * (1.0 + (double) (em & 0x07FF) / 2048.0);
1654 bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num) {
1657 unsigned long int addlen;
1659 opj_image_info_t *info = j2k->image_info;
1660 int tileno, packno, numtiles = info->th * info->tw, numpacks = info->num;
1662 if (!j2k || !jwmarker ) {
1663 opj_event_msg(j2k->cinfo, EVT_ERROR, "J2K handle or JPWL markers list badly allocated\n");
1667 /* main_head_end: how many markers are there before? */
1669 for (mm = 0; mm < jwmarker_num; mm++)
1670 if (jwmarker[mm].pos < (unsigned long int) info->main_head_end)
1671 addlen += jwmarker[mm].len + 2;
1672 info->main_head_end += addlen;
1674 /* codestream_size: always increment with all markers */
1676 for (mm = 0; mm < jwmarker_num; mm++)
1677 addlen += jwmarker[mm].len + 2;
1678 info->codestream_size += addlen;
1680 /* navigate through all the tiles */
1681 for (tileno = 0; tileno < numtiles; tileno++) {
1683 /* start_pos: increment with markers before SOT */
1685 for (mm = 0; mm < jwmarker_num; mm++)
1686 if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].start_pos)
1687 addlen += jwmarker[mm].len + 2;
1688 info->tile[tileno].start_pos += addlen;
1690 /* end_header: increment with markers before of it */
1692 for (mm = 0; mm < jwmarker_num; mm++)
1693 if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].end_header)
1694 addlen += jwmarker[mm].len + 2;
1695 info->tile[tileno].end_header += addlen;
1697 /* end_pos: increment with markers before the end of this tile */
1698 /* code is disabled, since according to JPWL no markers can be beyond TPH */
1700 for (mm = 0; mm < jwmarker_num; mm++)
1701 if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].end_pos)
1702 addlen += jwmarker[mm].len + 2;*/
1703 info->tile[tileno].end_pos += addlen;
1705 /* navigate through all the packets in this tile */
1706 for (packno = 0; packno < numpacks; packno++) {
1708 /* start_pos: increment with markers before the packet */
1709 /* disabled for the same reason as before */
1711 for (mm = 0; mm < jwmarker_num; mm++)
1712 if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].packet[packno].start_pos)
1713 addlen += jwmarker[mm].len + 2;*/
1714 info->tile[tileno].packet[packno].start_pos += addlen;
1716 /* end_pos: increment if marker is before the end of packet */
1717 /* disabled for the same reason as before */
1719 for (mm = 0; mm < jwmarker_num; mm++)
1720 if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].packet[packno].end_pos)
1721 addlen += jwmarker[mm].len + 2;*/
1722 info->tile[tileno].packet[packno].end_pos += addlen;
1730 #endif /* USE_JPWL */