CSJ2K.j2k.codestream.reader.HeaderDecoder.readCOD C# (CSharp) Метод

readCOD() приватный Метод

Reads a COD marker segment and realigns the codestream where the next marker should be found.
If an I/O error occurs while reading from the /// encoder header stream /// ///
private readCOD ( 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 /// ///
Результат void
        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.Generic.List<System.Int32>[] v = new System.Collections.Generic.List<System.Int32>[2];
            v[0] = new List<int>(10);
            v[1] = new List<int>(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);
            }
        }