From 0afea36ba524418a92862cb0ce2bffc3bcaa74c8 Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Wed, 3 Jan 2024 15:53:38 -0800 Subject: [PATCH] Rename ImageFileFormat.Unspecified to Unknown --- NAPS2.Images.Gdi/GdiExtensions.cs | 2 +- NAPS2.Images.Gdi/GdiImage.cs | 6 +++--- NAPS2.Images.Gtk/GtkImage.cs | 6 +++--- NAPS2.Images.ImageSharp/ImageSharpImage.cs | 6 +++--- NAPS2.Images.Mac/MacImage.cs | 6 +++--- NAPS2.Images.Wpf/WpfImage.cs | 6 +++--- NAPS2.Images/IMemoryImage.cs | 2 +- NAPS2.Images/ImageContext.cs | 10 +++++----- NAPS2.Images/ImageExtensions.cs | 8 ++++---- NAPS2.Images/ImageFileFormat.cs | 2 +- NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs | 2 +- NAPS2.Sdk.Tests/Images/ImageExportHelperTests.cs | 2 +- NAPS2.Sdk.Tests/Images/MemoryImageTests.cs | 2 +- NAPS2.Sdk/Images/ImageExportHelper.cs | 2 +- NAPS2.Sdk/ImportExport/FileImporter.cs | 2 +- NAPS2.Sdk/Pdf/PdfExporter.cs | 2 +- NAPS2.Sdk/Serialization/ImageSerializer.cs | 2 +- 17 files changed, 34 insertions(+), 34 deletions(-) diff --git a/NAPS2.Images.Gdi/GdiExtensions.cs b/NAPS2.Images.Gdi/GdiExtensions.cs index a7cd8a692..def2e1a53 100644 --- a/NAPS2.Images.Gdi/GdiExtensions.cs +++ b/NAPS2.Images.Gdi/GdiExtensions.cs @@ -63,7 +63,7 @@ public static class GdiExtensions { return ImageFileFormat.Tiff; } - return ImageFileFormat.Unspecified; + return ImageFileFormat.Unknown; } public static PixelFormat AsPixelFormat(this ImagePixelFormat pixelFormat) diff --git a/NAPS2.Images.Gdi/GdiImage.cs b/NAPS2.Images.Gdi/GdiImage.cs index 38445c07b..75b45e19b 100644 --- a/NAPS2.Images.Gdi/GdiImage.cs +++ b/NAPS2.Images.Gdi/GdiImage.cs @@ -60,9 +60,9 @@ public class GdiImage : IMemoryImage public ImagePixelFormat LogicalPixelFormat { get; set; } - public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unspecified, ImageSaveOptions? options = null) + public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { imageFormat = ImageContext.GetFileFormatFromExtension(path); } @@ -82,7 +82,7 @@ public class GdiImage : IMemoryImage public void Save(Stream stream, ImageFileFormat imageFormat, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { throw new ArgumentException("Format required to save to a stream", nameof(imageFormat)); } diff --git a/NAPS2.Images.Gtk/GtkImage.cs b/NAPS2.Images.Gtk/GtkImage.cs index 4b066cb8a..a542ffe6b 100644 --- a/NAPS2.Images.Gtk/GtkImage.cs +++ b/NAPS2.Images.Gtk/GtkImage.cs @@ -72,10 +72,10 @@ public class GtkImage : IMemoryImage public ImagePixelFormat LogicalPixelFormat { get; set; } - public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unspecified, + public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { imageFormat = ImageContext.GetFileFormatFromExtension(path); } @@ -94,7 +94,7 @@ public class GtkImage : IMemoryImage public void Save(Stream stream, ImageFileFormat imageFormat, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { throw new ArgumentException("Format required to save to a stream", nameof(imageFormat)); } diff --git a/NAPS2.Images.ImageSharp/ImageSharpImage.cs b/NAPS2.Images.ImageSharp/ImageSharpImage.cs index 4c5fa47f7..1d3f7c198 100644 --- a/NAPS2.Images.ImageSharp/ImageSharpImage.cs +++ b/NAPS2.Images.ImageSharp/ImageSharpImage.cs @@ -108,10 +108,10 @@ public class ImageSharpImage : IMemoryImage public ImagePixelFormat LogicalPixelFormat { get; set; } - public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unspecified, + public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { imageFormat = ImageContext.GetFileFormatFromExtension(path); } @@ -125,7 +125,7 @@ public class ImageSharpImage : IMemoryImage public void Save(Stream stream, ImageFileFormat imageFormat, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { throw new ArgumentException("Format required to save to a stream", nameof(imageFormat)); } diff --git a/NAPS2.Images.Mac/MacImage.cs b/NAPS2.Images.Mac/MacImage.cs index ac21f16f7..3cf197754 100644 --- a/NAPS2.Images.Mac/MacImage.cs +++ b/NAPS2.Images.Mac/MacImage.cs @@ -122,10 +122,10 @@ public class MacImage : IMemoryImage public ImagePixelFormat LogicalPixelFormat { get; set; } - public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unspecified, + public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { imageFormat = ImageContext.GetFileFormatFromExtension(path); } @@ -139,7 +139,7 @@ public class MacImage : IMemoryImage public void Save(Stream stream, ImageFileFormat imageFormat, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { throw new ArgumentException("Format required to save to a stream", nameof(imageFormat)); } diff --git a/NAPS2.Images.Wpf/WpfImage.cs b/NAPS2.Images.Wpf/WpfImage.cs index b7da17d94..6b630ff57 100644 --- a/NAPS2.Images.Wpf/WpfImage.cs +++ b/NAPS2.Images.Wpf/WpfImage.cs @@ -98,11 +98,11 @@ public class WpfImage : IMemoryImage public ImagePixelFormat LogicalPixelFormat { get; set; } - public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unspecified, + public void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null) { if (_disposed) throw new InvalidOperationException(); - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { imageFormat = ImageContext.GetFileFormatFromExtension(path); } @@ -119,7 +119,7 @@ public class WpfImage : IMemoryImage public void Save(Stream stream, ImageFileFormat imageFormat, ImageSaveOptions? options = null) { if (_disposed) throw new InvalidOperationException(); - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { throw new ArgumentException("Format required to save to a stream", nameof(imageFormat)); } diff --git a/NAPS2.Images/IMemoryImage.cs b/NAPS2.Images/IMemoryImage.cs index 272a11721..4b4ea01a0 100644 --- a/NAPS2.Images/IMemoryImage.cs +++ b/NAPS2.Images/IMemoryImage.cs @@ -80,7 +80,7 @@ public interface IMemoryImage : IImageStorage /// The path to save the image file to. /// The file format to use. /// Options for saving, e.g. JPEG quality. - void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unspecified, ImageSaveOptions? options = null); + void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null); /// /// Saves the image to the given stream. The file format must be specified. diff --git a/NAPS2.Images/ImageContext.cs b/NAPS2.Images/ImageContext.cs index 5998c310a..7b2fdc327 100644 --- a/NAPS2.Images/ImageContext.cs +++ b/NAPS2.Images/ImageContext.cs @@ -16,7 +16,7 @@ public abstract class ImageContext ".jpg" or ".jpeg" => ImageFileFormat.Jpeg, ".tif" or ".tiff" => ImageFileFormat.Tiff, ".jp2" or ".jpx" => ImageFileFormat.Jpeg2000, - _ => ImageFileFormat.Unspecified + _ => ImageFileFormat.Unknown }; } @@ -24,7 +24,7 @@ public abstract class ImageContext { if (!stream.CanSeek) { - return ImageFileFormat.Unspecified; + return ImageFileFormat.Unknown; } var firstBytes = new byte[8]; stream.Seek(0, SeekOrigin.Begin); @@ -39,7 +39,7 @@ public abstract class ImageContext [0x49, 0x49, 0x2A, 0x00, ..] => ImageFileFormat.Tiff, [0x4D, 0x4D, 0x00, 0x2A, ..] => ImageFileFormat.Tiff, [_, _, _, _, 0x6A, 0x50, 0x20, 0x20, ..] => ImageFileFormat.Jpeg2000, - _ => ImageFileFormat.Unspecified + _ => ImageFileFormat.Unknown }; } @@ -142,7 +142,7 @@ public abstract class ImageContext var format = GetFileFormatFromFirstBytes(stream); CheckSupportsFormat(format); var image = LoadCore(stream, format); - if (image.OriginalFileFormat == ImageFileFormat.Unspecified) + if (image.OriginalFileFormat == ImageFileFormat.Unknown) { image.OriginalFileFormat = format; } @@ -219,7 +219,7 @@ public abstract class ImageContext { await foreach (var image in source) { - if (image.OriginalFileFormat == ImageFileFormat.Unspecified) + if (image.OriginalFileFormat == ImageFileFormat.Unknown) { image.OriginalFileFormat = format; } diff --git a/NAPS2.Images/ImageExtensions.cs b/NAPS2.Images/ImageExtensions.cs index b05ab4483..efc2c0adf 100644 --- a/NAPS2.Images/ImageExtensions.cs +++ b/NAPS2.Images/ImageExtensions.cs @@ -38,9 +38,9 @@ public static class ImageExtensions /// The file format to use. /// Options for saving, e.g. JPEG quality. public static void Save(this IRenderableImage image, string path, - ImageFileFormat imageFormat = ImageFileFormat.Unspecified, ImageSaveOptions? options = null) + ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { imageFormat = ImageContext.GetFileFormatFromExtension(path); } @@ -61,9 +61,9 @@ public static class ImageExtensions /// The file format to use. /// Options for saving, e.g. JPEG quality. public static void Save(this IRenderableImage image, Stream stream, - ImageFileFormat imageFormat = ImageFileFormat.Unspecified, ImageSaveOptions? options = null) + ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null) { - if (imageFormat == ImageFileFormat.Unspecified) + if (imageFormat == ImageFileFormat.Unknown) { throw new ArgumentException("Format required to save to a stream", nameof(imageFormat)); } diff --git a/NAPS2.Images/ImageFileFormat.cs b/NAPS2.Images/ImageFileFormat.cs index 996f291f2..416861993 100644 --- a/NAPS2.Images/ImageFileFormat.cs +++ b/NAPS2.Images/ImageFileFormat.cs @@ -2,7 +2,7 @@ namespace NAPS2.Images; public enum ImageFileFormat { - Unspecified, + Unknown, Bmp, Jpeg, Jpeg2000, diff --git a/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs b/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs index 4f5675799..43a579a38 100644 --- a/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs +++ b/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs @@ -47,7 +47,7 @@ internal class SaveImagesOperation : OperationBase subFileName = placeholders.Substitute(fileName, batch); } var format = ImageContext.GetFileFormatFromExtension(subFileName); - if (format == ImageFileFormat.Unspecified) + if (format == ImageFileFormat.Unknown) { throw new ArgumentException($"Could not infer file format from extension: {subFileName}"); } diff --git a/NAPS2.Sdk.Tests/Images/ImageExportHelperTests.cs b/NAPS2.Sdk.Tests/Images/ImageExportHelperTests.cs index 9f163a721..8795591d2 100644 --- a/NAPS2.Sdk.Tests/Images/ImageExportHelperTests.cs +++ b/NAPS2.Sdk.Tests/Images/ImageExportHelperTests.cs @@ -82,7 +82,7 @@ public class ImageExportHelperTests : ContextualTests public void SaveSmallestFormat_SmallerJpeg() { var color = LoadImage(ImageResources.dog_png); - color.OriginalFileFormat = ImageFileFormat.Unspecified; + color.OriginalFileFormat = ImageFileFormat.Unknown; var path = Path.Combine(FolderPath, "test"); var fullPath = _helper.SaveSmallestFormat(path, color, BitDepth.Color, false, -1, out var format); diff --git a/NAPS2.Sdk.Tests/Images/MemoryImageTests.cs b/NAPS2.Sdk.Tests/Images/MemoryImageTests.cs index 778ba3bdf..b21c1ccd1 100644 --- a/NAPS2.Sdk.Tests/Images/MemoryImageTests.cs +++ b/NAPS2.Sdk.Tests/Images/MemoryImageTests.cs @@ -111,6 +111,6 @@ public class MemoryImageTests : ContextualTests var path = Path.Combine(FolderPath, "test.png"); using var stream = new FileStream(path, FileMode.CreateNew); - Assert.Throws(() => image.Save(stream, ImageFileFormat.Unspecified)); + Assert.Throws(() => image.Save(stream, ImageFileFormat.Unknown)); } } \ No newline at end of file diff --git a/NAPS2.Sdk/Images/ImageExportHelper.cs b/NAPS2.Sdk/Images/ImageExportHelper.cs index d12532dbd..8cdd396fc 100644 --- a/NAPS2.Sdk/Images/ImageExportHelper.cs +++ b/NAPS2.Sdk/Images/ImageExportHelper.cs @@ -78,6 +78,6 @@ internal class ImageExportHelper return new ImageExportFormat(ImageFileFormat.Jpeg, ImagePixelFormat.RGB24); } // No inherent preference for Jpeg or Png, the caller can decide - return new ImageExportFormat(ImageFileFormat.Unspecified, ImagePixelFormat.RGB24); + return new ImageExportFormat(ImageFileFormat.Unknown, ImagePixelFormat.RGB24); } } \ No newline at end of file diff --git a/NAPS2.Sdk/ImportExport/FileImporter.cs b/NAPS2.Sdk/ImportExport/FileImporter.cs index 04c40f907..957d0519d 100644 --- a/NAPS2.Sdk/ImportExport/FileImporter.cs +++ b/NAPS2.Sdk/ImportExport/FileImporter.cs @@ -34,7 +34,7 @@ public class FileImporter { return _pdfImporter.Import(filePath, importParams, progress); } - if (ImageContext.GetFileFormatFromExtension(filePath) != ImageFileFormat.Unspecified) + if (ImageContext.GetFileFormatFromExtension(filePath) != ImageFileFormat.Unknown) { return _imageImporter.Import(filePath, importParams, progress); } diff --git a/NAPS2.Sdk/Pdf/PdfExporter.cs b/NAPS2.Sdk/Pdf/PdfExporter.cs index d30177350..9f739a581 100644 --- a/NAPS2.Sdk/Pdf/PdfExporter.cs +++ b/NAPS2.Sdk/Pdf/PdfExporter.cs @@ -705,7 +705,7 @@ public class PdfExporter public ImageExportFormat PrepareForExport(ImageMetadata metadata) { var exportFormat = new ImageExportHelper().GetExportFormat(Image, metadata.BitDepth, metadata.Lossless); - if (exportFormat.FileFormat == ImageFileFormat.Unspecified) + if (exportFormat.FileFormat == ImageFileFormat.Unknown) { exportFormat = exportFormat with { FileFormat = ImageFileFormat.Jpeg }; } diff --git a/NAPS2.Sdk/Serialization/ImageSerializer.cs b/NAPS2.Sdk/Serialization/ImageSerializer.cs index 6a5c87031..b67dc5cd0 100644 --- a/NAPS2.Sdk/Serialization/ImageSerializer.cs +++ b/NAPS2.Sdk/Serialization/ImageSerializer.cs @@ -66,7 +66,7 @@ internal static class ImageSerializer result.TypeHint = memoryStorage.TypeHint; break; case IMemoryImage imageStorage: - var fileFormat = imageStorage.OriginalFileFormat == ImageFileFormat.Unspecified + var fileFormat = imageStorage.OriginalFileFormat == ImageFileFormat.Unknown ? ImageFileFormat.Jpeg : imageStorage.OriginalFileFormat; result.FileContent = ByteString.FromStream(imageStorage.SaveToMemoryStream(fileFormat));