示例#1
0
        public static QuantizationFactorsArray GetProgQuantizationFactorsForChunk(ProgressiveChunk chunk)
        {
            RFX_PROGRESSIVE_CODEC_QUANT quant   = RdpegfxTileUtils.GetProgCodecQuant((ProgressiveChunk_Values)chunk);
            QuantizationFactorsArray    factors = ConvertProgQuant(quant);

            return(factors);
        }
        private static void ComputeOriginalLL3FromDeltas(short[] input, bool useReduceExtrapolate)
        {
            int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, useReduceExtrapolate);
            int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len;

            for (int i = ll3Idx + 1; i < RdpegfxTileUtils.ComponentElementCount; i++)
            {
                input[i] = (short)(input[i] + input[i - 1]);
            }
        }
        private static void ComputeLL3Deltas(Triplet <short[]> input, bool UseReduceExtrapolate)
        {
            int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, 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--)
            {
                foreach (var component in input)
                {
                    component[i] = (short)(component[i] - component[i - 1]);
                }
            }
        }
 // Should maintain a LastFrame
 public static void SubBandDiffing(Triplet <short[]> input, Triplet <short[]> lastFrame, bool UseReduceExtrapolate, out Triplet <short[]> output, out bool useDiffing)
 {
     // According to TD SubBandDiffing step is mandatory and in SubBandDiffing decide whether or not use diffing
     short[] x, y, z;
     output = null;
     if (lastFrame == null)
     {
         x = new short[input.X.Length];
         Array.Copy(input.X, x, input.X.Length);
         y = new short[input.Y.Length];
         Array.Copy(input.Y, y, input.Y.Length);
         z = new short[input.Z.Length];
         Array.Copy(input.Z, z, input.Z.Length);
         output     = new Triplet <short[]>(x, y, z);
         useDiffing = false;
     }
     else
     {
         short[] yDiffDwt, cbDiffDwt, crDiffDwt;
         int     lenOfNonLL3Band = (RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, UseReduceExtrapolate));// ? 81 : 64;
         int     yNewZeroCount, cbNewZeroCount, crNewZeroCount;
         int     yDiffZeroCount, cbDiffZeroCount, crDiffZeroCount;
         yDiffDwt  = RdpegfxTileUtils.SubDiffingDwt(input.X, lastFrame.X, lenOfNonLL3Band, out yNewZeroCount, out yDiffZeroCount);
         cbDiffDwt = RdpegfxTileUtils.SubDiffingDwt(input.Y, lastFrame.Y, lenOfNonLL3Band, out cbNewZeroCount, out cbDiffZeroCount);
         crDiffDwt = RdpegfxTileUtils.SubDiffingDwt(input.Z, lastFrame.Z, lenOfNonLL3Band, out crNewZeroCount, out crDiffZeroCount);
         // According to TD we should only compare the zeros in Luma (Y) component
         // Need to be confirmed
         if ((yDiffDwt != null && cbDiffDwt != null && crDiffDwt != null) && yNewZeroCount < yDiffZeroCount)
         {
             //use difference tile
             output     = new Triplet <short[]>(yDiffDwt, cbDiffDwt, crDiffDwt);
             useDiffing = true;
         }
         else
         {
             // don't use difference tile
             x = new short[input.X.Length];
             Array.Copy(input.X, x, input.X.Length);
             y = new short[input.Y.Length];
             Array.Copy(input.Y, y, input.Y.Length);
             z = new short[input.Z.Length];
             Array.Copy(input.Z, z, input.Z.Length);
             output     = new Triplet <short[]>(x, y, z);
             useDiffing = false;
         }
     }
 }
        // The output format is
        // firstPass [X, Y, Z]
        // ProgressivePass1 [encodedX, encodedY, encodedZ]
        // ProgressivePass1 [rawX, rawY, rawZ]
        // ...
        public static void RLGR_SRLEncode(List <Triplet <short[]> > input, ProgressiveQuantizationFactors proQuants, EntropyAlgorithm mode, bool UseReduceExtrapolate, out List <Triplet <byte[]> > output)
        {
            output = new List <Triplet <byte[]> >();
            byte[] x, y, z;

            // fisrt pass
            Triplet <short[]> firstPass = input[0];

            ComputeLL3Deltas(firstPass, UseReduceExtrapolate);
            RFXEncode.RFXEncoderWrapper.RLGREncode(firstPass.X, mode, out x);
            RFXEncode.RFXEncoderWrapper.RLGREncode(firstPass.Y, mode, out y);
            RFXEncode.RFXEncoderWrapper.RLGREncode(firstPass.Z, mode, out z);
            output.Add(new Triplet <byte[]>(x, y, z));

            // fake encodingContext used for SRL encode
            var encodingContext = new RfxProgressiveCodecContext(new [] { RdpegfxTileUtils.GetCodecQuant(ImageQuality_Values.Midium) }, 0, 0, 0, UseReduceExtrapolate);

            encodingContext.DAS = new DwtTile(firstPass.X, firstPass.Y, firstPass.Z);

            var progQuantList = new List <RFX_PROGRESSIVE_CODEC_QUANT>();

            foreach (var quant in proQuants.ProgQuants)
            {
                progQuantList.Add(Utility.ConvertProgQuant(quant));
            }

            // progressive pass
            for (int i = 1; i < input.Count; i++)
            {
                Triplet <short[]> progressivePass = input[i];
                encodingContext.ProgQ         = new DwtTile(progressivePass.X, progressivePass.Y, progressivePass.Z);
                encodingContext.prevProgQuant = progQuantList[i - 1];
                EncodedTile encodedTile = SRLEncode(encodingContext, progQuantList[i]);
                output.Add(new Triplet <byte[]>(encodedTile.YEncodedData, encodedTile.CbEncodedData, encodedTile.CrEncodedData));
                output.Add(new Triplet <byte[]>(encodedTile.YRawData, encodedTile.CbRawData, encodedTile.CrRawData));
                encodingContext.DAS.Add(new DwtTile(progressivePass.X, progressivePass.Y, progressivePass.Z));
                encodingContext.prevProgQuant = progQuantList[i];
            }
        }
        public static void SRLDecode(
            Triplet <byte[]> decodedData,
            Triplet <byte[]> rawData,
            QuantizationFactorsArray quant,
            Triplet <short[]> DAS,
            QuantizationFactorsArray preQuant,
            bool useReduceExtrapolate,
            out Triplet <short[]> output)
        {
            RFX_PROGRESSIVE_CODEC_QUANT progCodecQuant = Utility.ConvertProgQuant(quant);
            RFX_PROGRESSIVE_CODEC_QUANT preCodecQuant  = Utility.ConvertProgQuant(preQuant);
            // construct the fake parameter to invoke RfxProgressiveDecoder.SRLDecode
            var codecContext = new RfxProgressiveCodecContext(new[] { RdpegfxTileUtils.GetCodecQuant(ImageQuality_Values.Midium) }, 0, 0, 0, useReduceExtrapolate);
            var encodeTile   = new EncodedTile
            {
                YEncodedData         = decodedData.X,
                CbEncodedData        = decodedData.Y,
                CrEncodedData        = decodedData.Z,
                YRawData             = rawData.X,
                CbRawData            = rawData.Y,
                CrRawData            = rawData.Z,
                ProgCodecQuant       = progCodecQuant,
                UseReduceExtrapolate = useReduceExtrapolate // Important
            };
            var sentTile = new DwtTile(DAS.X, DAS.Y, DAS.Z);

            sentTile.ProgCodecQuant = preCodecQuant;
            var frame = new SurfaceFrame(0, RdpegfxTileUtils.TileSize, RdpegfxTileUtils.TileSize);

            frame.UpdateTileDwtQ(new TileIndex(0, 0, RdpegfxTileUtils.TileSize, RdpegfxTileUtils.TileSize), sentTile);
            frame.UpdateTriState(new TileIndex(0, 0, RdpegfxTileUtils.TileSize, RdpegfxTileUtils.TileSize), sentTile);
            var tileState = new TileState(frame, new TileIndex(0, 0, RdpegfxTileUtils.TileSize, RdpegfxTileUtils.TileSize));

            SRLDecode(codecContext, encodeTile, tileState);
            output = new Triplet <short[]>(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent);
        }