Skip to content

Commit

Permalink
Remove BitDepth from ImageMetadata
Browse files Browse the repository at this point in the history
This is obsolete now that we have LogicalPixelFormat
  • Loading branch information
cyanfish committed Jan 4, 2024
1 parent 3703298 commit 85fa644
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 98 deletions.
3 changes: 0 additions & 3 deletions NAPS2.Lib.Tests/Recovery/RecoveryStorageManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void IndexFileDefaultMetadata()

Assert.Contains("00001.jpg</FileName>", indexFileContent);
Assert.Contains("00002.jpg</FileName>", indexFileContent);
Assert.Contains("<BitDepth>C24Bit</BitDepth>", indexFileContent);
Assert.Contains("<HighQuality>false</HighQuality>", indexFileContent);
}

Expand All @@ -79,14 +78,12 @@ public void IndexFileCustomMetadata()
var image1 = new UiImage(
ScanningContext.CreateProcessedImage(
ImageContext.Create(100, 100, ImagePixelFormat.RGB24),
BitDepth.Grayscale,
true,
-1,
PageSize.A4));

_imageList.Mutate(new ListMutation<UiImage>.Append(image1));
var indexFileContent = File.ReadAllText(Path.Combine(_recoveryFolder, "index.xml"));
Assert.Contains("<BitDepth>Grayscale</BitDepth>", indexFileContent);
Assert.Contains("<HighQuality>true</HighQuality>", indexFileContent);
Assert.Contains("<PageSize>210x297 mm</PageSize>", indexFileContent);
}
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Lib/Recovery/RecoverableFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public bool TryRecover(Action<ProcessedImage> imageCallback, RecoveryParams reco
private ProcessedImage CreateRecoveredImage(RecoveryParams recoveryParams, IImageStorage storage,
RecoveryIndexImage indexImage)
{
var processedImage = _scanningContext.CreateProcessedImage(storage, indexImage.BitDepth.ToBitDepth(),
var processedImage = _scanningContext.CreateProcessedImage(storage,
indexImage.HighQuality, -1, PageSize.Parse(indexImage.PageSize),
indexImage.TransformList!.ToImmutableList());

Expand Down
2 changes: 0 additions & 2 deletions NAPS2.Lib/Recovery/RecoveryIndexImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class RecoveryIndexImage

public List<Transform>? TransformList { get; set; }

public ScanBitDepth BitDepth { get; set; }

public bool HighQuality { get; set; }

public string? PageSize { get; set; }
Expand Down
1 change: 0 additions & 1 deletion NAPS2.Lib/Recovery/RecoveryStorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private void WriteIndex(IEnumerable<UiImage> images)
return new RecoveryIndexImage
{
FileName = Path.GetFileName(storage.FullPath),
BitDepth = processedImage.Metadata.BitDepth.ToScanBitDepth(),
HighQuality = processedImage.Metadata.Lossless,
PageSize = processedImage.Metadata.PageSize?.ToString(),
TransformList = processedImage.TransformState.Transforms.ToList()
Expand Down
30 changes: 15 additions & 15 deletions NAPS2.Sdk.Tests/Images/ImageExportHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void SaveSmallestFormat_BlackAndWhite()
var bw = LoadImage(ImageResources.dog_bw).PerformTransform(new BlackWhiteTransform());
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, bw, BitDepth.BlackAndWhite, false, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, bw, false, -1, out var format);

AssertPng(format, fullPath, ImageResources.dog_bw);
}
Expand All @@ -29,42 +29,42 @@ public void SaveSmallestFormat_BlackAndWhiteWithColorBitDepth()
var bw = LoadImage(ImageResources.dog_bw).PerformTransform(new BlackWhiteTransform());
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, bw, BitDepth.Color, false, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, bw, false, -1, out var format);

AssertPng(format, fullPath, ImageResources.dog_bw);
}

[Fact]
public void SaveSmallestFormat_ColorWithBlackWhiteBitDepth()
public void SaveSmallestFormat_ColorHighQuality()
{
var color = LoadImage(ImageResources.dog);
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, color, BitDepth.BlackAndWhite, false, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, color, true, -1, out var format);

AssertPng(format, fullPath, ImageResources.dog_bw, ImageAsserts.XPLAT_RMSE_THRESHOLD);
AssertPng(format, fullPath, ImageResources.dog);
}

[Fact]
public void SaveSmallestFormat_ColorHighQuality()
public void SaveSmallestFormat_LogicalBlackWhite()
{
var color = LoadImage(ImageResources.dog);
var bw = LoadImage(ImageResources.dog_bw_24bit);
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, color, BitDepth.Color, true, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, bw, false, -1, out var format);

AssertPng(format, fullPath, ImageResources.dog);
AssertPng(format, fullPath, ImageResources.dog_bw);
}

[Fact]
public void SaveSmallestFormat_SmallerPng()
{
var bw = LoadImage(ImageResources.dog_bw_24bit);
var bw = LoadImage(ImageResources.dog_clustered_gray);
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, bw, BitDepth.Color, false, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, bw, false, -1, out var format);

AssertPng(format, fullPath, ImageResources.dog_bw);
AssertPng(format, fullPath, ImageResources.dog_clustered_gray);
}

[Fact]
Expand All @@ -73,7 +73,7 @@ public void SaveSmallestFormat_OriginalPng()
var color = LoadImage(ImageResources.dog_png);
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, color, BitDepth.Color, false, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, color, false, -1, out var format);

AssertPng(format, fullPath, ImageResources.dog);
}
Expand All @@ -85,7 +85,7 @@ public void SaveSmallestFormat_SmallerJpeg()
color.OriginalFileFormat = ImageFileFormat.Unknown;
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, color, BitDepth.Color, false, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, color, false, -1, out var format);

AssertJpeg(format, fullPath, ImageResources.dog);
}
Expand All @@ -96,7 +96,7 @@ public void SaveSmallestFormat_OriginalJpeg()
var color = LoadImage(ImageResources.dog_bw_jpg);
var path = Path.Combine(FolderPath, "test");

var fullPath = _helper.SaveSmallestFormat(path, color, BitDepth.Color, false, -1, out var format);
var fullPath = _helper.SaveSmallestFormat(path, color, false, -1, out var format);

AssertJpeg(format, fullPath, ImageResources.dog_bw);
}
Expand Down
2 changes: 0 additions & 2 deletions NAPS2.Sdk.Tests/Images/ImageSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public void SerializesMetadata(StorageConfig config)

using var sourceImage = ScanningContext.CreateProcessedImage(
LoadImage(ImageResources.dog), // TODO: Use an actual grayscale image
BitDepth.Grayscale,
true,
-1,
PageSize.A4,
Expand All @@ -33,7 +32,6 @@ public void SerializesMetadata(StorageConfig config)
Assert.Single(destImage.TransformState.Transforms);
Assert.Equal(300, Assert.IsType<BrightnessTransform>(destImage.TransformState.Transforms[0]).Brightness);
Assert.True(destImage.Metadata.Lossless);
Assert.Equal(BitDepth.Grayscale, destImage.Metadata.BitDepth);
Assert.Equal(PageSize.A4, destImage.Metadata.PageSize);
ImageAsserts.Similar(ImageResources.dog_b_p300, destImage);
}
Expand Down
16 changes: 7 additions & 9 deletions NAPS2.Sdk.Tests/Images/ProcessedImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ public void Construct()
{
var storage = LoadImage(ImageResources.dog);

var metadata1 = new ImageMetadata(BitDepth.Color, false, null);
var metadata1 = new ImageMetadata(false, null);
var postProcessingData1 = new PostProcessingData();
var transformState1 = TransformState.Empty;
var image1 = new ProcessedImage(ImageContext, storage, metadata1, postProcessingData1, transformState1);
Assert.Equal(storage, image1.Storage);
Assert.Equal(BitDepth.Color, image1.Metadata.BitDepth);
Assert.False(image1.Metadata.Lossless);
Assert.True(image1.TransformState.IsEmpty);

var metadata2 = new ImageMetadata(BitDepth.BlackAndWhite, true, null);
var metadata2 = new ImageMetadata(true, null);
var postProcessingData2 = new PostProcessingData();
var transformState2 = new TransformState(ImmutableList<Transform>.Empty.Add(new CropTransform(0, 50, 0, 50)));
var image2 = new ProcessedImage(ImageContext, storage, metadata2, postProcessingData2, transformState2);
Assert.Equal(storage, image2.Storage);
Assert.Equal(BitDepth.BlackAndWhite, image2.Metadata.BitDepth);
Assert.True(image2.Metadata.Lossless);
Assert.Single(image2.TransformState.Transforms);
var cropTransform = Assert.IsType<CropTransform>(image2.TransformState.Transforms[0]);
Expand All @@ -39,7 +37,7 @@ public void Construct()
public void StorageDisposed()
{
var storageMock = Substitute.For<IImageStorage>();
var metadata = new ImageMetadata(BitDepth.Color, false, null);
var metadata = new ImageMetadata(false, null);

var image = new ProcessedImage(
ImageContext, storageMock, metadata, new PostProcessingData(), TransformState.Empty);
Expand All @@ -52,7 +50,7 @@ public void StorageDisposed()
public void StorageDisposedOnlyAfterAllClonesDisposed()
{
var storageMock = Substitute.For<IImageStorage>();
var metadata = new ImageMetadata(BitDepth.Color, false, null);
var metadata = new ImageMetadata(false, null);

var image = new ProcessedImage(
ImageContext, storageMock, metadata, new PostProcessingData(), TransformState.Empty);
Expand Down Expand Up @@ -80,7 +78,7 @@ public void StorageDisposedOnlyAfterAllClonesDisposed()
public void TransformSimplification()
{
var storageMock = Substitute.For<IImageStorage>();
var metadata = new ImageMetadata(BitDepth.Color, false, null);
var metadata = new ImageMetadata(false, null);

var image = new ProcessedImage(
ImageContext, storageMock, metadata, new PostProcessingData(), TransformState.Empty);
Expand Down Expand Up @@ -118,7 +116,7 @@ public void TransformSimplification()
public void MultipleTransforms()
{
var storageMock = Substitute.For<IImageStorage>();
var metadata = new ImageMetadata(BitDepth.Color, false, null);
var metadata = new ImageMetadata(false, null);

var image = new ProcessedImage(
ImageContext, storageMock, metadata, new PostProcessingData(), TransformState.Empty);
Expand Down Expand Up @@ -157,7 +155,7 @@ public void MultipleTransforms()
public void CloneAfterDisposed()
{
var storageMock = Substitute.For<IImageStorage>();
var metadata = new ImageMetadata(BitDepth.Color, false, null);
var metadata = new ImageMetadata(false, null);

var image = new ProcessedImage(
ImageContext, storageMock, metadata, new PostProcessingData(), TransformState.Empty);
Expand Down
4 changes: 0 additions & 4 deletions NAPS2.Sdk.Tests/ImportExport/ImageImporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public async Task ImportPngImage()
Assert.True(File.Exists(storage.FullPath));
Assert.Equal(Path.Combine(FolderPath, "recovery"), Path.GetDirectoryName(storage.FullPath));
Assert.True(result[0].Metadata.Lossless);
Assert.Equal(BitDepth.Color, result[0].Metadata.BitDepth);
Assert.Null(result[0].PostProcessingData.Thumbnail);
Assert.False(result[0].PostProcessingData.Barcode.IsDetectionAttempted);
Assert.True(result[0].TransformState.IsEmpty);
Expand All @@ -54,7 +53,6 @@ public async Task ImportJpegImage()
Assert.True(File.Exists(storage.FullPath));
Assert.Equal(Path.Combine(FolderPath, "recovery"), Path.GetDirectoryName(storage.FullPath));
Assert.False(result[0].Metadata.Lossless);
Assert.Equal(BitDepth.Color, result[0].Metadata.BitDepth);
Assert.Null(result[0].PostProcessingData.Thumbnail);
Assert.False(result[0].PostProcessingData.Barcode.IsDetectionAttempted);
Assert.True(result[0].TransformState.IsEmpty);
Expand All @@ -79,12 +77,10 @@ public async Task ImportTiffImage()
Assert.Equal(3, result.Count);
AssertUsesRecoveryStorage(result[0].Storage, "00001.jpg");
Assert.False(result[0].Metadata.Lossless);
Assert.Equal(BitDepth.Color, result[0].Metadata.BitDepth);
ImageAsserts.Similar(ImageResources.dog, result[0]);

AssertUsesRecoveryStorage(result[2].Storage, "00003.jpg");
Assert.False(result[2].Metadata.Lossless);
Assert.Equal(BitDepth.Color, result[2].Metadata.BitDepth);
ImageAsserts.Similar(ImageResources.stock_cat, result[2]);

result[0].Dispose();
Expand Down
12 changes: 6 additions & 6 deletions NAPS2.Sdk.Tests/Pdf/PdfBenchmarkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PdfBenchmarkTests : ContextualTests
public async Task PdfSharpExport300()
{
var filePath = Path.Combine(FolderPath, "test");
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog), BitDepth.Color,
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog),
false, -1, null, Enumerable.Empty<Transform>());

var pdfExporter = new PdfExporter(ScanningContext);
Expand All @@ -24,7 +24,7 @@ public async Task PdfSharpExportHuge()
{
var filePath = Path.Combine(FolderPath, "test");
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog_huge),
BitDepth.Color, false, -1, null, Enumerable.Empty<Transform>());
false, -1, null, Enumerable.Empty<Transform>());

var pdfExporter = new PdfExporter(ScanningContext);
await pdfExporter.Export(filePath + ".pdf", new[] { image });
Expand All @@ -35,7 +35,7 @@ public async Task PdfSharpExportHugePng()
{
var filePath = Path.Combine(FolderPath, "test");
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog_huge_png),
BitDepth.Color, true, -1, null, Enumerable.Empty<Transform>());
true, -1, null, Enumerable.Empty<Transform>());

var pdfExporter = new PdfExporter(ScanningContext);
await pdfExporter.Export(filePath + ".pdf", new[] { image });
Expand All @@ -45,7 +45,7 @@ public async Task PdfSharpExportHugePng()
public async Task PdfiumExport300()
{
var filePath = Path.Combine(FolderPath, "test");
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog), BitDepth.Color,
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog),
false, -1, null, Enumerable.Empty<Transform>());

var pdfExporter = new PdfiumPdfExporter(ScanningContext);
Expand All @@ -60,7 +60,7 @@ public async Task PdfiumExportHuge()
{
var filePath = Path.Combine(FolderPath, "test");
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog_huge),
BitDepth.Color, false, -1, null, Enumerable.Empty<Transform>());
false, -1, null, Enumerable.Empty<Transform>());

var pdfExporter = new PdfiumPdfExporter(ScanningContext);
await pdfExporter.Export(filePath + ".pdf", new[] { image });
Expand All @@ -71,7 +71,7 @@ public async Task PdfiumExportHugePng()
{
var filePath = Path.Combine(FolderPath, "test");
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog_huge_png),
BitDepth.Color, true, -1, null, Enumerable.Empty<Transform>());
true, -1, null, Enumerable.Empty<Transform>());

var pdfExporter = new PdfiumPdfExporter(ScanningContext);
await pdfExporter.Export(filePath + ".pdf", new[] { image });
Expand Down
14 changes: 7 additions & 7 deletions NAPS2.Sdk.Tests/Pdf/PdfExportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async Task ExportPngImage(StorageConfig storageConfig)

var filePath = Path.Combine(FolderPath, "test.pdf");
using var image = ScanningContext.CreateProcessedImage(
LoadImage(ImageResources.dog_png), BitDepth.Color, true, -1, null);
LoadImage(ImageResources.dog_png), true, -1, null);

await _exporter.Export(filePath, new[] { image });

Expand All @@ -118,7 +118,7 @@ public async Task ExportUnalignedPngImage(StorageConfig storageConfig)
var filePath = Path.Combine(FolderPath, "test.pdf");
// Width is 99 (not divisible by 4)
var image = ScanningContext.CreateProcessedImage(
LoadImage(ImageResources.dog_99w), BitDepth.Color, true, -1, null);
LoadImage(ImageResources.dog_99w), true, -1, null);

await _exporter.Export(filePath, new[] { image });

Expand All @@ -134,7 +134,7 @@ public async Task ExportAlphaImage(StorageConfig storageConfig)

var filePath = Path.Combine(FolderPath, "test.pdf");
using var image = ScanningContext.CreateProcessedImage(
LoadImage(ImageResources.dog_alpha), BitDepth.Color, false, -1, null);
LoadImage(ImageResources.dog_alpha), false, -1, null);

await _exporter.Export(filePath, new[] { image });

Expand All @@ -151,7 +151,7 @@ public async Task ExportMaskedImage(StorageConfig storageConfig)

var filePath = Path.Combine(FolderPath, "test.pdf");
using var image = ScanningContext.CreateProcessedImage(
LoadImage(ImageResources.dog_mask), BitDepth.Color, false, -1, null);
LoadImage(ImageResources.dog_mask), false, -1, null);

await _exporter.Export(filePath, new[] { image });

Expand Down Expand Up @@ -218,7 +218,7 @@ public async Task ExportBlackAndWhiteImageByMetadata(StorageConfig storageConfig

var filePath = Path.Combine(FolderPath, "test.pdf");
using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog_bw_24bit),
BitDepth.BlackAndWhite, true, -1, null);
true, -1, null);

await _exporter.Export(filePath, new[] { image });

Expand Down Expand Up @@ -426,7 +426,7 @@ public async Task ExportWithPageSize(StorageConfig storageConfig)
var filePath = Path.Combine(FolderPath, "test.pdf");
var sourceImage = ImageContext.Create(850, 1100, ImagePixelFormat.RGB24);
sourceImage.SetResolution(99.4f, 99.4f);
using var image = ScanningContext.CreateProcessedImage(sourceImage, BitDepth.Color, false, -1, PageSize.Letter);
using var image = ScanningContext.CreateProcessedImage(sourceImage, false, -1, PageSize.Letter);

await _exporter.Export(filePath, new[] { image });

Expand All @@ -443,7 +443,7 @@ public async Task ExportWithMismatchedPageSize(StorageConfig storageConfig)
var filePath = Path.Combine(FolderPath, "test.pdf");
var sourceImage = ImageContext.Create(850, 1100, ImagePixelFormat.RGB24);
sourceImage.SetResolution(98, 98);
using var image = ScanningContext.CreateProcessedImage(sourceImage, BitDepth.Color, false, -1, PageSize.Letter);
using var image = ScanningContext.CreateProcessedImage(sourceImage, false, -1, PageSize.Letter);

await _exporter.Export(filePath, new[] { image });

Expand Down
Loading

0 comments on commit 85fa644

Please sign in to comment.