/// <summary>
        /// Get the progressive codec quantity for the specified chunk
        /// </summary>
        /// <param name="chunk">the chunk type</param>
        /// <returns>The progressive codec quant for the specified chunk</returns>
        public static RFX_PROGRESSIVE_CODEC_QUANT GetProgCodecQuant(ProgressiveChunk_Values chunk)
        {
            RFX_PROGRESSIVE_CODEC_QUANT progQuant = new RFX_PROGRESSIVE_CODEC_QUANT();

            progQuant.yQuantValues  = new RFX_COMPONMENT_CODEC_QUANT();
            progQuant.cbQuantValues = new RFX_COMPONMENT_CODEC_QUANT();
            progQuant.crQuantValues = new RFX_COMPONMENT_CODEC_QUANT();

            //Y
            progQuant.yQuantValues.LL3_HL3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LL3) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HL3) << 4));
            progQuant.yQuantValues.LH3_HH3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LH3) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HH3) << 4));
            progQuant.yQuantValues.HL2_LH2 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HL2) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LH2) << 4));
            progQuant.yQuantValues.HH2_HL1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HH2) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HL1) << 4));
            progQuant.yQuantValues.LH1_HH1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LH1) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HH1) << 4));

            //Cb
            progQuant.cbQuantValues.LL3_HL3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LL3) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HL3) << 4));
            progQuant.cbQuantValues.LH3_HH3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LH3) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HH3) << 4));
            progQuant.cbQuantValues.HL2_LH2 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HL2) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LH2) << 4));
            progQuant.cbQuantValues.HH2_HL1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HH2) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HL1) << 4));
            progQuant.cbQuantValues.LH1_HH1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LH1) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HH1) << 4));

            //Cr
            progQuant.crQuantValues.LL3_HL3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LL3) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HL3) << 4));
            progQuant.crQuantValues.LH3_HH3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LH3) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HH3) << 4));
            progQuant.crQuantValues.HL2_LH2 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HL2) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LH2) << 4));
            progQuant.crQuantValues.HH2_HL1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HH2) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HL1) << 4));
            progQuant.crQuantValues.LH1_HH1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LH1) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HH1) << 4));

            return(progQuant);
        }
        /// <summary>
        /// Get the bit-pos for a given chunk
        /// </summary>
        /// <param name="chunk">The chunk</param>
        /// <param name="component">The compoent</param>
        /// <param name="band">The band</param>
        /// <returns>The bit-pos of the given band for the given chunk</returns>
        public static int GetBitPosForQuant(RFX_PROGRESSIVE_CODEC_QUANT quants, TileComponents component, BandType_Values band)
        {
            RFX_COMPONMENT_CODEC_QUANT quantsComponet = quants.yQuantValues;

            switch (component)
            {
            case TileComponents.Y:
                quantsComponet = quants.yQuantValues;
                break;

            case TileComponents.Cb:
                quantsComponet = quants.cbQuantValues;
                break;

            case TileComponents.Cr:
                quantsComponet = quants.crQuantValues;
                break;
            }
            switch (band)
            {
            case BandType_Values.LL3:
                return(quantsComponet.LL3_HL3 & 0x0F);

            case BandType_Values.HL3:
                return(quantsComponet.LL3_HL3 >> 4);

            case BandType_Values.LH3:
                return(quantsComponet.LH3_HH3 & 0x0F);

            case BandType_Values.HH3:
                return(quantsComponet.LH3_HH3 >> 4);

            case BandType_Values.HL2:
                return(quantsComponet.HL2_LH2 & 0x0F);

            case BandType_Values.LH2:
                return(quantsComponet.HL2_LH2 >> 4);

            case BandType_Values.HH2:
                return(quantsComponet.HH2_HL1 & 0x0F);

            case BandType_Values.HL1:
                return(quantsComponet.HH2_HL1 >> 4);

            case BandType_Values.LH1:
                return(quantsComponet.LH1_HH1 & 0x0F);

            case BandType_Values.HH1:
                return(quantsComponet.LH1_HH1 >> 4);

            default:
                return(0);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="y">Y component data</param>
 /// <param name="cb">Cb component data</param>
 /// <param name="cr">Cr component data</param>
 /// <param name="quant">Codec quantity</param>
 /// <param name="bReduceExtrapolate">Indicates if used Reduce-Extrapolate method in DWT</param>
 /// <param name="progQuant">The progressive codec quantity</param>
 public DwtTile(short[] y, short[] cb, short[] cr, TS_RFX_CODEC_QUANT[] quantVals, byte quantIdxY, byte quantIdxCb, byte quantIdxCr, bool bReduceExtrapolate, RFX_PROGRESSIVE_CODEC_QUANT progQuant = null)
 {
     // Clone the array, make sure different DwtTitle cannot hold the same array reference
     Y_DwtQ               = (short[])y.Clone();
     Cb_DwtQ              = (short[])cb.Clone();
     Cr_DwtQ              = (short[])cr.Clone();
     CodecQuantVals       = quantVals;
     this.QuantIdxY       = quantIdxY;
     this.QuantIdxCb      = quantIdxCb;
     this.QuantIdxCr      = quantIdxCr;
     UseReduceExtrapolate = bReduceExtrapolate;
     ProgCodecQuant       = progQuant;
 }
Ejemplo n.º 4
0
 protected static void DTS_Component(DwtBands dwt, TileComponents component, RFX_PROGRESSIVE_CODEC_QUANT quants)
 {
     //HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, and LL3
     DTS_Band(dwt.HL1, BandType_Values.HL1, component, quants);
     DTS_Band(dwt.LH1, BandType_Values.LH1, component, quants);
     DTS_Band(dwt.HH1, BandType_Values.HH1, component, quants);
     DTS_Band(dwt.HL2, BandType_Values.HL2, component, quants);
     DTS_Band(dwt.LH2, BandType_Values.LH2, component, quants);
     DTS_Band(dwt.HH2, BandType_Values.HH2, component, quants);
     DTS_Band(dwt.HL3, BandType_Values.HL3, component, quants);
     DTS_Band(dwt.LH3, BandType_Values.LH3, component, quants);
     DTS_Band(dwt.HH3, BandType_Values.HH3, component, quants);
     DTS_Band(dwt.LL3, BandType_Values.LL3, component, quants);
 }
 /// <summary>
 /// Consturctor
 /// </summary>
 /// <param name="tsRfxCodecQuantVals">Codec quantity values array</param>
 /// <param name="quantIdxY">Index of Y component in quantity array</param>
 /// <param name="quantIdxCb">Index of Cb component in quantity array</param>
 /// <param name="quantIdxCr">Index of Cr component in quantity array</param>
 /// <param name="bProgressive">indicates if use progressive codec</param>
 /// <param name="bTileDiff">indicates if sub-diffing</param>
 /// <param name="bReduceExtrapolate">Indicates if use Reduce-Extrapolate method in DWT</param>
 public RfxProgressiveCodecContext(
     TS_RFX_CODEC_QUANT[] tsRfxCodecQuantVals,
     byte quantIdxY,
     byte quantIdxCb,
     byte quantIdxCr,
     bool bProgressive = false,
     bool bTileDiff = true,
     bool bReduceExtrapolate = true)
     : base(tsRfxCodecQuantVals, quantIdxY, quantIdxCb, quantIdxCr, EntropyAlgorithm.CLW_ENTROPY_RLGR1)
 {
     UseProgressive = bProgressive;
     UseDifferenceTile = bTileDiff;
     UseReduceExtrapolate = bReduceExtrapolate;
     prevProgQuant = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_None);
 }
 /// <summary>
 /// Consturctor
 /// </summary>
 /// <param name="tsRfxCodecQuantVals">Codec quantity values array</param>
 /// <param name="quantIdxY">Index of Y component in quantity array</param>
 /// <param name="quantIdxCb">Index of Cb component in quantity array</param>
 /// <param name="quantIdxCr">Index of Cr component in quantity array</param>
 /// <param name="bProgressive">indicates if use progressive codec</param>
 /// <param name="bTileDiff">indicates if sub-diffing</param>
 /// <param name="bReduceExtrapolate">Indicates if use Reduce-Extrapolate method in DWT</param>
 public RfxProgressiveCodecContext(
     TS_RFX_CODEC_QUANT[] tsRfxCodecQuantVals,
     byte quantIdxY,
     byte quantIdxCb,
     byte quantIdxCr,
     bool bProgressive       = false,
     bool bTileDiff          = true,
     bool bReduceExtrapolate = true)
     : base(tsRfxCodecQuantVals, quantIdxY, quantIdxCb, quantIdxCr, EntropyAlgorithm.CLW_ENTROPY_RLGR1)
 {
     UseProgressive       = bProgressive;
     UseDifferenceTile    = bTileDiff;
     UseReduceExtrapolate = bReduceExtrapolate;
     prevProgQuant        = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_None);
 }
 static void ProgressiveQuantization_Band(short[] bandData, BandType_Values band, TileComponents component, RFX_PROGRESSIVE_CODEC_QUANT quants)
 {
     int bitPos = RdpegfxTileUtils.GetBitPosForQuant(quants, component, band);
     for (int i = 0; i < bandData.Length; i++)
     {
         bandData[i] = FunProgQ(bandData[i], bitPos, band);
     }
 }
 protected static void ProgressiveQuantization_Component(DwtBands dwt, TileComponents component, RFX_PROGRESSIVE_CODEC_QUANT quants)
 {
     //HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, and LL3
     ProgressiveQuantization_Band(dwt.HL1, BandType_Values.HL1, component, quants);
     ProgressiveQuantization_Band(dwt.LH1, BandType_Values.LH1, component, quants);
     ProgressiveQuantization_Band(dwt.HH1, BandType_Values.HH1, component, quants);
     ProgressiveQuantization_Band(dwt.HL2, BandType_Values.HL2, component, quants);
     ProgressiveQuantization_Band(dwt.LH2, BandType_Values.LH2, component, quants);
     ProgressiveQuantization_Band(dwt.HH2, BandType_Values.HH2, component, quants);
     ProgressiveQuantization_Band(dwt.HL3, BandType_Values.HL3, component, quants);
     ProgressiveQuantization_Band(dwt.LH3, BandType_Values.LH3, component, quants);
     ProgressiveQuantization_Band(dwt.HH3, BandType_Values.HH3, component, quants);
     ProgressiveQuantization_Band(dwt.LL3, BandType_Values.LL3, component, quants);
 }
        /// <summary>
        /// Get the progressive codec quantity for the specified chunk
        /// </summary>
        /// <param name="chunk">the chunk type</param>
        /// <returns>The progressive codec quant for the specified chunk</returns>
        public static RFX_PROGRESSIVE_CODEC_QUANT GetProgCodecQuant(ProgressiveChunk_Values chunk)
        {
            RFX_PROGRESSIVE_CODEC_QUANT progQuant = new RFX_PROGRESSIVE_CODEC_QUANT();
            progQuant.yQuantValues = new RFX_COMPONMENT_CODEC_QUANT();
            progQuant.cbQuantValues = new RFX_COMPONMENT_CODEC_QUANT();
            progQuant.crQuantValues = new RFX_COMPONMENT_CODEC_QUANT();

            //Y
            progQuant.yQuantValues.LL3_HL3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LL3) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HL3) << 4));
            progQuant.yQuantValues.LH3_HH3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LH3) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HH3) << 4));
            progQuant.yQuantValues.HL2_LH2 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HL2) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LH2) << 4));
            progQuant.yQuantValues.HH2_HL1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HH2) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HL1) << 4));
            progQuant.yQuantValues.LH1_HH1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.LH1) | (GetBitPosForChunk(chunk, TileComponents.Y, BandType_Values.HH1) << 4));

            //Cb
            progQuant.cbQuantValues.LL3_HL3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LL3) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HL3) << 4));
            progQuant.cbQuantValues.LH3_HH3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LH3) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HH3) << 4));
            progQuant.cbQuantValues.HL2_LH2 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HL2) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LH2) << 4));
            progQuant.cbQuantValues.HH2_HL1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HH2) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HL1) << 4));
            progQuant.cbQuantValues.LH1_HH1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.LH1) | (GetBitPosForChunk(chunk, TileComponents.Cb, BandType_Values.HH1) << 4));

            //Cr
            progQuant.crQuantValues.LL3_HL3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LL3) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HL3) << 4));
            progQuant.crQuantValues.LH3_HH3 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LH3) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HH3) << 4));
            progQuant.crQuantValues.HL2_LH2 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HL2) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LH2) << 4));
            progQuant.crQuantValues.HH2_HL1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HH2) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HL1) << 4));
            progQuant.crQuantValues.LH1_HH1 = (byte)(GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.LH1) | (GetBitPosForChunk(chunk, TileComponents.Cr, BandType_Values.HH1) << 4));

            return progQuant;
        }
 /// <summary>
 /// Get the bit-pos for a given chunk
 /// </summary>
 /// <param name="chunk">The chunk</param>
 /// <param name="component">The compoent</param>
 /// <param name="band">The band</param>
 /// <returns>The bit-pos of the given band for the given chunk</returns>
 public static int GetBitPosForQuant(RFX_PROGRESSIVE_CODEC_QUANT quants, TileComponents component, BandType_Values band)
 {
     RFX_COMPONMENT_CODEC_QUANT quantsComponet = quants.yQuantValues;
     switch (component)
     {
         case TileComponents.Y:
             quantsComponet = quants.yQuantValues;
             break;
         case TileComponents.Cb:
             quantsComponet = quants.cbQuantValues;
             break;
         case TileComponents.Cr:
             quantsComponet = quants.crQuantValues;
             break;
     }
     switch (band)
     {
         case BandType_Values.LL3:
             return quantsComponet.LL3_HL3 & 0x0F;
         case BandType_Values.HL3:
             return quantsComponet.LL3_HL3 >> 4;
         case BandType_Values.LH3:
             return quantsComponet.LH3_HH3 & 0x0F;
         case BandType_Values.HH3:
             return quantsComponet.LH3_HH3 >> 4;
         case BandType_Values.HL2:
             return quantsComponet.HL2_LH2 & 0x0F;
         case BandType_Values.LH2:
             return quantsComponet.HL2_LH2 >> 4;
         case BandType_Values.HH2:
             return quantsComponet.HH2_HL1 & 0x0F;
         case BandType_Values.HL1:
             return quantsComponet.HH2_HL1 >> 4;
         case BandType_Values.LH1:
             return quantsComponet.LH1_HH1 & 0x0F;
         case BandType_Values.HH1:
             return quantsComponet.LH1_HH1 >> 4;
         default:
             return 0;
     }
 }
Ejemplo n.º 11
0
        static void DTS_Band(short[] bandData, BandType_Values band, TileComponents component, RFX_PROGRESSIVE_CODEC_QUANT quants)
        {
            int bitPos = RdpegfxTileUtils.GetBitPosForQuant(quants, component, band);

            for (int i = 0; i < bandData.Length; i++)
            {
                bandData[i] = FunDTS(bandData[i], bitPos, band);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Encode a Tile
        /// </summary>
        /// <param name="encodingContext">The tile encoding context</param>
        /// <param name="enTileInfo">The tile to be encoded</param>
        /// <returns>A array of CompressedTile which contains the encoded tiles</returns>
        public static EncodedTile[] EncodeTile(RfxProgressiveCodecContext encodingContext, TileState enTileInfo)
        {
            EncodedTileType targetType = encodingContext.UseProgressive ? EncodedTileType.FirstPass : EncodedTileType.Simple;

            //File RGB
            FillRgbData(encodingContext, enTileInfo.GetRgb());

            //Do color conversion
            RemoteFXEncoder.RGBToYCbCr(encodingContext);

            //Do DWT
            if (encodingContext.UseReduceExtrapolate)
            {
                //Do DWT using UseReduce Extrapolate method
                DWT(encodingContext);
            }
            else
            {
                RemoteFXEncoder.DWT(encodingContext);
            }

            //Do quantiztion
            Quantization(encodingContext);

            //Do linearization (LL3 delta not computed)
            Linearization_NoLL3Delta(encodingContext);

            //Update new DWT to tile
            DwtTile dwt = new DwtTile(
                (short[])encodingContext.YComponent.Clone(),
                (short[])encodingContext.CbComponent.Clone(),
                (short[])encodingContext.CrComponent.Clone(),
                encodingContext.CodecQuantVals,
                encodingContext.QuantIdxY,
                encodingContext.QuantIdxCb,
                encodingContext.QuantIdxCr,
                encodingContext.UseReduceExtrapolate
                );

            enTileInfo.UpdateDwt(dwt);


            //Sub-Band Diffing
            if (encodingContext.UseDifferenceTile)
            {
                SubBandDiffing_DT(encodingContext, enTileInfo);
            }

            if (targetType == EncodedTileType.Simple)
            {
                ComputeLL3Deltas(encodingContext);

                RemoteFXEncoder.RLGREncode(encodingContext);
                EncodedTile cpTile = new EncodedTile();
                cpTile.YEncodedData         = (byte[])encodingContext.YData.Clone();
                cpTile.CbEncodedData        = (byte[])encodingContext.CbData.Clone();
                cpTile.CrEncodedData        = (byte[])encodingContext.CrData.Clone();
                cpTile.DataType             = EncodedTileType.Simple;
                cpTile.IsDifferenceTile     = encodingContext.UseDifferenceTile;
                cpTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate;
                cpTile.CodecQuantVals       = encodingContext.CodecQuantVals;
                cpTile.QuantIdxY            = encodingContext.QuantIdxY;
                cpTile.QuantIdxCb           = encodingContext.QuantIdxCb;
                cpTile.QuantIdxCr           = encodingContext.QuantIdxCr;
                cpTile.ProgCodecQuant       = null;
                return(new EncodedTile[] { cpTile });
            }
            else
            {
                List <EncodedTile> progCTileList = new List <EncodedTile>();
                //Init DRS, DAS
                encodingContext.DRS = new DwtTile(encodingContext.YComponent, encodingContext.CbComponent, encodingContext.CrComponent);
                encodingContext.DAS = new DwtTile(new short[RdpegfxTileUtils.ComponentElementCount], new short[RdpegfxTileUtils.ComponentElementCount], new short[RdpegfxTileUtils.ComponentElementCount]);

                #region Chunk 25, first pass

                ProgressiveQuantization(encodingContext, ProgressiveChunk_Values.kChunk_25);

                //Compute ProgQ LL3 deltas
                encodingContext.YComponent  = encodingContext.ProgQ.Y_DwtQ;
                encodingContext.CbComponent = encodingContext.ProgQ.Cb_DwtQ;
                encodingContext.CrComponent = encodingContext.ProgQ.Cr_DwtQ;

                ComputeLL3Deltas(encodingContext);

                RemoteFXEncoder.RLGREncode(encodingContext);
                EncodedTile firstPassTile = new EncodedTile();
                firstPassTile.YEncodedData         = (byte[])encodingContext.YData.Clone();
                firstPassTile.CbEncodedData        = (byte[])encodingContext.CbData.Clone();
                firstPassTile.CrEncodedData        = (byte[])encodingContext.CrData.Clone();
                firstPassTile.DataType             = EncodedTileType.FirstPass;
                firstPassTile.IsDifferenceTile     = encodingContext.UseDifferenceTile;
                firstPassTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate;
                firstPassTile.CodecQuantVals       = encodingContext.CodecQuantVals;
                firstPassTile.QuantIdxY            = encodingContext.QuantIdxY;
                firstPassTile.QuantIdxCb           = encodingContext.QuantIdxCb;
                firstPassTile.QuantIdxCr           = encodingContext.QuantIdxCr;
                firstPassTile.ProgCodecQuant       = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_25);
                progCTileList.Add(firstPassTile);
                encodingContext.prevProgQuant = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_25);

                //Update DRS
                encodingContext.DRS.Sub(encodingContext.DTS);
                //Update DAS
                encodingContext.DAS.Add(encodingContext.DTS);
                #endregion

                #region Chunk 50,75,100, upgrade pass
                ProgressiveChunk_Values[] upgradeChunks = { ProgressiveChunk_Values.kChunk_50, ProgressiveChunk_Values.kChunk_75, ProgressiveChunk_Values.kChunk_100 };

                foreach (ProgressiveChunk_Values tChunk in upgradeChunks)
                {
                    ProgressiveQuantization(encodingContext, tChunk);

                    RFX_PROGRESSIVE_CODEC_QUANT progquant = RdpegfxTileUtils.GetProgCodecQuant(tChunk);

                    progCTileList.Add(SRLEncode(encodingContext, progquant));

                    //Update DRS
                    encodingContext.DRS.Sub(encodingContext.DTS);
                    //Update DAS
                    encodingContext.DAS.Add(encodingContext.DTS);

                    encodingContext.prevProgQuant = progquant;
                }

                return(progCTileList.ToArray());

                #endregion
            }
        }
 public static void ProgressiveDeQuantization(RfxProgressiveCodecContext codecContext, RFX_PROGRESSIVE_CODEC_QUANT progCodecQuant)
 {
     ProgressiveDeQuantization_Component(codecContext.YComponent, progCodecQuant.yQuantValues, codecContext.UseReduceExtrapolate);
     ProgressiveDeQuantization_Component(codecContext.CbComponent, progCodecQuant.cbQuantValues, codecContext.UseReduceExtrapolate);
     ProgressiveDeQuantization_Component(codecContext.CrComponent, progCodecQuant.crQuantValues, codecContext.UseReduceExtrapolate);
 }
        public static void SRLDecode(RfxProgressiveCodecContext codecContext, EncodedTile enTile, TileState tState)
        {
            SRLDecoder yDecoder  = null;
            SRLDecoder cbDecoder = null;
            SRLDecoder crDecoder = null;

            List <short> yData    = new List <short>();
            List <short> cbData   = new List <short>();
            List <short> crData   = new List <short>();
            DwtTile      triState = tState.GetTriState();
            RFX_PROGRESSIVE_CODEC_QUANT prvProgQuant = tState.GetDwt().ProgCodecQuant;
            int nonLL3Len = RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, enTile.UseReduceExtrapolate);

            if (enTile.YEncodedData != null)
            {
                yDecoder = new SRLDecoder(enTile.YEncodedData);
            }

            if (enTile.CbEncodedData != null)
            {
                cbDecoder = new SRLDecoder(enTile.CbEncodedData);
            }

            if (enTile.CrEncodedData != null)
            {
                crDecoder = new SRLDecoder(enTile.CrEncodedData);
            }

            BitStream yRaw  = BitStream.GetFromBytes(enTile.YRawData);
            BitStream cbRaw = BitStream.GetFromBytes(enTile.CbRawData);
            BitStream crRaw = BitStream.GetFromBytes(enTile.CrRawData);

            for (int i = 0; i < RdpegfxTileUtils.ComponentElementCount; i++)
            {
                BandType_Values band = RdpegfxTileUtils.GetBandByIndex(i, enTile.UseReduceExtrapolate);

                //Y
                int curBitPos = RdpegfxTileUtils.GetBitPosFromQuant(enTile.ProgCodecQuant.yQuantValues, band);
                int prvBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prvProgQuant.yQuantValues, band);
                int bitCount  = prvBitPos - curBitPos;
                int sign      = triState.Y_DwtQ[i];
                if (bitCount > 0)
                {
                    if (sign == 0 && i < nonLL3Len)
                    {
                        if (yDecoder != null)
                        {
                            short?decodedValue = yDecoder.DecodeOne(bitCount);
                            if (decodedValue.HasValue)
                            {
                                yData.Add(decodedValue.Value);
                            }
                            else
                            {
                                yData.Add(0);
                            }
                        }
                        else
                        {
                            yData.Add(0);
                        }
                    }
                    else
                    {
                        int output;
                        if (yRaw.ReadInt32(bitCount, out output))
                        {
                            if (sign < 0 && i < nonLL3Len)
                            {
                                output = -output;
                            }
                            yData.Add((short)output);
                        }
                        else
                        {
                            yData.Add(0);
                        }
                    }
                }
                else
                {
                    yData.Add(0);
                }

                //Cb
                curBitPos = RdpegfxTileUtils.GetBitPosFromQuant(enTile.ProgCodecQuant.cbQuantValues, band);
                prvBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prvProgQuant.cbQuantValues, band);
                bitCount  = prvBitPos - curBitPos;
                sign      = triState.Cb_DwtQ[i];
                if (bitCount > 0)
                {
                    if (sign == 0 && i < nonLL3Len)
                    {
                        if (cbDecoder != null)
                        {
                            short?decodedValue = cbDecoder.DecodeOne(bitCount);
                            if (decodedValue.HasValue)
                            {
                                cbData.Add(decodedValue.Value);
                            }
                            else
                            {
                                cbData.Add(0);
                            }
                        }
                        else
                        {
                            cbData.Add(0);
                        }
                    }
                    else
                    {
                        int output;
                        if (cbRaw.ReadInt32(bitCount, out output))
                        {
                            if (sign < 0 && i < nonLL3Len)
                            {
                                output = -output;
                            }
                            cbData.Add((short)output);
                        }
                        else
                        {
                            cbData.Add(0);
                        }
                    }
                }
                else
                {
                    cbData.Add(0);
                }

                //cr
                curBitPos = RdpegfxTileUtils.GetBitPosFromQuant(enTile.ProgCodecQuant.crQuantValues, band);
                prvBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prvProgQuant.crQuantValues, band);
                bitCount  = prvBitPos - curBitPos;
                sign      = triState.Cr_DwtQ[i];
                if (bitCount > 0)
                {
                    if (sign == 0 && i < nonLL3Len)
                    {
                        if (crDecoder != null)
                        {
                            short?decodedValue = crDecoder.DecodeOne(bitCount);
                            if (decodedValue.HasValue)
                            {
                                crData.Add(decodedValue.Value);
                            }
                            else
                            {
                                crData.Add(0);
                            }
                        }
                        else
                        {
                            crData.Add(0);
                        }
                    }
                    else
                    {
                        int output;
                        if (crRaw.ReadInt32(bitCount, out output))
                        {
                            if (sign < 0 && i < nonLL3Len)
                            {
                                output = -output;
                            }
                            crData.Add((short)output);
                        }
                        else
                        {
                            crData.Add(0);
                        }
                    }
                }
                else
                {
                    crData.Add(0);
                }
            }

            codecContext.YComponent  = yData.ToArray();
            codecContext.CbComponent = cbData.ToArray();
            codecContext.CrComponent = crData.ToArray();
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="y">Y component data</param>
 /// <param name="cb">Cb component data</param>
 /// <param name="cr">Cr component data</param>
 /// <param name="quant">Codec quantity</param>
 /// <param name="bReduceExtrapolate">Indicates if used Reduce-Extrapolate method in DWT</param>
 /// <param name="progQuant">The progressive codec quantity</param>
 public DwtTile(short[] y, short[] cb, short[] cr, TS_RFX_CODEC_QUANT[] quantVals, byte quantIdxY, byte quantIdxCb, byte quantIdxCr, bool bReduceExtrapolate, RFX_PROGRESSIVE_CODEC_QUANT progQuant = null)
 {
     // Clone the array, make sure different DwtTitle cannot hold the same array reference
     Y_DwtQ = (short[])y.Clone();
     Cb_DwtQ = (short[])cb.Clone();
     Cr_DwtQ = (short[])cr.Clone();
     CodecQuantVals = quantVals;
     this.QuantIdxY = quantIdxY;
     this.QuantIdxCb = quantIdxCb;
     this.QuantIdxCr = quantIdxCr;
     UseReduceExtrapolate = bReduceExtrapolate;
     ProgCodecQuant = progQuant;
 }
 public static void ProgressiveDeQuantization(RfxProgressiveCodecContext codecContext, RFX_PROGRESSIVE_CODEC_QUANT progCodecQuant )
 {
     ProgressiveDeQuantization_Component(codecContext.YComponent,  progCodecQuant.yQuantValues, codecContext.UseReduceExtrapolate);
     ProgressiveDeQuantization_Component(codecContext.CbComponent,  progCodecQuant.cbQuantValues, codecContext.UseReduceExtrapolate);
     ProgressiveDeQuantization_Component(codecContext.CrComponent, progCodecQuant.crQuantValues, codecContext.UseReduceExtrapolate);
 }