load smaller main images by default

This commit is contained in:
Colin McMillen 2023-08-24 23:38:25 -04:00
parent 50b0e8d8e0
commit 67736630e0
2 changed files with 25 additions and 14 deletions

View File

@ -47,19 +47,23 @@ public class Photo {
ParseExif(info.Metadata.ExifProfile); ParseExif(info.Metadata.ExifProfile);
} }
public async void LoadAsync() { public async void LoadAsync(Vector2i size) {
// We don't assign to this.image until Load() is done, because we might // We don't assign to this.image until Load() is done, because we might
// edit the image due to rotation (etc) and don't want to try generating // edit the image due to rotation (etc) and don't want to try generating
// a texture for it until that's already happened. // a texture for it until that's already happened.
LastTouch = touchCounter++; LastTouch = touchCounter++;
Image<Rgba32> tmp = await Image.LoadAsync<Rgba32>(Filename); // TODO: if we zoom in to more than the display size, actually load the whole image?
DecoderOptions options = new DecoderOptions {
TargetSize = new Size(size.X, size.Y)
};
Image<Rgba32> tmp = await Image.LoadAsync<Rgba32>(options, Filename);
Util.RotateImageFromExif(tmp, Orientation); Util.RotateImageFromExif(tmp, Orientation);
image = tmp; image = tmp;
} }
public async void LoadThumbnailAsync() { public async void LoadThumbnailAsync(Vector2i size) {
DecoderOptions options = new DecoderOptions { DecoderOptions options = new DecoderOptions {
TargetSize = new Size(256, 256) TargetSize = new Size(size.X, size.Y)
}; };
Image<Rgba32> tmp = await Image.LoadAsync<Rgba32>(options, Filename); Image<Rgba32> tmp = await Image.LoadAsync<Rgba32>(options, Filename);
Util.RotateImageFromExif(tmp, Orientation); Util.RotateImageFromExif(tmp, Orientation);
@ -282,11 +286,6 @@ public class Photo {
public Texture Texture() { public Texture Texture() {
LastTouch = touchCounter++; LastTouch = touchCounter++;
if (thumbnailTexture == placeholder && thumbnail != null) {
thumbnailTexture = new(thumbnail);
thumbnail.Dispose();
thumbnail = null;
}
if (texture == placeholder && image != null) { if (texture == placeholder && image != null) {
// The texture needs to be created on the GL thread, so we instantiate // The texture needs to be created on the GL thread, so we instantiate
// it here (since this is called from OnRenderFrame), as long as the // it here (since this is called from OnRenderFrame), as long as the
@ -299,6 +298,15 @@ public class Photo {
return texture != placeholder ? texture : thumbnailTexture; return texture != placeholder ? texture : thumbnailTexture;
} }
public Texture ThumbnailTexture() {
if (thumbnailTexture == placeholder && thumbnail != null) {
thumbnailTexture = new(thumbnail);
thumbnail.Dispose();
thumbnail = null;
}
return thumbnailTexture;
}
public string Description() { public string Description() {
string date = DateTimeOriginal.ToString("yyyy-MM-dd HH:mm:ss"); string date = DateTimeOriginal.ToString("yyyy-MM-dd HH:mm:ss");
return String.Format( return String.Format(

View File

@ -211,6 +211,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();
@ -225,6 +226,7 @@ public class UiGeometry {
int numThumbnails = Math.Max(WindowSize.Y / 100, 1); int numThumbnails = Math.Max(WindowSize.Y / 100, 1);
int thumbnailHeight = WindowSize.Y / numThumbnails; int thumbnailHeight = WindowSize.Y / numThumbnails;
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}"); Console.WriteLine($"thumbnail size: {thumbnailWidth}x{thumbnailHeight}");
for (int i = 0; i < numThumbnails; i++) { for (int i = 0; i < numThumbnails; i++) {
@ -352,6 +354,7 @@ public class Game : GameWindow {
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) :
base(gwSettings, nwSettings) { base(gwSettings, nwSettings) {
activeTool = viewTool; activeTool = viewTool;
geometry = new UiGeometry(nwSettings.Size, STAR_FILLED.Size.X);
} }
private static string outputRoot = @"c:\users\colin\desktop\totte-output"; private static string outputRoot = @"c:\users\colin\desktop\totte-output";
@ -363,7 +366,7 @@ public class Game : GameWindow {
private static Texture STAR_EMPTY = Util.RenderStar(20, false); private static Texture STAR_EMPTY = Util.RenderStar(20, false);
private static Texture STAR_SMALL = Util.RenderStar(6, true); private static Texture STAR_SMALL = Util.RenderStar(6, true);
UiGeometry geometry = new(); UiGeometry geometry;
FpsCounter fpsCounter = new(); FpsCounter fpsCounter = new();
// Four points, each consisting of (x, y, z, tex_x, tex_y). // Four points, each consisting of (x, y, z, tex_x, tex_y).
@ -717,13 +720,13 @@ public class Game : GameWindow {
} }
} }
foreach (Photo p in toLoad) { foreach (Photo p in toLoad) {
await Task.Run( () => { p.LoadAsync(); }); await Task.Run( () => { p.LoadAsync(geometry.PhotoBox.Size); });
} }
} }
private async void LoadThumbnailsAsync() { private async void LoadThumbnailsAsync() {
foreach (Photo p in allPhotos) { foreach (Photo p in allPhotos) {
await Task.Run( () => { p.LoadThumbnailAsync(); }); await Task.Run( () => { p.LoadThumbnailAsync(geometry.ThumbnailSize); });
} }
} }
@ -799,7 +802,7 @@ public class Game : GameWindow {
} }
Photo photo = photos[ribbonIndex + i]; Photo photo = photos[ribbonIndex + i];
Box2i box = geometry.ThumbnailBoxes[i]; Box2i box = geometry.ThumbnailBoxes[i];
DrawTexture(photo.Texture(), box); DrawTexture(photo.ThumbnailTexture(), box);
for (int j = 0; j < photo.Rating; j++) { for (int j = 0; j < photo.Rating; j++) {
DrawTexture(STAR_SMALL, box.Min.X + 8 + ((STAR_SMALL.Size.X + 2) * j), box.Min.Y + 8); DrawTexture(STAR_SMALL, box.Min.X + 8 + ((STAR_SMALL.Size.X + 2) * j), box.Min.Y + 8);
} }