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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an instance from the given DWT data
        /// </summary>
        /// <param name="data">The linearization DWT data</param>
        /// <param name="useReduceExtrapolate">Indicates if Reduce-Extrapolate method used in DWT</param>
        /// <returns>A DWTBands instance</returns>
        public static DwtBands GetFromLinearizationResult(short[] data, bool useReduceExtrapolate)
        {
            int      curIdx = 0;
            DwtBands bDwt   = new DwtBands();

            bDwt.HL1 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.HL1, useReduceExtrapolate)];
            bDwt.LH1 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.LH1, useReduceExtrapolate)];
            bDwt.HH1 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.HH1, useReduceExtrapolate)];
            bDwt.HL2 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.HL2, useReduceExtrapolate)];
            bDwt.LH2 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.LH2, useReduceExtrapolate)];
            bDwt.HH2 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.HH2, useReduceExtrapolate)];
            bDwt.HL3 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.HL3, useReduceExtrapolate)];
            bDwt.LH3 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.LH3, useReduceExtrapolate)];
            bDwt.HH3 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.HH3, useReduceExtrapolate)];
            bDwt.LL3 = new short[RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, useReduceExtrapolate)];


            Array.Copy(data, curIdx, bDwt.HL1, 0, bDwt.HL1.Length); curIdx += bDwt.HL1.Length;
            Array.Copy(data, curIdx, bDwt.LH1, 0, bDwt.LH1.Length); curIdx += bDwt.LH1.Length;
            Array.Copy(data, curIdx, bDwt.HH1, 0, bDwt.HH1.Length); curIdx += bDwt.HH1.Length;
            Array.Copy(data, curIdx, bDwt.HL2, 0, bDwt.HL2.Length); curIdx += bDwt.HL2.Length;
            Array.Copy(data, curIdx, bDwt.LH2, 0, bDwt.LH2.Length); curIdx += bDwt.LH2.Length;
            Array.Copy(data, curIdx, bDwt.HH2, 0, bDwt.HH2.Length); curIdx += bDwt.HH2.Length;
            Array.Copy(data, curIdx, bDwt.HL3, 0, bDwt.HL3.Length); curIdx += bDwt.HL3.Length;
            Array.Copy(data, curIdx, bDwt.LH3, 0, bDwt.LH3.Length); curIdx += bDwt.LH3.Length;
            Array.Copy(data, curIdx, bDwt.HH3, 0, bDwt.HH3.Length); curIdx += bDwt.HH3.Length;
            Array.Copy(data, curIdx, bDwt.LL3, 0, bDwt.LL3.Length); curIdx += bDwt.LL3.Length;

            return(bDwt);
        }
        public static void ComputeOriginalLL3FromDeltas(RfxProgressiveCodecContext codecContext)
        {
            int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, codecContext.UseReduceExtrapolate);
            int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len;

            for (int i = ll3Idx + 1; i < RdpegfxTileUtils.ComponentElementCount; i++)
            {
                codecContext.YComponent[i]  = (short)(codecContext.YComponent[i] + codecContext.YComponent[i - 1]);
                codecContext.CbComponent[i] = (short)(codecContext.CbComponent[i] + codecContext.CbComponent[i - 1]);
                codecContext.CrComponent[i] = (short)(codecContext.CrComponent[i] + codecContext.CrComponent[i - 1]);
            }
        }
Exemplo n.º 4
0
        public static void ComputeLL3Deltas(RfxProgressiveCodecContext encodingContext)
        {
            int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate);
            int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len;

            //for (int i = ll3Idx + 1; i < TileUtils.ComponentElementCount; i++)
            for (int i = RdpegfxTileUtils.ComponentElementCount - 1; i >= ll3Idx + 1; i--)
            {
                encodingContext.YComponent[i]  = (short)(encodingContext.YComponent[i] - encodingContext.YComponent[i - 1]);
                encodingContext.CbComponent[i] = (short)(encodingContext.CbComponent[i] - encodingContext.CbComponent[i - 1]);
                encodingContext.CrComponent[i] = (short)(encodingContext.CrComponent[i] - encodingContext.CrComponent[i - 1]);
            }
        }
Exemplo n.º 5
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
 }
Exemplo n.º 6
0
        //SRLEncode
        public static EncodedTile SRLEncode(RfxProgressiveCodecContext encodingContext, Rdpegfx.RFX_PROGRESSIVE_CODEC_QUANT progQuant)
        {
            SRLEncoder encoder = new SRLEncoder();

            List <short> yDataToSrl  = new List <short>();
            List <short> cbDataToSrl = new List <short>();
            List <short> crDataToSrl = new List <short>();

            List <int> yDataToSrlBitLen  = new List <int>();
            List <int> cbDataToSrlBitLen = new List <int>();
            List <int> crDataToSrlBitLen = new List <int>();

            BitStream yRawBitStream  = new BitStream();
            BitStream cbRawBitStream = new BitStream();
            BitStream crRawBitStream = new BitStream();

            int nonLL3Len = RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate);

            Rdpegfx.RFX_PROGRESSIVE_CODEC_QUANT prevProgQuant = encodingContext.prevProgQuant;
            Rdpegfx.RFX_PROGRESSIVE_CODEC_QUANT curProgQuant  = progQuant;

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

                int targetBitPos = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.yQuantValues, band);
                int prevBitPos   = RdpegfxTileUtils.GetBitPosFromQuant(prevProgQuant.yQuantValues, band);
                int bitCount     = prevBitPos - targetBitPos;
                if (bitCount > 0)
                {
                    if (encodingContext.DAS.Y_DwtQ[i] == 0 && i < nonLL3Len)
                    {
                        yDataToSrl.Add(encodingContext.ProgQ.Y_DwtQ[i]);
                        yDataToSrlBitLen.Add(bitCount);
                    }
                    else
                    {
                        //Add raw data
                        yRawBitStream.WriteBits(bitCount, Math.Abs(encodingContext.ProgQ.Y_DwtQ[i]));
                    }
                }

                targetBitPos = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.cbQuantValues, band);
                prevBitPos   = RdpegfxTileUtils.GetBitPosFromQuant(prevProgQuant.cbQuantValues, band);
                bitCount     = prevBitPos - targetBitPos;
                if (bitCount > 0)
                {
                    if (encodingContext.DAS.Cb_DwtQ[i] == 0 && i < nonLL3Len)
                    {
                        cbDataToSrl.Add(encodingContext.ProgQ.Cb_DwtQ[i]);
                        cbDataToSrlBitLen.Add(bitCount);
                    }
                    else
                    {
                        //Add raw data
                        cbRawBitStream.WriteBits(bitCount, Math.Abs(encodingContext.ProgQ.Cb_DwtQ[i]));
                    }
                }

                targetBitPos = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.crQuantValues, band);
                prevBitPos   = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.crQuantValues, band);
                bitCount     = prevBitPos - targetBitPos;
                if (bitCount > 0)
                {
                    if (encodingContext.DAS.Cr_DwtQ[i] == 0 && i < nonLL3Len)
                    {
                        crDataToSrl.Add(encodingContext.ProgQ.Cr_DwtQ[i]);
                        crDataToSrlBitLen.Add(bitCount);
                    }
                    else
                    {
                        //Add raw data
                        crRawBitStream.WriteBits(bitCount, Math.Abs(encodingContext.ProgQ.Cr_DwtQ[i]));
                    }
                }
            }

            encodingContext.YData  = encoder.Encode(yDataToSrl.ToArray(), yDataToSrlBitLen.ToArray());
            encodingContext.CbData = encoder.Encode(cbDataToSrl.ToArray(), cbDataToSrlBitLen.ToArray());
            encodingContext.CrData = encoder.Encode(crDataToSrl.ToArray(), crDataToSrlBitLen.ToArray());

            EncodedTile ugTile = new EncodedTile();

            ugTile.YEncodedData         = (byte[])encodingContext.YData.Clone();
            ugTile.CbEncodedData        = (byte[])encodingContext.CbData.Clone();
            ugTile.CrEncodedData        = (byte[])encodingContext.CrData.Clone();
            ugTile.YRawData             = yRawBitStream.ToBytes();
            ugTile.CbRawData            = cbRawBitStream.ToBytes();
            ugTile.CrRawData            = crRawBitStream.ToBytes();
            ugTile.DataType             = EncodedTileType.UpgradePass;
            ugTile.IsDifferenceTile     = encodingContext.UseDifferenceTile;
            ugTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate;
            ugTile.CodecQuantVals       = encodingContext.CodecQuantVals;
            ugTile.QuantIdxY            = encodingContext.QuantIdxY;
            ugTile.QuantIdxCb           = encodingContext.QuantIdxCb;
            ugTile.QuantIdxCr           = encodingContext.QuantIdxCr;
            ugTile.ProgCodecQuant       = curProgQuant;

            return(ugTile);
        }
        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();
        }