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);
}
public async void LoadAsync() {
public async void LoadAsync(Vector2i size) {
// 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
// a texture for it until that's already happened.
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);
image = tmp;
}
public async void LoadThumbnailAsync() {
public async void LoadThumbnailAsync(Vector2i size) {
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);
Util.RotateImageFromExif(tmp, Orientation);
@ -282,11 +286,6 @@ public class Photo {
public Texture Texture() {
LastTouch = touchCounter++;
if (thumbnailTexture == placeholder && thumbnail != null) {
thumbnailTexture = new(thumbnail);
thumbnail.Dispose();
thumbnail = null;
}
if (texture == placeholder && image != null) {
// 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
@ -299,6 +298,15 @@ public class Photo {
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() {
string date = DateTimeOriginal.ToString("yyyy-MM-dd HH:mm:ss");
return String.Format(

View File

@ -211,6 +211,7 @@ public class UiGeometry {
public static Vector2i MIN_WINDOW_SIZE = new(1024, 768);
public readonly Vector2i WindowSize;
public readonly Vector2i ThumbnailSize;
public readonly Box2i ThumbnailBox;
public readonly List<Box2i> ThumbnailBoxes = new();
public readonly List<Box2i> StarBoxes = new();
@ -225,8 +226,9 @@ public class UiGeometry {
int numThumbnails = Math.Max(WindowSize.Y / 100, 1);
int thumbnailHeight = WindowSize.Y / numThumbnails;
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++) {
Box2i box = Util.MakeBox(WindowSize.X - thumbnailWidth, i * thumbnailHeight,
thumbnailWidth, thumbnailHeight);
@ -352,6 +354,7 @@ public class Game : GameWindow {
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) :
base(gwSettings, nwSettings) {
activeTool = viewTool;
geometry = new UiGeometry(nwSettings.Size, STAR_FILLED.Size.X);
}
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_SMALL = Util.RenderStar(6, true);
UiGeometry geometry = new();
UiGeometry geometry;
FpsCounter fpsCounter = new();
// 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) {
await Task.Run( () => { p.LoadAsync(); });
await Task.Run( () => { p.LoadAsync(geometry.PhotoBox.Size); });
}
}
private async void LoadThumbnailsAsync() {
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];
Box2i box = geometry.ThumbnailBoxes[i];
DrawTexture(photo.Texture(), box);
DrawTexture(photo.ThumbnailTexture(), box);
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);
}