From 2fc662c9e9e5bc0730c37ef88eb3ff8476b301db Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 7 Nov 2013 10:57:12 -0500 Subject: optimize image processor when gdi can be skipped --- MediaBrowser.Model/Drawing/DrawingUtils.cs | 64 ++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Model/Drawing/DrawingUtils.cs') diff --git a/MediaBrowser.Model/Drawing/DrawingUtils.cs b/MediaBrowser.Model/Drawing/DrawingUtils.cs index 8f66029fe..e95b5e375 100644 --- a/MediaBrowser.Model/Drawing/DrawingUtils.cs +++ b/MediaBrowser.Model/Drawing/DrawingUtils.cs @@ -1,4 +1,5 @@ - +using System.Globalization; + namespace MediaBrowser.Model.Drawing { /// @@ -131,20 +132,77 @@ namespace MediaBrowser.Model.Drawing /// public struct ImageSize { + private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); + + private double _height; + private double _width; + /// /// Gets or sets the height. /// /// The height. - public double Height { get; set; } + public double Height + { + get + { + return _height; + } + set + { + _height = value; + } + } + /// /// Gets or sets the width. /// /// The width. - public double Width { get; set; } + public double Width + { + get { return _width; } + set { _width = value; } + } public bool Equals(ImageSize size) { return Width.Equals(size.Width) && Height.Equals(size.Height); } + + public override string ToString() + { + return string.Format("{0}-{1}", Width, Height); + } + + public ImageSize(string value) + { + _width = 0; + + _height = 0; + + ParseValue(value); + } + + private void ParseValue(string value) + { + if (!string.IsNullOrEmpty(value)) + { + var parts = value.Split('-'); + + if (parts.Length == 2) + { + double val; + + if (double.TryParse(parts[0], NumberStyles.Any, UsCulture, out val)) + { + _width = val; + } + + if (double.TryParse(parts[1], NumberStyles.Any, UsCulture, out val)) + { + _height = val; + } + } + } + } } } -- cgit v1.2.3