mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 15:26:55 +03:00
Match thumbnail placeholders to background
This commit is contained in:
parent
d392260cae
commit
80dc5c0635
54
NAPS2.Images/Bitwise/FillColorImageOp.cs
Normal file
54
NAPS2.Images/Bitwise/FillColorImageOp.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
namespace NAPS2.Images.Bitwise;
|
||||||
|
|
||||||
|
public class FillColorImageOp : UnaryBitwiseImageOp
|
||||||
|
{
|
||||||
|
private readonly byte _r, _g, _b, _a;
|
||||||
|
|
||||||
|
public FillColorImageOp(byte r, byte g, byte b, byte a)
|
||||||
|
{
|
||||||
|
_r = r;
|
||||||
|
_g = g;
|
||||||
|
_b = b;
|
||||||
|
_a = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PerformCore(BitwiseImageData data, int partStart, int partEnd)
|
||||||
|
{
|
||||||
|
if (data.bytesPerPixel is 1 or 3 or 4)
|
||||||
|
{
|
||||||
|
PerformRgba(data, partStart, partEnd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unsupported pixel format");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private unsafe void PerformRgba(BitwiseImageData data, int partStart, int partEnd)
|
||||||
|
{
|
||||||
|
bool gray = data.bytesPerPixel == 1;
|
||||||
|
byte luma = (byte) ((_r * R_MULT + _g * G_MULT + _b * B_MULT) / 1000);
|
||||||
|
for (int i = partStart; i < partEnd; i++)
|
||||||
|
{
|
||||||
|
var row = data.ptr + data.stride * i;
|
||||||
|
for (int j = 0; j < data.w; j++)
|
||||||
|
{
|
||||||
|
var pixel = row + j * data.bytesPerPixel;
|
||||||
|
if (gray)
|
||||||
|
{
|
||||||
|
*pixel = luma;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*(pixel + data.rOff) = _r;
|
||||||
|
*(pixel + data.gOff) = _g;
|
||||||
|
*(pixel + data.bOff) = _b;
|
||||||
|
}
|
||||||
|
if (data.hasAlpha)
|
||||||
|
{
|
||||||
|
*(pixel + data.aOff) = _a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using Eto.Drawing;
|
using Eto.Drawing;
|
||||||
using Eto.Forms;
|
using Eto.Forms;
|
||||||
|
using NAPS2.Images.Bitwise;
|
||||||
|
|
||||||
namespace NAPS2.EtoForms;
|
namespace NAPS2.EtoForms;
|
||||||
|
|
||||||
@ -40,4 +41,9 @@ public static class EtoExtensions
|
|||||||
{
|
{
|
||||||
return checkBox.Checked == true;
|
return checkBox.Checked == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Fill(this IMemoryImage image, Color color)
|
||||||
|
{
|
||||||
|
new FillColorImageOp((byte) color.Rb, (byte) color.Gb, (byte) color.Bb, (byte) color.Ab).Perform(image);
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,11 +9,13 @@ namespace NAPS2.Images;
|
|||||||
public class UiThumbnailProvider
|
public class UiThumbnailProvider
|
||||||
{
|
{
|
||||||
private readonly ImageContext _imageContext;
|
private readonly ImageContext _imageContext;
|
||||||
|
private readonly ColorScheme _colorScheme;
|
||||||
private IMemoryImage? _placeholder;
|
private IMemoryImage? _placeholder;
|
||||||
|
|
||||||
public UiThumbnailProvider(ImageContext imageContext)
|
public UiThumbnailProvider(ImageContext imageContext, ColorScheme colorScheme)
|
||||||
{
|
{
|
||||||
_imageContext = imageContext;
|
_imageContext = imageContext;
|
||||||
|
_colorScheme = colorScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMemoryImage GetThumbnail(UiImage img, int thumbnailSize)
|
public IMemoryImage GetThumbnail(UiImage img, int thumbnailSize)
|
||||||
@ -43,6 +45,7 @@ public class UiThumbnailProvider
|
|||||||
}
|
}
|
||||||
_placeholder?.Dispose();
|
_placeholder?.Dispose();
|
||||||
_placeholder = _imageContext.Create(thumbnailSize, thumbnailSize, ImagePixelFormat.RGB24);
|
_placeholder = _imageContext.Create(thumbnailSize, thumbnailSize, ImagePixelFormat.RGB24);
|
||||||
|
_placeholder.Fill(_colorScheme.BackgroundColor);
|
||||||
_placeholder = EtoPlatform.Current.DrawHourglass(_imageContext, _placeholder);
|
_placeholder = EtoPlatform.Current.DrawHourglass(_imageContext, _placeholder);
|
||||||
return _placeholder;
|
return _placeholder;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user