/// <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

            }
        }
        /// <summary>
        /// Decode an encoded tile
        /// </summary>
        /// <param name="enTile">Represents an encoded tile.</param>
        /// <param name="tState">The context state of the tile that going to be decoded.</param>
        public static void DecodeTile(EncodedTile enTile, TileState tState)
        {
            RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext(
                enTile.CodecQuantVals,
                enTile.QuantIdxY,
                enTile.QuantIdxCb,
                enTile.QuantIdxCr,
                enTile.DataType == EncodedTileType.Simple ? false : true,
                enTile.IsDifferenceTile,
                enTile.UseReduceExtrapolate);

            //RLGR/SRL Decode
            if (enTile.DataType == EncodedTileType.FirstPass || enTile.DataType == EncodedTileType.Simple)
            {   //first pass or simple
                codecContext.YData  = enTile.YEncodedData;
                codecContext.CbData = enTile.CbEncodedData;
                codecContext.CrData = enTile.CrEncodedData;
                RemoteFXDecoder.RLGRDecode(codecContext);
                ComputeOriginalLL3FromDeltas(codecContext);
            }
            else
            {
                SRLDecode(codecContext, enTile, tState);
            }

            //Progressive Dequantization
            if (enTile.DataType != EncodedTileType.Simple)
            {
                ProgressiveDeQuantization(codecContext, enTile.ProgCodecQuant);
            }

            // Create a DwtTile instance for tri-state
            DwtTile triStateDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent,
                                              enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant);

            //Set Tri-State for progressive codec
            if (enTile.DataType == EncodedTileType.FirstPass)
            {
                //DwtTile tileTriStat = SetTriState(diffDwt, enTile.UseReduceExtrapolate);
                tState.UpdateTriState(triStateDwt);
            }
            else if (enTile.DataType == EncodedTileType.UpgradePass)
            {
                DwtTile prvStat = tState.GetTriState();
                prvStat.Add(triStateDwt);
                // update ProCodecQuant
                prvStat.ProgCodecQuant = triStateDwt.ProgCodecQuant;
                tState.UpdateTriState(prvStat);
            }

            // Create another DwtTile instance for DWT Data.
            // The data in diffDwt is the same as triStateDwt, this will makesure the DWT data and tri-state not share the same DWT tile instance
            DwtTile diffDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent,
                                          enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant);

            //Sum difference
            if (enTile.IsDifferenceTile || enTile.DataType == EncodedTileType.UpgradePass)
            {
                tState.AddDwt(diffDwt);
            }
            else
            {
                tState.UpdateDwt(diffDwt);
            }
        }
Пример #3
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
            }
        }
        /// <summary>
        /// Decode an encoded tile
        /// </summary>
        /// <param name="enTile">Represents an encoded tile.</param>
        /// <param name="tState">The context state of the tile that going to be decoded.</param>
        public static void DecodeTile(EncodedTile enTile, TileState tState)
        {
            RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext(
                enTile.CodecQuantVals,
                enTile.QuantIdxY,
                enTile.QuantIdxCb,
                enTile.QuantIdxCr,
                enTile.DataType == EncodedTileType.Simple ? false : true,
                enTile.IsDifferenceTile,
                enTile.UseReduceExtrapolate);

            //RLGR/SRL Decode
            if (enTile.DataType == EncodedTileType.FirstPass || enTile.DataType == EncodedTileType.Simple)
            {   //first pass or simple
                codecContext.YData = enTile.YEncodedData;
                codecContext.CbData = enTile.CbEncodedData;
                codecContext.CrData = enTile.CrEncodedData;
                RemoteFXDecoder.RLGRDecode(codecContext);
                ComputeOriginalLL3FromDeltas(codecContext);
            }
            else
            {
                SRLDecode(codecContext, enTile, tState);
            }

            //Progressive Dequantization
            if (enTile.DataType != EncodedTileType.Simple)
            {
                ProgressiveDeQuantization(codecContext, enTile.ProgCodecQuant);
            }

            // Create a DwtTile instance for tri-state
            DwtTile triStateDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent,
                enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant);

            //Set Tri-State for progressive codec
            if (enTile.DataType == EncodedTileType.FirstPass)
            {
                //DwtTile tileTriStat = SetTriState(diffDwt, enTile.UseReduceExtrapolate);
                tState.UpdateTriState(triStateDwt);
            }
            else if (enTile.DataType == EncodedTileType.UpgradePass)
            {
                DwtTile prvStat = tState.GetTriState();
                prvStat.Add(triStateDwt);
                // update ProCodecQuant
                prvStat.ProgCodecQuant = triStateDwt.ProgCodecQuant;
                tState.UpdateTriState(prvStat);
            }

            // Create another DwtTile instance for DWT Data.
            // The data in diffDwt is the same as triStateDwt, this will makesure the DWT data and tri-state not share the same DWT tile instance
            DwtTile diffDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent,
                enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant);

            //Sum difference
            if ( enTile.IsDifferenceTile || enTile.DataType == EncodedTileType.UpgradePass)
            {
                tState.AddDwt(diffDwt);
            }
            else
            {
                tState.UpdateDwt(diffDwt);
            }
        }