Remove some warnings

pull/1154/head
Bond_009 6 years ago
parent 64805410c2
commit c189d31a2b

@ -174,18 +174,15 @@ namespace Emby.Drawing.Skia
var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost);
using (var image = SKImage.FromBitmap(bitmap))
{
using (var subset = image.Subset(newRect))
{
return SKBitmap.FromImage(subset);
}
}
}
public ImageSize GetImageSize(string path)
{
using (var s = new SKFileStream(path))
{
using (var codec = SKCodec.Create(s))
{
var info = codec.Info;
@ -197,7 +194,6 @@ namespace Emby.Drawing.Skia
};
}
}
}
private static bool HasDiacritics(string text)
{
@ -234,36 +230,36 @@ namespace Emby.Drawing.Skia
return tempPath;
}
private static SKCodecOrigin GetSKCodecOrigin(ImageOrientation? orientation)
private static SKEncodedOrigin GetSKCodecOrigin(ImageOrientation? orientation)
{
if (!orientation.HasValue)
{
return SKCodecOrigin.TopLeft;
return SKEncodedOrigin.TopLeft;
}
switch (orientation.Value)
{
case ImageOrientation.TopRight:
return SKCodecOrigin.TopRight;
return SKEncodedOrigin.TopRight;
case ImageOrientation.RightTop:
return SKCodecOrigin.RightTop;
return SKEncodedOrigin.RightTop;
case ImageOrientation.RightBottom:
return SKCodecOrigin.RightBottom;
return SKEncodedOrigin.RightBottom;
case ImageOrientation.LeftTop:
return SKCodecOrigin.LeftTop;
return SKEncodedOrigin.LeftTop;
case ImageOrientation.LeftBottom:
return SKCodecOrigin.LeftBottom;
return SKEncodedOrigin.LeftBottom;
case ImageOrientation.BottomRight:
return SKCodecOrigin.BottomRight;
return SKEncodedOrigin.BottomRight;
case ImageOrientation.BottomLeft:
return SKCodecOrigin.BottomLeft;
return SKEncodedOrigin.BottomLeft;
default:
return SKCodecOrigin.TopLeft;
return SKEncodedOrigin.TopLeft;
}
}
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))
{
@ -275,7 +271,6 @@ namespace Emby.Drawing.Skia
if (requiresTransparencyHack || forceCleanBitmap)
{
using (var stream = new SKFileStream(NormalizePath(path, fileSystem)))
{
using (var codec = SKCodec.Create(stream))
{
if (codec == null)
@ -292,7 +287,7 @@ namespace Emby.Drawing.Skia
// decode
codec.GetPixels(bitmap.Info, bitmap.GetPixels());
origin = codec.Origin;
origin = codec.EncodedOrigin;
}
else
{
@ -302,7 +297,6 @@ namespace Emby.Drawing.Skia
return bitmap;
}
}
}
var resultBitmap = SKBitmap.Decode(NormalizePath(path, fileSystem));
@ -320,11 +314,11 @@ namespace Emby.Drawing.Skia
}
}
origin = SKCodecOrigin.TopLeft;
origin = SKEncodedOrigin.TopLeft;
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)
{
@ -339,7 +333,7 @@ namespace Emby.Drawing.Skia
private SKBitmap GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
{
SKCodecOrigin origin;
SKEncodedOrigin origin;
if (autoOrient)
{
@ -347,7 +341,7 @@ namespace Emby.Drawing.Skia
if (bitmap != null)
{
if (origin != SKCodecOrigin.TopLeft)
if (origin != SKEncodedOrigin.TopLeft)
{
using (bitmap)
{
@ -362,7 +356,7 @@ namespace Emby.Drawing.Skia
return GetBitmap(path, cropWhitespace, false, orientation, out origin);
}
private SKBitmap OrientImage(SKBitmap bitmap, SKCodecOrigin origin)
private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
{
//var transformations = {
// 2: { rotate: 0, flip: true},
@ -377,7 +371,7 @@ namespace Emby.Drawing.Skia
switch (origin)
{
case SKCodecOrigin.TopRight:
case SKEncodedOrigin.TopRight:
{
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
using (var surface = new SKCanvas(rotated))
@ -390,7 +384,7 @@ namespace Emby.Drawing.Skia
return rotated;
}
case SKCodecOrigin.BottomRight:
case SKEncodedOrigin.BottomRight:
{
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
using (var surface = new SKCanvas(rotated))
@ -408,7 +402,7 @@ namespace Emby.Drawing.Skia
return rotated;
}
case SKCodecOrigin.BottomLeft:
case SKEncodedOrigin.BottomLeft:
{
var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
using (var surface = new SKCanvas(rotated))
@ -429,7 +423,7 @@ namespace Emby.Drawing.Skia
return rotated;
}
case SKCodecOrigin.LeftTop:
case SKEncodedOrigin.LeftTop:
{
// TODO: Remove dual canvases, had trouble with flipping
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);
using (var surface = new SKCanvas(rotated))
@ -469,7 +463,7 @@ namespace Emby.Drawing.Skia
return rotated;
}
case SKCodecOrigin.RightBottom:
case SKEncodedOrigin.RightBottom:
{
// TODO: Remove dual canvases, had trouble with flipping
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);
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))
{
// create canvas used to draw into bitmap
using (var canvas = new SKCanvas(saveBitmap))
{
// set background color if present
@ -583,17 +575,15 @@ namespace Emby.Drawing.Skia
// Add blur if option is present
if (blur > 0)
{
using (var paint = new SKPaint())
{
// create image from resized bitmap to apply blur
using (var paint = new SKPaint())
using (var filter = SKImageFilter.CreateBlur(blur, blur))
{
paint.ImageFilter = filter;
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
}
}
}
else
{
// draw resized bitmap onto canvas
@ -622,7 +612,6 @@ namespace Emby.Drawing.Skia
}
}
}
}
return outputPath;
}

@ -99,11 +99,9 @@ namespace Emby.Drawing.Skia
using (var resizeBitmap = new SKBitmap(iWidth, iHeight, currentBitmap.ColorType, currentBitmap.AlphaType))
{
currentBitmap.Resize(resizeBitmap, SKBitmapResizeMethod.Lanczos3);
// determine how much to crop
// crop image
int ix = (int)Math.Abs((iWidth - iSlice) / 2);
using (var image = SKImage.FromBitmap(resizeBitmap))
{
// crop image
using (var subset = image.Subset(SKRectI.Create(ix, 0, iSlice, iHeight)))
{
// draw image onto canvas
@ -113,17 +111,14 @@ namespace Emby.Drawing.Skia
{
continue;
}
using (var croppedBitmap = SKBitmap.FromImage(subset))
{
// 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))
{
// resize to half height
croppedBitmap.Resize(reflectionBitmap, SKBitmapResizeMethod.Lanczos3);
using (var flippedBitmap = new SKBitmap(reflectionBitmap.Width, reflectionBitmap.Height, reflectionBitmap.ColorType, reflectionBitmap.AlphaType))
{
using (var flippedCanvas = new SKCanvas(flippedBitmap))
{
// flip image vertically
@ -153,9 +148,6 @@ namespace Emby.Drawing.Skia
}
}
}
}
}
}
return bitmap;
}
@ -172,7 +164,7 @@ namespace Emby.Drawing.Skia
currentIndex = 0;
}
SKCodecOrigin origin;
SKEncodedOrigin origin;
bitmap = SkiaEncoder.Decode(paths[currentIndex], false, _fileSystem, null, out origin);
imagesTested[currentIndex] = 0;
@ -202,7 +194,6 @@ namespace Emby.Drawing.Skia
{
for (var y = 0; y < 2; y++)
{
SKCodecOrigin origin;
int newIndex;
using (var currentBitmap = GetNextValidImage(paths, imageIndex, out newIndex))

Loading…
Cancel
Save