示例#1
0
 public static extern void openjpeg_openjp2_opj_cparameters_t_set_prog_order(IntPtr parameters, ProgressionOrder value);
示例#2
0
        public CodMarker(
            bool usePrecincts,
            bool useEph,
            bool useSop,
            Size codeblockSize,
            Size[] precinctSizes,
            ProgressionOrder progression,
            ushort qualityLayers,
            bool useMultiComponentTransform,
            WaveletTransform waveletFilter,
            byte decompositionLevels,
            CodeblockStyle cblkStyle)
            : base(MarkerType.COD)
        {
            _scod  = CodingStyle.None;
            _scod |=
                usePrecincts ? CodingStyle.UsePrecincts : CodingStyle.None;
            _scod |=
                useSop ? CodingStyle.UseSopMarker : CodingStyle.None;
            _scod |=
                useEph ? CodingStyle.UseEphMarker: CodingStyle.None;

            Progression                   = progression;
            QualityLayers                 = qualityLayers;
            DecompositionLevels           = decompositionLevels;
            UseMultipleComponentTransform = useMultiComponentTransform;
            CBlkStyle     = cblkStyle;
            WaveletFilter = waveletFilter;

            // width > max || height > max
            if ((new List <int> {
                codeblockSize.Width,
                codeblockSize.Height,
                MAX_CBLK_SIZE
            }).Max() != MAX_CBLK_SIZE)
            {
                throw new ArgumentOutOfRangeException(
                          "Codeblock dimensions must be up to "
                          + MAX_CBLK_SIZE + " samples on each side");
            }

            bool isCodeblockPow2 =
                BitHacks.IsPowerOf2((uint)codeblockSize.Width) &&
                BitHacks.IsPowerOf2((uint)codeblockSize.Height);

            if (!isCodeblockPow2)
            {
                throw new ArgumentException(
                          "Codeblock size must be power of 2");
            }

            // codeblock size range is [4,64], and is a power of 2.
            // to save space and fill it inside a byte,
            // codestream specifies them using the 2-exponent in the range
            // [0, 16]. The additional 2 is implicit.
            _cblkExpnX  = (byte)(BitHacks.LogFloor2((uint)codeblockSize.Width));
            _cblkExpnX -= 2;

            _cblkExpnY  = (byte)(BitHacks.LogFloor2((uint)codeblockSize.Height));
            _cblkExpnY -= 2;

            if (UsePrecincts)
            {
                bool valid = precinctSizes.Any();
                valid &= precinctSizes.Length <= (decompositionLevels + 1);
                valid &= precinctSizes
                         .All(prc => BitHacks.IsPowerOf2((uint)prc.Width));
                valid &= precinctSizes
                         .All(prc => BitHacks.IsPowerOf2((uint)prc.Height));
                if (!valid)
                {
                    throw new ArgumentException(
                              "precincts unspecified or not power of two");
                }

                _ppx = new byte[decompositionLevels + 1];
                _ppx = new byte[decompositionLevels + 1];

                int idx = 0;
                foreach (var prc in precinctSizes)
                {
                    _ppx[idx] = (byte)BitHacks.LogFloor2((uint)prc.Width);
                    _ppy[idx] = (byte)BitHacks.LogFloor2((uint)prc.Height);
                    idx++;
                }

                for (; idx <= decompositionLevels; idx++)
                {
                    // there is at least one element in ppx/ppy
                    // because we checked that precSizes.Any()
                    _ppx[idx] = _ppx[idx - 1];
                    _ppy[idx] = _ppy[idx - 1];
                }
            }
            else
            {
                // maximal precincts: size 2^15
                _ppx = new byte[] { 0xF };
                _ppy = new byte[] { 0xF };
            }

            _markerBody   = GenerateMarkerBody();
            _markerLength = (ushort)(_markerBody.Length + 2);
        }