Esempio n. 1
0
	// Plays a video either locally (must be in the StreamingAssets folder or accessible via full path) or remotely.  The video format must be compatible with the current
	// device.  Many devices have different supported video formats so choose the most common (probably 3gp).
	// When playing a video from the StreamingAssets folder you only need to provide the filename via the pathOrUrl parameter.
	public static void playMovie( string pathOrUrl, uint bgColor, bool showControls, ScalingMode scalingMode, bool closeOnTouch )
	{
		if( Application.platform != RuntimePlatform.Android )
			return;
		
		_plugin.Call( "playMovie", pathOrUrl, (int)bgColor, showControls, (int)scalingMode, closeOnTouch );
	}
Esempio n. 2
0
        internal static Icon FromImage(Image image, int size, bool keepAspectRatio, ScalingMode scalingMode)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image), PublicResources.ArgumentNull);
            }

            var  resultSize = new Size(size, size);
            Size targetSize = resultSize;

            // Same size and image is Bitmap
            if (image is Bitmap bitmap && bitmap.Size == targetSize)
            {
                return(FromBitmap(bitmap));
            }

            // Different size or image is not a Bitmap
            Size sourceSize     = image.Size;
            var  targetLocation = Point.Empty;

            if (keepAspectRatio && targetSize != sourceSize)
            {
                float ratio = Math.Min((float)targetSize.Width / sourceSize.Width, (float)targetSize.Height / sourceSize.Height);
                targetSize     = new Size((int)(sourceSize.Width * ratio), (int)(sourceSize.Height * ratio));
                targetLocation = new Point((resultSize.Width >> 1) - (targetSize.Width >> 1), (resultSize.Height >> 1) - (targetSize.Height >> 1));
            }

            using (var result = new Bitmap(resultSize.Width, resultSize.Height))
            {
                image.DrawInto(result, new Rectangle(targetLocation, targetSize), scalingMode);
                return(FromBitmap(result));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Clones this image with the specified rotation.
        /// </summary>
        /// <param name="image">The original image</param>
        /// <param name="angle">The angle to rotate the image</param>
        /// <param name="dispose">If true, disposes this image upon cloning.</param>
        /// <param name="mode">FitToContent will resize the clone accordingly to fit the rotated content. <br />
        /// Overflow will maintain the original size and clip content.</param>
        /// <returns>A clone of this image with the specified rotation.</returns>
        public static Image Rotate(this Image image, double angle, bool dispose, ScalingMode mode = ScalingMode.Overflow)
        {
            var width  = image.Width;
            var height = image.Height;

            if (mode == ScalingMode.FitContent)
            {
                var o = angle % 180;
                var d = Math.Sqrt(Math.Pow(image.Width, 2) + Math.Pow(image.Height, 2));
                var a = (Math.Atan((double)image.Height / image.Width) * 180 / Math.PI) + (o > 90 ? 180 - o : o);
                height = (int)(Math.Sin(a * Math.PI / 180) * d);
                a      = (Math.Atan((double)-image.Height / image.Width) * 180 / Math.PI) + (o > 90 ? 180 - o : o);
                width  = (int)(Math.Cos(a * Math.PI / 180) * d);
            }
            var newImage = new Bitmap(width, height);

            using (var gfx = Graphics.FromImage(newImage))
            {
                gfx.TranslateTransform(-image.Width / (float)2, -image.Height / (float)2, MatrixOrder.Prepend);
                gfx.RotateTransform((float)angle, MatrixOrder.Append);
                gfx.TranslateTransform(newImage.Width / (float)2, newImage.Height / (float)2, MatrixOrder.Append);
                gfx.DrawImage(image, 0, 0);
            }
            if (dispose)
            {
                image.Dispose();
            }
            return(newImage);
        }
Esempio n. 4
0
    void OnEnable()
    {
        // Disable temporarily and update values before enabling
        _canvas.enabled = false;

        textScale    = _textController.defaultTextScale;
        _scalingMode = _textController.defaultScalingMode;
        _alwaysOnTop = _textController.defaultAlwaysOnTop;
    }
Esempio n. 5
0
        public void DrawIntoWithResizeTest(PixelFormat pixelFormat, ScalingMode scalingMode)
        {
            using var bmp = Icons.Information.ExtractBitmap(new Size(256, 256)).ConvertPixelFormat(pixelFormat);
            var targetRect = new Rectangle(Point.Empty, bmp.Size);

            targetRect.Inflate(-32, -32);
            bmp.DrawInto(bmp, targetRect, scalingMode);
            SaveImage($"{pixelFormat}, {scalingMode}", bmp);
        }
Esempio n. 6
0
    // Plays a video either locally (must be in the StreamingAssets folder or accessible via full path) or remotely.  The video format must be compatible with the current
    // device.  Many devices have different supported video formats so choose the most common (probably 3gp).
    // When playing a video from the StreamingAssets folder you only need to provide the filename via the pathOrUrl parameter.
    public static void playMovie(string pathOrUrl, uint bgColor, bool showControls, ScalingMode scalingMode, bool closeOnTouch)
    {
        if (Application.platform != RuntimePlatform.Android)
        {
            return;
        }

        _plugin.Call("playMovie", pathOrUrl, (int)bgColor, showControls, (int)scalingMode, closeOnTouch);
    }
Esempio n. 7
0
 public void AcceptPictureDescriptorScalingMode(ScalingMode scalingMode, PrintContext parameter)
 {
     if (scalingMode.ScalingModeType == ScalingModeType.Metric)
     {
         parameter.WriteLine("Scaling Mode: {0} (Factor {1})", scalingMode.ScalingModeType, scalingMode.MetricScalingFactor);
     }
     else
     {
         parameter.WriteLine("Scaling Mode: {0}", scalingMode.ScalingModeType);
     }
 }
Esempio n. 8
0
        private void UpdateScaleMode()
        {
            ScalingMode++;

            if ((int)ScalingMode > Enum.GetValues(typeof(ScalingMode)).Length - 1)
            {
                ScalingMode = ScalingMode.Uniform;
            }

            SetScaleModeText();
        }
Esempio n. 9
0
 private void SetScalingMode(ScalingMode newScalingMode, bool save)
 {
     nearestToolStripMenuItem.Checked = newScalingMode == ScalingMode.Nearest;
     cRTToolStripMenuItem.Checked     = newScalingMode == ScalingMode.CRT;
     hqx2xToolStripMenuItem.Checked   = newScalingMode == ScalingMode.Hqx2x;
     displayOutput.ScalingMode        = newScalingMode;
     if (save)
     {
         Settings.Default.ScalingMode = newScalingMode;
         Settings.Default.Save();
     }
 }
Esempio n. 10
0
        // if there is no dryCost exponent, use the mass exponent instead
        public static void treatMassAndCost(Dictionary <string, ScaleExponents> Exponents)
        {
            if (!Exponents.ContainsKey("Part"))
            {
                return;
            }

            if (!Exponents["Part"]._exponents.ContainsKey("mass"))
            {
                return;
            }

            string massExponent = Exponents["Part"]._exponents["mass"].Exponent;

            if (!Exponents.ContainsKey("TweakScale"))
            {
                ConfigNode node = new ConfigNode();
                node.name = "TweakScale";
                node.id   = "TweakScale";
                node.AddValue("!DryCost", massExponent);
                node.AddValue("MassScale", massExponent);
                Exponents.Add("TweakScale", new ScaleExponents(node));
            }
            else
            {
                if (Exponents["TweakScale"]._exponents.ContainsKey("DryCost"))
                {
                    // force relative scaling
                    ScalingMode tmp = Exponents["TweakScale"]._exponents["DryCost"];
                    tmp.UseRelativeScaling = true;
                    Exponents["TweakScale"]._exponents["DryCost"] = tmp;
                }
                else
                {
                    Exponents["TweakScale"]._exponents.Add("DryCost", new ScalingMode(massExponent, true));
                }

                // move mass exponent into TweakScale module
                if (Exponents["TweakScale"]._exponents.ContainsKey("MassScale"))
                {
                    Tools.LogWf("treatMassAndCost: TweakScale/MassScale exponent already exists!");
                }
                else
                {
                    Exponents["TweakScale"]._exponents.Add("MassScale", new ScalingMode(massExponent, false));
                }
            }
            //Exponents["Part"]._exponents.Remove("mass");
        }
Esempio n. 11
0
        public mModifyResize(ResizingMode Mode, ScalingMode Type, int Width, int Height)
        {
            ResizingType = Mode;
            ScalingType  = Type;

            Effect      = new ResizeFilter();
            Effect.Mode = (ResizeMode)(int)ResizingType;
            Effect.BitmapScalingMode = (BitmapScalingMode)(int)ScalingType;
            Effect.Width             = Unit.Pixel(Width);
            Effect.Height            = Unit.Pixel(Height);

            Effect.Enabled = true;

            filter = Effect;
        }
    public void RegisterForScaling(ScalingMode mode)
    {
        if (GestureManager.Instance == null)
        {
            return;
        }

        OnRegisteringForScaling.Invoke();
        if (mode == ScalingMode.Manipulation)
        {
            GestureManager.Instance.RegisterGameObjectForScalingUsingManipulation(this);
        }
        else if (mode == ScalingMode.Navigation)
        {
            GestureManager.Instance.RegisterGameObjectForScalingUsingNavigation(this);
        }
        // change this to scalable i.e. this rather than gameObject
    }
Esempio n. 13
0
    public void ResizeScalingMode(int newSize)
    {
        if (newSize == scalingModes.Length)
        {
            return;
        }
        var newScalingModes = new ScalingMode[newSize];

        for (int i = 0; i < scalingModes.Length; i++)
        {
            if (i >= newSize)
            {
                continue;
            }
            newScalingModes[i] = scalingModes[i];
        }
        scalingModes = newScalingModes;
    }
Esempio n. 14
0
        public void DrawIntoWithResizeTargetOutOfBoundsTest(int size, ScalingMode scalingMode)
        {
            var sourceSize = new Size(size, size);
            var targetSize = new Size(100, 100);

            using var bmpSource = Icons.Information.ExtractBitmap(sourceSize);
            using var bmpRef    = new Bitmap(targetSize.Width, targetSize.Height);
            using var bmpResult = new Bitmap(targetSize.Width, targetSize.Height);

            Rectangle srcRect = Rectangle.Round(new RectangleF(size * 0.1f, size * 0.0625f, size * 0.75f, size * 0.85f));

            using (var g = Graphics.FromImage(bmpRef))
            {
                g.InterpolationMode = scalingMode == ScalingMode.NearestNeighbor ? InterpolationMode.NearestNeighbor : InterpolationMode.HighQualityBicubic;

                // no cut
                var targetRect = new Rectangle(30, 30, 30, 30);
                g.DrawImage(bmpSource, targetRect, srcRect, GraphicsUnit.Pixel);
                bmpSource.DrawInto(bmpResult, srcRect, targetRect, scalingMode);

                // cut left
                targetRect = new Rectangle(-20, 5, 30, 30);
                g.DrawImage(bmpSource, targetRect, srcRect, GraphicsUnit.Pixel);
                bmpSource.DrawInto(bmpResult, srcRect, targetRect, scalingMode);

                // cut top
                targetRect = new Rectangle(50, -20, 30, 30);
                g.DrawImage(bmpSource, targetRect, srcRect, GraphicsUnit.Pixel);
                bmpSource.DrawInto(bmpResult, srcRect, targetRect, scalingMode);

                // cut right
                targetRect = new Rectangle(90, 50, 30, 30);
                g.DrawImage(bmpSource, targetRect, srcRect, GraphicsUnit.Pixel);
                bmpSource.DrawInto(bmpResult, srcRect, targetRect, scalingMode);

                // cut bottom
                targetRect = new Rectangle(10, 90, 30, 30);
                g.DrawImage(bmpSource, targetRect, srcRect, GraphicsUnit.Pixel);
                bmpSource.DrawInto(bmpResult, srcRect, targetRect, scalingMode);
            }

            SaveImage($"{scalingMode} {sourceSize.Width}x{sourceSize.Height} to {bmpResult.Width}x{bmpResult.Height} Reference", bmpRef);
            SaveImage($"{scalingMode} {sourceSize.Width}x{sourceSize.Height} to {bmpResult.Width}x{bmpResult.Height}", bmpResult);
        }
Esempio n. 15
0
 // Update is called once per frame
 void Update()
 {
     if (ScalingMode.ScaleUp == _scalingMode)
     {
         if (transform.localScale.x < 1.0f)
         {
             float scaleAmount = 1.0f / timeToScaleUp * Time.deltaTime;
             transform.localScale = new Vector3(Mathf.Min(1.0f, transform.localScale.x + scaleAmount),
                                                Mathf.Min(1.0f, transform.localScale.y + scaleAmount),
                                                1.0f);
         }
         else
         {
             _scalingMode = ScalingMode.None;
         }
     }
     else if (ScalingMode.ScaleDown == _scalingMode)
     {
         if (transform.localScale.x > 0.0f)
         {
             float scaleAmount = 1.0f / timeToScaleDown * Time.deltaTime;
             transform.localScale = new Vector3(Mathf.Max(0.0f, transform.localScale.x - scaleAmount),
                                                Mathf.Max(0.0f, transform.localScale.y - scaleAmount),
                                                1.0f);
         }
         else
         {
             // We're done, can destroy ourselves.
             _scalingMode = ScalingMode.None;
             Destroy(gameObject);
         }
     }
     else // should we timeout and start collapsing ourselves?
     {
         if (Time.time - _startTime > maxLifetime)
         {
             ScaleDown();
         }
     }
 }
Esempio n. 16
0
 // Update is called once per frame
 void Update()
 {
     if (ScalingMode.ScaleUp == _scalingMode)
     {
         if (transform.localScale.x < 1.0f)
         {
             float scaleAmount = 1.0f / timeToScaleUp * Time.deltaTime;
             transform.localScale = new Vector3(Mathf.Min(1.0f, transform.localScale.x + scaleAmount),
                                                Mathf.Min(1.0f, transform.localScale.y + scaleAmount),
                                                1.0f);
         }
         else
         {
             _scalingMode = ScalingMode.None;
         }
     }
     else if (ScalingMode.ScaleDown == _scalingMode)
     {
         if (transform.localScale.x > 0.0f)
         {
             float scaleAmount = 1.0f / timeToScaleDown * Time.deltaTime;
             transform.localScale = new Vector3(Mathf.Max(0.0f, transform.localScale.x - scaleAmount),
                                                Mathf.Max(0.0f, transform.localScale.y - scaleAmount),
                                                1.0f);
         }
         else
         {
             // We're done, can destroy ourselves.
             _scalingMode = ScalingMode.None;
             Destroy(gameObject);
         }
     }
     else // should we timeout and start collapsing ourselves?
     {
         if (Time.time - _startTime > maxLifetime)
         {
             ScaleDown();
         }
     }
 }
Esempio n. 17
0
    static int ScalingFactorSingle(ScalingMode scalingMode)
    {
        switch (scalingMode)
        {
        case x2:
            return(2);

        case x4:
            return(4);

        case x10:
            return(10);

        case eagle2:
            return(2);

        case eagle3:
            return(3);
        }

        return(1);
    }
Esempio n. 18
0
        /// <summary>
        /// Returns a new result based on this one, scaled to make it easy to compare with
        /// the given standard.
        /// </summary>
        /// <param name="standard">The standard to scale to</param>
        /// <param name="mode">How to scale the result</param>
        public BenchmarkResult ScaleToStandard(BenchmarkResult standard, ScalingMode mode)
        {
            if (this == standard)
            {
                return(this);
            }
            switch (mode)
            {
            case ScalingMode.VaryDuration:
                double   iterationsFactor = (double)standard.iterations / iterations;
                TimeSpan scaledDuration   = TimeSpan.FromTicks((long)(duration.Ticks * iterationsFactor));
                return(new BenchmarkResult(name, scaledDuration, standard.iterations));

            case ScalingMode.VaryIterations:
                double durationFactor   = (double)standard.duration.Ticks / duration.Ticks;
                ulong  scaledIterations = (ulong)(iterations * durationFactor);
                return(new BenchmarkResult(name, standard.duration, scaledIterations));

            default:
                throw new ArgumentOutOfRangeException("mode");
            }
        }
        internal static (float, Func <float, float>) GetInterpolation(this ScalingMode scalingMode)
        {
            switch (scalingMode)
            {
            case ScalingMode.NearestNeighbor:
                return(1f, x => x);

            case ScalingMode.Box:
                return(0.5f, BoxInterpolation);

            case ScalingMode.Bilinear:
                return(1f, BilinearInterpolation);

            case ScalingMode.Bicubic:
                return(2f, BicubicInterpolation);

            case ScalingMode.Lanczos2:
                return(2f, Lanczos2Interpolation);

            case ScalingMode.Lanczos3:
                return(3f, Lanczos3Interpolation);

            case ScalingMode.Spline:
                return(2f, SplineInterpolation);

            case ScalingMode.CatmullRom:
                return(2f, CatmullRomInterpolation);

            case ScalingMode.MitchellNetravali:
                return(2f, MitchellNetravaliInterpolation);

            case ScalingMode.Robidoux:
                return(2f, RobidouxInterpolation);

            default:
                throw new InvalidOperationException(Res.InternalError($"Unexpected scaling mode: {scalingMode}"));
            }
        }
Esempio n. 20
0
        public void DrawIntoWithResizeSourceOutOfBoundsTest(int size, ScalingMode scalingMode)
        {
            var sourceSize = new Size(size, size);
            var targetSize = new Size(256, 256);

            using var bmpSource = Icons.Information.ExtractBitmap(sourceSize);
            using var bmpRef    = new Bitmap(targetSize.Width, targetSize.Height);
            using var bmpResult = new Bitmap(targetSize.Width, targetSize.Height);

            Rectangle srcRect = Rectangle.Round(new RectangleF(size * 0.75f, size * 0.25f, size * 0.5f, size * 0.5f));

            using (var g = Graphics.FromImage(bmpRef))
            {
                g.InterpolationMode = scalingMode == ScalingMode.NearestNeighbor ? InterpolationMode.NearestNeighbor : InterpolationMode.HighQualityBicubic;

                var targetRect = new Rectangle(0, 0, 120, 120);
                g.DrawImage(bmpSource, targetRect, srcRect, GraphicsUnit.Pixel);
                bmpSource.DrawInto(bmpResult, srcRect, targetRect, scalingMode);
            }

            SaveImage($"{scalingMode} {sourceSize.Width}x{sourceSize.Height} to {bmpResult.Width}x{bmpResult.Height} Reference", bmpRef);
            SaveImage($"{scalingMode} {sourceSize.Width}x{sourceSize.Height} to {bmpResult.Width}x{bmpResult.Height}", bmpResult);
        }
Esempio n. 21
0
        public void DrawIntoWithResizeDitheringTest(PixelFormat formatDst, ScalingMode scalingMode)
        {
            var ditherers = new Dictionary <string, IDitherer>
            {
                ["(no dithering)"]               = null,
                ["Ordered"]                      = OrderedDitherer.Bayer8x8,
                ["Error Diffusion (raster)"]     = ErrorDiffusionDitherer.FloydSteinberg,
                ["Error Diffusion (serpentine)"] = ErrorDiffusionDitherer.FloydSteinberg.ConfigureProcessingDirection(true),
            };

            foreach (KeyValuePair <string, IDitherer> ditherer in ditherers)
            {
                using var bmpSrc = Icons.Information.ExtractBitmap(new Size(256, 256));
                using var bmpDst = new Bitmap(bmpSrc.Width, bmpSrc.Height, formatDst);

                if (!formatDst.HasAlpha())
                {
                    bmpDst.Clear(Color.Transparent, ditherer.Value, Color.Silver);
                }

                var targetRect = new Rectangle(Point.Empty, bmpSrc.Size);
                targetRect.Inflate(-32, -32);

                // shrink
                Assert.DoesNotThrow(() => bmpSrc.DrawInto(bmpDst, targetRect, ditherer.Value, scalingMode));

                // enlarge
                targetRect = new Rectangle(160, 160, 100, 100);
                Assert.DoesNotThrow(() => Icons.Information.ExtractBitmap(new Size(16, 16)).DrawInto(bmpDst, targetRect, ditherer.Value, scalingMode));

                // gradient overlay
                using var bmp = GenerateAlphaGradientBitmap(new Size(192, 192));
                bmp.DrawInto(bmpDst, new Point(32, 32), ditherer.Value);

                SaveImage($"{formatDst} {scalingMode} {ditherer.Key}", bmpDst);
            }
        }
Esempio n. 22
0
 /// <summary>
 /// Clones this image with the specified rotation.
 /// </summary>
 /// <param name="image">The original image</param>
 /// <param name="angle">The angle to rotate the image</param>
 /// <param name="mode">FitToContent will resize the clone accordingly to fit the rotated content. <br />
 /// Overflow will maintain the original size and clip content.</param>
 /// <returns>A clone of this image with the specified rotation.</returns>
 public static Image Rotate(this Image image, double angle, ScalingMode mode = ScalingMode.Overflow)
 {
     return(image.Rotate(angle, true, mode));
 }
Esempio n. 23
0
        /// <summary>
        /// Rescales destination exponentValue according to its associated exponent.
        /// </summary>
        /// <param name="current">The current exponentValue.</param>
        /// <param name="baseValue">The unscaled exponentValue, gotten from the prefab.</param>
        /// <param name="name">The name of the field.</param>
        /// <param name="scalingMode">Information on exactly how to scale this.</param>
        /// <param name="factor">The rescaling factor.</param>
        /// <returns>The rescaled exponentValue.</returns>
        private static void Rescale(MemberUpdater current, MemberUpdater baseValue, string name, ScalingMode scalingMode, ScalingFactor factor)
        {
            var exponentValue = scalingMode.Exponent;
            var exponent = double.NaN;
            double[] values = null;
            if (exponentValue.Contains(','))
            {
                if (factor.index == -1)
                {
                    Tools.LogWf("Value list used for freescale part exponent field {0}: {1}", name, exponentValue);
                    return;
                }
                values = Tools.ConvertString(exponentValue, new double[] { });
                if (values.Length <= factor.index)
                {
                    Tools.LogWf("Too few values given for {0}. Expected at least {1}, got {2}: {3}", name, factor.index + 1, values.Length, exponentValue);
                    return;
                }
            }
            else if (!double.TryParse(exponentValue, out exponent))
            {
                Tools.LogWf("Invalid exponent {0} for field {1}", exponentValue, name);
            }

            double multiplyBy = 1;
            if (!double.IsNaN(exponent))
              multiplyBy = Math.Pow(scalingMode.UseRelativeScaling ? factor.relative.linear : factor.absolute.linear, exponent);

            if (current.MemberType.GetInterface("IList") != null)
            {
                var v = (IList)current.Value;
                var v2 = (IList)baseValue.Value;
                if(v == null)
                {
                    Tools.LogWf("current.Value == null!");
                    return;
                }

                for (var i = 0; i < v.Count && i < v2.Count; ++i)
                {
                    if (values != null)
                    {
                        v[i] = values[factor.index];
                    }
                    else if (!double.IsNaN(exponent))
                    {
                        if (v[i] is float)
                        {
                            v[i] = (float)v2[i] * multiplyBy;
                        }
                        else if (v[i] is double)
                        {
                            v[i] = (double)v2[i] * multiplyBy;
                        }
                        else if (v[i] is Vector3)
                        {
                            v[i] = (Vector3)v2[i] * (float)multiplyBy;
                        }
                    }
                }
            }

            if (values != null)
            {
                if (current.MemberType == typeof (float))
                {
                    current.Set((float)values[factor.index]);
                }
                else if (current.MemberType == typeof(float))
                {
                    current.Set(values[factor.index]);
                }

            }
            else if (!double.IsNaN(exponent))
            {
                current.Scale(multiplyBy, baseValue);
            }
        }
Esempio n. 24
0
 public void ScaleDown()
 {
     transform.GetChild(0).GetComponent<CircleCollider2D>().enabled = false;
     _scalingMode = ScalingMode.ScaleDown;
     _loopingSound.FadeOut();
 }
Esempio n. 25
0
 public void StopScaling()
 {
     _scalingMode = ScalingMode.None;
 }
Esempio n. 26
0
 public ScalingModeDisplay(string name, ScalingMode mode)
 {
     Name = name;
     Mode = mode;
 }
Esempio n. 27
0
 public ResultSuite Scale(BenchmarkResult standard, ScalingMode mode)
 {
     return(new ResultSuite(name, results.Select(x => x.ScaleToStandard(standard, mode))));
 }
Esempio n. 28
0
        /// <summary>
        /// Rescales destination exponentValue according to its associated exponent.
        /// </summary>
        /// <param name="current">The current exponentValue.</param>
        /// <param name="baseValue">The unscaled exponentValue, gotten from the prefab.</param>
        /// <param name="name">The name of the field.</param>
        /// <param name="scalingMode">Information on exactly how to scale this.</param>
        /// <param name="factor">The rescaling factor.</param>
        /// <returns>The rescaled exponentValue.</returns>
        static private void Rescale(MemberUpdater current, MemberUpdater baseValue, string name, ScalingMode scalingMode, ScalingFactor factor)
        {
            string exponentValue = scalingMode.Exponent;
            double exponent      = double.NaN;

            double[] values = null;
            if (exponentValue.Contains(','))
            {
                if (factor.index == -1)
                {
                    Tools.LogWf("Value list used for freescale part exponent field {0}: {1}", name, exponentValue);
                    return;
                }
                values = Tools.ConvertString(exponentValue, new double[] { });
                if (values.Length <= factor.index)
                {
                    Tools.LogWf("Too few values given for {0}. Expected at least {1}, got {2}: {3}", name, factor.index + 1, values.Length, exponentValue);
                    return;
                }
            }
            else if (!double.TryParse(exponentValue, out exponent))
            {
                Tools.LogWf("Invalid exponent {0} for field {1}", exponentValue, name);
            }

            double multiplyBy = 1;

            if (!double.IsNaN(exponent))
            {
                multiplyBy = Math.Pow(scalingMode.UseRelativeScaling ? factor.relative.linear : factor.absolute.linear, exponent);
            }

            if (current.MemberType.GetInterface("IList") != null)
            {
                IList v  = (IList)current.Value;
                IList v2 = (IList)baseValue.Value;
                if (v == null)
                {
                    Tools.LogWf("current.Value == null!");
                    return;
                }

                for (int i = 0; i < v.Count && i < v2.Count; ++i)
                {
                    if (values != null)
                    {
                        v[i] = values[factor.index];
                    }
                    else if (!double.IsNaN(exponent) && (exponent != 0))
                    {
                        if (v[i] is float)
                        {
                            v[i] = (float)v2[i] * multiplyBy;
                        }
                        else if (v[i] is double)
                        {
                            v[i] = (double)v2[i] * multiplyBy;
                        }
                        else if (v[i] is Vector3)
                        {
                            v[i] = (Vector3)v2[i] * (float)multiplyBy;
                        }
                    }
                }
            }

            if (values != null)
            {
                if (current.MemberType == typeof(float))
                {
                    current.Set((float)values[factor.index]);
                }
                else if (current.MemberType == typeof(float))
                {
                    current.Set(values[factor.index]);
                }
            }
            else if (!double.IsNaN(exponent) && (exponent != 0))
            {
                current.Scale(multiplyBy, baseValue);
            }
        }
Esempio n. 29
0
 internal ResizeTask(Size size, ScalingMode scalingMode)
 {
     Size        = size;
     ScalingMode = scalingMode;
 }
Esempio n. 30
0
 public virtual void AcceptPictureDescriptorScalingMode(ScalingMode scalingMode, T parameter)
 {
     // intentionally left blank
 }
Esempio n. 31
0
 public void SetScalingMode(ScalingMode newMode, float newScale)
 {
     _scalingMode = newMode;
     textScale    = newScale;
 }
Esempio n. 32
0
        /// <summary>
        /// Clones this image scaled to fit the specified size.
        /// </summary>
        /// <param name="image">The original image.</param>
        /// <param name="size">The size to scale the clone to.</param>
        /// <param name="backgroundColor">The color to fill unused image space with.</param>
        /// <param name="dispose">If true, disposes this image upon cloning.</param>
        /// <param name="mode">FitToContent will scale the content to be completely contained in the specified size. <br />
        /// Overflow will maximize the image to completely fill the specified size, clipping excess content.</param>
        /// <returns>A clone of this image scaled to the specified size.</returns>
        public static Image ScaleToFit(this Image image, Size size, Color backgroundColor, bool dispose = true, ScalingMode mode = ScalingMode.FitContent)
        {
            var widthRatio  = (double)size.Width / image.Width;
            var heightRatio = (double)size.Height / image.Height;
            var scaleRatio  = mode == ScalingMode.Overflow
                                 ? Math.Max(widthRatio, heightRatio)
                                 : Math.Min(widthRatio, heightRatio);
            var width  = image.Width * scaleRatio;
            var height = image.Height * scaleRatio;

            var newImage = new Bitmap(size.Width, size.Height);

            using (var gfx = Graphics.FromImage(newImage))
            {
                if (!backgroundColor.IsEmpty)
                {
                    gfx.Clear(backgroundColor);
                }
                gfx.DrawImage(image,
                              (float)((newImage.Width - width) / 2), (float)((newImage.Height - height) / 2),
                              (float)width, (float)height);
            }
            if (dispose)
            {
                image.Dispose();
            }
            return(newImage);
        }
Esempio n. 33
0
 /// <summary>
 /// Clones this image scaled to fit the specified size.
 /// </summary>
 /// <param name="image">The original image.</param>
 /// <param name="size">The size to scale the clone to.</param>
 /// <param name="backgroundColor">The color to fill unused image space with.</param>
 /// <param name="mode">FitToContent will scale the content to be completely contained in the specified size. <br />
 /// Overflow will maximize the image to completely fill the specified size, clipping excess content.</param>
 /// <returns>A clone of this image scaled to the specified size.</returns>
 public static Image ScaleToFit(this Image image, Size size, Color backgroundColor, ScalingMode mode = ScalingMode.FitContent)
 {
     return(image.ScaleToFit(size, backgroundColor, true, mode));
 }
Esempio n. 34
0
 public static extern int imaqScale(IntPtr dest, IntPtr source, int xScale, int yScale, ScalingMode scaleMode, Rect rect);
Esempio n. 35
0
 /// <summary>
 /// Scales the contents of this result suite in the given mode, using the best result
 /// (in terms of score) as the "standard".
 /// </summary>
 public ResultSuite ScaleByBest(ScalingMode mode)
 {
     return(Scale(FindBest(), mode));
 }
Esempio n. 36
0
 /// <summary>
 /// Clones this image scaled to fit the specified size.
 /// </summary>
 /// <param name="image">The original image.</param>
 /// <param name="size">The size to scale the clone to.</param>
 /// <param name="mode">FitToContent will scale the content to be completely contained in the specified size. <br />
 /// Overflow will maximize the image to completely fill the specified size, clipping excess content.</param>
 /// <returns>A clone of this image scaled to the specified size.</returns>
 public static Image ScaleToFit(this Image image, Size size, ScalingMode mode = ScalingMode.FitContent)
 {
     return(image.ScaleToFit(size, default(Color), true, mode));
 }