Merge pull request #724 from Bond-009/skia

Move Skia back into it's own project
pull/728/head
Andrew Rabert 6 years ago committed by GitHub
commit f74bfcb343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,12 +5,6 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="1.68.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="1.68.0" />
<PackageReference Include="Jellyfin.SkiaSharp.NativeAssets.LinuxArm" Version="1.68.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" /> <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" /> <ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\SharedVersion.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="1.68.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="1.68.0" />
<PackageReference Include="Jellyfin.SkiaSharp.NativeAssets.LinuxArm" Version="1.68.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
</ItemGroup>
</Project>

@ -2,7 +2,7 @@ using System;
using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Drawing;
using SkiaSharp; using SkiaSharp;
namespace Emby.Drawing namespace Jellyfin.Drawing.Skia
{ {
public static class PercentPlayedDrawer public static class PercentPlayedDrawer
{ {

@ -1,7 +1,7 @@
using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Drawing;
using SkiaSharp; using SkiaSharp;
namespace Emby.Drawing namespace Jellyfin.Drawing.Skia
{ {
public static class PlayedIndicatorDrawer public static class PlayedIndicatorDrawer
{ {

@ -12,7 +12,7 @@ using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SkiaSharp; using SkiaSharp;
namespace Emby.Drawing namespace Jellyfin.Drawing.Skia
{ {
public class SkiaEncoder : IImageEncoder public class SkiaEncoder : IImageEncoder
{ {
@ -72,16 +72,11 @@ namespace Emby.Drawing
_logger.LogInformation("SkiaSharp version: " + GetVersion()); _logger.LogInformation("SkiaSharp version: " + GetVersion());
} }
public static string GetVersion() public static Version GetVersion()
{ => typeof(SKBitmap).GetTypeInfo().Assembly.GetName().Version;
return typeof(SKBitmap).GetTypeInfo().Assembly.GetName().Version.ToString();
}
private static bool IsTransparent(SKColor color) private static bool IsTransparent(SKColor color)
{ => (color.Red == 255 && color.Green == 255 && color.Blue == 255) || color.Alpha == 0;
return (color.Red == 255 && color.Green == 255 && color.Blue == 255) || color.Alpha == 0;
}
public static SKEncodedImageFormat GetImageFormat(ImageFormat selectedFormat) public static SKEncodedImageFormat GetImageFormat(ImageFormat selectedFormat)
{ {
@ -130,34 +125,52 @@ namespace Emby.Drawing
for (int row = 0; row < bitmap.Height; ++row) for (int row = 0; row < bitmap.Height; ++row)
{ {
if (IsTransparentRow(bitmap, row)) if (IsTransparentRow(bitmap, row))
{
topmost = row + 1; topmost = row + 1;
else break; }
else
{
break;
}
} }
int bottommost = bitmap.Height; int bottommost = bitmap.Height;
for (int row = bitmap.Height - 1; row >= 0; --row) for (int row = bitmap.Height - 1; row >= 0; --row)
{ {
if (IsTransparentRow(bitmap, row)) if (IsTransparentRow(bitmap, row))
{
bottommost = row; bottommost = row;
else break; }
else
{
break;
}
} }
int leftmost = 0, rightmost = bitmap.Width; int leftmost = 0, rightmost = bitmap.Width;
for (int col = 0; col < bitmap.Width; ++col) for (int col = 0; col < bitmap.Width; ++col)
{ {
if (IsTransparentColumn(bitmap, col)) if (IsTransparentColumn(bitmap, col))
{
leftmost = col + 1; leftmost = col + 1;
}
else else
{
break; break;
} }
}
for (int col = bitmap.Width - 1; col >= 0; --col) for (int col = bitmap.Width - 1; col >= 0; --col)
{ {
if (IsTransparentColumn(bitmap, col)) if (IsTransparentColumn(bitmap, col))
{
rightmost = col; rightmost = col;
}
else else
{
break; break;
} }
}
var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost); var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost);
@ -180,9 +193,7 @@ namespace Emby.Drawing
} }
private static bool HasDiacritics(string text) private static bool HasDiacritics(string text)
{ => !string.Equals(text, text.RemoveDiacritics(), StringComparison.Ordinal);
return !string.Equals(text, text.RemoveDiacritics(), StringComparison.Ordinal);
}
private static bool RequiresSpecialCharacterHack(string path) private static bool RequiresSpecialCharacterHack(string path)
{ {
@ -243,6 +254,7 @@ namespace Emby.Drawing
} }
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 SKEncodedOrigin origin) internal static SKBitmap Decode(string path, bool forceCleanBitmap, IFileSystem fileSystem, ImageOrientation? orientation, out SKEncodedOrigin origin)
{ {
if (!fileSystem.FileExists(path)) if (!fileSystem.FileExists(path))
@ -267,7 +279,7 @@ namespace Emby.Drawing
var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height, !requiresTransparencyHack); var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height, !requiresTransparencyHack);
// decode // decode
codec.GetPixels(bitmap.Info, bitmap.GetPixels()); var _ = codec.GetPixels(bitmap.Info, bitmap.GetPixels());
origin = codec.EncodedOrigin; origin = codec.EncodedOrigin;
@ -316,16 +328,13 @@ namespace Emby.Drawing
{ {
var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out origin); var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out origin);
if (bitmap != null) if (bitmap != null && origin != SKEncodedOrigin.TopLeft)
{
if (origin != SKEncodedOrigin.TopLeft)
{ {
using (bitmap) using (bitmap)
{ {
return OrientImage(bitmap, origin); return OrientImage(bitmap, origin);
} }
} }
}
return bitmap; return bitmap;
} }
@ -347,7 +356,6 @@ namespace Emby.Drawing
switch (origin) switch (origin)
{ {
case SKEncodedOrigin.TopRight: case SKEncodedOrigin.TopRight:
{ {
var rotated = new SKBitmap(bitmap.Width, bitmap.Height); var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
@ -366,11 +374,8 @@ namespace Emby.Drawing
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))
{ {
float px = bitmap.Width; float px = (float)bitmap.Width / 2;
px /= 2; float py = (float)bitmap.Height / 2;
float py = bitmap.Height;
py /= 2;
surface.RotateDegrees(180, px, py); surface.RotateDegrees(180, px, py);
surface.DrawBitmap(bitmap, 0, 0); surface.DrawBitmap(bitmap, 0, 0);
@ -384,11 +389,9 @@ namespace Emby.Drawing
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))
{ {
float px = bitmap.Width; float px = (float)bitmap.Width / 2;
px /= 2;
float py = bitmap.Height; float py = (float)bitmap.Height / 2;
py /= 2;
surface.Translate(rotated.Width, 0); surface.Translate(rotated.Width, 0);
surface.Scale(-1, 1); surface.Scale(-1, 1);
@ -412,7 +415,6 @@ namespace Emby.Drawing
surface.RotateDegrees(90); surface.RotateDegrees(90);
surface.DrawBitmap(bitmap, 0, 0); surface.DrawBitmap(bitmap, 0, 0);
} }
var flippedBitmap = new SKBitmap(rotated.Width, rotated.Height); var flippedBitmap = new SKBitmap(rotated.Width, rotated.Height);
@ -477,8 +479,7 @@ namespace Emby.Drawing
return rotated; return rotated;
} }
default: default: return bitmap;
return bitmap;
} }
} }
@ -488,6 +489,7 @@ namespace Emby.Drawing
{ {
throw new ArgumentNullException(nameof(inputPath)); throw new ArgumentNullException(nameof(inputPath));
} }
if (string.IsNullOrWhiteSpace(inputPath)) if (string.IsNullOrWhiteSpace(inputPath))
{ {
throw new ArgumentNullException(nameof(outputPath)); throw new ArgumentNullException(nameof(outputPath));
@ -507,11 +509,11 @@ namespace Emby.Drawing
throw new ArgumentOutOfRangeException(string.Format("Skia unable to read image {0}", inputPath)); throw new ArgumentOutOfRangeException(string.Format("Skia unable to read image {0}", inputPath));
} }
//_logger.LogInformation("Color type {0}", bitmap.Info.ColorType);
var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height); var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height);
if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize) && !autoOrient) if (!options.CropWhiteSpace
&& options.HasDefaultOptions(inputPath, originalImageSize)
&& !autoOrient)
{ {
// Just spit out the original file if all the options are default // Just spit out the original file if all the options are default
return inputPath; return inputPath;
@ -522,7 +524,7 @@ namespace Emby.Drawing
var width = newImageSize.Width; var width = newImageSize.Width;
var height = newImageSize.Height; var height = newImageSize.Height;
using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) using (var resizedBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType))
{ {
// scale image // scale image
bitmap.ScalePixels(resizedBitmap, SKFilterQuality.High); bitmap.ScalePixels(resizedBitmap, SKFilterQuality.High);
@ -532,14 +534,12 @@ namespace Emby.Drawing
{ {
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath)); _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath));
using (var outputStream = new SKFileWStream(outputPath)) using (var outputStream = new SKFileWStream(outputPath))
{
using (var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels())) using (var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels()))
{ {
pixmap.Encode(outputStream, skiaOutputFormat, quality); pixmap.Encode(outputStream, skiaOutputFormat, quality);
return outputPath; return outputPath;
} }
} }
}
// create bitmap to use for canvas drawing used to draw into bitmap // 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))
@ -600,8 +600,7 @@ namespace Emby.Drawing
public void CreateImageCollage(ImageCollageOptions options) public void CreateImageCollage(ImageCollageOptions options)
{ {
double ratio = options.Width; double ratio = (double)options.Width / options.Height;
ratio /= options.Height;
if (ratio >= 1.4) if (ratio >= 1.4)
{ {
@ -613,7 +612,7 @@ namespace Emby.Drawing
} }
else else
{ {
// @todo create Poster collage capability // TODO: Create Poster collage capability
new StripCollageBuilder(_appPaths, _fileSystem).BuildSquareCollage(options.InputPaths, options.OutputPath, options.Width, options.Height); new StripCollageBuilder(_appPaths, _fileSystem).BuildSquareCollage(options.InputPaths, options.OutputPath, options.Width, options.Height);
} }
} }

@ -5,7 +5,7 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using SkiaSharp; using SkiaSharp;
namespace Emby.Drawing namespace Jellyfin.Drawing.Skia
{ {
public class StripCollageBuilder public class StripCollageBuilder
{ {
@ -43,15 +43,9 @@ namespace Emby.Drawing
return SKEncodedImageFormat.Png; return SKEncodedImageFormat.Png;
} }
public void BuildPosterCollage(string[] paths, string outputPath, int width, int height)
{
// @todo
}
public void BuildSquareCollage(string[] paths, string outputPath, int width, int height) public void BuildSquareCollage(string[] paths, string outputPath, int width, int height)
{ {
using (var bitmap = BuildSquareCollageBitmap(paths, width, height)) using (var bitmap = BuildSquareCollageBitmap(paths, width, height))
{
using (var outputStream = new SKFileWStream(outputPath)) using (var outputStream = new SKFileWStream(outputPath))
{ {
using (var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels())) using (var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels()))
@ -60,7 +54,6 @@ namespace Emby.Drawing
} }
} }
} }
}
public void BuildThumbCollage(string[] paths, string outputPath, int width, int height) public void BuildThumbCollage(string[] paths, string outputPath, int width, int height)
{ {

@ -2,7 +2,7 @@ using System.Globalization;
using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Drawing;
using SkiaSharp; using SkiaSharp;
namespace Emby.Drawing namespace Jellyfin.Drawing.Skia
{ {
public static class UnplayedCountIndicator public static class UnplayedCountIndicator
{ {

@ -49,6 +49,7 @@
<ProjectReference Include="..\Emby.Drawing\Emby.Drawing.csproj" /> <ProjectReference Include="..\Emby.Drawing\Emby.Drawing.csproj" />
<ProjectReference Include="..\Emby.IsoMounting\IsoMounter\IsoMounter.csproj" /> <ProjectReference Include="..\Emby.IsoMounting\IsoMounter\IsoMounter.csproj" />
<ProjectReference Include="..\Emby.Server.Implementations\Emby.Server.Implementations.csproj" /> <ProjectReference Include="..\Emby.Server.Implementations\Emby.Server.Implementations.csproj" />
<ProjectReference Include="..\Jellyfin.Drawing.Skia\Jellyfin.Drawing.Skia.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -13,6 +13,7 @@ using Emby.Server.Implementations;
using Emby.Server.Implementations.EnvironmentInfo; using Emby.Server.Implementations.EnvironmentInfo;
using Emby.Server.Implementations.IO; using Emby.Server.Implementations.IO;
using Emby.Server.Implementations.Networking; using Emby.Server.Implementations.Networking;
using Jellyfin.Drawing.Skia;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Globalization;

@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26730.3 VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
@ -56,6 +56,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
SharedVersion.cs = SharedVersion.cs SharedVersion.cs = SharedVersion.cs
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Drawing.Skia", "Jellyfin.Drawing.Skia\Jellyfin.Drawing.Skia.csproj", "{154872D9-6C12-4007-96E3-8F70A58386CE}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -158,6 +160,10 @@ Global
{07E39F42-A2C6-4B32-AF8C-725F957A73FF}.Debug|Any CPU.Build.0 = Debug|Any CPU {07E39F42-A2C6-4B32-AF8C-725F957A73FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07E39F42-A2C6-4B32-AF8C-725F957A73FF}.Release|Any CPU.ActiveCfg = Release|Any CPU {07E39F42-A2C6-4B32-AF8C-725F957A73FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07E39F42-A2C6-4B32-AF8C-725F957A73FF}.Release|Any CPU.Build.0 = Release|Any CPU {07E39F42-A2C6-4B32-AF8C-725F957A73FF}.Release|Any CPU.Build.0 = Release|Any CPU
{154872D9-6C12-4007-96E3-8F70A58386CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{154872D9-6C12-4007-96E3-8F70A58386CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{154872D9-6C12-4007-96E3-8F70A58386CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{154872D9-6C12-4007-96E3-8F70A58386CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save