put raws into root folder, jpgs into jpg/. thumbnail size tweaked to be the same as what uigeometry says

This commit is contained in:
Colin McMillen 2023-09-19 22:18:12 -04:00
parent 775252b567
commit ed4044a115
2 changed files with 13 additions and 15 deletions

View File

@ -169,21 +169,20 @@ public class Photo {
String.Format("{0:D2}", DateTimeOriginal.Month), String.Format("{0:D2}", DateTimeOriginal.Month),
String.Format("{0:D2}", DateTimeOriginal.Day)); String.Format("{0:D2}", DateTimeOriginal.Day));
Directory.CreateDirectory(directory); Directory.CreateDirectory(directory);
Directory.CreateDirectory(Path.Combine(directory, "1-raw")); Directory.CreateDirectory(Path.Combine(directory, "jpg"));
Directory.CreateDirectory(Path.Combine(directory, "2-jpg"));
Directory.CreateDirectory(Path.Combine(directory, "3-edit"));
string baseFilename = Path.GetFileName(Filename); string baseFilename = Path.GetFileName(Filename);
string rawFilename = Path.ChangeExtension(Filename, "cr3"); string rawFilename = Path.ChangeExtension(Filename, "cr3");
// FIXME: if there's a JPG but not a RAW, make a "RAW" that's the
// camera's original JPG converted to something lossless (PNG? TIFF?).
if (Path.Exists(rawFilename)) { if (Path.Exists(rawFilename)) {
string rawOut = Path.Combine(directory, "1-raw", Path.GetFileName(rawFilename)); string rawOut = Path.Combine(directory, Path.GetFileName(rawFilename));
if (!Path.Exists(rawOut)) { if (!Path.Exists(rawOut)) {
System.IO.File.Copy(rawFilename, rawOut); System.IO.File.Copy(rawFilename, rawOut);
toast.Set($"{rawFilename} => {rawOut}"); toast.Set($"{rawFilename} => {rawOut}");
} }
} }
// FIXME: add comments / captions as ImageDescription?
using (Image<Rgba32> image = await Image.LoadAsync<Rgba32>(Filename)) { using (Image<Rgba32> image = await Image.LoadAsync<Rgba32>(Filename)) {
Util.RotateImageFromExif(image, Orientation); Util.RotateImageFromExif(image, Orientation);
@ -215,19 +214,17 @@ public class Photo {
image.Metadata.XmpProfile = UpdateXmp(image.Metadata.XmpProfile); image.Metadata.XmpProfile = UpdateXmp(image.Metadata.XmpProfile);
string jpgOut = Path.Combine(directory, "2-jpg", baseFilename);
await image.SaveAsync(jpgOut, new JpegEncoder() { Quality = 100 });
toast.Set($"{Filename} => {jpgOut}");
if (RotationDegreeHundredths != 0) { if (RotationDegreeHundredths != 0) {
image.Mutate(x => x.Rotate(RotationDegreeHundredths / 100f)); image.Mutate(x => x.Rotate(RotationDegreeHundredths / 100f));
} }
if (CropRectangle != Rectangle.Empty) { if (CropRectangle != Rectangle.Empty) {
image.Mutate(x => x.Crop(CropRectangle)); image.Mutate(x => x.Crop(CropRectangle));
} }
string editOut = Path.Combine(directory, "3-edit", baseFilename);
await image.SaveAsync(editOut, new JpegEncoder() { Quality = 100 }); string jpgOut = Path.Combine(directory, "jpg", baseFilename);
toast.Set($"{Filename} => {editOut}"); await image.SaveAsync(jpgOut, new JpegEncoder() { Quality = 100 });
toast.Set($"{Filename} => {jpgOut}");
// await image.SaveAsync(editOut, new PngEncoder() { // await image.SaveAsync(editOut, new PngEncoder() {
// BitDepth = PngBitDepth.Bit8, ChunkFilter = PngChunkFilter.None, ColorType = PngColorType.Rgb, // BitDepth = PngBitDepth.Bit8, ChunkFilter = PngChunkFilter.None, ColorType = PngColorType.Rgb,
// CompressionLevel = PngCompressionLevel.BestCompression, FilterMethod = PngFilterMethod.Adaptive, // CompressionLevel = PngCompressionLevel.BestCompression, FilterMethod = PngFilterMethod.Adaptive,

View File

@ -341,6 +341,7 @@ public class UiGeometry {
public static Vector2i MIN_WINDOW_SIZE = new(1024, 768); public static Vector2i MIN_WINDOW_SIZE = new(1024, 768);
public readonly Vector2i WindowSize; public readonly Vector2i WindowSize;
public readonly Vector2i ThumbnailSize;
public readonly Box2i ThumbnailBox; public readonly Box2i ThumbnailBox;
public readonly List<Box2i> ThumbnailBoxes = new(); public readonly List<Box2i> ThumbnailBoxes = new();
public readonly List<Box2i> StarBoxes = new(); public readonly List<Box2i> StarBoxes = new();
@ -355,8 +356,8 @@ public class UiGeometry {
int numThumbnailsPerColumn = Math.Max(WindowSize.Y / 100, 1); int numThumbnailsPerColumn = Math.Max(WindowSize.Y / 100, 1);
int thumbnailHeight = WindowSize.Y / numThumbnailsPerColumn; int thumbnailHeight = WindowSize.Y / numThumbnailsPerColumn;
int thumbnailWidth = (int) (1.0 * thumbnailHeight * CameraInfo.AspectRatio); int thumbnailWidth = (int) (1.0 * thumbnailHeight * CameraInfo.AspectRatio);
ThumbnailSize = new(thumbnailWidth, thumbnailHeight);
Console.WriteLine($"thumbnail size: {thumbnailWidth}x{thumbnailHeight}");
int thumbnailColumns = 3; int thumbnailColumns = 3;
for (int j = thumbnailColumns; j > 0; j--) { for (int j = thumbnailColumns; j > 0; j--) {
for (int i = 0; i < numThumbnailsPerColumn; i++) { for (int i = 0; i < numThumbnailsPerColumn; i++) {
@ -846,7 +847,7 @@ public class Game : GameWindow {
// string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\09\06\jpg"); // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\09\06\jpg");
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); // string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\");
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\08\03"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\08\03");
string[] files = Directory.GetFiles(@"c:\users\colin\desktop\17\2-jpg"); string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
@ -948,7 +949,7 @@ public class Game : GameWindow {
List<Task> tasks = new(); List<Task> tasks = new();
foreach (Photo p in allPhotos) { foreach (Photo p in allPhotos) {
tasks.Add(Task.Run( () => { tasks.Add(Task.Run( () => {
p.LoadThumbnailAsync(new Vector2i(150, 150)); p.LoadThumbnailAsync(geometry.ThumbnailSize);
lock (numThumbnailsLoadedLock) { lock (numThumbnailsLoadedLock) {
numThumbnailsLoaded++; numThumbnailsLoaded++;
toast.Set($"[{numThumbnailsLoaded}/{allPhotos.Count}] Loading thumbnails"); toast.Set($"[{numThumbnailsLoaded}/{allPhotos.Count}] Loading thumbnails");