mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-27 12:31:57 +00:00
add more methods to file system interface
This commit is contained in:
@@ -172,7 +172,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
|
||||
var quality = options.Quality ?? 90;
|
||||
|
||||
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.BackgroundColor);
|
||||
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -241,7 +241,9 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
|
||||
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
thumbnailGraph.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
thumbnailGraph.CompositingMode = string.IsNullOrEmpty(options.BackgroundColor) && !options.PercentPlayed.HasValue && !options.AddPlayedIndicator ? CompositingMode.SourceCopy : CompositingMode.SourceOver;
|
||||
thumbnailGraph.CompositingMode = string.IsNullOrEmpty(options.BackgroundColor) && !options.UnplayedCount.HasValue && !options.AddPlayedIndicator && !options.PercentPlayed.HasValue ?
|
||||
CompositingMode.SourceCopy :
|
||||
CompositingMode.SourceOver;
|
||||
|
||||
SetBackgroundColor(thumbnailGraph, options);
|
||||
|
||||
@@ -347,28 +349,31 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
/// <param name="options">The options.</param>
|
||||
private void DrawIndicator(Graphics graphics, int imageWidth, int imageHeight, ImageProcessingOptions options)
|
||||
{
|
||||
if (!options.AddPlayedIndicator && !options.PercentPlayed.HasValue)
|
||||
if (!options.AddPlayedIndicator && !options.UnplayedCount.HasValue && !options.PercentPlayed.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var percentOffset = 0;
|
||||
|
||||
if (options.AddPlayedIndicator)
|
||||
{
|
||||
var currentImageSize = new Size(imageWidth, imageHeight);
|
||||
|
||||
new WatchedIndicatorDrawer().Process(graphics, currentImageSize);
|
||||
|
||||
percentOffset = 0 - WatchedIndicatorDrawer.IndicatorWidth;
|
||||
new PlayedIndicatorDrawer().DrawPlayedIndicator(graphics, currentImageSize);
|
||||
}
|
||||
else if (options.UnplayedCount.HasValue)
|
||||
{
|
||||
var currentImageSize = new Size(imageWidth, imageHeight);
|
||||
|
||||
new UnplayedCountIndicator().DrawUnplayedCountIndicator(graphics, currentImageSize, options.UnplayedCount.Value);
|
||||
}
|
||||
|
||||
if (options.PercentPlayed.HasValue)
|
||||
{
|
||||
var currentImageSize = new Size(imageWidth, imageHeight);
|
||||
|
||||
new PercentPlayedDrawer().Process(graphics, currentImageSize, options.PercentPlayed.Value, percentOffset);
|
||||
new PercentPlayedDrawer().Process(graphics, currentImageSize, options.PercentPlayed.Value);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -465,10 +470,15 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
return new Tuple<string, DateTime>(croppedImagePath, _fileSystem.GetLastWriteTimeUtc(croppedImagePath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increment this when indicator drawings change
|
||||
/// </summary>
|
||||
private const string IndicatorVersion = "1";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cache file path based on a set of parameters
|
||||
/// </summary>
|
||||
private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, bool addPlayedIndicator, int? percentPlayed, string backgroundColor)
|
||||
private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, bool addPlayedIndicator, double? percentPlayed, int? unwatchedCount, string backgroundColor)
|
||||
{
|
||||
var filename = originalPath;
|
||||
|
||||
@@ -485,16 +495,31 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
filename += "f=" + format;
|
||||
}
|
||||
|
||||
var hasIndicator = false;
|
||||
|
||||
if (addPlayedIndicator)
|
||||
{
|
||||
filename += "pl=true";
|
||||
hasIndicator = true;
|
||||
}
|
||||
|
||||
if (percentPlayed.HasValue)
|
||||
{
|
||||
filename += "p=" + percentPlayed.Value;
|
||||
hasIndicator = true;
|
||||
}
|
||||
|
||||
if (unwatchedCount.HasValue)
|
||||
{
|
||||
filename += "p=" + unwatchedCount.Value;
|
||||
hasIndicator = true;
|
||||
}
|
||||
|
||||
if (hasIndicator)
|
||||
{
|
||||
filename += "iv=" + IndicatorVersion;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(backgroundColor))
|
||||
{
|
||||
filename += "b=" + backgroundColor;
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Drawing
|
||||
{
|
||||
public class PercentPlayedDrawer
|
||||
{
|
||||
private const int IndicatorWidth = 80;
|
||||
private const int IndicatorHeight = 50;
|
||||
private const int FontSize = 30;
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
private const int IndicatorHeight = 10;
|
||||
|
||||
public void Process(Graphics graphics, Size imageSize, int percent, int rightOffset)
|
||||
public void Process(Graphics graphics, Size imageSize, double percent)
|
||||
{
|
||||
var x = imageSize.Width - IndicatorWidth + rightOffset;
|
||||
var y = imageSize.Height - IndicatorHeight;
|
||||
|
||||
using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 102, 192, 16)))
|
||||
using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 0, 0, 0)))
|
||||
{
|
||||
graphics.FillRectangle(backdroundBrush, x, 0, IndicatorWidth, IndicatorHeight);
|
||||
const int innerX = 0;
|
||||
var innerY = y;
|
||||
var innerWidth = imageSize.Width;
|
||||
var innerHeight = imageSize.Height;
|
||||
|
||||
var text = string.Format("{0}%", percent.ToString(_usCulture));
|
||||
graphics.FillRectangle(backdroundBrush, innerX, innerY, innerWidth, innerHeight);
|
||||
|
||||
x = imageSize.Width - (percent < 10 ? 66 : 75) + rightOffset;
|
||||
|
||||
using (var font = new Font(FontFamily.GenericSansSerif, FontSize, FontStyle.Regular, GraphicsUnit.Pixel))
|
||||
using (var foregroundBrush = new SolidBrush(Color.FromArgb(82, 181, 75)))
|
||||
{
|
||||
using (var fontBrush = new SolidBrush(Color.White))
|
||||
{
|
||||
graphics.DrawString(text, font, fontBrush, x, 6);
|
||||
}
|
||||
double foregroundWidth = innerWidth;
|
||||
foregroundWidth *= percent;
|
||||
foregroundWidth /= 100;
|
||||
|
||||
graphics.FillRectangle(foregroundBrush, innerX, innerY, Convert.ToInt32(Math.Round(foregroundWidth)), innerHeight);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,31 @@
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Drawing
|
||||
{
|
||||
public class WatchedIndicatorDrawer
|
||||
public class PlayedIndicatorDrawer
|
||||
{
|
||||
private const int IndicatorHeight = 50;
|
||||
public const int IndicatorWidth = 50;
|
||||
private const int FontSize = 50;
|
||||
private const int OffsetFromTopRightCorner = 10;
|
||||
|
||||
public void Process(Graphics graphics, Size imageSize)
|
||||
public void DrawPlayedIndicator(Graphics graphics, Size imageSize)
|
||||
{
|
||||
var x = imageSize.Width - IndicatorWidth;
|
||||
var x = imageSize.Width - IndicatorWidth - OffsetFromTopRightCorner;
|
||||
|
||||
using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 204, 51, 51)))
|
||||
using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 82, 181, 75)))
|
||||
{
|
||||
graphics.FillRectangle(backdroundBrush, x, 0, IndicatorWidth, IndicatorHeight);
|
||||
graphics.FillEllipse(backdroundBrush, x, OffsetFromTopRightCorner, IndicatorWidth, IndicatorHeight);
|
||||
|
||||
const string text = "a";
|
||||
|
||||
x = imageSize.Width - 55;
|
||||
x = imageSize.Width - 55 - OffsetFromTopRightCorner;
|
||||
|
||||
using (var font = new Font("Webdings", FontSize, FontStyle.Regular, GraphicsUnit.Pixel))
|
||||
{
|
||||
using (var fontBrush = new SolidBrush(Color.White))
|
||||
{
|
||||
graphics.DrawString(text, font, fontBrush, x, -2);
|
||||
graphics.DrawString("a", font, fontBrush, x, OffsetFromTopRightCorner - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Drawing
|
||||
{
|
||||
public class UnplayedCountIndicator
|
||||
{
|
||||
private const int IndicatorHeight = 50;
|
||||
public const int IndicatorWidth = 50;
|
||||
private const int OffsetFromTopRightCorner = 10;
|
||||
|
||||
public void DrawUnplayedCountIndicator(Graphics graphics, Size imageSize, int count)
|
||||
{
|
||||
var x = imageSize.Width - IndicatorWidth - OffsetFromTopRightCorner;
|
||||
|
||||
using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 82, 181, 75)))
|
||||
{
|
||||
graphics.FillEllipse(backdroundBrush, x, OffsetFromTopRightCorner, IndicatorWidth, IndicatorHeight);
|
||||
|
||||
var text = count.ToString();
|
||||
|
||||
x = imageSize.Width - 50 - OffsetFromTopRightCorner;
|
||||
var y = OffsetFromTopRightCorner + 7;
|
||||
var fontSize = 30;
|
||||
|
||||
if (text.Length == 1)
|
||||
{
|
||||
x += 11;
|
||||
}
|
||||
else if (text.Length == 2)
|
||||
{
|
||||
x += 3;
|
||||
}
|
||||
else if (text.Length == 3)
|
||||
{
|
||||
//x += 1;
|
||||
y += 3;
|
||||
fontSize = 24;
|
||||
}
|
||||
|
||||
using (var font = new Font("Sans-Serif", fontSize, FontStyle.Regular, GraphicsUnit.Pixel))
|
||||
{
|
||||
using (var fontBrush = new SolidBrush(Color.White))
|
||||
{
|
||||
graphics.DrawString(text, font, fontBrush, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user