mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-15 23:58:57 +00:00
Merge branch 'master' into trickplay
This commit is contained in:
@@ -31,8 +31,12 @@
|
||||
<ProjectReference Include="..\..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Code analysers-->
|
||||
<!-- Code Analyzers-->
|
||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<PackageReference Include="IDisposableAnalyzers">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
|
||||
@@ -126,8 +126,8 @@ public class SkiaEncoder : IImageEncoder
|
||||
var svg = new SKSvg();
|
||||
try
|
||||
{
|
||||
svg.Load(path);
|
||||
return new ImageDimensions(Convert.ToInt32(svg.Picture.CullRect.Width), Convert.ToInt32(svg.Picture.CullRect.Height));
|
||||
using var picture = svg.Load(path);
|
||||
return new ImageDimensions(Convert.ToInt32(picture.CullRect.Width), Convert.ToInt32(picture.CullRect.Height));
|
||||
}
|
||||
catch (FormatException skiaColorException)
|
||||
{
|
||||
@@ -192,7 +192,7 @@ public class SkiaEncoder : IImageEncoder
|
||||
return path;
|
||||
}
|
||||
|
||||
var tempPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + Path.GetExtension(path));
|
||||
var tempPath = Path.Combine(_appPaths.TempDirectory, string.Concat(Guid.NewGuid().ToString(), Path.GetExtension(path.AsSpan())));
|
||||
var directory = Path.GetDirectoryName(tempPath) ?? throw new ResourceNotFoundException($"Provided path ({tempPath}) is not valid.");
|
||||
Directory.CreateDirectory(directory);
|
||||
File.Copy(path, tempPath, true);
|
||||
@@ -204,20 +204,10 @@ public class SkiaEncoder : IImageEncoder
|
||||
{
|
||||
if (!orientation.HasValue)
|
||||
{
|
||||
return SKEncodedOrigin.TopLeft;
|
||||
return SKEncodedOrigin.Default;
|
||||
}
|
||||
|
||||
return orientation.Value switch
|
||||
{
|
||||
ImageOrientation.TopRight => SKEncodedOrigin.TopRight,
|
||||
ImageOrientation.RightTop => SKEncodedOrigin.RightTop,
|
||||
ImageOrientation.RightBottom => SKEncodedOrigin.RightBottom,
|
||||
ImageOrientation.LeftTop => SKEncodedOrigin.LeftTop,
|
||||
ImageOrientation.LeftBottom => SKEncodedOrigin.LeftBottom,
|
||||
ImageOrientation.BottomRight => SKEncodedOrigin.BottomRight,
|
||||
ImageOrientation.BottomLeft => SKEncodedOrigin.BottomLeft,
|
||||
_ => SKEncodedOrigin.TopLeft
|
||||
};
|
||||
return (SKEncodedOrigin)orientation.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -436,7 +426,8 @@ public class SkiaEncoder : IImageEncoder
|
||||
|
||||
// scale image (the FromImage creates a copy)
|
||||
var imageInfo = new SKImageInfo(width, height, bitmap.ColorType, bitmap.AlphaType, bitmap.ColorSpace);
|
||||
using var resizedBitmap = SKBitmap.FromImage(ResizeImage(bitmap, imageInfo));
|
||||
using var resizedImage = ResizeImage(bitmap, imageInfo);
|
||||
using var resizedBitmap = SKBitmap.FromImage(resizedImage);
|
||||
|
||||
// If all we're doing is resizing then we can stop now
|
||||
if (!hasBackgroundColor && !hasForegroundColor && blur == 0 && !hasIndicator)
|
||||
@@ -493,10 +484,8 @@ public class SkiaEncoder : IImageEncoder
|
||||
Directory.CreateDirectory(directory);
|
||||
using (var outputStream = new SKFileWStream(outputPath))
|
||||
{
|
||||
using (var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels()))
|
||||
{
|
||||
pixmap.Encode(outputStream, skiaOutputFormat, quality);
|
||||
}
|
||||
using var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels());
|
||||
pixmap.Encode(outputStream, skiaOutputFormat, quality);
|
||||
}
|
||||
|
||||
return outputPath;
|
||||
|
||||
@@ -19,7 +19,6 @@ public static class SkiaHelper
|
||||
public static SKBitmap? GetNextValidImage(SkiaEncoder skiaEncoder, IReadOnlyList<string> paths, int currentIndex, out int newIndex)
|
||||
{
|
||||
var imagesTested = new Dictionary<int, int>();
|
||||
SKBitmap? bitmap = null;
|
||||
|
||||
while (imagesTested.Count < paths.Count)
|
||||
{
|
||||
@@ -28,7 +27,7 @@ public static class SkiaHelper
|
||||
currentIndex = 0;
|
||||
}
|
||||
|
||||
bitmap = skiaEncoder.Decode(paths[currentIndex], false, null, out _);
|
||||
SKBitmap? bitmap = skiaEncoder.Decode(paths[currentIndex], false, null, out _);
|
||||
|
||||
imagesTested[currentIndex] = 0;
|
||||
|
||||
@@ -36,11 +35,12 @@ public static class SkiaHelper
|
||||
|
||||
if (bitmap is not null)
|
||||
{
|
||||
break;
|
||||
newIndex = currentIndex;
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
newIndex = currentIndex;
|
||||
return bitmap;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ public partial class StripCollageBuilder
|
||||
_skiaEncoder = skiaEncoder;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"[^\p{IsCJKUnifiedIdeographs}\p{IsCJKUnifiedIdeographsExtensionA}\p{IsKatakana}\p{IsHiragana}\p{IsHangulSyllables}\p{IsHangulJamo}]")]
|
||||
private static partial Regex NonCjkPatternRegex();
|
||||
|
||||
[GeneratedRegex(@"\p{IsArabic}|\p{IsArmenian}|\p{IsHebrew}|\p{IsSyriac}|\p{IsThaana}")]
|
||||
private static partial Regex IsRtlTextRegex();
|
||||
|
||||
@@ -35,25 +38,25 @@ public partial class StripCollageBuilder
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(outputPath);
|
||||
|
||||
var ext = Path.GetExtension(outputPath);
|
||||
var ext = Path.GetExtension(outputPath.AsSpan());
|
||||
|
||||
if (string.Equals(ext, ".jpg", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(ext, ".jpeg", StringComparison.OrdinalIgnoreCase))
|
||||
if (ext.Equals(".jpg", StringComparison.OrdinalIgnoreCase)
|
||||
|| ext.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return SKEncodedImageFormat.Jpeg;
|
||||
}
|
||||
|
||||
if (string.Equals(ext, ".webp", StringComparison.OrdinalIgnoreCase))
|
||||
if (ext.Equals(".webp", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return SKEncodedImageFormat.Webp;
|
||||
}
|
||||
|
||||
if (string.Equals(ext, ".gif", StringComparison.OrdinalIgnoreCase))
|
||||
if (ext.Equals(".gif", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return SKEncodedImageFormat.Gif;
|
||||
}
|
||||
|
||||
if (string.Equals(ext, ".bmp", StringComparison.OrdinalIgnoreCase))
|
||||
if (ext.Equals(".bmp", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return SKEncodedImageFormat.Bmp;
|
||||
}
|
||||
@@ -123,8 +126,7 @@ public partial class StripCollageBuilder
|
||||
var typeFace = SKTypeface.FromFamilyName("sans-serif", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright);
|
||||
|
||||
// use the system fallback to find a typeface for the given CJK character
|
||||
var nonCjkPattern = @"[^\p{IsCJKUnifiedIdeographs}\p{IsCJKUnifiedIdeographsExtensionA}\p{IsKatakana}\p{IsHiragana}\p{IsHangulSyllables}\p{IsHangulJamo}]";
|
||||
var filteredName = Regex.Replace(libraryName ?? string.Empty, nonCjkPattern, string.Empty);
|
||||
var filteredName = NonCjkPatternRegex().Replace(libraryName ?? string.Empty, string.Empty);
|
||||
if (!string.IsNullOrEmpty(filteredName))
|
||||
{
|
||||
typeFace = SKFontManager.Default.MatchCharacter(null, SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright, null, filteredName[0]);
|
||||
@@ -187,12 +189,12 @@ public partial class StripCollageBuilder
|
||||
|
||||
// Scale image. The FromBitmap creates a copy
|
||||
var imageInfo = new SKImageInfo(cellWidth, cellHeight, currentBitmap.ColorType, currentBitmap.AlphaType, currentBitmap.ColorSpace);
|
||||
using var resizedBitmap = SKBitmap.FromImage(SkiaEncoder.ResizeImage(currentBitmap, imageInfo));
|
||||
using var resizeImage = SkiaEncoder.ResizeImage(currentBitmap, imageInfo);
|
||||
|
||||
// draw this image into the strip at the next position
|
||||
var xPos = x * cellWidth;
|
||||
var yPos = y * cellHeight;
|
||||
canvas.DrawBitmap(resizedBitmap, xPos, yPos);
|
||||
canvas.DrawImage(resizeImage, xPos, yPos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user