static DwtTile SetTriState(DwtTile inputTile, bool useReduceExtrapolate)
        {
            int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, useReduceExtrapolate);
            int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len;

            DwtTile stateTile = new DwtTile(
                new short[RdpegfxTileUtils.ComponentElementCount],  //y state
                new short[RdpegfxTileUtils.ComponentElementCount],  //cb state
                new short[RdpegfxTileUtils.ComponentElementCount]); //cr state

            for (int i = 0; i < RdpegfxTileUtils.ComponentElementCount; i++)
            {
                if (i < ll3Idx)
                {
                    stateTile.Y_DwtQ[i]  = (short)Math.Sign(inputTile.Y_DwtQ[i]);
                    stateTile.Cb_DwtQ[i] = (short)Math.Sign(inputTile.Cb_DwtQ[i]);
                    stateTile.Cr_DwtQ[i] = (short)Math.Sign(inputTile.Cr_DwtQ[i]);
                }
                else
                {
                    stateTile.Y_DwtQ[i]  = 1;
                    stateTile.Cb_DwtQ[i] = 1;
                    stateTile.Cr_DwtQ[i] = 1;
                }
            }
            return(stateTile);
        }
Esempio n. 2
0
 //Compute the difference tile dwt
 public static void SubBandDiffing_DT(RfxProgressiveCodecContext encodingContext, TileState enTileInfo)
 {
     if (encodingContext.UseDifferenceTile)
     {
         DwtTile oldDwt = enTileInfo.GetOldDwt();
         if (oldDwt != null)
         {
             short[] yDiffDwt, cbDiffDwt, crDiffDwt;
             int     lenOfNonLL3Band = (RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate));// ? 81 : 64;
             int     yNewZeroCount, cbNewZeroCount, crNewZeroCount;
             int     yDiffZeroCount, cbDiffZeroCount, crDiffZeroCount;
             yDiffDwt  = RdpegfxTileUtils.SubDiffingDwt(encodingContext.YComponent, oldDwt.Y_DwtQ, lenOfNonLL3Band, out yNewZeroCount, out yDiffZeroCount);
             cbDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.CbComponent, oldDwt.Cb_DwtQ, lenOfNonLL3Band, out cbNewZeroCount, out cbDiffZeroCount);
             crDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.CrComponent, oldDwt.Cr_DwtQ, lenOfNonLL3Band, out crNewZeroCount, out crDiffZeroCount);
             if ((yDiffDwt != null && cbDiffDwt != null && crDiffDwt != null) &&
                 (yNewZeroCount + cbNewZeroCount + crNewZeroCount < yDiffZeroCount + cbDiffZeroCount + crDiffZeroCount))
             {//use difference tile
                 encodingContext.YComponent  = yDiffDwt;
                 encodingContext.CbComponent = cbDiffDwt;
                 encodingContext.CrComponent = crDiffDwt;
                 return;
             }
         }
     }
     encodingContext.UseDifferenceTile = false;//use orginal tile
 }
Esempio n. 3
0
        /// <summary>
        /// Add DWT data into this tile
        /// </summary>
        /// <param name="diffDwt">the DWT tile</param>
        public void AddDwt(DwtTile diffDwt)
        {
            DwtTile orgDwt = GetDwt();

            diffDwt.Add(orgDwt);
            UpdateDwt(diffDwt);
        }
Esempio n. 4
0
 /// <summary>
 /// Add a DWT tile
 /// </summary>
 /// <param name="addTile">The DWT tile to add</param>
 public void Add(DwtTile addTile)
 {
     for (int i = 0; i < this.Y_DwtQ.Length; i++)
     {
         this.Y_DwtQ[i]  = (short)(this.Y_DwtQ[i] + addTile.Y_DwtQ[i]);
         this.Cb_DwtQ[i] = (short)(this.Cb_DwtQ[i] + addTile.Cb_DwtQ[i]);
         this.Cr_DwtQ[i] = (short)(this.Cr_DwtQ[i] + addTile.Cr_DwtQ[i]);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Sub a DWT tile
 /// </summary>
 /// <param name="subTile">The DWT tile to subtract</param>
 public void Sub(DwtTile subTile)
 {
     for (int i = 0; i < this.Y_DwtQ.Length; i++)
     {
         this.Y_DwtQ[i]  = (short)(this.Y_DwtQ[i] - subTile.Y_DwtQ[i]);
         this.Cb_DwtQ[i] = (short)(this.Cb_DwtQ[i] - subTile.Cb_DwtQ[i]);
         this.Cr_DwtQ[i] = (short)(this.Cr_DwtQ[i] - subTile.Cr_DwtQ[i]);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Get the different tiles of this surface
        /// </summary>
        /// <param name="bRgb">If true, check if Rgb data exist for specified frame; otherwise, check if Dwt data exist.</param>
        /// <returns>The array of different tiles.</returns>
        public TileIndex[] GetDiffIndexes(bool bRgb)
        {
            if (this.pendingUpdateIndexs != null && this.pendingUpdateIndexs.Length <= RdpegfxTileUtils.TileDiffMinCount)
            {
                return(this.pendingUpdateIndexs);
            }

            if (CurrentFrame == null)
            {
                return(null);
            }
            if (LastFrame == null)
            {
                return(this.pendingUpdateIndexs);
            }
            List <TileIndex> diffIndexList = new List <TileIndex>();

            for (int xIndex = 0; xIndex *RdpegfxTileUtils.TileSize < this.Width; xIndex++)
            {
                for (int yIndex = 0; yIndex *RdpegfxTileUtils.TileSize < this.Height; yIndex++)
                {
                    TileIndex tIndex = new TileIndex((ushort)xIndex, (ushort)yIndex, this.Width, this.Height);
                    if (CurrentFrame.IsIndexInScope(tIndex, bRgb))
                    {
                        //diffIndexList.Add(tIndex);
                        if (LastFrame != null && LastFrame.IsIndexInScope(tIndex, bRgb))
                        {
                            if (bRgb)
                            {
                                RgbTile prvRgb = LastFrame.GetRgbTile(tIndex);
                                RgbTile curRgb = CurrentFrame.GetRgbTile(tIndex);
                                if (!curRgb.EqualsWith(prvRgb))
                                {
                                    diffIndexList.Add(tIndex);
                                }
                            }
                            else
                            {
                                DwtTile prvDwt = LastFrame.GetDwt(tIndex);
                                DwtTile curDwt = CurrentFrame.GetDwt(tIndex);
                                if (!curDwt.EqualsWith(prvDwt))
                                {
                                    diffIndexList.Add(tIndex);
                                }
                            }
                        }
                        else
                        {
                            diffIndexList.Add(tIndex);
                        }
                    }
                }
            }
            return(diffIndexList.ToArray());
        }
Esempio n. 7
0
        /// <summary>
        /// Convert Dwts to an image object
        /// </summary>
        /// <returns>The image returned from this surface</returns>
        public Bitmap DwtToImage()
        {
            Bitmap   surfImg = new Bitmap(this.Width, this.Height);
            Graphics gSurf   = Graphics.FromImage(surfImg);

            foreach (TileIndex index in this.dwtQDic.Keys)
            {
                DwtTile dwtQ = dwtQDic[index];
                gSurf.DrawImage(dwtQ.ToImage(), index.X * RdpegfxTileUtils.TileSize, index.Y * RdpegfxTileUtils.TileSize);
            }
            gSurf.Dispose();
            return(surfImg);
        }
Esempio n. 8
0
        static DwtTile GetDTS(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk)
        {
            DwtBands yBD  = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate);

            DTS_Component(yBD, TileComponents.Y, chunk);
            DTS_Component(cbBD, TileComponents.Cb, chunk);
            DTS_Component(crBD, TileComponents.Cr, chunk);

            DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData());

            return(dwtDts);
        }
Esempio n. 9
0
        public static void ProgressiveQuantization(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk)
        {
            DwtBands yBD  = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate);

            ProgressiveQuantization_Component(yBD, TileComponents.Y, chunk);
            ProgressiveQuantization_Component(cbBD, TileComponents.Cb, chunk);
            ProgressiveQuantization_Component(crBD, TileComponents.Cr, chunk);

            DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData());

            encodingContext.ProgQ = dwtDts;

            //Compute DTS
            encodingContext.DTS = GetDTS(encodingContext, chunk);
        }
Esempio n. 10
0
 /// <summary>
 /// Update the tri-state of a tile
 /// </summary>
 /// <param name="index">The tile index</param>
 /// <param name="stat">The tri-state of the specified tile</param>
 public void UpdateTriState(TileIndex index, DwtTile stat)
 {
     if (index.X * RdpegfxTileUtils.TileSize >= this.Width || index.Y * RdpegfxTileUtils.TileSize >= this.Height)
     {
         return;
     }
     lock (triStateDic)
     {
         if (triStateDic.ContainsKey(index))
         {
             triStateDic[index] = stat;
         }
         else
         {
             triStateDic.Add(index, stat);
         }
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Update the coefficients after DWT and Quantization of specified tile.
 /// </summary>
 /// <param name="index">The index of the tile.</param>
 /// <param name="dwtQ">The DwtQ coefficients.</param>
 public void UpdateTileDwtQ(TileIndex index, DwtTile dwtQ)
 {
     if (index.X * RdpegfxTileUtils.TileSize >= this.Width || index.Y * RdpegfxTileUtils.TileSize >= this.Height)
     {
         return;
     }
     lock (dwtQDic)
     {
         if (dwtQDic.ContainsKey(index))
         {
             dwtQDic[index] = dwtQ;
         }
         else
         {
             dwtQDic.Add(index, dwtQ);
         }
     }
 }
 /// <summary>
 /// Sub a DWT tile
 /// </summary>
 /// <param name="subTile">The DWT tile to subtract</param>
 public void Sub(DwtTile subTile)
 {
     for (int i = 0; i < this.Y_DwtQ.Length; i++)
     {
         this.Y_DwtQ[i] = (short)(this.Y_DwtQ[i] - subTile.Y_DwtQ[i]);
         this.Cb_DwtQ[i] = (short)(this.Cb_DwtQ[i] - subTile.Cb_DwtQ[i]);
         this.Cr_DwtQ[i] = (short)(this.Cr_DwtQ[i] - subTile.Cr_DwtQ[i]);
     }
 }
        /// <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);
            }
        }
        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();
        }
Esempio n. 15
0
 /// <summary>
 /// Update the tri-state of this tile
 /// </summary>
 /// <param name="newDwt">a DWT tile</param>
 public void UpdateTriState(DwtTile newDwt)
 {
     NewFrame.UpdateTriState(Index, newDwt);
 }
 /// <summary>
 /// Add a DWT tile
 /// </summary>
 /// <param name="addTile">The DWT tile to add</param>
 public void Add(DwtTile addTile)
 {
     for (int i = 0; i < this.Y_DwtQ.Length; i++)
     {
         this.Y_DwtQ[i] = (short)(this.Y_DwtQ[i] + addTile.Y_DwtQ[i]);
         this.Cb_DwtQ[i] = (short)(this.Cb_DwtQ[i] + addTile.Cb_DwtQ[i]);
         this.Cr_DwtQ[i] = (short)(this.Cr_DwtQ[i] + addTile.Cr_DwtQ[i]);
     }
 }
 /// <summary>
 /// Update the DWT data of this tile
 /// </summary>
 /// <param name="newDwt">the DWT tile</param>
 public void UpdateDwt(DwtTile newDwt)
 {
     NewFrame.UpdateTileDwtQ(Index, newDwt);
 }
 /// <summary>
 /// Update the coefficients after DWT and Quantization of specified tile.
 /// </summary>
 /// <param name="index">The index of the tile.</param>
 /// <param name="dwtQ">The DwtQ coefficients.</param>
 public void UpdateTileDwtQ(TileIndex index, DwtTile dwtQ)
 {
     if (index.X * RdpegfxTileUtils.TileSize >= this.Width || index.Y * RdpegfxTileUtils.TileSize >= this.Height) return;
     lock (dwtQDic)
     {
         if (dwtQDic.ContainsKey(index))
         {
             dwtQDic[index] = dwtQ;
         }
         else
         {
             dwtQDic.Add(index, dwtQ);
         }
     }
 }
 /// <summary>
 /// Update the tri-state of this tile
 /// </summary>
 /// <param name="newDwt">a DWT tile</param>
 public void UpdateTriState(DwtTile newDwt)
 {
     NewFrame.UpdateTriState(Index, newDwt);
 }
Esempio n. 20
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>
 /// Compare if equals with a given DWT tile
 /// </summary>
 /// <param name="cpTile">The specified DWT tile.</param>
 /// <returns>True if equals, otherwise false</returns>
 public bool EqualsWith(DwtTile cpTile)
 {
     return ShortArrayEquals(this.Y_DwtQ, cpTile.Y_DwtQ) &&
         ShortArrayEquals(this.Cb_DwtQ, cpTile.Cb_DwtQ) &&
         ShortArrayEquals(this.Cr_DwtQ, cpTile.Cr_DwtQ);
 }
        public static void ProgressiveQuantization(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk)
        {
            DwtBands yBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate);

            ProgressiveQuantization_Component(yBD, TileComponents.Y, chunk);
            ProgressiveQuantization_Component(cbBD, TileComponents.Cb, chunk);
            ProgressiveQuantization_Component(crBD, TileComponents.Cr, chunk);

            DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData());
            encodingContext.ProgQ = dwtDts;

            //Compute DTS
            encodingContext.DTS = GetDTS(encodingContext, chunk);
        }
        static void SetTriState(DwtTile inputTile, bool useReduceExtrapolate)
        {
            int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, useReduceExtrapolate);
            int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len;

            DwtTile stateTile = new DwtTile(
                new short[RdpegfxTileUtils.ComponentElementCount], //y state
                new short[RdpegfxTileUtils.ComponentElementCount], //cb state
                new short[RdpegfxTileUtils.ComponentElementCount]); //cr state

            for (int i = 0; i < RdpegfxTileUtils.ComponentElementCount; i++)
            {
                if (i < ll3Idx)
                {
                    if (inputTile.Y_DwtQ[i] == 0)
                    {
                        stateTile.Y_DwtQ[i] = 0;
                    }
                    else if (inputTile.Y_DwtQ[i] > 0)
                    {
                        stateTile.Y_DwtQ[i] = 1;
                    } if (inputTile.Y_DwtQ[i] < 0)
                    {
                        stateTile.Y_DwtQ[i] = -1;
                    }

                    if (inputTile.Cb_DwtQ[i] == 0)
                    {
                        stateTile.Cb_DwtQ[i] = 0;
                    }
                    else if (inputTile.Cb_DwtQ[i] > 0)
                    {
                        stateTile.Cb_DwtQ[i] = 1;
                    } if (inputTile.Cb_DwtQ[i] < 0)
                    {
                        stateTile.Cb_DwtQ[i] = -1;
                    }

                    if (inputTile.Cr_DwtQ[i] == 0)
                    {
                        stateTile.Cr_DwtQ[i] = 0;
                    }
                    else if (inputTile.Cr_DwtQ[i] > 0)
                    {
                        stateTile.Cr_DwtQ[i] = 1;
                    } if (inputTile.Cr_DwtQ[i] < 0)
                    {
                        stateTile.Cr_DwtQ[i] = -1;
                    }
                }
                else
                {
                    stateTile.Y_DwtQ[i] = 1;
                    stateTile.Cb_DwtQ[i] = 1;
                    stateTile.Cr_DwtQ[i] = 1;
                }
            }
        }
 /// <summary>
 /// Add DWT data into this tile
 /// </summary>
 /// <param name="diffDwt">the DWT tile</param>
 public void AddDwt(DwtTile diffDwt)
 {
     DwtTile orgDwt = GetDwt();
     diffDwt.Add(orgDwt);
     UpdateDwt(diffDwt);
 }
 /// <summary>
 /// Update the tri-state of a tile
 /// </summary>
 /// <param name="index">The tile index</param>
 /// <param name="stat">The tri-state of the specified tile</param>
 public void UpdateTriState(TileIndex index, DwtTile stat)
 {
     if (index.X * RdpegfxTileUtils.TileSize >= this.Width || index.Y * RdpegfxTileUtils.TileSize >= this.Height) return;
     lock (triStateDic)
     {
         if (triStateDic.ContainsKey(index))
         {
             triStateDic[index] = stat;
         }
         else
         {
             triStateDic.Add(index, stat);
         }
     }
 }
Esempio n. 26
0
 /// <summary>
 /// Compare if equals with a given DWT tile
 /// </summary>
 /// <param name="cpTile">The specified DWT tile.</param>
 /// <returns>True if equals, otherwise false</returns>
 public bool EqualsWith(DwtTile cpTile)
 {
     return(ShortArrayEquals(this.Y_DwtQ, cpTile.Y_DwtQ) &&
            ShortArrayEquals(this.Cb_DwtQ, cpTile.Cb_DwtQ) &&
            ShortArrayEquals(this.Cr_DwtQ, cpTile.Cr_DwtQ));
 }
        static DwtTile GetDTS(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk)
        {
            DwtBands yBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate);
            DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate);

            DTS_Component(yBD, TileComponents.Y, chunk);
            DTS_Component(cbBD, TileComponents.Cb, chunk);
            DTS_Component(crBD, TileComponents.Cr, chunk);

            DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData());
            return dwtDts;
        }
Esempio n. 28
0
 /// <summary>
 /// Update the DWT data of this tile
 /// </summary>
 /// <param name="newDwt">the DWT tile</param>
 public void UpdateDwt(DwtTile newDwt)
 {
     NewFrame.UpdateTileDwtQ(Index, newDwt);
 }
        /// <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);
            }
        }