mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 05:57:20 -04:00
Rewrite CropWhitespace
This commit is contained in:
parent
4a356efa2c
commit
36b05157f0
1 changed files with 10 additions and 37 deletions
|
@ -139,54 +139,27 @@ namespace Jellyfin.Drawing.Skia
|
|||
private SKBitmap CropWhiteSpace(SKBitmap bitmap)
|
||||
{
|
||||
var topmost = 0;
|
||||
for (int row = 0; row < bitmap.Height; ++row)
|
||||
while (topmost < bitmap.Height && IsTransparentRow(bitmap, topmost))
|
||||
{
|
||||
if (IsTransparentRow(bitmap, row))
|
||||
{
|
||||
topmost = row + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
topmost++;
|
||||
}
|
||||
|
||||
int bottommost = bitmap.Height;
|
||||
for (int row = bitmap.Height - 1; row >= 0; --row)
|
||||
while (bottommost >= 0 && IsTransparentRow(bitmap, bottommost - 1))
|
||||
{
|
||||
if (IsTransparentRow(bitmap, row))
|
||||
{
|
||||
bottommost = row;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
bottommost--;
|
||||
}
|
||||
|
||||
int leftmost = 0, rightmost = bitmap.Width;
|
||||
for (int col = 0; col < bitmap.Width; ++col)
|
||||
var leftmost = 0;
|
||||
while (leftmost < bitmap.Width && IsTransparentColumn(bitmap, leftmost))
|
||||
{
|
||||
if (IsTransparentColumn(bitmap, col))
|
||||
{
|
||||
leftmost = col + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
leftmost++;
|
||||
}
|
||||
|
||||
for (int col = bitmap.Width - 1; col >= 0; --col)
|
||||
var rightmost = bitmap.Width;
|
||||
while (rightmost >= 0 && IsTransparentColumn(bitmap, rightmost - 1))
|
||||
{
|
||||
if (IsTransparentColumn(bitmap, col))
|
||||
{
|
||||
rightmost = col;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
rightmost--;
|
||||
}
|
||||
|
||||
var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue