Rename ImageFileFormat.Unspecified to Unknown

This commit is contained in:
Ben Olden-Cooligan 2024-01-03 15:53:38 -08:00
parent 0b93ca2a15
commit 0afea36ba5
17 changed files with 34 additions and 34 deletions

View File

@ -63,7 +63,7 @@ public static class GdiExtensions
{
return ImageFileFormat.Tiff;
}
return ImageFileFormat.Unspecified;
return ImageFileFormat.Unknown;
}
public static PixelFormat AsPixelFormat(this ImagePixelFormat pixelFormat)

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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));
}

View File

@ -80,7 +80,7 @@ public interface IMemoryImage : IImageStorage
/// <param name="path">The path to save the image file to.</param>
/// <param name="imageFormat">The file format to use.</param>
/// <param name="options">Options for saving, e.g. JPEG quality.</param>
void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unspecified, ImageSaveOptions? options = null);
void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null);
/// <summary>
/// Saves the image to the given stream. The file format must be specified.

View File

@ -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;
}

View File

@ -38,9 +38,9 @@ public static class ImageExtensions
/// <param name="imageFormat">The file format to use.</param>
/// <param name="options">Options for saving, e.g. JPEG quality.</param>
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
/// <param name="imageFormat">The file format to use.</param>
/// <param name="options">Options for saving, e.g. JPEG quality.</param>
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));
}

View File

@ -2,7 +2,7 @@ namespace NAPS2.Images;
public enum ImageFileFormat
{
Unspecified,
Unknown,
Bmp,
Jpeg,
Jpeg2000,

View File

@ -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}");
}

View File

@ -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);

View File

@ -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<ArgumentException>(() => image.Save(stream, ImageFileFormat.Unspecified));
Assert.Throws<ArgumentException>(() => image.Save(stream, ImageFileFormat.Unknown));
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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 };
}

View File

@ -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));