public ActionResult Decode()
        {
            dynamic obj = GetJsonObject(Request.InputStream);

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

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

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

            Tile tile = null;

            if (decOrHex.Equals("hex"))
            {
                tile = Tile.FromStrings(new Triplet <string>(
                                            obj.Inputs.Y, obj.Inputs.Cb, obj.Inputs.Cr),
                                        new HexTileSerializer());
            }
            else
            {
                tile = Tile.FromStrings(new Triplet <string>(
                                            obj.Inputs.Y, obj.Inputs.Cb, obj.Inputs.Cr),
                                        new IntegerTileSerializer());
            }
            _codecAction.DoAction(tile);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        /// <summary>
        /// return an index page according to the inputs
        /// </summary>
        /// <returns></returns>
        public ActionResult IndexWithInputs()
        {
            dynamic obj = GetJsonObject(Request.InputStream);

            // retrieve the quant
            QuantizationFactorsArray quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);
            EntropyAlgorithm         algorithm  = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);


            _viewModel = new RFXDecodeViewModel();
            // Updates parameters
            ((RFXDecodeViewModel)_viewModel).ProvideParam(quantArray, algorithm);
            Triplet <string> triplet = JsonHelper.RetrieveTriplet(obj.Inputs);

            ((RFXDecodeViewModel)_viewModel).ProvidePanelInputs(triplet.ToArray());

            var envValues = new Dictionary <string, object>()
            {
                { ModelKey, _viewModel },
                { isModelValid, true }
            };

            SaveToSession(envValues);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public async Task <IActionResult> IndexWithInputs()
        {
            try
            {
                using (var bodyStream = new StreamReader(Request.Body))
                {
                    var bodyText = await bodyStream.ReadToEndAsync();

                    dynamic obj = JsonConvert.DeserializeObject(bodyText);

                    // retrieve the quant
                    QuantizationFactorsArray quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);
                    EntropyAlgorithm         algorithm  = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);

                    _viewModel = new RFXDecodeViewModel();
                    // Updates parameters
                    ((RFXDecodeViewModel)_viewModel).ProvideParam(quantArray, algorithm);
                    Triplet <string> triplet = JsonHelper.RetrieveTriplet(obj.Inputs);
                    ((RFXDecodeViewModel)_viewModel).ProvidePanelInputs(triplet.ToArray());

                    var envValues = new Dictionary <string, object>()
                    {
                        { ModelKey, _viewModel },
                        { isModelValid, true }
                    };

                    SaveToSession(envValues);
                }
                return(Json(ReturnResult <string> .Success("Success")));
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }
        // 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 override ActionResult LayerPanel()
        {
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

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

            var layersGroup = new List <PanelViewModel>();

            var CodecActionDic = (Dictionary <int, ICodecAction>)Session[ConstantCodecActionDic];

            _codecAction = CodecActionDic == null ? null : (CodecActionDic.ContainsKey(layer) ? CodecActionDic[layer] : null);

            if (_codecAction == null)
            {
                return(PartialView("_Layers", layersGroup));
            }

            if (name.Equals(Constants.DECODE_NAME_RECONSTRUCTEDFRAME))
            {
                return(DecodedImage(layer));
            }

            // 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", layersGroup));
            }

            // create layers accroding to the given layer.
            // This is different with others
            string           idPrefix   = name.Replace(' ', '-').Replace('/', '-') + "-input-layer-" + layer;
            var              layerPanel = new PanelViewModel(idPrefix, "Layer " + layer);
            Tile             result     = action.Result.FirstOrDefault();
            Triplet <string> triplet    = result.GetStrings(TileSerializerFactory.GetDefaultSerizlizer());
            var              tabx       = new TabViewModel {
                Id = idPrefix + "-Y", Title = "Y", Content = triplet.X, Editable = false
            };
            var taby = new TabViewModel {
                Id = idPrefix + "-Cb", Title = "Cb", Content = triplet.Y, Editable = false
            };
            var tabz = new TabViewModel {
                Id = idPrefix + "-Cr", Title = "Cr", Content = triplet.Z, Editable = false
            };

            layerPanel.Tabs = new List <TabViewModel> {
                tabx, taby, tabz
            };
            layersGroup.Add(layerPanel);

            return(PartialView("_Layers", layersGroup));
        }
        public static QuantizationFactorsArray RetrieveQuantsArray(dynamic obj)
        {
            var quantList = new List <QuantizationFactors>();

            foreach (var componet in obj)
            {
                var quant = JsonHelper.CastTo <QuantizationFactors>(componet);
                quantList.Add(quant);
            }
            var quantArray = new QuantizationFactorsArray
            {
                quants = quantList.ToArray()
            };

            return(quantArray);
        }
        public ActionResult IndexWithInputs()
        {
            dynamic obj = GetJsonObject(Request.InputStream);

            foreach (var input in obj)
            {
                // TODO: refine this
                if (input != null && input.Inputs != null)
                {
                    int layer = JsonHelper.CastTo <int>(input.Layer);
                    if (layer == 0)
                    {
                        // TODO: refine this
                        // retrieve the quant
                        var quantArray = JsonHelper.RetrieveQuantsArray(input.Params.QuantizationFactorsArray);
                        // retrive the progressive quants
                        var progQuantList = new List <QuantizationFactorsArray>();
                        foreach (var layerQuant in input.Params.ProgQuantizationArray)
                        {
                            var layerQuants = JsonHelper.RetrieveQuantsArray(layerQuant);
                            progQuantList.Add(layerQuants);
                        }
                        var progQuantarray = new ProgressiveQuantizationFactors
                        {
                            ProgQuants = progQuantList
                        };

                        EntropyAlgorithm     algorithm            = JsonHelper.CastTo <EntropyAlgorithm>(input.Params.EntropyAlgorithm);
                        UseDifferenceTile    useDifferenceTile    = JsonHelper.CastTo <UseDifferenceTile>(input.Params.UseDifferenceTile);
                        UseReduceExtrapolate useReduceExtrapolate = JsonHelper.CastTo <UseReduceExtrapolate>(input.Params.UseReduceExtrapolate);

                        _viewModel = new RFXPDecodeViewModel(0);
                        ((RFXPDecodeViewModel)_viewModel).ProvideParam(quantArray, progQuantarray, algorithm, useDifferenceTile, useReduceExtrapolate);
                        ((RFXPDecodeViewModel)_viewModel).ProvidePanelInputs(layer, input.Inputs[0], input.Inputs[1], input.Inputs[2]);

                        Session[ModelKey]        = _viewModel;
                        Session[isPreFrameValid] = true;
                    }
                    Decode(input);
                    // Updates Decode Status
                    UpdateDecodeStatus(layer);
                }
            }
            Session[IsValid] = true;
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
예제 #8
0
        public override ActionResult InputPanel([FromBody] LayerPanelRequest request)
        {
            string name = JsonHelper.CastTo <string>(request.name);

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

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

            layers = GenerateLayers(name, action.Input, true);

            return(PartialView("_Layers", layers));
        }
예제 #9
0
        public virtual ActionResult LayerPanel()
        {
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

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

            if (name.Equals(Constants.DECODE_NAME_RECONSTRUCTEDFRAME))
            {
                return(DecodedImage());
            }

            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));
            }

            for (int index = 0; index < action.Result.Length; index++)
            {
                string           idPrefix = name.Replace(' ', '-') + "-layer-" + index;
                var              layer    = new PanelViewModel(idPrefix, "Layer " + index);
                Tile             result   = action.Result[index];
                Triplet <string> triplet  = result.GetStrings(TileSerializerFactory.GetDefaultSerizlizer());
                var              tabx     = new TabViewModel {
                    Id = idPrefix + "-Y", Title = "Y", Content = triplet.X, Editable = false
                };
                var taby = new TabViewModel {
                    Id = idPrefix + "-Cb", Title = "Cb", Content = triplet.Y, Editable = false
                };
                var tabz = new TabViewModel {
                    Id = idPrefix + "-Cr", Title = "Cr", Content = triplet.Z, Editable = false
                };
                layer.Tabs = new List <TabViewModel> {
                    tabx, taby, tabz
                };
                layers.Add(layer);
            }

            return(PartialView("_Layers", layers));
        }
        public override ActionResult InputPanel()
        {
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

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

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

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

            layers = GenerateLayers(name, action.Input, true);

            return(PartialView("_Layers", layers));
        }
        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 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;

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



            // TODO: error handle
            var encodeImagePath = (string)Session[EncodedImage];
            var tile            = Tile.FromFile(encodeImagePath);

            _codecAction.DoAction(tile);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        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));
        }
        public async Task <IActionResult> Decode()
        {
            try
            {
                using (var bodyStream = new StreamReader(Request.Body))
                {
                    var bodyText = await bodyStream.ReadToEndAsync();

                    dynamic obj = (JObject)JsonConvert.DeserializeObject(bodyText);

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

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

                    Tile    tile       = null;
                    JObject jsonInputs = JObject.Parse(obj["Inputs"].ToString());
                    dynamic objInputs  = JsonConvert.DeserializeObject(jsonInputs.ToString());
                    string  y          = jsonInputs["Y"].ToString();
                    string  cb         = jsonInputs["Cb"].ToString();
                    string  cr         = jsonInputs["Cr"].ToString();

                    if (decOrHex.Equals("hex"))
                    {
                        tile = Tile.FromStrings(new Triplet <string>(y, cb, cr),
                                                new HexTileSerializer());
                    }
                    else
                    {
                        tile = Tile.FromStrings(new Triplet <string>(y, cb, cr),
                                                new IntegerTileSerializer());
                    }
                    _codecAction.DoAction(tile);

                    return(Json(ReturnResult <string> .Success("Success")));
                }
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }
        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 async Task <IActionResult> IndexWithInputs()
        {
            try
            {
                using (var bodyStream = new StreamReader(Request.Body))
                {
                    var bodyText = await bodyStream.ReadToEndAsync();

                    dynamic obj = JsonConvert.DeserializeObject(bodyText);

                    foreach (var input in obj)
                    {
                        // TODO: refine this
                        if (input != null && input.Inputs != null)
                        {
                            int layer = JsonHelper.CastTo <int>(input.Layer);
                            if (layer == 0)
                            {
                                // TODO: refine this
                                // retrieve the quant
                                var quantArray = JsonHelper.RetrieveQuantsArray(input.Params.QuantizationFactorsArray);
                                // retrive the progressive quants
                                var progQuantList = new List <QuantizationFactorsArray>();
                                foreach (var layerQuant in input.Params.ProgQuantizationArray)
                                {
                                    var layerQuants = JsonHelper.RetrieveQuantsArray(layerQuant);
                                    progQuantList.Add(layerQuants);
                                }
                                var progQuantarray = new ProgressiveQuantizationFactors
                                {
                                    ProgQuants = progQuantList
                                };

                                EntropyAlgorithm     algorithm            = JsonHelper.CastTo <EntropyAlgorithm>(input.Params.EntropyAlgorithm);
                                UseDifferenceTile    useDifferenceTile    = JsonHelper.CastTo <UseDifferenceTile>(input.Params.UseDifferenceTile);
                                UseReduceExtrapolate useReduceExtrapolate = JsonHelper.CastTo <UseReduceExtrapolate>(input.Params.UseReduceExtrapolate);

                                _viewModel = new RFXPDecodeViewModel(0);
                                ((RFXPDecodeViewModel)_viewModel).ProvideParam(quantArray, progQuantarray, algorithm, useDifferenceTile, useReduceExtrapolate);

                                JArray jsonInputs = JArray.Parse(input["Inputs"].ToString());
                                ((RFXPDecodeViewModel)_viewModel).ProvidePanelInputs(layer, jsonInputs[0].TrimEnter(), jsonInputs[1].TrimEnter(), jsonInputs[2].TrimEnter());

                                this.HttpContext.Session.SetObject(ModelKey, _viewModel);
                                this.HttpContext.Session.SetObject(isPreFrameValid, true);
                            }

                            Decode(input);
                            // Updates Decode Status
                            await UpdateDecodeStatus(layer);
                        }
                    }
                }

                this.HttpContext.Session.SetObject(IsValid, true);
                return(Json(ReturnResult <string> .Success("Success")));
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }
        public virtual ActionResult Recompute([FromBody] RecomputeRequest request)
        {
            // gets the action with the same name as the argument
            var action = _codecAction.SubActions.FirstOrDefault(c => c.Name.Equals(request.Action));

            // if action not found
            if (action == null)
            {
                return(Json(ReturnResult <string> .Fail("Action not found")));
            }

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

            foreach (var _action in _codecAction.SubActions)
            {
                _action.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;
                _action.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]   = JsonHelper.CastTo <EntropyAlgorithm>(request.Params.EntropyAlgorithm);
            }

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

            foreach (var tileJson in request.Inputs)
            {
                Triplet <string> triplet    = JsonHelper.RetrieveTriplet(tileJson);
                string           dataFormat = request.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.FirstOrDefault());

            // 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(request.Action))
                    {
                        following = true;
                    }
                }
            }

            return(Json(ReturnResult <string> .Success("Success")));
        }
        public override ActionResult InputPanel()
        {
            // TODO: Extract Common with function Panel
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

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

            var layersGroup = new List <PanelViewModel>();

            var CodecActionDic = (Dictionary <int, ICodecAction>)Session[ConstantCodecActionDic];

            _codecAction = CodecActionDic == null ? null : (CodecActionDic.ContainsKey(layer) ? CodecActionDic[layer] : null);

            if (_codecAction == null)
            {
                return(PartialView("_Layers", layersGroup));
            }

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

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

            // create layers accroding to the given layer.
            // This is different with others
            string idPrefix   = name.Replace(' ', '-').Replace('/', '-') + "-output-layer-" + layer;
            var    layerPanel = new PanelViewModel(idPrefix, "Layer " + layer);

            if (action.Input.Length > 1 && layer > 0)
            {
                Tile             input      = action.Input[0];
                Tile             rawInput   = action.Input[1];
                Triplet <string> triplet    = input.GetStrings(TileSerializerFactory.GetDefaultSerizlizer());
                Triplet <string> rawTriplet = rawInput.GetStrings(TileSerializerFactory.GetDefaultSerizlizer());
                var tabx = new TabViewModel {
                    Id = idPrefix + "-Y", Title = "Y", Content = triplet.X, Editable = true
                };
                var tabrawx = new TabViewModel {
                    Id = idPrefix + "-YRaw", Title = "Y Raw Data", Content = rawTriplet.X, Editable = true
                };
                var taby = new TabViewModel {
                    Id = idPrefix + "-Cb", Title = "Cb", Content = triplet.Y, Editable = true
                };
                var tabrawy = new TabViewModel {
                    Id = idPrefix + "-CbRaw", Title = "Cb Raw Data", Content = rawTriplet.Y, Editable = true
                };
                var tabz = new TabViewModel {
                    Id = idPrefix + "-Cr", Title = "Cr", Content = triplet.Z, Editable = true
                };
                var tabrawz = new TabViewModel {
                    Id = idPrefix + "-CrRaw", Title = "Cr Raw Data", Content = rawTriplet.Z, Editable = true
                };

                layerPanel.Tabs = new List <TabViewModel> {
                    tabx, tabrawx, taby, tabrawy, tabz, tabrawz
                };
                layersGroup.Add(layerPanel);
            }
            else
            {
                Tile             input   = action.Input.FirstOrDefault();
                Triplet <string> triplet = input.GetStrings(TileSerializerFactory.GetDefaultSerizlizer());
                var tabx = new TabViewModel {
                    Id = idPrefix + "-Y", Title = "Y", Content = triplet.X, Editable = true
                };
                var taby = new TabViewModel {
                    Id = idPrefix + "-Cb", Title = "Cb", Content = triplet.Y, Editable = true
                };
                var tabz = new TabViewModel {
                    Id = idPrefix + "-Cr", Title = "Cr", Content = triplet.Z, Editable = true
                };
                layerPanel.Tabs = new List <TabViewModel> {
                    tabx, taby, tabz
                };
                layersGroup.Add(layerPanel);
            }

            return(PartialView("_Layers", layersGroup));
        }
예제 #20
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 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));
        }
예제 #22
0
        public async Task <IActionResult> Encode()
        {
            try
            {
                using (var bodyStream = new StreamReader(Request.Body))
                {
                    var bodyText = await bodyStream.ReadToEndAsync();

                    dynamic obj        = JsonConvert.DeserializeObject(bodyText);
                    var     quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);
                    _codecAction.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;
                    _codecAction.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]   = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);

                    // TODO: error handle
                    var encodeImagePath = this.HttpContext.Session.Get <string>(EncodedImage);
                    if (string.IsNullOrEmpty(encodeImagePath))
                    {
                        throw new FileNotFoundException("No image found, image size should less than 1MB, please check and try again.");
                    }
                    var tile = Tile.FromFile(encodeImagePath);

                    _codecAction.DoAction(tile);

                    return(Json(ReturnResult <string> .Success("Success")));
                }
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }