Rename ImagePixelFormat.Unsupported to Unknown

This commit is contained in:
Ben Olden-Cooligan 2024-01-03 15:55:02 -08:00
parent 0afea36ba5
commit 37032983f5
16 changed files with 25 additions and 25 deletions

View File

@ -95,7 +95,7 @@ public static class GdiExtensions
case PixelFormat.Format1bppIndexed:
return ImagePixelFormat.BW1;
default:
return ImagePixelFormat.Unsupported;
return ImagePixelFormat.Unknown;
}
}

View File

@ -50,7 +50,7 @@ public class GdiImage : IMemoryImage
{
if (lockMode != LockMode.ReadOnly)
{
LogicalPixelFormat = ImagePixelFormat.Unsupported;
LogicalPixelFormat = ImagePixelFormat.Unknown;
}
return GdiImageLockState.Create(Bitmap, lockMode, out imageData);
}

View File

@ -46,7 +46,7 @@ public class GtkImage : IMemoryImage
{
if (lockMode != LockMode.ReadOnly)
{
LogicalPixelFormat = ImagePixelFormat.Unsupported;
LogicalPixelFormat = ImagePixelFormat.Unknown;
}
var ptr = Pixbuf.Pixels;
var stride = Pixbuf.Rowstride;

View File

@ -60,7 +60,7 @@ public class GtkImageContext : ImageContext
public override IMemoryImage Create(int width, int height, ImagePixelFormat pixelFormat)
{
if (pixelFormat == ImagePixelFormat.Unsupported)
if (pixelFormat == ImagePixelFormat.Unknown)
{
throw new ArgumentException("Unsupported pixel format");
}

View File

@ -75,7 +75,7 @@ public class GtkImageTransformer : AbstractImageTransformer<GtkImage>
protected override GtkImage PerformTransform(GtkImage image, GrayscaleTransform transform)
{
new DecolorBitwiseImageOp(false).Perform(image);
if (image.LogicalPixelFormat != ImagePixelFormat.Unsupported)
if (image.LogicalPixelFormat != ImagePixelFormat.Unknown)
{
image.LogicalPixelFormat = ImagePixelFormat.Gray8;
}

View File

@ -63,7 +63,7 @@ public class ImageSharpImage : IMemoryImage
{
if (lockMode != LockMode.ReadOnly)
{
LogicalPixelFormat = ImagePixelFormat.Unsupported;
LogicalPixelFormat = ImagePixelFormat.Unknown;
}
var memoryHandle = PixelFormat switch
{

View File

@ -55,7 +55,7 @@ public class ImageSharpImageContext : ImageContext
public override IMemoryImage Create(int width, int height, ImagePixelFormat pixelFormat)
{
if (pixelFormat == ImagePixelFormat.Unsupported)
if (pixelFormat == ImagePixelFormat.Unknown)
{
throw new ArgumentException("Unsupported pixel format");
}

View File

@ -32,7 +32,7 @@ public class MacImage : IMemoryImage
bool isDeviceColorSpace = Rep.ColorSpaceName == NSColorSpace.DeviceRGB ||
Rep.ColorSpaceName == NSColorSpace.DeviceWhite;
#pragma warning restore CA1416,CA1422
if (PixelFormat == ImagePixelFormat.Unsupported)
if (PixelFormat == ImagePixelFormat.Unknown)
{
var rep = MacBitmapHelper.CopyRep(Rep);
ReplaceRep(rep);
@ -65,7 +65,7 @@ public class MacImage : IMemoryImage
{ BitsPerPixel: 32, BitsPerSample: 8, SamplesPerPixel: 3 } => ImagePixelFormat.RGB24,
{ BitsPerPixel: 8, BitsPerSample: 8, SamplesPerPixel: 1 } => ImagePixelFormat.Gray8,
{ BitsPerPixel: 1, BitsPerSample: 1, SamplesPerPixel: 1 } => ImagePixelFormat.BW1,
_ => ImagePixelFormat.Unsupported
_ => ImagePixelFormat.Unknown
};
}
@ -94,7 +94,7 @@ public class MacImage : IMemoryImage
{
if (lockMode != LockMode.ReadOnly)
{
LogicalPixelFormat = ImagePixelFormat.Unsupported;
LogicalPixelFormat = ImagePixelFormat.Unknown;
}
var ptr = Rep.BitmapData;
var stride = (int) Rep.BytesPerRow;
@ -166,7 +166,7 @@ public class MacImage : IMemoryImage
_ => throw new InvalidOperationException("Unsupported image format")
};
var targetFormat = options.PixelFormatHint;
if (imageFormat == ImageFileFormat.Bmp && targetFormat == ImagePixelFormat.Unsupported &&
if (imageFormat == ImageFileFormat.Bmp && targetFormat == ImagePixelFormat.Unknown &&
PixelFormat == ImagePixelFormat.Gray8)
{
// Workaround for issue in some macOS versions with 8bit BMPs

View File

@ -70,7 +70,7 @@ public class WpfImage : IMemoryImage
if (_disposed) throw new InvalidOperationException();
if (lockMode != LockMode.ReadOnly)
{
LogicalPixelFormat = ImagePixelFormat.Unsupported;
LogicalPixelFormat = ImagePixelFormat.Unknown;
}
var subPixelType = GetSubPixelType();
imageData = new BitwiseImageData((byte*) Bitmap.BackBuffer,

View File

@ -64,7 +64,7 @@ public class WpfImageContext : ImageContext
public override IMemoryImage Create(int width, int height, ImagePixelFormat pixelFormat)
{
if (pixelFormat == ImagePixelFormat.Unsupported)
if (pixelFormat == ImagePixelFormat.Unknown)
{
throw new ArgumentException("Unsupported pixel format");
}

View File

@ -118,7 +118,7 @@ public static class ImageExtensions
public static ImagePixelFormat UpdateLogicalPixelFormat(this IMemoryImage image)
{
if (image.LogicalPixelFormat != ImagePixelFormat.Unsupported)
if (image.LogicalPixelFormat != ImagePixelFormat.Unknown)
{
return image.LogicalPixelFormat;
}
@ -183,11 +183,11 @@ public static class ImageExtensions
public static IMemoryImage CopyWithPixelFormat(this IMemoryImage source, ImageContext imageContext,
ImagePixelFormat pixelFormat)
{
if (pixelFormat == ImagePixelFormat.Unsupported) throw new ArgumentException();
if (pixelFormat == ImagePixelFormat.Unknown) throw new ArgumentException();
var newImage = source.CopyBlankWithPixelFormat(imageContext, pixelFormat);
new CopyBitwiseImageOp().Perform(source, newImage);
newImage.OriginalFileFormat = source.OriginalFileFormat;
if (source.LogicalPixelFormat != ImagePixelFormat.Unsupported)
if (source.LogicalPixelFormat != ImagePixelFormat.Unknown)
{
newImage.LogicalPixelFormat =
source.LogicalPixelFormat < pixelFormat ? source.LogicalPixelFormat : pixelFormat;
@ -226,7 +226,7 @@ public static class ImageExtensions
public static IMemoryImage CopyBlankWithPixelFormat(this IMemoryImage source, ImageContext imageContext,
ImagePixelFormat pixelFormat)
{
if (pixelFormat == ImagePixelFormat.Unsupported) throw new ArgumentException();
if (pixelFormat == ImagePixelFormat.Unknown) throw new ArgumentException();
var newImage = imageContext.Create(source.Width, source.Height, pixelFormat);
newImage.SetResolution(source.HorizontalResolution, source.VerticalResolution);
return newImage;

View File

@ -2,7 +2,7 @@
public enum ImagePixelFormat
{
Unsupported,
Unknown,
BW1,
Gray8,
RGB24,

View File

@ -4,8 +4,8 @@ namespace NAPS2.Images;
internal static class PixelFormatHelper
{
public static PixelFormatHelper<T> Create<T>(T image,
ImagePixelFormat targetFormat = ImagePixelFormat.Unsupported,
ImagePixelFormat minFormat = ImagePixelFormat.Unsupported) where T : IMemoryImage
ImagePixelFormat targetFormat = ImagePixelFormat.Unknown,
ImagePixelFormat minFormat = ImagePixelFormat.Unknown) where T : IMemoryImage
{
return new PixelFormatHelper<T>(image, targetFormat, minFormat);
}
@ -18,7 +18,7 @@ internal class PixelFormatHelper<T> : IDisposable where T : IMemoryImage
image.UpdateLogicalPixelFormat();
// TODO: Maybe we can be aware of the target filetype, e.g. JPEG doesn't have 1bpp. Although the specifics
// are going to be platform-dependent.
if (targetFormat == ImagePixelFormat.Unsupported)
if (targetFormat == ImagePixelFormat.Unknown)
{
// If targetFormat is not specified, we'll use the logical format to minimize on-disk size.
targetFormat = image.LogicalPixelFormat;

View File

@ -14,7 +14,7 @@ public abstract class AbstractImageTransformer<TImage> where TImage : IMemoryIma
public TImage Apply(TImage image, Transform transform)
{
if (image.PixelFormat == ImagePixelFormat.Unsupported)
if (image.PixelFormat == ImagePixelFormat.Unknown)
{
throw new ArgumentException("Unsupported pixel format for transforms");
}

View File

@ -68,7 +68,7 @@ public static class ImageAsserts
private static void Similar(IMemoryImage first, IMemoryImage second,
double rmseThreshold, bool ignoreResolution, bool isSimilar)
{
if (first.PixelFormat == ImagePixelFormat.Unsupported || second.PixelFormat == ImagePixelFormat.Unsupported)
if (first.PixelFormat == ImagePixelFormat.Unknown || second.PixelFormat == ImagePixelFormat.Unknown)
{
throw new InvalidOperationException($"Unsupported pixel formats {first.PixelFormat} {second.PixelFormat}");
}

View File

@ -135,7 +135,7 @@ internal class DeviceOperator : ICScannerDeviceDelegate
(ICScannerPixelDataType.Gray, 1, 8) => (ImagePixelFormat.Gray8, SubPixelType.Gray),
(ICScannerPixelDataType.Rgb, 3, 8) => (ImagePixelFormat.RGB24, SubPixelType.Rgb),
(ICScannerPixelDataType.Rgb, 4, 8) => (ImagePixelFormat.RGB24, SubPixelType.Rgbn),
_ => (ImagePixelFormat.Unsupported, null)
_ => (ImagePixelFormat.Unknown, null)
};
_logger.LogDebug(
"Image data: width {Width}, height {Height}, type {Type}, comp {Comp}, " +
@ -147,7 +147,7 @@ internal class DeviceOperator : ICScannerDeviceDelegate
_logger.LogDebug($"Flushing image with color sync profile {data.ColorSyncProfilePath}");
FlushImageWithColorSpace(fullBuffer, data, subPixelType);
}
else if (pixelFormat != ImagePixelFormat.Unsupported && subPixelType != null)
else if (pixelFormat != ImagePixelFormat.Unknown && subPixelType != null)
{
_logger.LogDebug($"Flushing image with pixel format {pixelFormat}");
FlushImageDirectly(fullBuffer, data, subPixelType, pixelFormat);