/// <summary> Splits the current subband in its four subbands. It changes the status /// of this element (from a leaf to a node, and sets the filters), creates /// the childs and initializes them. An IllegalArgumentException is thrown /// if this subband is not a leaf. /// /// <p>It uses the initChilds() method to initialize the childs.</p> /// /// </summary> /// <param name="hfilter">The horizontal wavelet filter used to decompose this /// subband. It has to be a SynWTFilter object. /// /// </param> /// <param name="vfilter">The vertical wavelet filter used to decompose this /// subband. It has to be a SynWTFilter object. /// /// </param> /// <returns> A reference to the LL leaf (subb_LL). /// /// </returns> /// <seealso cref="Subband.initChilds"> /// /// </seealso> protected internal override Subband split(WaveletFilter hfilter, WaveletFilter vfilter) { // Test that this is a node if (isNode) { throw new System.ArgumentException(); } // Modify this element into a node and set the filters isNode = true; this.hFilter = (SynWTFilter)hfilter; this.vFilter = (SynWTFilter)vfilter; // Create childs subb_LL = new SubbandSyn(); subb_LH = new SubbandSyn(); subb_HL = new SubbandSyn(); subb_HH = new SubbandSyn(); // Assign parent subb_LL.parent = this; subb_HL.parent = this; subb_LH.parent = this; subb_HH.parent = this; // Initialize childs initChilds(); // Return reference to LL subband return(subb_LL); }
/// <summary> Splits the current subband in its four subbands. It changes the status /// of this element (from a leaf to a node, and sets the filters), creates /// the childs and initializes them. An IllegalArgumentException is thrown /// if this subband is not a leaf. /// /// <p>It uses the initChilds() method to initialize the childs.</p> /// /// </summary> /// <param name="hfilter">The horizontal wavelet filter used to decompose this /// subband. It has to be a SynWTFilter object. /// /// </param> /// <param name="vfilter">The vertical wavelet filter used to decompose this /// subband. It has to be a SynWTFilter object. /// /// </param> /// <returns> A reference to the LL leaf (subb_LL). /// /// </returns> /// <seealso cref="Subband.initChilds"> /// /// </seealso> protected internal override Subband split(WaveletFilter hfilter, WaveletFilter vfilter) { // Test that this is a node if (isNode) { throw new System.ArgumentException(); } // Modify this element into a node and set the filters isNode = true; this.hFilter = (SynWTFilter) hfilter; this.vFilter = (SynWTFilter) vfilter; // Create childs subb_LL = new SubbandSyn(); subb_LH = new SubbandSyn(); subb_HL = new SubbandSyn(); subb_HH = new SubbandSyn(); // Assign parent subb_LL.parent = this; subb_HL.parent = this; subb_LH.parent = this; subb_HH.parent = this; // Initialize childs initChilds(); // Return reference to LL subband return subb_LL; }
/// <summary> Reads the COC marker segment and realigns the codestream where the next /// marker should be found. /// /// </summary> /// <param name="ehs">The encoder header stream. /// /// </param> /// <param name="mainh">Flag indicating whether or not this marker segment is read /// from the main header. /// /// </param> /// <param name="tileIdx">The index of the current tile /// /// </param> /// <param name="tpIdx">Tile-part index /// /// </param> /// <exception cref="IOException">If an I/O error occurs while reading from the /// encoder header stream /// /// </exception> //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'" private void readCOC(System.IO.BinaryReader ehs, bool mainh, int tileIdx, int tpIdx) { int cComp; // current component SynWTFilter[] hfilters, vfilters; //int tmp, l; int ecOptions; System.Int32[] cblk; System.String errMsg; HeaderInfo.COC ms = hi.NewCOC; // Lcoc (marker length) ms.lcoc = ehs.ReadUInt16(); // Ccoc if (nComp < 257) { cComp = ms.ccoc = ehs.ReadByte(); } else { cComp = ms.ccoc = ehs.ReadUInt16(); } if (cComp >= nComp) { throw new CorruptedCodestreamException("Invalid component index " + "in QCC marker"); } // Scoc (block style) int cstyle = ms.scoc = ehs.ReadByte(); if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_PRECINCT_PARTITION) != 0) { precinctPartitionIsUsed = true; // Remove flag cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_PRECINCT_PARTITION); } else { precinctPartitionIsUsed = false; } // SPcoc // decomposition levels int mrl = ms.spcoc_ndl = ehs.ReadByte(); // Read the code-blocks dimensions cblk = new System.Int32[2]; ms.spcoc_cw = ehs.ReadByte(); cblk[0] = (System.Int32) (1 << (ms.spcoc_cw + 2)); if (cblk[0] < CSJ2K.j2k.entropy.StdEntropyCoderOptions.MIN_CB_DIM || cblk[0] > CSJ2K.j2k.entropy.StdEntropyCoderOptions.MAX_CB_DIM) { errMsg = "Non-valid code-block width in SPcod field, " + "COC marker"; throw new CorruptedCodestreamException(errMsg); } ms.spcoc_ch = ehs.ReadByte(); cblk[1] = (System.Int32) (1 << (ms.spcoc_ch + 2)); if (cblk[1] < CSJ2K.j2k.entropy.StdEntropyCoderOptions.MIN_CB_DIM || cblk[1] > CSJ2K.j2k.entropy.StdEntropyCoderOptions.MAX_CB_DIM) { errMsg = "Non-valid code-block height in SPcod field, " + "COC marker"; throw new CorruptedCodestreamException(errMsg); } if ((cblk[0] * cblk[1]) > CSJ2K.j2k.entropy.StdEntropyCoderOptions.MAX_CB_AREA) { errMsg = "Non-valid code-block area in SPcod field, " + "COC marker"; throw new CorruptedCodestreamException(errMsg); } if (mainh) { decSpec.cblks.setCompDef(cComp, (System.Object) (cblk)); } else { decSpec.cblks.setTileCompVal(tileIdx, cComp, (System.Object) (cblk)); } // Read entropy block mode options // NOTE: currently OPT_SEG_SYMBOLS is not included here ecOptions = ms.spcoc_cs = ehs.ReadByte(); if ((ecOptions & ~ (CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_BYPASS | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_RESET_MQ | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_TERM_PASS | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_VERT_STR_CAUSAL | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_PRED_TERM | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_SEG_SYMBOLS)) != 0) { throw new CorruptedCodestreamException("Unknown \"code-block " + "context\" in SPcoc field, " + "COC marker: 0x" + System.Convert.ToString(ecOptions, 16)); } // Read wavelet filter for tile or image hfilters = new SynWTFilter[1]; vfilters = new SynWTFilter[1]; hfilters[0] = readFilter(ehs, ms.spcoc_t); vfilters[0] = hfilters[0]; // Fill the filter spec // If this is the main header, set the default value, if it is the // tile header, set default for this tile SynWTFilter[][] hvfilters = new SynWTFilter[2][]; hvfilters[0] = hfilters; hvfilters[1] = vfilters; // Get precinct partition sizes System.Collections.ArrayList[] v = new System.Collections.ArrayList[2]; v[0] = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); v[1] = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); int val = CSJ2K.j2k.codestream.Markers.PRECINCT_PARTITION_DEF_SIZE; if (!precinctPartitionIsUsed) { System.Int32 w, h; w = (System.Int32) (1 << (val & 0x000F)); v[0].Add(w); h = (System.Int32) (1 << (((val & 0x00F0) >> 4))); v[1].Add(h); } else { ms.spcoc_ps = new int[mrl + 1]; for (int rl = mrl; rl >= 0; rl--) { System.Int32 w, h; val = ms.spcoc_ps[rl] = ehs.ReadByte(); w = (System.Int32) (1 << (val & 0x000F)); v[0].Insert(0, w); h = (System.Int32) (1 << (((val & 0x00F0) >> 4))); v[1].Insert(0, h); } } if (mainh) { decSpec.pss.setCompDef(cComp, v); } else { decSpec.pss.setTileCompVal(tileIdx, cComp, v); } precinctPartitionIsUsed = true; // Check marker length checkMarkerLength(ehs, "COD marker"); if (mainh) { hi.cocValue["main_c" + cComp] = ms; decSpec.wfs.setCompDef(cComp, hvfilters); decSpec.dls.setCompDef(cComp, (System.Object) mrl); decSpec.ecopts.setCompDef(cComp, (System.Object) ecOptions); } else { hi.cocValue["t" + tileIdx + "_c" + cComp] = ms; decSpec.wfs.setTileCompVal(tileIdx, cComp, hvfilters); decSpec.dls.setTileCompVal(tileIdx, cComp, (System.Object) mrl); decSpec.ecopts.setTileCompVal(tileIdx, cComp, (System.Object) ecOptions); } }
/// <summary> Reads a COD marker segment and realigns the codestream where the next /// marker should be found. /// /// </summary> /// <param name="ehs">The encoder header stream. /// /// </param> /// <param name="mainh">Flag indicating whether or not this marker segment is read /// from the main header. /// /// </param> /// <param name="tileIdx">The index of the current tile /// /// </param> /// <param name="tpIdx">Tile-part index /// /// </param> /// <exception cref="IOException">If an I/O error occurs while reading from the /// encoder header stream /// /// </exception> //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'" private void readCOD(System.IO.BinaryReader ehs, bool mainh, int tileIdx, int tpIdx) { int cstyle; // The block style SynWTFilter[] hfilters, vfilters; //int l; System.Int32[] cblk; System.String errMsg; //bool sopUsed = false; //bool ephUsed = false; HeaderInfo.COD ms = hi.NewCOD; // Lcod (marker length) ms.lcod = ehs.ReadUInt16(); // Scod (block style) // We only support wavelet transformed data cstyle = ms.scod = ehs.ReadByte(); if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_PRECINCT_PARTITION) != 0) { precinctPartitionIsUsed = true; // Remove flag cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_PRECINCT_PARTITION); } else { precinctPartitionIsUsed = false; } // SOP markers if (mainh) { hi.codValue["main"] = ms; if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_USE_SOP) != 0) { // SOP markers are used decSpec.sops.setDefault((System.Object) "true".ToUpper().Equals("TRUE")); //sopUsed = true; // Remove flag cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_USE_SOP); } else { // SOP markers are not used decSpec.sops.setDefault((System.Object) "false".ToUpper().Equals("TRUE")); } } else { hi.codValue["t" + tileIdx] = ms; if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_USE_SOP) != 0) { // SOP markers are used decSpec.sops.setTileDef(tileIdx, (System.Object) "true".ToUpper().Equals("TRUE")); //sopUsed = true; // Remove flag cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_USE_SOP); } else { // SOP markers are not used decSpec.sops.setTileDef(tileIdx, (System.Object) "false".ToUpper().Equals("TRUE")); } } // EPH markers if (mainh) { if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_USE_EPH) != 0) { // EPH markers are used decSpec.ephs.setDefault((System.Object) "true".ToUpper().Equals("TRUE")); //ephUsed = true; // Remove flag cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_USE_EPH); } else { // EPH markers are not used decSpec.ephs.setDefault((System.Object) "false".ToUpper().Equals("TRUE")); } } else { if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_USE_EPH) != 0) { // EPH markers are used decSpec.ephs.setTileDef(tileIdx, (System.Object) "true".ToUpper().Equals("TRUE")); //ephUsed = true; // Remove flag cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_USE_EPH); } else { // EPH markers are not used decSpec.ephs.setTileDef(tileIdx, (System.Object) "false".ToUpper().Equals("TRUE")); } } // Code-block partition origin if ((cstyle & (CSJ2K.j2k.codestream.Markers.SCOX_HOR_CB_PART | CSJ2K.j2k.codestream.Markers.SCOX_VER_CB_PART)) != 0) { FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Code-block partition origin " + "different from (0,0). This is defined in JPEG 2000" + " part 2 and may not be supported by all JPEG " + "2000 decoders."); } if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_HOR_CB_PART) != 0) { if (cb0x != - 1 && cb0x == 0) { throw new System.ArgumentException("Code-block partition " + "origin redefined in new" + " COD marker segment. Not" + " supported by JJ2000"); } cb0x = 1; cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_HOR_CB_PART); } else { if (cb0x != - 1 && cb0x == 1) { throw new System.ArgumentException("Code-block partition " + "origin redefined in new" + " COD marker segment. Not" + " supported by JJ2000"); } cb0x = 0; } if ((cstyle & CSJ2K.j2k.codestream.Markers.SCOX_VER_CB_PART) != 0) { if (cb0y != - 1 && cb0y == 0) { throw new System.ArgumentException("Code-block partition " + "origin redefined in new" + " COD marker segment. Not" + " supported by JJ2000"); } cb0y = 1; cstyle &= ~ (CSJ2K.j2k.codestream.Markers.SCOX_VER_CB_PART); } else { if (cb0y != - 1 && cb0y == 1) { throw new System.ArgumentException("Code-block partition " + "origin redefined in new" + " COD marker segment. Not" + " supported by JJ2000"); } cb0y = 0; } // SGcod // Read the progressive order ms.sgcod_po = ehs.ReadByte(); // Read the number of layers ms.sgcod_nl = ehs.ReadUInt16(); if (ms.sgcod_nl <= 0 || ms.sgcod_nl > 65535) { throw new CorruptedCodestreamException("Number of layers out of " + "range: 1--65535"); } // Multiple component transform ms.sgcod_mct = ehs.ReadByte(); // SPcod // decomposition levels int mrl = ms.spcod_ndl = ehs.ReadByte(); if (mrl > 32) { throw new CorruptedCodestreamException("Number of decomposition " + "levels out of range: " + "0--32"); } // Read the code-blocks dimensions cblk = new System.Int32[2]; ms.spcod_cw = ehs.ReadByte(); cblk[0] = (System.Int32) (1 << (ms.spcod_cw + 2)); if (cblk[0] < CSJ2K.j2k.entropy.StdEntropyCoderOptions.MIN_CB_DIM || cblk[0] > CSJ2K.j2k.entropy.StdEntropyCoderOptions.MAX_CB_DIM) { errMsg = "Non-valid code-block width in SPcod field, " + "COD marker"; throw new CorruptedCodestreamException(errMsg); } ms.spcod_ch = ehs.ReadByte(); cblk[1] = (System.Int32) (1 << (ms.spcod_ch + 2)); if (cblk[1] < CSJ2K.j2k.entropy.StdEntropyCoderOptions.MIN_CB_DIM || cblk[1] > CSJ2K.j2k.entropy.StdEntropyCoderOptions.MAX_CB_DIM) { errMsg = "Non-valid code-block height in SPcod field, " + "COD marker"; throw new CorruptedCodestreamException(errMsg); } if ((cblk[0] * cblk[1]) > CSJ2K.j2k.entropy.StdEntropyCoderOptions.MAX_CB_AREA) { errMsg = "Non-valid code-block area in SPcod field, " + "COD marker"; throw new CorruptedCodestreamException(errMsg); } if (mainh) { decSpec.cblks.setDefault((System.Object) (cblk)); } else { decSpec.cblks.setTileDef(tileIdx, (System.Object) (cblk)); } // Style of the code-block coding passes int ecOptions = ms.spcod_cs = ehs.ReadByte(); if ((ecOptions & ~ (CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_BYPASS | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_RESET_MQ | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_TERM_PASS | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_VERT_STR_CAUSAL | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_PRED_TERM | CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_SEG_SYMBOLS)) != 0) { throw new CorruptedCodestreamException("Unknown \"code-block " + "style\" in SPcod field, " + "COD marker: 0x" + System.Convert.ToString(ecOptions, 16)); } // Read wavelet filter for tile or image hfilters = new SynWTFilter[1]; vfilters = new SynWTFilter[1]; hfilters[0] = readFilter(ehs, ms.spcod_t); vfilters[0] = hfilters[0]; // Fill the filter spec // If this is the main header, set the default value, if it is the // tile header, set default for this tile SynWTFilter[][] hvfilters = new SynWTFilter[2][]; hvfilters[0] = hfilters; hvfilters[1] = vfilters; // Get precinct partition sizes System.Collections.ArrayList[] v = new System.Collections.ArrayList[2]; v[0] = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); v[1] = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); int val = CSJ2K.j2k.codestream.Markers.PRECINCT_PARTITION_DEF_SIZE; if (!precinctPartitionIsUsed) { System.Int32 w, h; w = (System.Int32) (1 << (val & 0x000F)); v[0].Add(w); h = (System.Int32) (1 << (((val & 0x00F0) >> 4))); v[1].Add(h); } else { ms.spcod_ps = new int[mrl + 1]; for (int rl = mrl; rl >= 0; rl--) { System.Int32 w, h; val = ms.spcod_ps[mrl - rl] = ehs.ReadByte(); w = (System.Int32) (1 << (val & 0x000F)); v[0].Insert(0, w); h = (System.Int32) (1 << (((val & 0x00F0) >> 4))); v[1].Insert(0, h); } } if (mainh) { decSpec.pss.setDefault(v); } else { decSpec.pss.setTileDef(tileIdx, v); } precinctPartitionIsUsed = true; // Check marker length checkMarkerLength(ehs, "COD marker"); // Store specifications in decSpec if (mainh) { decSpec.wfs.setDefault(hvfilters); decSpec.dls.setDefault((System.Object) mrl); decSpec.ecopts.setDefault((System.Object) ecOptions); decSpec.cts.setDefault((System.Object) ms.sgcod_mct); decSpec.nls.setDefault((System.Object) ms.sgcod_nl); decSpec.pos.setDefault((System.Object) ms.sgcod_po); } else { decSpec.wfs.setTileDef(tileIdx, hvfilters); decSpec.dls.setTileDef(tileIdx, (System.Object) mrl); decSpec.ecopts.setTileDef(tileIdx, (System.Object) ecOptions); decSpec.cts.setTileDef(tileIdx, (System.Object) ms.sgcod_mct); decSpec.nls.setTileDef(tileIdx, (System.Object) ms.sgcod_nl); decSpec.pos.setTileDef(tileIdx, (System.Object) ms.sgcod_po); } }