Exemplo n.º 1
0
        public virtual ActionResult DecodedImage()
        {
            string       decodeImage     = DateTime.Now.Ticks + ".bmp";
            ICodecAction restructedFrame = _codecAction.SubActions.LastOrDefault();

            if (restructedFrame.Result == null)
            {
                return(PartialView("_Image", null));
            }
            Tile   result = restructedFrame.Result.FirstOrDefault();
            Bitmap bitmap = result.GetBitmap();

            string decodedPath = Server.MapPath("~/Images/Decoded");

            if (!Directory.Exists(decodedPath))
            {
                Directory.CreateDirectory(decodedPath);
            }

            var path         = "~/Images/Decoded/" + decodeImage;
            var physicalPath = Server.MapPath(path);

            bitmap.Save(physicalPath, ImageFormat.Bmp);
            return(PartialView("_Image", path));
        }
        // This Action may cost much time. TODO: improve it
        public override ActionResult LayerPanel()
        {
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

            string name = JsonHelper.CastTo <string>(obj.name);

            var layers = new List <PanelViewModel>();
            // gets the action with the same name as the argument
            var action = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(name));

            if (action == null || action.Result == null)
            {
                return(PartialView("_Layers", layers));
            }

            layers = GenerateLayers(name, action.Result, false);
            // add UseDifferenceTile
            ICodecAction subbandDiffingAction = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_SUBBANDDIFFING));

            if (subbandDiffingAction != null)
            {
                var parameters  = new Dictionary <string, string>();
                var use_diffing = "False";
                if (action.Parameters.ContainsKey(Constants.PARAM_NAME_USE_DIFFERENCE_TILE) &&
                    action.Parameters[Constants.PARAM_NAME_USE_DIFFERENCE_TILE] is UseDifferenceTile &&
                    ((UseDifferenceTile)action.Parameters[Constants.PARAM_NAME_USE_DIFFERENCE_TILE]).Enabled)
                {
                    use_diffing = "True";
                }
                parameters.Add("use-diffing", use_diffing);
                ViewBag.Parameters = parameters;
            }

            return(PartialView("_Layers", layers));
        }
        public ActionResult DecodedImage(int layer)
        {
            var          CodecActionDic = (Dictionary <int, ICodecAction>)Session[ConstantCodecActionDic];
            ICodecAction action         = CodecActionDic == null ? null : (CodecActionDic.ContainsKey(layer) ? CodecActionDic[layer] : null);

            // TODO: Error Handler
            if (action == null)
            {
                return(null);
            }

            string decodedPath = Server.MapPath("~/Images/Decoded");

            if (!Directory.Exists(decodedPath))
            {
                Directory.CreateDirectory(decodedPath);
            }

            string       decodeImage     = DateTime.Now.Ticks + ".bmp";
            ICodecAction restructedFrame = action.SubActions.LastOrDefault();
            Tile         result          = restructedFrame.Result.FirstOrDefault();
            Bitmap       bitmap          = result.GetBitmap();
            var          path            = "~/Images/Decoded/" + decodeImage;
            var          physicalPath    = Server.MapPath(path);

            bitmap.Save(physicalPath, ImageFormat.Bmp);
            return(PartialView("_Image", path));
        }
        public ActionResult DecodedImage(int layer)
        {
            var          CodecActionDic = this.HttpContext.Session.Get <Dictionary <int, ICodecAction> >(ConstantCodecActionDic);
            ICodecAction action         = CodecActionDic == null ? null : (CodecActionDic.ContainsKey(layer) ? CodecActionDic[layer] : null);

            // TODO: Error Handler
            if (action == null)
            {
                return(null);
            }

            string       decodeImage     = DateTime.Now.Ticks + ".bmp";
            ICodecAction restructedFrame = action.SubActions.LastOrDefault();
            Tile         result          = restructedFrame.Result.FirstOrDefault();
            Bitmap       bitmap          = result.GetBitmap();

            string decodedPath = Path.Combine(this._hostingEnvironment.WebRootPath, "Images/Decoded");

            if (!Directory.Exists(decodedPath))
            {
                Directory.CreateDirectory(decodedPath);
            }

            var path = Path.Combine(decodedPath, decodeImage);

            bitmap.Save(path, ImageFormat.Bmp);
            return(PartialView("_Image", $"~/Images/Decoded/{decodeImage}"));
        }
Exemplo n.º 5
0
 protected void LoadFromSession()
 {
     if (Session != null)
     {
         if (Session[ActionKey] != null)
         {
             _codecAction = (ICodecAction)Session[ActionKey];
         }
         if (Session[ModelKey] != null)
         {
             _viewModel = (ICodecViewModel)Session[ModelKey];
         }
     }
 }
Exemplo n.º 6
0
        public async Task <IActionResult> Encode()
        {
            try
            {
                using (var bodyStream = new StreamReader(Request.Body))
                {
                    var bodyText = await bodyStream.ReadToEndAsync();

                    dynamic obj = JsonConvert.DeserializeObject(bodyText);

                    // retrieve the quant
                    var quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);
                    _codecAction.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;

                    // retrive the progressive quants
                    var progQuantList = new List <QuantizationFactorsArray>();
                    foreach (var layer in obj.Params.ProgQuantizationArray)
                    {
                        var layerQuants = JsonHelper.RetrieveQuantsArray(layer);
                        progQuantList.Add(layerQuants);
                    }
                    var progQuantarray = new ProgressiveQuantizationFactors
                    {
                        ProgQuants = progQuantList
                    };
                    _codecAction.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANT_LIST] = progQuantarray;

                    _codecAction.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]      = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);
                    _codecAction.Parameters[Constants.PARAM_NAME_USE_REDUCE_EXTRAPOLATE] = JsonHelper.CastTo <UseReduceExtrapolate>(obj.Params.UseReduceExtrapolate);

                    // TODO: error handle
                    var   preFramePath = this.HttpContext.Session.Get <string>(PreviousFrameImage);
                    Frame preFrame     = Utility.GetPreviousFrame(preFramePath, _codecAction.Parameters);

                    var encodeImagePath = this.HttpContext.Session.Get <string>(EncodedImage);
                    var tile            = Tile.FromFile(encodeImagePath);

                    ICodecAction diffing = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PENCODE_NAME_SUBBANDDIFFING));
                    diffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME] = preFrame;

                    _codecAction.DoAction(new[] { tile });
                }
                return(Json(ReturnResult <string> .Success("Success")));
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }
        public void TryRFXPEncode()
        {
            Tile tile = Tile.FromFile("D:\\Sandbox\\CodecInput\\test2.bmp");
            // Frame preFrame = GetPreviousFrame("D:\\Sandbox\\CodecInput\\test.bmp");

            Frame preFrame = null;

            var          rfxPEncode = new CodecToolSet.Core.RFXPEncode.RFXPEncode();
            ICodecAction diffing    = rfxPEncode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PENCODE_NAME_SUBBANDDIFFING));

            diffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME] = preFrame;
            Tile[] rfxPEncodeOut = rfxPEncode.DoAction(new[] { tile });
            for (int i = 0; i < rfxPEncodeOut.Length; i++)
            {
                rfxPEncodeOut[i].SaveToFile(String.Format(@"D:\TEMP\rfxPEncodeOut{0}.txt", i));
            }
        }
        public ActionResult Encode()
        {
            dynamic obj = GetJsonObject(Request.InputStream);

            // retrieve the quant
            var quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);

            _codecAction.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;

            // retrive the progressive quants
            var progQuantList = new List <QuantizationFactorsArray>();

            foreach (var layer in obj.Params.ProgQuantizationArray)
            {
                var layerQuants = JsonHelper.RetrieveQuantsArray(layer);
                progQuantList.Add(layerQuants);
            }
            var progQuantarray = new ProgressiveQuantizationFactors
            {
                ProgQuants = progQuantList
            };

            _codecAction.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANT_LIST] = progQuantarray;

            _codecAction.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]      = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);
            _codecAction.Parameters[Constants.PARAM_NAME_USE_REDUCE_EXTRAPOLATE] = JsonHelper.CastTo <UseReduceExtrapolate>(obj.Params.UseReduceExtrapolate);

            // TODO: error handle
            var   preFramePath = (string)Session[PreviousFrameImage];
            Frame preFrame     = Utility.GetPreviousFrame(preFramePath, _codecAction.Parameters);

            var encodeImagePath = (string)Session[EncodedImage];
            var tile            = Tile.FromFile(encodeImagePath);

            ICodecAction diffing = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PENCODE_NAME_SUBBANDDIFFING));

            diffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME] = preFrame;

            _codecAction.DoAction(new[] { tile });

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public virtual ActionResult DecodedImage()
        {
            string       decodeImage     = DateTime.Now.Ticks + ".bmp";
            ICodecAction restructedFrame = _codecAction.SubActions.LastOrDefault();

            if (restructedFrame.Result == null)
            {
                return(PartialView("_Image", null));
            }
            Tile   result = restructedFrame.Result.FirstOrDefault();
            Bitmap bitmap = result.GetBitmap();

            string decodedPath = Path.Combine(this._hostingEnvironment.WebRootPath, "Images/Decoded");

            if (!Directory.Exists(decodedPath))
            {
                Directory.CreateDirectory(decodedPath);
            }

            var path = Path.Combine(decodedPath, decodeImage);

            bitmap.Save(path, ImageFormat.Bmp);
            return(PartialView("_Image", $"~/Images/Decoded/{decodeImage}"));
        }
        protected void LoadFromSession()
        {
            _codecAction = HttpContext.Session.Get <ICodecAction>(ActionKey);

            _viewModel = HttpContext.Session.Get <ICodecViewModel>(ModelKey);
        }
        public override ActionResult Recompute()
        {
            // TODO: Add parameters obtain into a function
            dynamic obj = GetJsonObject(Request.InputStream);

            string name = JsonHelper.CastTo <string>(obj.Action);

            // gets the action with the same name as the argument
            var action = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(name));

            // if action not found
            if (action == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            // retrieve the quant
            var quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);

            _codecAction.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;

            // retrive the progressive quants
            var progQuantList = new List <QuantizationFactorsArray>();

            foreach (var layer in obj.Params.ProgQuantizationArray)
            {
                var layerQuants = JsonHelper.RetrieveQuantsArray(layer);
                progQuantList.Add(layerQuants);
            }
            var progQuantarray = new ProgressiveQuantizationFactors
            {
                ProgQuants = progQuantList
            };

            _codecAction.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANT_LIST] = progQuantarray;

            _codecAction.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]      = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);
            _codecAction.Parameters[Constants.PARAM_NAME_USE_REDUCE_EXTRAPOLATE] = JsonHelper.CastTo <UseReduceExtrapolate>(obj.Params.UseReduceExtrapolate);

            // TODO: error handle
            var   preFramePath = (string)Session[PreviousFrameImage];
            Frame preFrame     = Utility.GetPreviousFrame(preFramePath, _codecAction.Parameters);

            ICodecAction diffing = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PENCODE_NAME_SUBBANDDIFFING));

            diffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME] = preFrame;

            // retrive tiles from Inputs
            var tileList = new List <Tile>();

            foreach (var tileJson in obj.Inputs)
            {
                Triplet <string> triplet = JsonHelper.RetrieveTriplet(tileJson);

                string dataFormat = obj.Params.UseDataFormat;
                Tile   tile       = null;
                if (dataFormat.Equals(Constants.DataFormat.HEX))
                {
                    tile = Tile.FromStrings(triplet, new HexTileSerializer());
                }
                else
                {
                    tile = Tile.FromStrings(triplet, new IntegerTileSerializer());
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_11_5))
                {
                    tile.RightShift(5);
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_12_4))
                {
                    tile.RightShift(4);
                }

                tileList.Add(tile);
            }

            var result = action.DoAction(tileList.ToArray());

            // recompute the following steps and update
            bool following = false;

            Tile[] input = result;
            foreach (var act in _codecAction.SubActions)
            {
                if (following)
                {
                    result = act.DoAction(input);
                    input  = result;
                }
                else
                {
                    if (act.Name.Equals(name))
                    {
                        following = true;
                    }
                }
            }

            // TODO: recompute the following steps and update

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        private ICodecAction GetDecoderWithParameters(dynamic obj)
        {
            ICodecAction _rfxPDecode = new RFXPDecode();

            int layer = JsonHelper.CastTo <int>(obj.Layer);

            // retrieve the quant
            var quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);

            _rfxPDecode.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;

            // retrive the progressive quants
            var progQuantList = new List <QuantizationFactorsArray>();

            foreach (var layerQuant in obj.Params.ProgQuantizationArray)
            {
                var layerQuants = JsonHelper.RetrieveQuantsArray(layerQuant);
                progQuantList.Add(layerQuants);
            }
            var progQuantarray = new ProgressiveQuantizationFactors
            {
                ProgQuants = progQuantList
            };

            _rfxPDecode.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANT_LIST] = progQuantarray;

            _rfxPDecode.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]      = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);
            _rfxPDecode.Parameters[Constants.PARAM_NAME_USE_DIFFERENCE_TILE]    = JsonHelper.CastTo <UseDifferenceTile>(obj.Params.UseDifferenceTile);
            _rfxPDecode.Parameters[Constants.PARAM_NAME_USE_REDUCE_EXTRAPOLATE] = JsonHelper.CastTo <UseReduceExtrapolate>(obj.Params.UseReduceExtrapolate);

            if (layer == 0)
            {
                // Session used to store DAS and previous codec
                Tile DAS = Tile.FromArrays <short>(new Triplet <short[]>(
                                                       new short[Tile.TileSize * Tile.TileSize],
                                                       new short[Tile.TileSize * Tile.TileSize],
                                                       new short[Tile.TileSize * Tile.TileSize])
                                                   );
                Dictionary <int, ICodecAction> CodecActionDic = new Dictionary <int, ICodecAction>();
                Session[ConstantDAS]            = DAS;
                Session[ConstantCodecActionDic] = CodecActionDic;
                Session[ConstantDASDic]         = new Dictionary <int, Tile>();

                // TODO: error handle
                var   preFramePath = (string)Session[PreviousFrameImage];
                Frame preFrame     = Utility.GetPreviousFrame(preFramePath, _rfxPDecode.Parameters);
                Session[DecodePreviousFrame] = preFrame;
                Session[PreviousFrameDic]    = new Dictionary <int, Frame>();
            }

            // TODO: deal with null
            // Add current codecAction in the session
            Dictionary <int, ICodecAction> SessionCodecActionDic = (Dictionary <int, ICodecAction>)Session[ConstantCodecActionDic];

            SessionCodecActionDic[layer] = _rfxPDecode;

            var          EncodeType    = layer == 0 ? CodecToolSet.Core.EncodedTileType.EncodedType.FirstPass : CodecToolSet.Core.EncodedTileType.EncodedType.UpgradePass;
            ICodecAction rlgrSRLDecode = _rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_RLGRSRLDECODE));

            rlgrSRLDecode.Parameters[Constants.PARAM_NAME_ENCODED_TILE_TYPE] = new CodecToolSet.Core.EncodedTileType {
                Type = EncodeType
            };

            QuantizationFactorsArray progQuant          = progQuantarray.ProgQuants[layer];
            ICodecAction             progDeQuantization = _rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_PROGRESSIVEDEQUANTIZATION));

            progDeQuantization.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANTS] = progQuant;

            ICodecAction subbandDiffing = _rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_SUBBANDDIFFING));
            Frame        preframe       = (Frame)Session[DecodePreviousFrame];

            subbandDiffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME]    = preframe;
            subbandDiffing.Parameters[Constants.PARAM_NAME_ENCODED_TILE_TYPE] = new CodecToolSet.Core.EncodedTileType {
                Type = EncodeType
            };

            ICodecAction DeQuantization = _rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_DEQUANTIZATION));

            // deal with some intermediate parameters
            if (layer >= 1)
            {
                rlgrSRLDecode.Parameters[Constants.PARAM_NAME_DAS] = new Frame {
                    Tile = (Tile)Session[ConstantDAS]
                };
                rlgrSRLDecode.Parameters[Constants.PARAM_NAME_PREVIOUS_PROGRESSIVE_QUANTS] = progQuantarray.ProgQuants[layer - 1];
                rlgrSRLDecode.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANTS]          = progQuantarray.ProgQuants[layer];
            }

            return(_rfxPDecode);
        }
        // TODO: it not correct to put it here.
        private void Decode(dynamic obj)
        {
            int layer = JsonHelper.CastTo <int>(obj.Layer);

            ICodecAction _rfxPDecode = GetDecoderWithParameters(obj);

            string decOrHex = (string)obj.Params.DecOrHex;

            if (layer >= 1)
            {
                Tile tile    = null;
                Tile tileRaw = null;

                if (decOrHex.Equals("hex"))
                {
                    tile = Tile.FromStrings(new Triplet <string>(
                                                obj.Inputs[0], obj.Inputs[2], obj.Inputs[4]),
                                            new HexTileSerializer());

                    tileRaw = Tile.FromStrings(new Triplet <string>(
                                                   obj.Inputs[1], obj.Inputs[3], obj.Inputs[5]),
                                               new HexTileSerializer());
                }
                else
                {
                    tile = Tile.FromStrings(new Triplet <string>(
                                                obj.Inputs[0], obj.Inputs[2], obj.Inputs[4]),
                                            new IntegerTileSerializer());

                    tileRaw = Tile.FromStrings(new Triplet <string>(
                                                   obj.Inputs[1], obj.Inputs[3], obj.Inputs[5]),
                                               new IntegerTileSerializer());
                }

                _rfxPDecode.DoAction(new[] { tile, tileRaw });
            }
            else
            {
                Tile tile = null;
                if (decOrHex.Equals("hex"))
                {
                    tile = Tile.FromStrings(new Triplet <string>(
                                                obj.Inputs[0], obj.Inputs[1], obj.Inputs[2]),
                                            new HexTileSerializer());
                }
                else
                {
                    tile = Tile.FromStrings(new Triplet <string>(
                                                obj.Inputs[0], obj.Inputs[1], obj.Inputs[2]),
                                            new IntegerTileSerializer());
                }

                _rfxPDecode.DoAction(new[] { tile });
            }

            // Update DAS
            ICodecAction           rlgrSRLDecode = _rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_RLGRSRLDECODE));
            Dictionary <int, Tile> dasDic        = (Dictionary <int, Tile>)Session[ConstantDASDic];

            dasDic[layer] = rlgrSRLDecode.Result.FirstOrDefault();

            // Update PreFrame
            ICodecAction            subbandDiffing = _rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_SUBBANDDIFFING));
            Dictionary <int, Frame> preFrameDic    = (Dictionary <int, Frame>)Session[PreviousFrameDic];

            preFrameDic[layer] = new Frame {
                Tile = subbandDiffing.Result.FirstOrDefault()
            };
        }
        public override ActionResult Recompute()
        {
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

            int layer = JsonHelper.CastTo <int>(obj.Layer);

            ICodecAction _rfxDecode = GetDecoderWithParameters(obj);

            string name = JsonHelper.CastTo <string>(obj.Action);

            // gets the action with the same name as the argument
            var action = _rfxDecode.SubActions.SingleOrDefault(c => c.Name.Equals(name));

            // if action not found
            if (action == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            // retrive tiles from Inputs
            var tileList = new List <Tile>();

            foreach (var tileJson in obj.Inputs)
            {
                Triplet <string> triplet = JsonHelper.RetrieveTriplet(tileJson);

                string dataFormat = obj.Params.UseDataFormat;
                Tile   tile       = null;
                if (dataFormat.Equals(Constants.DataFormat.HEX))
                {
                    tile = Tile.FromStrings(triplet, new HexTileSerializer());
                }
                else
                {
                    tile = Tile.FromStrings(triplet, new IntegerTileSerializer());
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_11_5))
                {
                    tile.RightShift(5);
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_12_4))
                {
                    tile.RightShift(4);
                }

                tileList.Add(tile);
            }

            // hand over parameters
            foreach (var key in _rfxDecode.Parameters.Keys)
            {
                action.Parameters[key] = _rfxDecode.Parameters[key];
            }

            var result = action.DoAction(tileList.ToArray());

            // recompute the following steps and update
            bool following = false;

            Tile[] input = result;
            foreach (var act in _rfxDecode.SubActions)
            {
                if (following)
                {
                    // hand over parameters
                    foreach (var key in _rfxDecode.Parameters.Keys)
                    {
                        act.Parameters[key] = _rfxDecode.Parameters[key];
                    }
                    result = act.DoAction(input);
                    input  = result;
                }
                else
                {
                    if (act.Name.Equals(name))
                    {
                        following = true;
                    }
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public void TryRFXPDecode()
        {
            var rfxPDecode = new CodecToolSet.Core.RFXPDecode.RFXPDecode();

            //Frame preFrame = GetPreviousFrame("D:\\Sandbox\\CodecInput\\test.bmp");
            Frame preFrame = null;
            Tile  DAS      = Tile.FromArrays <short>(new Triplet <short[]>(new short[RdpegfxTileUtils.TileSize * RdpegfxTileUtils.TileSize], new short[RdpegfxTileUtils.TileSize * RdpegfxTileUtils.TileSize], new short[RdpegfxTileUtils.TileSize * RdpegfxTileUtils.TileSize]));

            // fisrt pass
            Tile fisrtPass = ReadTileFromFile(@"D:\TEMP\rfxPEncodeOut0.txt");

            ICodecAction rlgrSRLDecode = rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_RLGRSRLDECODE));

            rlgrSRLDecode.Parameters[Constants.PARAM_NAME_ENCODED_TILE_TYPE] = new CodecToolSet.Core.EncodedTileType {
                Type = CodecToolSet.Core.EncodedTileType.EncodedType.FirstPass
            };

            QuantizationFactorsArray quant = GetProgQuantizationFactorsForChunk(ProgressiveChunk_Values.kChunk_25);
            ICodecAction             progDeQuantization = rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_PROGRESSIVEDEQUANTIZATION));

            progDeQuantization.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANTS] = quant;

            ICodecAction subbandDiffing = rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_SUBBANDDIFFING));

            subbandDiffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME]    = preFrame;
            subbandDiffing.Parameters[Constants.PARAM_NAME_ENCODED_TILE_TYPE] = new CodecToolSet.Core.EncodedTileType {
                Type = CodecToolSet.Core.EncodedTileType.EncodedType.FirstPass
            };

            ICodecAction             DeQuantization = rfxPDecode.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PDECODE_NAME_DEQUANTIZATION));
            QuantizationFactorsArray quantArray     = new QuantizationFactorsArray();

            quantArray.quants = new QuantizationFactors[3] {
                DEFAULT_QUANT, DEFAULT_QUANT, DEFAULT_QUANT
            };
            DeQuantization.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;

            Tile[] rgbImage = rfxPDecode.DoAction(new[] { fisrtPass });
            rgbImage.FirstOrDefault().GetBitmap().Save("D:\\TEMP\\rfxPDecode0.bmp");

            DAS.Add(rlgrSRLDecode.Result.FirstOrDefault());
            preFrame = new Frame {
                Tile = subbandDiffing.Result.FirstOrDefault()
            };

            ProgressiveChunk_Values[] chunks = new[] { ProgressiveChunk_Values.kChunk_25, ProgressiveChunk_Values.kChunk_50, ProgressiveChunk_Values.kChunk_75, ProgressiveChunk_Values.kChunk_100 };

            for (int i = 1; i < chunks.Length; i++)
            {
                rlgrSRLDecode.Parameters[Constants.PARAM_NAME_ENCODED_TILE_TYPE] = new CodecToolSet.Core.EncodedTileType {
                    Type = CodecToolSet.Core.EncodedTileType.EncodedType.UpgradePass
                };
                subbandDiffing.Parameters[Constants.PARAM_NAME_ENCODED_TILE_TYPE] = new CodecToolSet.Core.EncodedTileType {
                    Type = CodecToolSet.Core.EncodedTileType.EncodedType.UpgradePass
                };
                subbandDiffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME] = preFrame;
                rlgrSRLDecode.Parameters[Constants.PARAM_NAME_DAS]             = new Frame {
                    Tile = DAS
                };
                rlgrSRLDecode.Parameters[Constants.PARAM_NAME_PREVIOUS_PROGRESSIVE_QUANTS] = GetProgQuantizationFactorsForChunk(chunks[i - 1]);
                rlgrSRLDecode.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANTS]          = GetProgQuantizationFactorsForChunk(chunks[i]);
                quant = GetProgQuantizationFactorsForChunk(chunks[i]);
                progDeQuantization.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANTS] = quant;

                Tile encodedTile = ReadTileFromFile(String.Format(@"D:\TEMP\rfxPEncodeOut{0}.txt", i * 2 - 1));
                Tile rawTile     = ReadTileFromFile(String.Format(@"D:\TEMP\rfxPEncodeOut{0}.txt", i * 2));

                rgbImage = rfxPDecode.DoAction(new[] { encodedTile, rawTile });
                rgbImage.FirstOrDefault().GetBitmap().Save(String.Format("D:\\TEMP\\rfxPDecode{0}.bmp", i));

                DAS.Add(rlgrSRLDecode.Result.FirstOrDefault());
                preFrame = new Frame {
                    Tile = subbandDiffing.Result.FirstOrDefault()
                };
            }
        }