Beispiel #1
0
        /// <summary>
        /// Encode the surface with Progressive Codec
        /// </summary>
        /// <param name="quality">The target encoded quality.</param>
        /// <param name="bProg">Indicates if encode progressively</param>
        /// <param name="bSubDiff">Indicates if sub-diffing with last frame of this surface</param>
        /// <param name="bReduceExtrapolate">Indicates if use Reduce Extrapolate method in DWT step.</param>
        /// <returns>The dictionary of tile index and encoded tile datas.</returns>
        public Dictionary <TileIndex, EncodedTile[]> ProgressiveEncode(ImageQuality_Values quality, bool bProg, bool bSubDiff, bool bReduceExtrapolate, bool ignoreUnchangedTile = true)
        {
            Dictionary <TileIndex, EncodedTile[]> encodedTileDic = new Dictionary <TileIndex, EncodedTile[]>();
            TS_RFX_CODEC_QUANT quant = RdpegfxTileUtils.GetCodecQuant(quality);

            TileIndex[] tileIndexArr;
            if (!ignoreUnchangedTile)
            {
                tileIndexArr = GetAllIndexes();
            }
            else
            {
                tileIndexArr = GetDiffIndexes(true);
            }

            foreach (TileIndex index in tileIndexArr)
            {
                RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext(
                    new TS_RFX_CODEC_QUANT[] { quant },
                    0,                   // quantization index of Y, set this paramter to 0 since only one quantization value in the array
                    0,                   // quantization index of Cb
                    0,                   // quantization index of Cr
                    bProg,               //progressive
                    bSubDiff,            //sub-diffing
                    bReduceExtrapolate); //reduce extrapolate
                TileState tState = new TileState(this, index);
                encodedTileDic.Add(index, RfxProgressiveEncoder.EncodeTile(codecContext, tState));
            }
            return(encodedTileDic);
        }
        protected static void dequantization_Component(short[,] compontent, TS_RFX_CODEC_QUANT tsRfxCodecQuant, bool useReduceExtrapolate)
        {
            // Quantization factor: HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, LL3
            Hashtable scaleValueTable = new Hashtable();
            int       HL1_Factor      = tsRfxCodecQuant.HL1_HH1 & 0x0f;
            int       LH1_Factor      = (tsRfxCodecQuant.HH2_LH1 & 0xf0) >> 4;
            int       HH1_Factor      = (tsRfxCodecQuant.HL1_HH1 & 0xf0) >> 4;
            int       HL2_Factor      = (tsRfxCodecQuant.LH2_HL2 & 0xf0) >> 4;
            int       LH2_Factor      = tsRfxCodecQuant.LH2_HL2 & 0x0f;
            int       HH2_Factor      = tsRfxCodecQuant.HH2_LH1 & 0x0f;
            int       HL3_Factor      = tsRfxCodecQuant.HL3_HH3 & 0x0f;
            int       LH3_Factor      = (tsRfxCodecQuant.LL3_LH3 & 0xf0) >> 4;
            int       HH3_Factor      = (tsRfxCodecQuant.HL3_HH3 & 0xf0) >> 4;
            int       LL3_Factor      = tsRfxCodecQuant.LL3_LH3 & 0x0f;

            int[] HL_Factor = { HL1_Factor, HL2_Factor, HL3_Factor };
            int[] LH_Factor = { LH1_Factor, LH2_Factor, LH3_Factor };
            int[] HH_Factor = { HH1_Factor, HH2_Factor, HH3_Factor };

            BandType_Values[] bandArr    = new BandType_Values[] { BandType_Values.HL1, BandType_Values.LH1, BandType_Values.HH1, BandType_Values.HL2, BandType_Values.LH2, BandType_Values.HH2, BandType_Values.HL3, BandType_Values.LH3, BandType_Values.HH3, BandType_Values.LL3 };
            int[]             bandFactor = new int[] { HL1_Factor, LH1_Factor, HH1_Factor, HL2_Factor, LH2_Factor, HH2_Factor, HL3_Factor, LH3_Factor, HH3_Factor, LL3_Factor };

            for (int i = 0; i < bandArr.Length; i++)
            {
                BandRect br = RdpegfxTileUtils.GetBandRect(bandArr[i], useReduceExtrapolate);
                doDequantization_Subband(compontent, br.left, br.top, br.right, br.bottom, bandFactor[i]);
            }
        }
        /// <summary>
        /// Get codec quant with the specified quality
        /// </summary>
        /// <param name="quality">the encoding quality</param>
        /// <returns>The codec quant</returns>
        public static TS_RFX_CODEC_QUANT GetCodecQuant(ImageQuality_Values quality)
        {
            TS_RFX_CODEC_QUANT quant = new TS_RFX_CODEC_QUANT();

            quant.LL3_LH3 = (byte)(GetQuantValue(quality, BandType_Values.LL3) | (GetQuantValue(quality, BandType_Values.LH3) << 4));
            quant.HL3_HH3 = (byte)(GetQuantValue(quality, BandType_Values.HL3) | (GetQuantValue(quality, BandType_Values.HH3) << 4));
            quant.LH2_HL2 = (byte)(GetQuantValue(quality, BandType_Values.LH2) | (GetQuantValue(quality, BandType_Values.HL2) << 4));
            quant.HH2_LH1 = (byte)(GetQuantValue(quality, BandType_Values.HH2) | (GetQuantValue(quality, BandType_Values.LH1) << 4));
            quant.HL1_HH1 = (byte)(GetQuantValue(quality, BandType_Values.HL1) | (GetQuantValue(quality, BandType_Values.HH1) << 4));
            return(quant);
        }
Beispiel #4
0
        public static TS_RFX_CODEC_QUANT ConvertRFXQuants(QuantizationFactors quant)
        {
            var rfxQuant = new TS_RFX_CODEC_QUANT
            {
                LL3_LH3 = (byte)((quant.LH3 << 4) | quant.LL3),
                HL3_HH3 = (byte)((quant.HH3 << 4) | quant.HL3),
                LH2_HL2 = (byte)((quant.HL2 << 4) | quant.LH2),
                HH2_LH1 = (byte)((quant.LH1 << 4) | quant.HH2),
                HL1_HH1 = (byte)((quant.HH1 << 4) | quant.HL1)
            };

            return(rfxQuant);
        }
        public static void Quantization(short[,] input, QuantizationFactors quant, bool UseReduceExtrapolate, out short[,] output)
        {
            var rfxQuant = new TS_RFX_CODEC_QUANT
            {
                LL3_LH3 = (byte)((quant.LH3 << 4) | quant.LL3),
                HL3_HH3 = (byte)((quant.HH3 << 4) | quant.HL3),
                LH2_HL2 = (byte)((quant.HL2 << 4) | quant.LH2),
                HH2_LH1 = (byte)((quant.LH1 << 4) | quant.HH2),
                HL1_HH1 = (byte)((quant.HH1 << 4) | quant.HL1)
            };

            output = new short[input.GetLength(0), input.GetLength(1)];
            Array.Copy(input, output, input.Length);
            doQuantization_Component(output, rfxQuant, UseReduceExtrapolate);
        }