public virtual ActionResult InputPanel([FromBody] LayerPanelRequest request)
        {
            var layers = new List <PanelViewModel>();

            try
            {
                // gets the action with the same name as the argument
                var action = _codecAction.SubActions.FirstOrDefault(c => c.Name.Equals(request.name));
                if (action == null || action.Input == null)
                {
                    return(PartialView("_Layers", layers));
                }

                for (int index = 0; index < action.Input.Length; index++)
                {
                    string           idPrefix = request.name.Replace(' ', '-').Replace('/', '-') + "-input-layer-" + index;
                    var              layer    = new PanelViewModel(idPrefix, "Layer " + index);
                    Tile             result   = action.Input[index];
                    Triplet <string> triplet  = result.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
                    };
                    layer.Tabs = new List <TabViewModel> {
                        tabx, taby, tabz
                    };
                    layers.Add(layer);
                }
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }

            return(PartialView("_Layers", layers));
        }
        public ActionResult Upload(IFormFile file, string imageType)
        {
            if (this.Request.Form.Files.Count > 1)
            {
                return(Json(ReturnResult <string> .Fail("Please upload 1 image each time.")));
            }
            // file type
            if (file != null && file.Length > 0)
            {
                string[] filenames = file.FileName.Split(new[] { '.' });
                string   filename  = String.Format("{0}_{1}.{2}", filenames[0], DateTime.Now.Ticks, filenames.Length >= 2 ? filenames[1] : "");

                string uploadPath = Path.Combine(this._hostingEnvironment.WebRootPath, ActionHelper.ImageUploadFolder);
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }

                var path = Path.Combine(uploadPath, filename);

                using (var fileStream = file.OpenReadStream())
                {
                    using (var newfileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        fileStream.CopyTo(newfileStream);
                    }
                }

                if (imageType.Equals(EncodedImage))
                {
                    this.HttpContext.Session.SetObject(EncodedImage, path);
                }
                else if (imageType.Equals(PreviousFrameImage))
                {
                    this.HttpContext.Session.SetObject(PreviousFrameImage, path);
                }
            }
            return(Json(ReturnResult <string> .Success("Success")));
        }
Esempio n. 3
0
        public IActionResult Save([FromBody] GuestBookRequestModel request)
        {
            try
            {
                if (string.IsNullOrEmpty(request.email) || string.IsNullOrEmpty(request.message))
                {
                    return(Json(ReturnResult <string> .Fail("Reqeust data is invalide")));
                }

                string guestbookPath = Path.Combine(this._hostingEnvironment.WebRootPath, "GuestBook");
                if (!Directory.Exists(guestbookPath))
                {
                    Directory.CreateDirectory(guestbookPath);
                }
                string guestbook = Path.Combine(guestbookPath, "gb-7E96D408-835C-474B-AED5-0214B3709DFB.txt");
                if (!System.IO.File.Exists(guestbook))
                {
                    System.IO.File.CreateText(guestbook).Close();
                }
                using (var writer = new StreamWriter(guestbook, true))
                {
                    writer.WriteLine("{");
                    writer.WriteLine("Email: " + request.email);
                    writer.WriteLine("Message:");
                    writer.WriteLine(request.message);
                    writer.WriteLine("}");
                    writer.WriteLine();
                    writer.WriteLine();
                }
                return(Json(ReturnResult <string> .Success("Success")));
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }
        public async Task <IActionResult> UpdateDecodeStatus(int layer)
        {
            try
            {
                Dictionary <int, Tile> dasDic = this.HttpContext.Session.Get <Dictionary <int, Tile> >(ConstantDASDic);

                if (dasDic.ContainsKey(layer))
                {
                    this.HttpContext.Session.Get <Tile>(ConstantDAS).Add(dasDic[layer]);
                }

                Dictionary <int, Frame> preFrameDic = this.HttpContext.Session.Get <Dictionary <int, Frame> >(PreviousFrameDic);
                if (preFrameDic.ContainsKey(layer))
                {
                    this.HttpContext.Session.SetObject(DecodePreviousFrame, preFrameDic[layer]);
                }

                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")));
        }
Esempio n. 6
0
        public override ActionResult Recompute([FromBody] RecomputeRequest request)
        {
            // TODO: Add parameters obtain into a function
            string name = JsonHelper.CastTo <string>(request.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(Json(ReturnResult <string> .Fail("Action not found")));
            }

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

            _codecAction.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;

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

            foreach (var layer in request.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>(request.Params.EntropyAlgorithm);
            _codecAction.Parameters[Constants.PARAM_NAME_USE_REDUCE_EXTRAPOLATE] = JsonHelper.CastTo <UseReduceExtrapolate>(request.Params.UseReduceExtrapolate);

            // TODO: error handle
            var   preFramePath = this.HttpContext.Session.Get <string>(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 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.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(Json(ReturnResult <string> .Success("Success")));
        }
        public override ActionResult Recompute([FromBody] RecomputeRequest request)
        {
            //dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

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

            ICodecAction _rfxDecode = GetDecoderWithParameters(request);

            string name = JsonHelper.CastTo <string>(request.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(Json(ReturnResult <string> .Fail("Action not found")));
            }

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

            // 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(Json(ReturnResult <string> .Success("Success")));
        }
        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 override ActionResult InputPanel([FromBody] LayerPanelRequest request)
        {
            // TODO: Extract Common with function Panel
            var layersGroup = new List <PanelViewModel>();

            try
            {
                var CodecActionDic = this.HttpContext.Session.Get <Dictionary <int, ICodecAction> >(ConstantCodecActionDic);
                _codecAction = CodecActionDic == null ? null : (CodecActionDic.ContainsKey(request.layer) ? CodecActionDic[request.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(request.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   = request.name.Replace(' ', '-').Replace('/', '-') + "-output-layer-" + request.layer;
                var    layerPanel = new PanelViewModel(idPrefix, "Layer " + request.layer);
                if (action.Input.Length > 1 && request.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);
                }
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }

            return(PartialView("_Layers", layersGroup));
        }