Browse Source

move choice of encoders into Photo itself

main
Colin McMillen 8 months ago
parent
commit
d72b804b92
  1. 11
      Photo.cs
  2. 3
      Program.cs

11
Photo.cs

@ -4,6 +4,7 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
using static System.IO.Path;
using System.Text;
using System.Xml.Linq;
@ -159,7 +160,7 @@ public class Photo {
}
}
public async void SaveAsJpegAsync(string outputRoot, JpegEncoder encoder) {
public async void SaveAsJpegAsync(string outputRoot) {
// FIXME: if nothing was changed about this image, just copy the file bytes directly, possibly with metadata changed?
string directory = Path.Combine(
outputRoot,
@ -215,14 +216,18 @@ public class Photo {
string jpgOut = Path.Combine(directory, "2-jpg", baseFilename);
Console.WriteLine($"{Filename} => {jpgOut}");
await image.SaveAsync(jpgOut, encoder);
await image.SaveAsync(jpgOut, new JpegEncoder() { Quality = 100 });
if (CropRectangle != Rectangle.Empty) {
image.Mutate(x => x.Crop(CropRectangle));
}
string editOut = Path.Combine(directory, "3-edit", baseFilename);
Console.WriteLine($"{Filename} => {editOut}");
await image.SaveAsync(editOut, encoder);
await image.SaveAsync(editOut, new JpegEncoder() { Quality = 100 });
// await image.SaveAsync(editOut, new PngEncoder() {
// BitDepth = PngBitDepth.Bit8, ChunkFilter = PngChunkFilter.None, ColorType = PngColorType.Rgb,
// CompressionLevel = PngCompressionLevel.BestCompression, FilterMethod = PngFilterMethod.Adaptive,
// InterlaceMethod = PngInterlaceMode.None });
}
}

3
Program.cs

@ -849,12 +849,11 @@ public class Game : GameWindow {
}
}
JpegEncoder encoder = new JpegEncoder() { Quality = 100 };
numPhotosToExport = photos.Count;
numPhotosExported = 0;
foreach (Photo p in photos) {
tasks.Add(Task.Run( () => {
p.SaveAsJpegAsync(outputRoot, encoder);
p.SaveAsJpegAsync(outputRoot);
lock (numPhotosExportedLock) {
numPhotosExported++;
toast.Set($"[{numPhotosExported}/{numPhotosToExport}] Exported {outputRoot}/{p.Filename}");

Loading…
Cancel
Save