Beispiel #1
0
        public static     SalientArea[] FromQuery(ResizeSettings s)
        {
            var salientareas = s.GetList <float>("c.salientareas", null);

            if (salientareas != null)
            {
                if (salientareas.Length % 5 != 0)
                {
                    throw new ImageProcessingException(400,
                                                       "Incorrect number of values provided in c.salientareas (must be multiple of 5). Usage: &c.salientareas=x1,y1,x2,y2,weight,x1,y1,x2,y2,weight");
                }

                return(salientareas.ToList()
                       .SplitList(5)
                       .Select(v => new SalientArea {
                    Area = new RectangleF(v[0], v[1], v[2] - v[0], v[3] - v[1]),
                    Weight = v[4]
                })
                       .ToArray());
            }

            var focus = s.GetList <float>("c.focus", null);

            if (focus != null && focus.Length == 2)
            {
                return(new[] { new SalientArea {
                                   Area = new RectangleF(focus[0], focus[1], 0, 0), Weight = 1
                               } });
            }

            if (focus != null && focus.Length > 2 && focus.Length % 4 == 0)
            {
                return(focus.ToList()
                       .SplitList(4)
                       .Select(v => new SalientArea {
                    Area = new RectangleF(v[0], v[1], v[2] - v[0], v[3] - v[1]),
                    Weight = 1
                })
                       .ToArray());
            }
            return(new SalientArea[0]);
        }
Beispiel #2
0
        private RectangleF determineManualCropWindow(ResizeSettings settings)
        {
            RectangleF cropWindow = copyRect;

            if (cropWindow.IsEmpty)
            {
                //Use the crop size if present.
                cropWindow = new RectangleF(new PointF(0, 0), originalSize);
                if (settings.GetList <double>("crop", 0, 4) != null)
                {
                    cropWindow = PolygonMath.ToRectangle(settings.getCustomCropSourceRect(originalSize)); //Round the custom crop rectangle coordinates
                    //Ensure right/bottom bounded after rounding completes
                    cropWindow.Width  = Math.Min(originalSize.Width - cropWindow.Left, cropWindow.Width);
                    cropWindow.Height = Math.Min(originalSize.Height - cropWindow.Top, cropWindow.Height);

                    if (cropWindow.Size.IsEmpty)
                    {
                        throw new Exception("You must specify a custom crop rectangle if crop=custom");
                    }
                }
            }
            return(cropWindow);
        }