mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-21 13:10:45 +02:00
Merge pull request #140 from Bond-009/skia
Remove some warnings for obsolete code.
This commit is contained in:
commit
afd6727c64
|
@ -174,18 +174,15 @@ namespace Emby.Drawing.Skia
|
||||||
var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost);
|
var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost);
|
||||||
|
|
||||||
using (var image = SKImage.FromBitmap(bitmap))
|
using (var image = SKImage.FromBitmap(bitmap))
|
||||||
{
|
|
||||||
using (var subset = image.Subset(newRect))
|
using (var subset = image.Subset(newRect))
|
||||||
{
|
{
|
||||||
return SKBitmap.FromImage(subset);
|
return SKBitmap.FromImage(subset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ImageSize GetImageSize(string path)
|
public ImageSize GetImageSize(string path)
|
||||||
{
|
{
|
||||||
using (var s = new SKFileStream(path))
|
using (var s = new SKFileStream(path))
|
||||||
{
|
|
||||||
using (var codec = SKCodec.Create(s))
|
using (var codec = SKCodec.Create(s))
|
||||||
{
|
{
|
||||||
var info = codec.Info;
|
var info = codec.Info;
|
||||||
|
@ -197,7 +194,6 @@ namespace Emby.Drawing.Skia
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static bool HasDiacritics(string text)
|
private static bool HasDiacritics(string text)
|
||||||
{
|
{
|
||||||
|
@ -234,36 +230,36 @@ namespace Emby.Drawing.Skia
|
||||||
return tempPath;
|
return tempPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SKCodecOrigin GetSKCodecOrigin(ImageOrientation? orientation)
|
private static SKEncodedOrigin GetSKEncodedOrigin(ImageOrientation? orientation)
|
||||||
{
|
{
|
||||||
if (!orientation.HasValue)
|
if (!orientation.HasValue)
|
||||||
{
|
{
|
||||||
return SKCodecOrigin.TopLeft;
|
return SKEncodedOrigin.TopLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (orientation.Value)
|
switch (orientation.Value)
|
||||||
{
|
{
|
||||||
case ImageOrientation.TopRight:
|
case ImageOrientation.TopRight:
|
||||||
return SKCodecOrigin.TopRight;
|
return SKEncodedOrigin.TopRight;
|
||||||
case ImageOrientation.RightTop:
|
case ImageOrientation.RightTop:
|
||||||
return SKCodecOrigin.RightTop;
|
return SKEncodedOrigin.RightTop;
|
||||||
case ImageOrientation.RightBottom:
|
case ImageOrientation.RightBottom:
|
||||||
return SKCodecOrigin.RightBottom;
|
return SKEncodedOrigin.RightBottom;
|
||||||
case ImageOrientation.LeftTop:
|
case ImageOrientation.LeftTop:
|
||||||
return SKCodecOrigin.LeftTop;
|
return SKEncodedOrigin.LeftTop;
|
||||||
case ImageOrientation.LeftBottom:
|
case ImageOrientation.LeftBottom:
|
||||||
return SKCodecOrigin.LeftBottom;
|
return SKEncodedOrigin.LeftBottom;
|
||||||
case ImageOrientation.BottomRight:
|
case ImageOrientation.BottomRight:
|
||||||
return SKCodecOrigin.BottomRight;
|
return SKEncodedOrigin.BottomRight;
|
||||||
case ImageOrientation.BottomLeft:
|
case ImageOrientation.BottomLeft:
|
||||||
return SKCodecOrigin.BottomLeft;
|
return SKEncodedOrigin.BottomLeft;
|
||||||
default:
|
default:
|
||||||
return SKCodecOrigin.TopLeft;
|
return SKEncodedOrigin.TopLeft;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" };
|
private static string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" };
|
||||||
internal static SKBitmap Decode(string path, bool forceCleanBitmap, IFileSystem fileSystem, ImageOrientation? orientation, out SKCodecOrigin origin)
|
internal static SKBitmap Decode(string path, bool forceCleanBitmap, IFileSystem fileSystem, ImageOrientation? orientation, out SKEncodedOrigin origin)
|
||||||
{
|
{
|
||||||
if (!fileSystem.FileExists(path))
|
if (!fileSystem.FileExists(path))
|
||||||
{
|
{
|
||||||
|
@ -275,12 +271,11 @@ namespace Emby.Drawing.Skia
|
||||||
if (requiresTransparencyHack || forceCleanBitmap)
|
if (requiresTransparencyHack || forceCleanBitmap)
|
||||||
{
|
{
|
||||||
using (var stream = new SKFileStream(NormalizePath(path, fileSystem)))
|
using (var stream = new SKFileStream(NormalizePath(path, fileSystem)))
|
||||||
{
|
|
||||||
using (var codec = SKCodec.Create(stream))
|
using (var codec = SKCodec.Create(stream))
|
||||||
{
|
{
|
||||||
if (codec == null)
|
if (codec == null)
|
||||||
{
|
{
|
||||||
origin = GetSKCodecOrigin(orientation);
|
origin = GetSKEncodedOrigin(orientation);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,17 +287,16 @@ namespace Emby.Drawing.Skia
|
||||||
// decode
|
// decode
|
||||||
codec.GetPixels(bitmap.Info, bitmap.GetPixels());
|
codec.GetPixels(bitmap.Info, bitmap.GetPixels());
|
||||||
|
|
||||||
origin = codec.Origin;
|
origin = codec.EncodedOrigin;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
origin = GetSKCodecOrigin(orientation);
|
origin = GetSKEncodedOrigin(orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var resultBitmap = SKBitmap.Decode(NormalizePath(path, fileSystem));
|
var resultBitmap = SKBitmap.Decode(NormalizePath(path, fileSystem));
|
||||||
|
|
||||||
|
@ -320,11 +314,11 @@ namespace Emby.Drawing.Skia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
origin = SKCodecOrigin.TopLeft;
|
origin = SKEncodedOrigin.TopLeft;
|
||||||
return resultBitmap;
|
return resultBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SKBitmap GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKCodecOrigin origin)
|
private SKBitmap GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
|
||||||
{
|
{
|
||||||
if (cropWhitespace)
|
if (cropWhitespace)
|
||||||
{
|
{
|
||||||
|
@ -339,7 +333,7 @@ namespace Emby.Drawing.Skia
|
||||||
|
|
||||||
private SKBitmap GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
|
private SKBitmap GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
|
||||||
{
|
{
|
||||||
SKCodecOrigin origin;
|
SKEncodedOrigin origin;
|
||||||
|
|
||||||
if (autoOrient)
|
if (autoOrient)
|
||||||
{
|
{
|
||||||
|
@ -347,7 +341,7 @@ namespace Emby.Drawing.Skia
|
||||||
|
|
||||||
if (bitmap != null)
|
if (bitmap != null)
|
||||||
{
|
{
|
||||||
if (origin != SKCodecOrigin.TopLeft)
|
if (origin != SKEncodedOrigin.TopLeft)
|
||||||
{
|
{
|
||||||
using (bitmap)
|
using (bitmap)
|
||||||
{
|
{
|
||||||
|
@ -362,7 +356,7 @@ namespace Emby.Drawing.Skia
|
||||||
return GetBitmap(path, cropWhitespace, false, orientation, out origin);
|
return GetBitmap(path, cropWhitespace, false, orientation, out origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SKBitmap OrientImage(SKBitmap bitmap, SKCodecOrigin origin)
|
private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
|
||||||
{
|
{
|
||||||
//var transformations = {
|
//var transformations = {
|
||||||
// 2: { rotate: 0, flip: true},
|
// 2: { rotate: 0, flip: true},
|
||||||
|
@ -377,7 +371,7 @@ namespace Emby.Drawing.Skia
|
||||||
switch (origin)
|
switch (origin)
|
||||||
{
|
{
|
||||||
|
|
||||||
case SKCodecOrigin.TopRight:
|
case SKEncodedOrigin.TopRight:
|
||||||
{
|
{
|
||||||
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
|
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
|
||||||
using (var surface = new SKCanvas(rotated))
|
using (var surface = new SKCanvas(rotated))
|
||||||
|
@ -390,7 +384,7 @@ namespace Emby.Drawing.Skia
|
||||||
return rotated;
|
return rotated;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SKCodecOrigin.BottomRight:
|
case SKEncodedOrigin.BottomRight:
|
||||||
{
|
{
|
||||||
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
|
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
|
||||||
using (var surface = new SKCanvas(rotated))
|
using (var surface = new SKCanvas(rotated))
|
||||||
|
@ -408,7 +402,7 @@ namespace Emby.Drawing.Skia
|
||||||
return rotated;
|
return rotated;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SKCodecOrigin.BottomLeft:
|
case SKEncodedOrigin.BottomLeft:
|
||||||
{
|
{
|
||||||
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
|
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
|
||||||
using (var surface = new SKCanvas(rotated))
|
using (var surface = new SKCanvas(rotated))
|
||||||
|
@ -429,7 +423,7 @@ namespace Emby.Drawing.Skia
|
||||||
return rotated;
|
return rotated;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SKCodecOrigin.LeftTop:
|
case SKEncodedOrigin.LeftTop:
|
||||||
{
|
{
|
||||||
// TODO: Remove dual canvases, had trouble with flipping
|
// TODO: Remove dual canvases, had trouble with flipping
|
||||||
using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width))
|
using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width))
|
||||||
|
@ -456,7 +450,7 @@ namespace Emby.Drawing.Skia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case SKCodecOrigin.RightTop:
|
case SKEncodedOrigin.RightTop:
|
||||||
{
|
{
|
||||||
var rotated = new SKBitmap(bitmap.Height, bitmap.Width);
|
var rotated = new SKBitmap(bitmap.Height, bitmap.Width);
|
||||||
using (var surface = new SKCanvas(rotated))
|
using (var surface = new SKCanvas(rotated))
|
||||||
|
@ -469,7 +463,7 @@ namespace Emby.Drawing.Skia
|
||||||
return rotated;
|
return rotated;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SKCodecOrigin.RightBottom:
|
case SKEncodedOrigin.RightBottom:
|
||||||
{
|
{
|
||||||
// TODO: Remove dual canvases, had trouble with flipping
|
// TODO: Remove dual canvases, had trouble with flipping
|
||||||
using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width))
|
using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width))
|
||||||
|
@ -493,7 +487,7 @@ namespace Emby.Drawing.Skia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case SKCodecOrigin.LeftBottom:
|
case SKEncodedOrigin.LeftBottom:
|
||||||
{
|
{
|
||||||
var rotated = new SKBitmap(bitmap.Height, bitmap.Width);
|
var rotated = new SKBitmap(bitmap.Height, bitmap.Width);
|
||||||
using (var surface = new SKCanvas(rotated))
|
using (var surface = new SKCanvas(rotated))
|
||||||
|
@ -569,10 +563,8 @@ namespace Emby.Drawing.Skia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create bitmap to use for canvas drawing
|
// create bitmap to use for canvas drawing used to draw into bitmap
|
||||||
using (var saveBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType))
|
using (var saveBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType))
|
||||||
{
|
|
||||||
// create canvas used to draw into bitmap
|
|
||||||
using (var canvas = new SKCanvas(saveBitmap))
|
using (var canvas = new SKCanvas(saveBitmap))
|
||||||
{
|
{
|
||||||
// set background color if present
|
// set background color if present
|
||||||
|
@ -583,17 +575,15 @@ namespace Emby.Drawing.Skia
|
||||||
|
|
||||||
// Add blur if option is present
|
// Add blur if option is present
|
||||||
if (blur > 0)
|
if (blur > 0)
|
||||||
{
|
|
||||||
using (var paint = new SKPaint())
|
|
||||||
{
|
{
|
||||||
// create image from resized bitmap to apply blur
|
// create image from resized bitmap to apply blur
|
||||||
|
using (var paint = new SKPaint())
|
||||||
using (var filter = SKImageFilter.CreateBlur(blur, blur))
|
using (var filter = SKImageFilter.CreateBlur(blur, blur))
|
||||||
{
|
{
|
||||||
paint.ImageFilter = filter;
|
paint.ImageFilter = filter;
|
||||||
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
|
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// draw resized bitmap onto canvas
|
// draw resized bitmap onto canvas
|
||||||
|
@ -604,7 +594,10 @@ namespace Emby.Drawing.Skia
|
||||||
if (hasForegroundColor)
|
if (hasForegroundColor)
|
||||||
{
|
{
|
||||||
Double opacity;
|
Double opacity;
|
||||||
if (!Double.TryParse(options.ForegroundLayer, out opacity)) opacity = .4;
|
if (!Double.TryParse(options.ForegroundLayer, out opacity))
|
||||||
|
{
|
||||||
|
opacity = .4;
|
||||||
|
}
|
||||||
|
|
||||||
canvas.DrawColor(new SKColor(0, 0, 0, (Byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver);
|
canvas.DrawColor(new SKColor(0, 0, 0, (Byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver);
|
||||||
}
|
}
|
||||||
|
@ -622,7 +615,6 @@ namespace Emby.Drawing.Skia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return outputPath;
|
return outputPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,11 +99,9 @@ namespace Emby.Drawing.Skia
|
||||||
using (var resizeBitmap = new SKBitmap(iWidth, iHeight, currentBitmap.ColorType, currentBitmap.AlphaType))
|
using (var resizeBitmap = new SKBitmap(iWidth, iHeight, currentBitmap.ColorType, currentBitmap.AlphaType))
|
||||||
{
|
{
|
||||||
currentBitmap.Resize(resizeBitmap, SKBitmapResizeMethod.Lanczos3);
|
currentBitmap.Resize(resizeBitmap, SKBitmapResizeMethod.Lanczos3);
|
||||||
// determine how much to crop
|
// crop image
|
||||||
int ix = (int)Math.Abs((iWidth - iSlice) / 2);
|
int ix = (int)Math.Abs((iWidth - iSlice) / 2);
|
||||||
using (var image = SKImage.FromBitmap(resizeBitmap))
|
using (var image = SKImage.FromBitmap(resizeBitmap))
|
||||||
{
|
|
||||||
// crop image
|
|
||||||
using (var subset = image.Subset(SKRectI.Create(ix, 0, iSlice, iHeight)))
|
using (var subset = image.Subset(SKRectI.Create(ix, 0, iSlice, iHeight)))
|
||||||
{
|
{
|
||||||
// draw image onto canvas
|
// draw image onto canvas
|
||||||
|
@ -113,17 +111,14 @@ namespace Emby.Drawing.Skia
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var croppedBitmap = SKBitmap.FromImage(subset))
|
|
||||||
{
|
|
||||||
// create reflection of image below the drawn image
|
// create reflection of image below the drawn image
|
||||||
|
using (var croppedBitmap = SKBitmap.FromImage(subset))
|
||||||
using (var reflectionBitmap = new SKBitmap(croppedBitmap.Width, croppedBitmap.Height / 2, croppedBitmap.ColorType, croppedBitmap.AlphaType))
|
using (var reflectionBitmap = new SKBitmap(croppedBitmap.Width, croppedBitmap.Height / 2, croppedBitmap.ColorType, croppedBitmap.AlphaType))
|
||||||
{
|
{
|
||||||
// resize to half height
|
// resize to half height
|
||||||
croppedBitmap.Resize(reflectionBitmap, SKBitmapResizeMethod.Lanczos3);
|
croppedBitmap.Resize(reflectionBitmap, SKBitmapResizeMethod.Lanczos3);
|
||||||
|
|
||||||
using (var flippedBitmap = new SKBitmap(reflectionBitmap.Width, reflectionBitmap.Height, reflectionBitmap.ColorType, reflectionBitmap.AlphaType))
|
using (var flippedBitmap = new SKBitmap(reflectionBitmap.Width, reflectionBitmap.Height, reflectionBitmap.ColorType, reflectionBitmap.AlphaType))
|
||||||
{
|
|
||||||
using (var flippedCanvas = new SKCanvas(flippedBitmap))
|
using (var flippedCanvas = new SKCanvas(flippedBitmap))
|
||||||
{
|
{
|
||||||
// flip image vertically
|
// flip image vertically
|
||||||
|
@ -153,9 +148,6 @@ namespace Emby.Drawing.Skia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +164,7 @@ namespace Emby.Drawing.Skia
|
||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SKCodecOrigin origin;
|
SKEncodedOrigin origin;
|
||||||
bitmap = SkiaEncoder.Decode(paths[currentIndex], false, _fileSystem, null, out origin);
|
bitmap = SkiaEncoder.Decode(paths[currentIndex], false, _fileSystem, null, out origin);
|
||||||
|
|
||||||
imagesTested[currentIndex] = 0;
|
imagesTested[currentIndex] = 0;
|
||||||
|
@ -202,7 +194,6 @@ namespace Emby.Drawing.Skia
|
||||||
{
|
{
|
||||||
for (var y = 0; y < 2; y++)
|
for (var y = 0; y < 2; y++)
|
||||||
{
|
{
|
||||||
SKCodecOrigin origin;
|
|
||||||
int newIndex;
|
int newIndex;
|
||||||
|
|
||||||
using (var currentBitmap = GetNextValidImage(paths, imageIndex, out newIndex))
|
using (var currentBitmap = GetNextValidImage(paths, imageIndex, out newIndex))
|
||||||
|
|
Loading…
Reference in a new issue