// 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 Decode()
        {
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

            Decode(obj);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        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));
        }
Ejemplo n.º 4
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 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 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));
        }
Ejemplo n.º 8
0
        public virtual ActionResult Recompute()
        {
            dynamic obj = CodecBaseController.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);

            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>(obj.Params.EntropyAlgorithm);
            }

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

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }