CSJ2K.j2k.codestream.reader.HeaderDecoder.readRGN C# (CSharp) Method

readRGN() private method

Reads the RGN marker segment of the codestream header.

May be used in tile or main header. If used in main header, it refers to the maxshift value of a component in all tiles. When used in tile header, only the particular tile-component is affected.

If an I/O error occurs while reading from the /// encoder header stream /// ///
private readRGN ( System ehs, bool mainh, int tileIdx, int tpIdx ) : void
ehs System The encoder header stream. /// ///
mainh bool Flag indicating whether or not this marker segment is read /// from the main header. /// ///
tileIdx int The index of the current tile /// ///
tpIdx int Tile-part index /// ///
return void
        private void readRGN(System.IO.BinaryReader ehs, bool mainh, int tileIdx, int tpIdx)
        {
            int comp; // ROI component
            //int i; // loop variable
            //int tempComp; // Component for
            HeaderInfo.RGN ms = hi.NewRGN;

            // Lrgn (marker length)
            ms.lrgn = ehs.ReadUInt16();

            // Read component
            ms.crgn = comp = (nComp < 257)?ehs.ReadByte():ehs.ReadUInt16();
            if (comp >= nComp)
            {
                throw new CorruptedCodestreamException("Invalid component " + "index in RGN marker" + comp);
            }

            // Read type of RGN.(Srgn)
            ms.srgn = ehs.ReadByte();

            // Check that we can handle it.
            if (ms.srgn != CSJ2K.j2k.codestream.Markers.SRGN_IMPLICIT)
                throw new CorruptedCodestreamException("Unknown or unsupported " + "Srgn parameter in ROI " + "marker");

            if (decSpec.rois == null)
            {
                // No maxshift spec defined
                // Create needed ModuleSpec
                decSpec.rois = new MaxShiftSpec(nTiles, nComp, ModuleSpec.SPEC_TYPE_TILE_COMP);
            }

            // SPrgn
            ms.sprgn = ehs.ReadByte();

            if (mainh)
            {
                hi.rgnValue["main_c" + comp] = ms;
                decSpec.rois.setCompDef(comp, (System.Object) ms.sprgn);
            }
            else
            {
                hi.rgnValue["t" + tileIdx + "_c" + comp] = ms;
                decSpec.rois.setTileCompVal(tileIdx, comp, (System.Object) ms.sprgn);
            }

            // Check marker length
            checkMarkerLength(ehs, "RGN marker");
        }