aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Drawing
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-01 13:26:31 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-01 13:26:31 -0500
commitb9d17c9bc765a0c59d81db6277300a6860bf8421 (patch)
tree8a7c538cb73c27b7e06f0055ce4f0bb45175e7aa /MediaBrowser.Server.Implementations/Drawing
parent88b638fbd69ed99bde7065f66af433b015977cb7 (diff)
add more methods to file system interface
Diffstat (limited to 'MediaBrowser.Server.Implementations/Drawing')
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs43
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs36
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/PlayedIndicatorDrawer.cs (renamed from MediaBrowser.Server.Implementations/Drawing/WatchedIndicatorDrawer.cs)18
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/UnplayedCountIndicator.cs55
4 files changed, 114 insertions, 38 deletions
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index 7ddf63cf8..0568f681a 100644
--- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
@@ -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);
+ new PlayedIndicatorDrawer().DrawPlayedIndicator(graphics, currentImageSize);
+ }
+ else if (options.UnplayedCount.HasValue)
+ {
+ var currentImageSize = new Size(imageWidth, imageHeight);
- percentOffset = 0 - WatchedIndicatorDrawer.IndicatorWidth;
+ 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)
@@ -466,9 +471,14 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
/// <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;
diff --git a/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs b/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs
index e2f5b6129..c621ace43 100644
--- a/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs
@@ -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);
}
}
-
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Drawing/WatchedIndicatorDrawer.cs b/MediaBrowser.Server.Implementations/Drawing/PlayedIndicatorDrawer.cs
index c889db304..7be187396 100644
--- a/MediaBrowser.Server.Implementations/Drawing/WatchedIndicatorDrawer.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/PlayedIndicatorDrawer.cs
@@ -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);
}
}
}
-
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Drawing/UnplayedCountIndicator.cs b/MediaBrowser.Server.Implementations/Drawing/UnplayedCountIndicator.cs
new file mode 100644
index 000000000..11d812a43
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Drawing/UnplayedCountIndicator.cs
@@ -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);
+ }
+ }
+ }
+ }
+ }
+}