mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-13 12:33:01 +03:00
Add GPL modules
This commit is contained in:
91
MediaBrowser.Model/Drawing/DrawingUtils.cs
Normal file
91
MediaBrowser.Model/Drawing/DrawingUtils.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
namespace MediaBrowser.Model.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Class DrawingUtils
|
||||
/// </summary>
|
||||
public static class DrawingUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Resizes a set of dimensions
|
||||
/// </summary>
|
||||
/// <param name="size">The original size object</param>
|
||||
/// <param name="width">A new fixed width, if desired</param>
|
||||
/// <param name="height">A new fixed height, if desired</param>
|
||||
/// <param name="maxWidth">A max fixed width, if desired</param>
|
||||
/// <param name="maxHeight">A max fixed height, if desired</param>
|
||||
/// <returns>A new size object</returns>
|
||||
public static ImageSize Resize(ImageSize size,
|
||||
double width,
|
||||
double height,
|
||||
double maxWidth,
|
||||
double maxHeight)
|
||||
{
|
||||
double newWidth = size.Width;
|
||||
double newHeight = size.Height;
|
||||
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
newWidth = width;
|
||||
newHeight = height;
|
||||
}
|
||||
|
||||
else if (height > 0)
|
||||
{
|
||||
newWidth = GetNewWidth(newHeight, newWidth, height);
|
||||
newHeight = height;
|
||||
}
|
||||
|
||||
else if (width > 0)
|
||||
{
|
||||
newHeight = GetNewHeight(newHeight, newWidth, width);
|
||||
newWidth = width;
|
||||
}
|
||||
|
||||
if (maxHeight > 0 && maxHeight < newHeight)
|
||||
{
|
||||
newWidth = GetNewWidth(newHeight, newWidth, maxHeight);
|
||||
newHeight = maxHeight;
|
||||
}
|
||||
|
||||
if (maxWidth > 0 && maxWidth < newWidth)
|
||||
{
|
||||
newHeight = GetNewHeight(newHeight, newWidth, maxWidth);
|
||||
newWidth = maxWidth;
|
||||
}
|
||||
|
||||
return new ImageSize { Width = newWidth, Height = newHeight };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the new width.
|
||||
/// </summary>
|
||||
/// <param name="currentHeight">Height of the current.</param>
|
||||
/// <param name="currentWidth">Width of the current.</param>
|
||||
/// <param name="newHeight">The new height.</param>
|
||||
/// <returns>System.Double.</returns>
|
||||
private static double GetNewWidth(double currentHeight, double currentWidth, double newHeight)
|
||||
{
|
||||
double scaleFactor = newHeight;
|
||||
scaleFactor /= currentHeight;
|
||||
scaleFactor *= currentWidth;
|
||||
|
||||
return scaleFactor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the new height.
|
||||
/// </summary>
|
||||
/// <param name="currentHeight">Height of the current.</param>
|
||||
/// <param name="currentWidth">Width of the current.</param>
|
||||
/// <param name="newWidth">The new width.</param>
|
||||
/// <returns>System.Double.</returns>
|
||||
private static double GetNewHeight(double currentHeight, double currentWidth, double newWidth)
|
||||
{
|
||||
double scaleFactor = newWidth;
|
||||
scaleFactor /= currentWidth;
|
||||
scaleFactor *= currentHeight;
|
||||
|
||||
return scaleFactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
MediaBrowser.Model/Drawing/ImageFormat.cs
Normal file
30
MediaBrowser.Model/Drawing/ImageFormat.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
namespace MediaBrowser.Model.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum ImageOutputFormat
|
||||
/// </summary>
|
||||
public enum ImageFormat
|
||||
{
|
||||
/// <summary>
|
||||
/// The BMP
|
||||
/// </summary>
|
||||
Bmp,
|
||||
/// <summary>
|
||||
/// The GIF
|
||||
/// </summary>
|
||||
Gif,
|
||||
/// <summary>
|
||||
/// The JPG
|
||||
/// </summary>
|
||||
Jpg,
|
||||
/// <summary>
|
||||
/// The PNG
|
||||
/// </summary>
|
||||
Png,
|
||||
/// <summary>
|
||||
/// The webp
|
||||
/// </summary>
|
||||
Webp
|
||||
}
|
||||
}
|
||||
15
MediaBrowser.Model/Drawing/ImageOrientation.cs
Normal file
15
MediaBrowser.Model/Drawing/ImageOrientation.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace MediaBrowser.Model.Drawing
|
||||
{
|
||||
public enum ImageOrientation
|
||||
{
|
||||
TopLeft = 1,
|
||||
TopRight = 2,
|
||||
BottomRight = 3,
|
||||
BottomLeft = 4,
|
||||
LeftTop = 5,
|
||||
RightTop = 6,
|
||||
RightBottom = 7,
|
||||
LeftBottom = 8,
|
||||
}
|
||||
}
|
||||
93
MediaBrowser.Model/Drawing/ImageSize.cs
Normal file
93
MediaBrowser.Model/Drawing/ImageSize.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace MediaBrowser.Model.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Struct ImageSize
|
||||
/// </summary>
|
||||
public struct ImageSize
|
||||
{
|
||||
private double _height;
|
||||
private double _width;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height.
|
||||
/// </summary>
|
||||
/// <value>The height.</value>
|
||||
public double Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
set
|
||||
{
|
||||
_height = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the width.
|
||||
/// </summary>
|
||||
/// <value>The width.</value>
|
||||
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);
|
||||
}
|
||||
|
||||
public ImageSize(int width, int height)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
public ImageSize(double width, double height)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
private void ParseValue(string value)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
string[] parts = value.Split('-');
|
||||
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
double val;
|
||||
|
||||
if (double.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
|
||||
{
|
||||
_width = val;
|
||||
}
|
||||
|
||||
if (double.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
|
||||
{
|
||||
_height = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user