2 * Copyright (c) 2007, Digital Signal Processing Laboratory, Universit� degli studi di Perugia (UPG), Italy
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
26 #include "OPJViewer.h"
28 /* From little endian to big endian, 2 bytes */
29 #define BYTE_SWAP2(X) ((X & 0x00FF) << 8) | ((X & 0xFF00) >> 8)
30 #define BYTE_SWAP4(X) ((X & 0x000000FF) << 24) | ((X & 0x0000FF00) << 8) | ((X & 0x00FF0000) >> 8) | ((X & 0xFF000000) >> 24)
32 /* From codestream to int values */
33 #define STREAM_TO_UINT32(C, P) (((unsigned long int) (C)[(P) + 0] << 24) + \
34 ((unsigned long int) (C)[(P) + 1] << 16) + \
35 ((unsigned long int) (C)[(P) + 2] << 8) + \
36 ((unsigned long int) (C)[(P) + 3] << 0))
38 #define STREAM_TO_UINT16(C, P) (((unsigned long int) (C)[(P) + 0] << 8) + \
39 ((unsigned long int) (C)[(P) + 1] << 0))
43 #define J2KMARK_NUM 24
79 // All the markers in one vector
80 unsigned short int marker_val[] = {
81 SOC_VAL, SOT_VAL, SOD_VAL, EOC_VAL,
83 COD_VAL, COC_VAL, RGN_VAL, QCD_VAL, QCC_VAL, POD_VAL,
84 TLM_VAL, PLM_VAL, PLT_VAL, PPM_VAL, PPT_VAL,
88 , EPB_VAL, ESD_VAL, EPC_VAL, RED_VAL
96 static const char *marker_name[] = {
97 "SOC", "SOT", "SOD", "EOC",
99 "COD", "COC", "RGN", "QCD", "QCC", "POD",
100 "TLM", "PLM", "PLT", "PPM", "PPT",
104 , "EPB", "ESD", "EPC", "RED"
111 // Marker descriptions
112 static const char *marker_descr[] = {
113 "Start of codestream", "Start of tile-part", "Start of data", "End of codestream",
114 "Image and tile size",
115 "Coding style default", "Coding style component", "Region-of-interest", "Quantization default",
116 "Quantization component", "Progression order change, default",
117 "Tile-part lengths, main header", "Packet length, main header", "Packets length, tile-part header",
118 "Packed packet headers, main header", "Packed packet headers, tile-part header",
119 "Start of packet", "End of packet header",
120 "Comment and extension"
122 , "Error Protection Block", "Error Sensitivity Descriptor", "Error Protection Capability",
123 "Residual Errors Descriptor"
126 , "Main security marker"
130 void OPJParseThread::ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid)
132 unsigned short int csiz = 0;
134 // check if the file is opened
135 if (m_file->IsOpened())
136 WriteText(wxT("File OK"));
140 // position at the beginning
141 m_file->Seek(offset, wxFromStart);
144 int m, inside_sod = 0, inside_sop = 0;
145 int nmarks = 0, maxmarks = 10000;
146 unsigned char onebyte[1];
147 unsigned char twobytes[2], firstbyte, secondbyte;
148 unsigned char fourbytes[4];
149 unsigned short int currmark;
150 unsigned short int currlen;
151 int lastPsot = 0, lastsotpos = 0;
153 WriteText(wxT("Start search..."));
156 #define OPJ_ADVANCE(A) {offset += A; if (offset < length) m_file->Seek(offset, wxFromStart); else return;}
159 while ((offset < length) && (!m_file->Eof())) {
162 if (m_file->Read(&firstbyte, 1) != 1)
166 if (firstbyte == 0xFF) {
168 // it is a possible marker
169 if (m_file->Read(&secondbyte, 1) != 1)
172 currmark = (((unsigned short int) firstbyte) << 8) + (unsigned short int) secondbyte;
176 // nope, advance by one and search again
182 for (m = 0; m < J2KMARK_NUM; m++) {
183 if (currmark == marker_val[m])
188 if (m == J2KMARK_NUM) {
189 // nope, advance by one and search again
194 // if we are inside SOD, only some markers are allowed
202 // randomly marker coincident data
203 if ((currmark != SOT_VAL) &&
204 (currmark != EOC_VAL) &&
205 (currmark != SOP_VAL) &&
206 (currmark != EPH_VAL)) {
212 if ((currmark == SOT_VAL)) {
214 if (offset < (lastsotpos + lastPsot)) {
218 // we were not in the last tile
219 /*if (lastPsot != 0) {
226 // beyond this point, the marker MUST BE real
228 // length of current marker segment
229 if ((currmark == SOD_VAL) ||
230 (currmark == SOC_VAL) ||
231 (currmark == EOC_VAL) ||
232 (currmark == EPH_VAL))
234 // zero length markers
240 if (m_file->Read(twobytes, 2) != 2)
243 currlen = (((unsigned short int) twobytes[0]) << 8) + (unsigned short int) twobytes[1];
246 // here we pass to AppendItem() normal and selected item images (we
247 // suppose that selected image follows the normal one in the enum)
249 image = m_tree->TreeCtrlIcon_Folder;
250 imageSel = image + 1;
253 wxTreeItemId currid = m_tree->AppendItem(parentid,
254 wxString::Format(wxT("%03d: "), nmarks) +
255 wxString::FromAscii(marker_name[m]) +
256 wxString::Format(wxT(" (0x%04X)"), marker_val[m]),
258 new OPJMarkerData(wxT("MARK") + wxString::Format(wxT(" (%d)"), marker_val[m]),
259 m_tree->m_fname.GetFullPath(), offset, offset + currlen + 1)
263 image = m_tree->TreeCtrlIcon_File;
264 imageSel = image + 1;
267 wxTreeItemId subcurrid1 = m_tree->AppendItem(currid,
268 wxT("*** ") + wxString::FromAscii(marker_descr[m]) + wxT(" ***"),
270 new OPJMarkerData(wxT("INFO"))
272 m_tree->SetItemFont(subcurrid1, *wxITALIC_FONT);
274 // position and length
275 wxTreeItemId subcurrid2 = m_tree->AppendItem(currid,
276 wxLongLong(offset).ToString() + wxT(" > ") + wxLongLong(offset + currlen + 1).ToString() +
277 wxT(", ") + wxString::Format(wxT("%d + 2 (%d)"), currlen, currlen + 2),
279 new OPJMarkerData(wxT("INFO"))
282 // give additional info on markers
290 // read packet number
291 if (m_file->Read(twobytes, 2) != 2)
293 int packnum = STREAM_TO_UINT16(twobytes, 0);
295 image = m_tree->TreeCtrlIcon_File;
296 imageSel = image + 1;
298 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
299 wxString::Format(wxT("Pack. no. %d"), packnum),
301 new OPJMarkerData(wxT("INFO"))
313 if (m_file->Read(onebyte, 1) != 1)
315 unsigned char pred = onebyte[0];
317 image = m_tree->TreeCtrlIcon_File;
318 imageSel = image + 1;
320 wxString address[] = {
321 wxT("Packet addressing"),
322 wxT("Byte-range addressing"),
323 wxT("Packet-range addressing"),
327 wxTreeItemId subcurrid = m_tree->AppendItem(currid,
328 address[(pred & 0xC0) >> 6],
330 new OPJMarkerData(wxT("INFO"))
333 subcurrid = m_tree->AppendItem(currid,
334 wxString::Format(wxT("%d bytes range"), (((pred & 0x02) >> 1) + 1) * 2),
336 new OPJMarkerData(wxT("INFO"))
339 subcurrid = m_tree->AppendItem(currid,
340 pred & 0x01 ? wxT("Errors/erasures in codestream") : wxT("Error free codestream"),
342 new OPJMarkerData(wxT("INFO"))
345 subcurrid = m_tree->AppendItem(currid,
346 wxString::Format(wxT("Residual corruption level: %d"), (pred & 0x38) >> 3),
348 new OPJMarkerData(wxT("INFO"))
359 unsigned short int cesd;
361 if (m_file->Read(onebyte, 1) != 1)
365 if (m_file->Read(twobytes, 2) != 2)
367 cesd = STREAM_TO_UINT16(twobytes, 0);
370 if (m_file->Read(onebyte, 1) != 1)
372 unsigned char pesd = onebyte[0];
374 image = m_tree->TreeCtrlIcon_File;
375 imageSel = image + 1;
377 wxTreeItemId subcurrid = m_tree->AppendItem(currid,
378 pesd & 0x01 ? wxT("Comp. average") : wxString::Format(wxT("Comp. no. %d"), cesd),
380 new OPJMarkerData(wxT("INFO"))
384 wxT("Relative error sensitivity"),
386 wxT("MSE reduction"),
388 wxT("PSNR increase"),
389 wxT("MAXERR (absolute peak error)"),
390 wxT("TSE (total squared error)"),
394 subcurrid = m_tree->AppendItem(currid,
395 meth[(pesd & 0x38) >> 3],
397 new OPJMarkerData(wxT("INFO"))
400 wxString address[] = {
401 wxT("Packet addressing"),
402 wxT("Byte-range addressing"),
403 wxT("Packet-range addressing"),
407 subcurrid = m_tree->AppendItem(currid,
408 address[(pesd & 0xC0) >> 6],
410 new OPJMarkerData(wxT("INFO"))
413 subcurrid = m_tree->AppendItem(currid,
414 wxString::Format(wxT("%d bytes/value, %d bytes range"), ((pesd & 0x04) >> 2) + 1, (((pesd & 0x02) >> 1) + 1) * 2),
416 new OPJMarkerData(wxT("INFO"))
427 if (m_file->Read(twobytes, 2) != 2)
429 unsigned short int pcrc = STREAM_TO_UINT16(twobytes, 0);
431 if (m_file->Read(fourbytes, 4) != 4)
433 unsigned long int dl = STREAM_TO_UINT32(fourbytes, 0);
435 if (m_file->Read(onebyte, 1) != 1)
437 unsigned char pepc = onebyte[0];
439 image = m_tree->TreeCtrlIcon_File;
440 imageSel = image + 1;
442 wxTreeItemId subcurrid = m_tree->AppendItem(currid,
443 wxString::Format(wxT("CRC-16 = 0x%x"), pcrc),
445 new OPJMarkerData(wxT("INFO"))
448 subcurrid = m_tree->AppendItem(currid,
449 wxString::Format(wxT("Tot. length = %d"), dl),
451 new OPJMarkerData(wxT("INFO"))
454 subcurrid = m_tree->AppendItem(currid,
455 wxString::Format(wxT("%s%s%s%s"),
456 pepc & 0x10 ? wxT("ESD, ") : wxT(""),
457 pepc & 0x20 ? wxT("RED, ") : wxT(""),
458 pepc & 0x40 ? wxT("EPB, ") : wxT(""),
459 pepc & 0x80 ? wxT("Info") : wxT("")
462 new OPJMarkerData(wxT("INFO"))
473 if (m_file->Read(onebyte, 1) != 1)
475 unsigned char depb = onebyte[0];
477 if (m_file->Read(fourbytes, 4) != 4)
479 unsigned long int ldpepb = STREAM_TO_UINT32(fourbytes, 0);
481 if (m_file->Read(fourbytes, 4) != 4)
483 unsigned long int pepb = STREAM_TO_UINT32(fourbytes, 0);
485 image = m_tree->TreeCtrlIcon_File;
486 imageSel = image + 1;
488 wxTreeItemId subcurrid = m_tree->AppendItem(currid,
489 wxString::Format(wxT("No. %d, %slatest, %spacked"),
491 depb & 0x40 ? wxT("") : wxT("not "),
492 depb & 0x80 ? wxT("") : wxT("un")),
494 new OPJMarkerData(wxT("INFO"))
497 subcurrid = m_tree->AppendItem(currid,
498 wxString::Format(wxT("%d bytes protected"), ldpepb),
500 new OPJMarkerData(wxT("INFO"))
503 if (pepb == 0x00000000)
505 subcurrid = m_tree->AppendItem(currid,
506 wxT("Predefined codes"),
508 new OPJMarkerData(wxT("INFO"))
511 else if ((pepb >= 0x10000000) && (pepb <= 0x1FFFFFFF)) {
513 wxString text = wxT("CRC code");
514 if (pepb == 0x10000000)
515 text << wxT(", CCITT (X25) 16 bits");
516 else if (pepb == 0x10000001)
517 text << wxT(", Ethernet 32 bits");
519 text << wxT(", JPWL RA");
520 subcurrid = m_tree->AppendItem(currid,
523 new OPJMarkerData(wxT("INFO"))
526 } else if ((pepb >= 0x20000000) && (pepb <= 0x2FFFFFFF)) {
529 subcurrid = m_tree->AppendItem(currid,
530 wxString::Format(wxT("RS code, RS(%d, %d)"),
531 (pepb & 0x0000FF00) >> 8,
532 (pepb & 0x000000FF)),
534 new OPJMarkerData(wxT("INFO"))
537 } else if ((pepb >= 0x30000000) && (pepb <= 0x3FFFFFFE))
539 subcurrid = m_tree->AppendItem(currid,
542 new OPJMarkerData(wxT("INFO"))
545 else if (pepb == 0xFFFFFFFF)
547 subcurrid = m_tree->AppendItem(currid,
550 new OPJMarkerData(wxT("INFO"))
572 if (m_file->Read(twobytes, 2) != 2)
574 unsigned short int rsiz = STREAM_TO_UINT16(twobytes, 0);
576 if (m_file->Read(fourbytes, 4) != 4)
578 unsigned long int xsiz = STREAM_TO_UINT32(fourbytes, 0);
580 if (m_file->Read(fourbytes, 4) != 4)
582 unsigned long int ysiz = STREAM_TO_UINT32(fourbytes, 0);
584 if (m_file->Read(fourbytes, 4) != 4)
586 unsigned long int xosiz = STREAM_TO_UINT32(fourbytes, 0);
588 if (m_file->Read(fourbytes, 4) != 4)
590 unsigned long int yosiz = STREAM_TO_UINT32(fourbytes, 0);
592 if (m_file->Read(fourbytes, 4) != 4)
594 unsigned long int xtsiz = STREAM_TO_UINT32(fourbytes, 0);
595 this->m_tree->m_childframe->m_twidth = xtsiz;
597 if (m_file->Read(fourbytes, 4) != 4)
599 unsigned long int ytsiz = STREAM_TO_UINT32(fourbytes, 0);
600 this->m_tree->m_childframe->m_theight = ytsiz;
602 if (m_file->Read(fourbytes, 4) != 4)
604 unsigned long int xtosiz = STREAM_TO_UINT32(fourbytes, 0);
605 this->m_tree->m_childframe->m_tx = xtosiz;
607 if (m_file->Read(fourbytes, 4) != 4)
609 unsigned long int ytosiz = STREAM_TO_UINT32(fourbytes, 0);
610 this->m_tree->m_childframe->m_ty = ytosiz;
612 if (m_file->Read(twobytes, 2) != 2)
614 csiz = STREAM_TO_UINT16(twobytes, 0);
616 bool equaldepth = true, equalsize = true;
617 unsigned char *ssiz = new unsigned char(csiz);
618 unsigned char *xrsiz = new unsigned char(csiz);
619 unsigned char *yrsiz = new unsigned char(csiz);
621 for (c = 0; c < csiz; c++) {
623 if (m_file->Read(&ssiz[c], 1) != 1)
627 equaldepth = equaldepth && (ssiz[c] == ssiz[c - 1]);
629 if (m_file->Read(&xrsiz[c], 1) != 1)
632 if (m_file->Read(&yrsiz[c], 1) != 1)
636 equalsize = equalsize && (xrsiz[c] == xrsiz[c - 1]) && (yrsiz[c] == yrsiz[c - 1]) ;
640 if (equaldepth && equalsize)
641 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
642 wxString::Format(wxT("I: %dx%d (%d, %d), %d c., %d%s bpp"),
645 csiz, ((ssiz[0] & 0x7F) + 1),
646 (ssiz[0] & 0x80) ? wxT("s") : wxT("u")),
648 new OPJMarkerData(wxT("INFO"))
651 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
652 wxString::Format(wxT("I: %dx%d (%d, %d), %d c."),
657 new OPJMarkerData(wxT("INFO"))
660 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
661 wxString::Format(wxT("T: %dx%d (%d, %d)"),
665 new OPJMarkerData(wxT("INFO"))
668 image = m_tree->TreeCtrlIcon_Folder;
669 imageSel = image + 1;
671 wxTreeItemId subcurrid4 = m_tree->AppendItem(currid,
674 new OPJMarkerData(wxT("INFO"))
677 image = m_tree->TreeCtrlIcon_File;
678 imageSel = image + 1;
680 for (c = 0; c < csiz; c++) {
682 wxTreeItemId subcurrid5 = m_tree->AppendItem(subcurrid4,
683 wxString::Format(wxT("#%d: %dx%d, %d%s bpp"),
685 xsiz/xrsiz[c], ysiz/yrsiz[c],
686 ((ssiz[c] & 0x7F) + 1),
687 (ssiz[c] & 0x80) ? wxT("s") : wxT("u")),
689 new OPJMarkerData(wxT("INFO"))
702 if (m_file->Read(twobytes, 2) != 2)
704 unsigned short int isot = STREAM_TO_UINT16(twobytes, 0);
706 if (m_file->Read(fourbytes, 4) != 4)
708 unsigned long int psot = STREAM_TO_UINT32(fourbytes, 0);
710 if (m_file->Read(onebyte, 1) != 1)
712 unsigned char tpsot = onebyte[0];
714 if (m_file->Read(onebyte, 1) != 1)
716 unsigned char tnsot = onebyte[0];
718 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
719 wxString::Format(wxT("tile %d, psot = %d, part %d of %d"), isot, psot, tpsot, tnsot),
721 new OPJMarkerData(wxT("INFO"))
735 unsigned short int ccoc;
737 if (m_file->Read(onebyte, 1) != 1)
741 if (m_file->Read(twobytes, 2) != 2)
743 ccoc = STREAM_TO_UINT16(twobytes, 0);
746 if (m_file->Read(onebyte, 1) != 1)
748 unsigned char scoc = onebyte[0];
750 wxTreeItemId subcurrid = m_tree->AppendItem(currid,
751 wxString::Format(wxT("Comp. no. %d"), ccoc),
753 new OPJMarkerData(wxT("INFO"))
758 text << wxT("Partitioned entropy coder");
760 text << wxT("Unpartitioned entropy coder");
762 subcurrid = m_tree->AppendItem(currid,
765 new OPJMarkerData(wxT("INFO"))
768 if (m_file->Read(onebyte, 1) != 1)
770 unsigned char decomplevs = onebyte[0];
772 if (m_file->Read(onebyte, 1) != 1)
774 unsigned char cbswidth = onebyte[0];
776 if (m_file->Read(onebyte, 1) != 1)
778 unsigned char cbsheight = onebyte[0];
780 if (m_file->Read(onebyte, 1) != 1)
782 unsigned char cbstyle = onebyte[0];
784 if (m_file->Read(onebyte, 1) != 1)
786 unsigned char transform = onebyte[0];
788 subcurrid = m_tree->AppendItem(currid,
789 wxString::Format(wxT("%d levels (%d resolutions)"), decomplevs, decomplevs + 1),
791 new OPJMarkerData(wxT("INFO"))
794 if (transform & 0x01)
795 text = wxT("5-3 reversible wavelet");
797 text = wxT("9-7 irreversible wavelet");
798 subcurrid = m_tree->AppendItem(currid,
801 new OPJMarkerData(wxT("INFO"))
804 subcurrid = m_tree->AppendItem(currid,
805 wxString::Format(wxT("Code-blocks: %dx%d"), 1 << ((cbswidth & 0x0F) + 2), 1 << ((cbsheight & 0x0F) + 2)),
807 new OPJMarkerData(wxT("INFO"))
810 image = m_tree->TreeCtrlIcon_Folder;
811 imageSel = image + 1;
813 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
814 wxT("Coding styles"),
816 new OPJMarkerData(wxT("INFO"))
819 image = m_tree->TreeCtrlIcon_File;
820 imageSel = image + 1;
823 text = wxT("Selective arithmetic coding bypass");
825 text = wxT("No selective arithmetic coding bypass");
826 wxTreeItemId subcurrid4 = m_tree->AppendItem(subcurrid3,
829 new OPJMarkerData(wxT("INFO"))
833 text = wxT("Reset context probabilities on coding pass boundaries");
835 text = wxT("No reset of context probabilities on coding pass boundaries");
836 subcurrid4 = m_tree->AppendItem(subcurrid3,
839 new OPJMarkerData(wxT("INFO"))
843 text = wxT("Termination on each coding passs");
845 text = wxT("No termination on each coding pass");
846 subcurrid4 = m_tree->AppendItem(subcurrid3,
849 new OPJMarkerData(wxT("INFO"))
853 text = wxT("Vertically stripe causal context");
855 text = wxT("No vertically stripe causal context");
856 subcurrid4 = m_tree->AppendItem(subcurrid3,
859 new OPJMarkerData(wxT("INFO"))
863 text = wxT("Predictable termination");
865 text = wxT("No predictable termination");
866 subcurrid4 = m_tree->AppendItem(subcurrid3,
869 new OPJMarkerData(wxT("INFO"))
873 text = wxT("Segmentation symbols are used");
875 text = wxT("No segmentation symbols are used");
876 subcurrid4 = m_tree->AppendItem(subcurrid3,
879 new OPJMarkerData(wxT("INFO"))
890 if (m_file->Read(onebyte, 1) != 1)
892 unsigned char scod = onebyte[0];
897 text << wxT("Partitioned entropy coder");
899 text << wxT("Unpartitioned entropy coder");
901 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
904 new OPJMarkerData(wxT("INFO"))
909 text << wxT("Possible SOPs");
911 text << wxT("No SOPs");
914 text << wxT(", possible EPHs");
916 text << wxT(", no EPHs");
918 subcurrid3 = m_tree->AppendItem(currid,
921 new OPJMarkerData(wxT("INFO"))
924 if (m_file->Read(onebyte, 1) != 1)
926 unsigned char progord = onebyte[0];
928 if (m_file->Read(twobytes, 2) != 2)
930 unsigned short int numlayers = STREAM_TO_UINT16(twobytes, 0);
932 if (m_file->Read(onebyte, 1) != 1)
934 unsigned char mctransform = onebyte[0];
936 if (m_file->Read(onebyte, 1) != 1)
938 unsigned char decomplevs = onebyte[0];
940 if (m_file->Read(onebyte, 1) != 1)
942 unsigned char cbswidth = onebyte[0];
944 if (m_file->Read(onebyte, 1) != 1)
946 unsigned char cbsheight = onebyte[0];
948 if (m_file->Read(onebyte, 1) != 1)
950 unsigned char cbstyle = onebyte[0];
952 if (m_file->Read(onebyte, 1) != 1)
954 unsigned char transform = onebyte[0];
956 subcurrid3 = m_tree->AppendItem(currid,
957 wxString::Format(wxT("%d levels (%d resolutions)"), decomplevs, decomplevs + 1),
959 new OPJMarkerData(wxT("INFO"))
980 text << wxT("unknown progression");
983 text << wxString::Format(wxT(", %d layers"), numlayers);
984 if (transform & 0x01)
985 text << wxT(", 5-3 rev.");
987 text << wxT(", 9-7 irr.");
988 subcurrid3 = m_tree->AppendItem(currid,
991 new OPJMarkerData(wxT("INFO"))
994 subcurrid3 = m_tree->AppendItem(currid,
995 wxString::Format(wxT("Code-blocks: %dx%d"), 1 << ((cbswidth & 0x0F) + 2), 1 << ((cbsheight & 0x0F) + 2)),
997 new OPJMarkerData(wxT("INFO"))
1000 switch (mctransform) {
1003 text = wxT("No MCT");
1008 text = wxT("Reversible MCT on 0, 1, 2");
1013 text = wxT("Irreversible MCT on 0, 1, 2");
1018 text = wxT("Unknown");
1022 subcurrid3 = m_tree->AppendItem(currid,
1025 new OPJMarkerData(wxT("INFO"))
1029 image = m_tree->TreeCtrlIcon_Folder;
1030 imageSel = image + 1;
1032 subcurrid3 = m_tree->AppendItem(currid,
1033 wxT("Coding styles"),
1035 new OPJMarkerData(wxT("INFO"))
1038 image = m_tree->TreeCtrlIcon_File;
1039 imageSel = image + 1;
1042 text = wxT("Selective arithmetic coding bypass");
1044 text = wxT("No selective arithmetic coding bypass");
1045 wxTreeItemId subcurrid4 = m_tree->AppendItem(subcurrid3,
1048 new OPJMarkerData(wxT("INFO"))
1052 text = wxT("Reset context probabilities on coding pass boundaries");
1054 text = wxT("No reset of context probabilities on coding pass boundaries");
1055 subcurrid4 = m_tree->AppendItem(subcurrid3,
1058 new OPJMarkerData(wxT("INFO"))
1062 text = wxT("Termination on each coding passs");
1064 text = wxT("No termination on each coding pass");
1065 subcurrid4 = m_tree->AppendItem(subcurrid3,
1068 new OPJMarkerData(wxT("INFO"))
1072 text = wxT("Vertically stripe causal context");
1074 text = wxT("No vertically stripe causal context");
1075 subcurrid4 = m_tree->AppendItem(subcurrid3,
1078 new OPJMarkerData(wxT("INFO"))
1082 text = wxT("Predictable termination");
1084 text = wxT("No predictable termination");
1085 subcurrid4 = m_tree->AppendItem(subcurrid3,
1088 new OPJMarkerData(wxT("INFO"))
1092 text = wxT("Segmentation symbols are used");
1094 text = wxT("No segmentation symbols are used");
1095 subcurrid4 = m_tree->AppendItem(subcurrid3,
1098 new OPJMarkerData(wxT("INFO"))
1109 unsigned short int cqcc;
1111 if (m_file->Read(onebyte, 1) != 1)
1115 if (m_file->Read(twobytes, 2) != 2)
1117 cqcc = STREAM_TO_UINT16(twobytes, 0);
1120 wxTreeItemId subcurrid = m_tree->AppendItem(currid,
1121 wxString::Format(wxT("Comp. no. %d"), cqcc),
1123 new OPJMarkerData(wxT("INFO"))
1126 if (m_file->Read(onebyte, 1) != 1)
1128 unsigned char sqcc = onebyte[0];
1131 switch (sqcc & 0x1F) {
1133 text = wxT("No quantization");
1136 text = wxT("Scalar implicit");
1139 text = wxT("Scalar explicit");
1142 text = wxT("Unknown");
1145 text << wxString::Format(wxT(", %d guard bits"), (sqcc & 0xE0) >> 5);
1146 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
1149 new OPJMarkerData(wxT("INFO"))
1160 if (m_file->Read(onebyte, 1) != 1)
1162 unsigned char sqcd = onebyte[0];
1165 switch (sqcd & 0x1F) {
1167 text = wxT("No quantization");
1170 text = wxT("Scalar implicit");
1173 text = wxT("Scalar explicit");
1176 text = wxT("Unknown");
1179 text << wxString::Format(wxT(", %d guard bits"), (sqcd & 0xE0) >> 5);
1180 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
1183 new OPJMarkerData(wxT("INFO"))
1195 char comment[showlen];
1198 if (m_file->Read(twobytes, 2) != 2)
1200 unsigned short int rcom = STREAM_TO_UINT16(twobytes, 0);
1204 text = wxT("Binary values");
1206 text = wxT("ISO 8859-1 (latin-1) values");
1207 else if (rcom < 65535)
1208 text = wxT("Reserved for registration");
1210 text = wxT("Reserved for extension");
1211 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
1214 new OPJMarkerData(wxT("INFO"))
1217 if (m_file->Read(comment, showlen) != showlen)
1219 comments = wxString::FromAscii(comment).Truncate(wxMin(showlen, currlen - 4));
1220 if ((currlen - 4) > showlen)
1221 comments << wxT("...");
1222 subcurrid3 = m_tree->AppendItem(currid,
1225 new OPJMarkerData(wxT("INFO"))
1235 if (m_file->Read(onebyte, 1) != 1)
1237 unsigned char ztlm = onebyte[0];
1239 if (m_file->Read(onebyte, 1) != 1)
1241 unsigned char stlm = onebyte[0];
1243 image = m_tree->TreeCtrlIcon_File;
1244 imageSel = image + 1;
1246 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
1247 wxString::Format(wxT("TLM #%d"), ztlm),
1249 new OPJMarkerData(wxT("INFO"))
1252 subcurrid3 = m_tree->AppendItem(currid,
1253 wxString::Format(wxT("%d bits/index, %d bits/length"),
1254 8 * ((stlm & 0x30) >> 4), 16 + 16 * ((stlm & 0x40) >> 6)),
1256 new OPJMarkerData(wxT("INFO"))
1261 numparts = (currlen - 2) / ( ((stlm & 0x30) >> 4) + 2 + 2 * ((stlm & 0x40) >> 6));
1263 image = m_tree->TreeCtrlIcon_Folder;
1264 imageSel = image + 1;
1266 subcurrid3 = m_tree->AppendItem(currid,
1269 new OPJMarkerData(wxT("INFO"))
1272 image = m_tree->TreeCtrlIcon_File;
1273 imageSel = image + 1;
1275 for (n = 0; n < numparts; n++) {
1277 unsigned short int ttlm;
1278 unsigned long int ptlm;
1280 switch (((stlm & 0x30) >> 4)) {
1287 if (m_file->Read(onebyte, 1) != 1)
1293 if (m_file->Read(twobytes, 2) != 2)
1295 ttlm = STREAM_TO_UINT16(twobytes, 0);
1300 switch (((stlm & 0x40) >> 6)) {
1303 if (m_file->Read(twobytes, 2) != 2)
1305 ptlm = STREAM_TO_UINT16(twobytes, 0);
1309 if (m_file->Read(fourbytes, 4) != 4)
1311 ptlm = STREAM_TO_UINT32(fourbytes, 0);
1316 wxTreeItemId subcurrid4 = m_tree->AppendItem(subcurrid3,
1317 wxString::Format(wxT("Tile %d: %d bytes"), ttlm, ptlm),
1319 new OPJMarkerData(wxT("INFO"))
1335 numchanges = (currlen - 2) / 7;
1337 numchanges = (currlen - 2) / 9;
1339 for (n = 0; n < numchanges; n++) {
1341 image = m_tree->TreeCtrlIcon_Folder;
1342 imageSel = image + 1;
1344 wxTreeItemId subcurrid3 = m_tree->AppendItem(currid,
1345 wxString::Format(wxT("Change #%d"), n),
1347 new OPJMarkerData(wxT("INFO"))
1350 if (m_file->Read(onebyte, 1) != 1)
1352 unsigned char rspod = onebyte[0];
1354 unsigned short int cspod;
1356 if (m_file->Read(onebyte, 1) != 1)
1360 if (m_file->Read(twobytes, 2) != 2)
1362 cspod = STREAM_TO_UINT16(twobytes, 0);
1365 if (m_file->Read(twobytes, 2) != 2)
1367 unsigned short int lyepod = STREAM_TO_UINT16(twobytes, 0);
1369 if (m_file->Read(onebyte, 1) != 1)
1371 unsigned char repod = onebyte[0];
1373 unsigned short int cepod;
1375 if (m_file->Read(onebyte, 1) != 1)
1379 if (m_file->Read(twobytes, 2) != 2)
1381 cepod = STREAM_TO_UINT16(twobytes, 0);
1384 if (m_file->Read(onebyte, 1) != 1)
1386 unsigned char ppod = onebyte[0];
1388 image = m_tree->TreeCtrlIcon_File;
1389 imageSel = image + 1;
1391 wxTreeItemId subcurrid4 = m_tree->AppendItem(subcurrid3,
1392 wxString::Format(wxT("%d <= Resolution < %d"), rspod, repod),
1394 new OPJMarkerData(wxT("INFO"))
1397 subcurrid4 = m_tree->AppendItem(subcurrid3,
1398 wxString::Format(wxT("%d <= Component < %d"), cspod, cepod),
1400 new OPJMarkerData(wxT("INFO"))
1403 subcurrid4 = m_tree->AppendItem(subcurrid3,
1404 wxString::Format(wxT("0 <= Layer < %d"), lyepod),
1406 new OPJMarkerData(wxT("INFO"))
1409 wxString text = wxT("");
1412 text << wxT("LRCP");
1415 text << wxT("RLCP");
1418 text << wxT("LRCP");
1421 text << wxT("RPCL");
1424 text << wxT("CPRL");
1427 text << wxT("unknown progression");
1430 subcurrid4 = m_tree->AppendItem(subcurrid3,
1433 new OPJMarkerData(wxT("INFO"))
1454 // increment number of markers
1455 if (nmarks++ >= maxmarks) {
1456 WriteText(wxT("Maximum amount of markers exceeded"));
1461 OPJ_ADVANCE(currlen + 2);
1464 WriteText(wxT("Search finished"));