2023-06-30 02:10:24 +00:00
|
|
|
|
using OpenTK.Graphics.OpenGL4;
|
|
|
|
|
using OpenTK.Mathematics;
|
|
|
|
|
using OpenTK.Windowing.Common;
|
2023-07-26 14:00:46 +00:00
|
|
|
|
using OpenTK.Windowing.Common.Input;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
using OpenTK.Windowing.Desktop;
|
|
|
|
|
using OpenTK.Windowing.GraphicsLibraryFramework;
|
2023-07-08 03:41:32 +00:00
|
|
|
|
// https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Image.html
|
2023-06-30 02:10:24 +00:00
|
|
|
|
using Image = SixLabors.ImageSharp.Image;
|
2023-07-23 22:42:08 +00:00
|
|
|
|
using SixLabors.Fonts;
|
2023-07-16 23:13:08 +00:00
|
|
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
2023-07-25 13:41:13 +00:00
|
|
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
|
2023-07-23 22:42:08 +00:00
|
|
|
|
using SixLabors.ImageSharp.Drawing.Processing;
|
|
|
|
|
using SixLabors.ImageSharp.Drawing;
|
2023-07-28 19:52:36 +00:00
|
|
|
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
2023-07-26 02:19:18 +00:00
|
|
|
|
using System;
|
2023-07-26 01:44:22 +00:00
|
|
|
|
using System.Diagnostics;
|
2023-07-23 22:42:08 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2023-08-01 00:50:53 +00:00
|
|
|
|
using System.Text;
|
2023-07-25 13:41:13 +00:00
|
|
|
|
using System.Xml.Linq;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
|
|
|
|
namespace SemiColinGames;
|
|
|
|
|
|
2023-07-26 02:19:18 +00:00
|
|
|
|
public class FpsCounter {
|
2023-07-26 15:25:14 +00:00
|
|
|
|
private readonly int[] frameTimes = new int[30];
|
2023-07-26 02:19:18 +00:00
|
|
|
|
private double fps = 0;
|
|
|
|
|
private int idx = 0;
|
|
|
|
|
|
|
|
|
|
public int Fps {
|
|
|
|
|
get => (int) Math.Ceiling(fps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update() {
|
|
|
|
|
var now = Environment.TickCount; // ms
|
|
|
|
|
if (frameTimes[idx] != 0) {
|
|
|
|
|
var timeElapsed = now - frameTimes[idx];
|
|
|
|
|
fps = 1000.0 * frameTimes.Length / timeElapsed;
|
|
|
|
|
}
|
|
|
|
|
frameTimes[idx] = now;
|
|
|
|
|
idx = (idx + 1) % frameTimes.Length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-07-06 22:31:50 +00:00
|
|
|
|
public class CameraInfo {
|
|
|
|
|
public readonly Vector2i Resolution;
|
|
|
|
|
|
|
|
|
|
private CameraInfo(Vector2i resolution) {
|
|
|
|
|
Resolution = resolution;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-08 04:33:15 +00:00
|
|
|
|
public static readonly CameraInfo NIKON_D7000 = new(new Vector2i(4928, 3264));
|
2023-07-16 23:13:08 +00:00
|
|
|
|
public static readonly CameraInfo CANON_EOS_R6M2 = new(new Vector2i(6000, 4000));
|
2023-07-08 04:33:15 +00:00
|
|
|
|
public static readonly CameraInfo IPHONE_12_MINI = new(new Vector2i(4032, 3024));
|
2023-07-06 22:31:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-08-03 22:38:21 +00:00
|
|
|
|
public enum ToolState {
|
|
|
|
|
Active,
|
|
|
|
|
Done,
|
|
|
|
|
Canceled
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public interface ITool {
|
|
|
|
|
void SetActivePhoto(Photo photo);
|
2023-08-03 22:38:21 +00:00
|
|
|
|
ToolState HandleInput(UiGeometry geometry, KeyboardState input, MouseState mouse, Game game);
|
2023-08-03 22:14:19 +00:00
|
|
|
|
string Status();
|
|
|
|
|
void Draw(UiGeometry geometry, Game game);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public class ViewTool : ITool {
|
|
|
|
|
Photo? activePhoto;
|
|
|
|
|
|
|
|
|
|
public void SetActivePhoto(Photo photo) {
|
|
|
|
|
activePhoto = photo;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:38:21 +00:00
|
|
|
|
public ToolState HandleInput(UiGeometry geometry, KeyboardState input, MouseState mouse, Game game) {
|
|
|
|
|
return ToolState.Active;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Status() {
|
2023-08-04 00:03:46 +00:00
|
|
|
|
return "";
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Draw(UiGeometry geometry, Game game) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:38:21 +00:00
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
// FIXME: remove unneeded dependencies on "Game" or at least refactor them a bit.
|
|
|
|
|
public class CropTool : ITool {
|
|
|
|
|
|
2023-08-04 00:03:46 +00:00
|
|
|
|
Photo activePhoto;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
Vector2i mouseDragStart;
|
|
|
|
|
Vector2i mouseDragEnd;
|
2023-08-03 22:38:21 +00:00
|
|
|
|
string status = "";
|
2023-08-03 22:14:19 +00:00
|
|
|
|
|
2023-08-04 00:03:46 +00:00
|
|
|
|
public CropTool(Photo photo) {
|
|
|
|
|
activePhoto = photo;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void SetActivePhoto(Photo photo) {
|
2023-08-04 00:03:46 +00:00
|
|
|
|
if (photo != activePhoto) {
|
2023-08-04 01:33:28 +00:00
|
|
|
|
mouseDragStart = Vector2i.Zero;
|
|
|
|
|
mouseDragEnd = Vector2i.Zero;
|
2023-08-04 00:03:46 +00:00
|
|
|
|
}
|
2023-08-03 22:14:19 +00:00
|
|
|
|
activePhoto = photo;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:38:21 +00:00
|
|
|
|
public ToolState HandleInput(UiGeometry geometry, KeyboardState input, MouseState mouse, Game game) {
|
2023-08-03 22:14:19 +00:00
|
|
|
|
Vector2i mousePosition = (Vector2i) mouse.Position;
|
2023-08-04 01:33:28 +00:00
|
|
|
|
Vector2i imagePosition = game.ScreenToImage(mousePosition);
|
2023-08-03 22:14:19 +00:00
|
|
|
|
|
|
|
|
|
if (mouse.IsButtonPressed(MouseButton.Button1)) {
|
|
|
|
|
if (geometry.PhotoBox.ContainsInclusive(mousePosition)) {
|
2023-08-04 01:33:28 +00:00
|
|
|
|
mouseDragStart = imagePosition;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mouse.IsButtonDown(MouseButton.Button1)) {
|
|
|
|
|
if (geometry.PhotoBox.ContainsInclusive(mousePosition)) {
|
2023-08-04 01:33:28 +00:00
|
|
|
|
mouseDragEnd = imagePosition;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
var (left, right, top, bottom) = GetCrop();
|
|
|
|
|
Vector2i size = new(right - left, bottom - top);
|
2023-08-04 03:21:10 +00:00
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
status = $"({left}, {top}) {size.X}x{size.Y}";
|
2023-08-03 22:38:21 +00:00
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
Rectangle crop = Rectangle.Empty;
|
|
|
|
|
if (size.X > 0 && size.Y > 0) {
|
|
|
|
|
crop = Rectangle.FromLTRB(left, top, right, bottom);
|
|
|
|
|
}
|
|
|
|
|
activePhoto.CropRectangle = crop;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
|
|
|
|
|
if (input.IsKeyPressed(Keys.Enter)) {
|
2023-08-03 22:38:21 +00:00
|
|
|
|
return ToolState.Done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input.IsKeyPressed(Keys.Escape)) {
|
|
|
|
|
activePhoto.CropRectangle = Rectangle.Empty;
|
|
|
|
|
return ToolState.Canceled;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
2023-08-03 22:38:21 +00:00
|
|
|
|
|
|
|
|
|
return ToolState.Active;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// left, right, top, bottom
|
|
|
|
|
(int, int, int, int) GetCrop() {
|
|
|
|
|
// FIXME: this expects the start point in the top left and the end point
|
|
|
|
|
// in the bottom right; some sign flipping needs to occur to make anchors
|
|
|
|
|
// in other direction work well.
|
|
|
|
|
Vector2i start = mouseDragStart;
|
|
|
|
|
Vector2i end = mouseDragEnd;
|
2023-08-04 00:03:46 +00:00
|
|
|
|
// FIXME: choose the aspect ratio based on the original image aspect ratio.
|
|
|
|
|
// FIXME: allow for unconstrained crop, 1:1, etc.
|
2023-08-03 22:14:19 +00:00
|
|
|
|
end.Y = Math.Min(end.Y, start.Y + (end.X - start.X) * 4 / 6);
|
|
|
|
|
end.X = start.X + (end.Y - start.Y) * 6 / 4;
|
|
|
|
|
int left = Math.Min(start.X, end.X);
|
|
|
|
|
int right = Math.Max(start.X, end.X);
|
|
|
|
|
int top = Math.Min(start.Y, end.Y);
|
|
|
|
|
int bottom = Math.Max(start.Y, end.Y);
|
|
|
|
|
return (left, right, top, bottom);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
public void Draw(UiGeometry geometry, Game game) {
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Status() {
|
2023-08-03 22:38:21 +00:00
|
|
|
|
return "[crop] " + status;
|
2023-08-03 22:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-07-16 23:23:03 +00:00
|
|
|
|
public class Photo {
|
2023-07-26 00:25:07 +00:00
|
|
|
|
public string Filename;
|
2023-07-24 20:07:17 +00:00
|
|
|
|
public bool Loaded = false;
|
2023-07-27 01:29:26 +00:00
|
|
|
|
public long LastTouch = 0;
|
2023-07-25 20:58:41 +00:00
|
|
|
|
public Vector2i Size;
|
2023-07-26 00:25:07 +00:00
|
|
|
|
public DateTime DateTimeOriginal;
|
2023-07-24 22:55:59 +00:00
|
|
|
|
public string CameraModel = "";
|
|
|
|
|
public string LensModel = "";
|
2023-08-03 02:29:04 +00:00
|
|
|
|
public string ShortLensModel = "";
|
2023-07-24 20:39:01 +00:00
|
|
|
|
public string FocalLength = "<unk>";
|
2023-07-24 20:07:17 +00:00
|
|
|
|
public string FNumber = "<unk>";
|
|
|
|
|
public string ExposureTime = "<unk>";
|
|
|
|
|
public string IsoSpeed = "<unk>";
|
2023-07-25 13:41:13 +00:00
|
|
|
|
public int Rating = 0;
|
2023-07-25 20:43:11 +00:00
|
|
|
|
public ushort Orientation = 1;
|
2023-08-02 05:05:10 +00:00
|
|
|
|
public Rectangle CropRectangle = Rectangle.Empty;
|
2023-07-24 20:07:17 +00:00
|
|
|
|
|
2023-07-27 01:29:26 +00:00
|
|
|
|
private static long touchCounter = 0;
|
2023-07-17 03:45:50 +00:00
|
|
|
|
private Texture texture;
|
|
|
|
|
private Texture placeholder;
|
2023-07-17 06:44:34 +00:00
|
|
|
|
private Image<Rgba32>? image = null;
|
2023-07-16 23:23:03 +00:00
|
|
|
|
|
2023-07-26 00:25:07 +00:00
|
|
|
|
public Photo(string filename, Texture placeholder) {
|
|
|
|
|
Filename = filename;
|
2023-07-17 03:45:50 +00:00
|
|
|
|
this.placeholder = placeholder;
|
|
|
|
|
texture = placeholder;
|
2023-07-25 20:58:41 +00:00
|
|
|
|
|
2023-07-26 00:25:07 +00:00
|
|
|
|
DateTime creationTime = File.GetCreationTime(filename); // Local time.
|
|
|
|
|
DateTimeOriginal = creationTime;
|
|
|
|
|
ImageInfo info = Image.Identify(filename);
|
2023-07-25 20:58:41 +00:00
|
|
|
|
Size = new(info.Size.Width, info.Size.Height);
|
2023-08-01 00:50:53 +00:00
|
|
|
|
Rating = ParseRating(info.Metadata.XmpProfile);
|
2023-07-25 20:58:41 +00:00
|
|
|
|
ParseExif(info.Metadata.ExifProfile);
|
2023-07-17 06:44:34 +00:00
|
|
|
|
}
|
2023-06-30 02:21:41 +00:00
|
|
|
|
|
2023-07-26 01:24:20 +00:00
|
|
|
|
public async void LoadAsync() {
|
2023-07-25 18:28:57 +00:00
|
|
|
|
// 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.
|
2023-07-27 01:29:26 +00:00
|
|
|
|
LastTouch = touchCounter++;
|
2023-07-26 00:25:07 +00:00
|
|
|
|
Image<Rgba32> tmp = await Image.LoadAsync<Rgba32>(Filename);
|
2023-07-25 21:10:51 +00:00
|
|
|
|
Util.RotateImageFromExif(tmp, Orientation);
|
|
|
|
|
image = tmp;
|
2023-07-17 00:06:37 +00:00
|
|
|
|
}
|
2023-07-17 03:45:50 +00:00
|
|
|
|
|
2023-07-28 16:27:53 +00:00
|
|
|
|
public void Unload() {
|
2023-07-26 02:00:43 +00:00
|
|
|
|
Loaded = false;
|
2023-07-26 01:24:20 +00:00
|
|
|
|
if (texture != placeholder) {
|
2023-07-28 16:19:15 +00:00
|
|
|
|
texture.Dispose();
|
2023-07-26 01:24:20 +00:00
|
|
|
|
texture = placeholder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 00:50:53 +00:00
|
|
|
|
public async void SaveAsJpegAsync(string outputRoot, JpegEncoder encoder) {
|
2023-07-28 20:00:08 +00:00
|
|
|
|
// FIXME: if nothing was changed about this image, just copy the file bytes directly, possibly with metadata changed?
|
2023-07-28 19:52:36 +00:00
|
|
|
|
string directory = System.IO.Path.Combine(
|
|
|
|
|
outputRoot,
|
|
|
|
|
String.Format("{0:D4}", DateTimeOriginal.Year),
|
|
|
|
|
String.Format("{0:D2}", DateTimeOriginal.Month),
|
|
|
|
|
String.Format("{0:D2}", DateTimeOriginal.Day));
|
|
|
|
|
Directory.CreateDirectory(directory);
|
|
|
|
|
string filename = System.IO.Path.Combine(directory, System.IO.Path.GetFileName(Filename));
|
|
|
|
|
Console.WriteLine("saving " + filename);
|
2023-07-28 21:54:00 +00:00
|
|
|
|
// FIXME: add comments / captions as ImageDescription?
|
|
|
|
|
// FIXME: strip some Exif tags for privacy reasons?
|
2023-07-28 20:28:18 +00:00
|
|
|
|
// FIXME: warn if the file already exists?
|
2023-07-28 20:32:54 +00:00
|
|
|
|
using (Image<Rgba32> image = await Image.LoadAsync<Rgba32>(Filename)) {
|
2023-07-28 21:54:00 +00:00
|
|
|
|
Util.RotateImageFromExif(image, Orientation);
|
2023-08-02 05:05:10 +00:00
|
|
|
|
if (CropRectangle != Rectangle.Empty) {
|
|
|
|
|
image.Mutate(x => x.Crop(CropRectangle));
|
|
|
|
|
}
|
2023-07-28 21:54:00 +00:00
|
|
|
|
|
|
|
|
|
ExifProfile exif = image.Metadata.ExifProfile ?? new();
|
|
|
|
|
exif.SetValue<ushort>(ExifTag.Orientation, 1);
|
|
|
|
|
exif.SetValue<string>(ExifTag.Artist, "Colin McMillen");
|
|
|
|
|
exif.SetValue<string>(ExifTag.Copyright, "Colin McMillen");
|
|
|
|
|
exif.SetValue<string>(ExifTag.Software, "Totte");
|
2023-08-01 15:30:06 +00:00
|
|
|
|
exif.SetValue<ushort>(ExifTag.Rating, (ushort) Rating);
|
2023-07-28 21:54:00 +00:00
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
string datetime = String.Format(
|
|
|
|
|
"{0:D4}:{1:D2}:{2:D2} {3:D2}:{4:D2}:{5:D2}",
|
|
|
|
|
now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
|
|
|
|
|
exif.SetValue<string>(ExifTag.DateTime, datetime);
|
|
|
|
|
|
2023-08-01 00:50:53 +00:00
|
|
|
|
image.Metadata.XmpProfile = UpdateXmp(image.Metadata.XmpProfile);
|
|
|
|
|
|
2023-07-28 20:28:18 +00:00
|
|
|
|
await image.SaveAsync(filename, encoder);
|
2023-07-28 19:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 00:50:53 +00:00
|
|
|
|
private XElement? GetXmpRoot(XmpProfile? xmp) {
|
2023-07-25 13:41:13 +00:00
|
|
|
|
if (xmp == null) {
|
2023-08-01 00:50:53 +00:00
|
|
|
|
return null;
|
2023-07-25 13:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
XDocument? doc = xmp.GetDocument();
|
|
|
|
|
if (doc == null) {
|
2023-08-01 00:50:53 +00:00
|
|
|
|
return null;
|
2023-07-25 13:41:13 +00:00
|
|
|
|
}
|
2023-08-01 00:50:53 +00:00
|
|
|
|
return doc.Root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int ParseRating(XmpProfile? xmp) {
|
|
|
|
|
XElement? root = GetXmpRoot(xmp);
|
2023-07-25 13:41:13 +00:00
|
|
|
|
if (root == null) {
|
2023-08-01 00:50:53 +00:00
|
|
|
|
return 0;
|
2023-07-25 13:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
foreach (XElement elt in root.Descendants()) {
|
|
|
|
|
if (elt.Name == "{http://ns.adobe.com/xap/1.0/}Rating") {
|
2023-08-01 00:50:53 +00:00
|
|
|
|
int rating = 0;
|
2023-07-25 13:41:13 +00:00
|
|
|
|
if (int.TryParse(elt.Value, out rating)) {
|
2023-08-01 00:50:53 +00:00
|
|
|
|
return rating;
|
2023-07-25 13:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-01 00:50:53 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private XmpProfile? UpdateXmp(XmpProfile? xmp) {
|
|
|
|
|
if (xmp == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
string xmlIn = Encoding.UTF8.GetString(xmp.ToByteArray());
|
|
|
|
|
int index = xmlIn.IndexOf("</xmp:Rating>");
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
return xmp;
|
|
|
|
|
}
|
|
|
|
|
string xmlOut = xmlIn.Substring(0, index - 1) + Rating.ToString() + xmlIn.Substring(index);
|
|
|
|
|
return new XmpProfile(Encoding.UTF8.GetBytes(xmlOut));
|
2023-07-25 13:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 00:25:07 +00:00
|
|
|
|
// Exif (and other image metadata) reference, from the now-defunct Metadata Working Group:
|
|
|
|
|
// https://web.archive.org/web/20180919181934/http://www.metadataworkinggroup.org/pdf/mwg_guidance.pdf
|
|
|
|
|
//
|
|
|
|
|
// Specifically:
|
|
|
|
|
//
|
|
|
|
|
// In general, date/time metadata is being used to describe the following scenarios:
|
|
|
|
|
// * Date/time original specifies when a photo was taken
|
|
|
|
|
// * Date/time digitized specifies when an image was digitized
|
|
|
|
|
// * Date/time modified specifies when a file was modified by the user
|
|
|
|
|
//
|
|
|
|
|
// Original Date/Time – Creation date of the intellectual content (e.g. the photograph), rather than the creation date of the content being shown
|
|
|
|
|
// Exif DateTimeOriginal (36867, 0x9003) and SubSecTimeOriginal (37521, 0x9291)
|
|
|
|
|
// IPTC DateCreated (IIM 2:55, 0x0237) and TimeCreated (IIM 2:60, 0x023C)
|
|
|
|
|
// XMP (photoshop:DateCreated)
|
|
|
|
|
//
|
|
|
|
|
// Digitized Date/Time – Creation date of the digital representation
|
|
|
|
|
// Exif DateTimeDigitized (36868, 0x9004) and SubSecTimeDigitized (37522, 0x9292)
|
|
|
|
|
// IPTC DigitalCreationDate (IIM 2:62, 0x023E) and DigitalCreationTime (IIM 2:63, 0x023F)
|
|
|
|
|
// XMP (xmp:CreateDate)
|
|
|
|
|
//
|
|
|
|
|
// Modification Date/Time – Modification date of the digital image file
|
|
|
|
|
// Exif DateTime (306, 0x132) and SubSecTime (37520, 0x9290)
|
|
|
|
|
// XMP (xmp:ModifyDate)
|
2023-07-28 21:54:00 +00:00
|
|
|
|
//
|
|
|
|
|
// See also: https://exiftool.org/TagNames/EXIF.html
|
2023-07-25 20:43:11 +00:00
|
|
|
|
private void ParseExif(ExifProfile? exifs) {
|
|
|
|
|
if (exifs == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IExifValue<ushort>? orientation;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.Orientation, out orientation)) {
|
|
|
|
|
Orientation = orientation.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IExifValue<string>? model;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.Model, out model)) {
|
|
|
|
|
CameraModel = model.Value ?? "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IExifValue<string>? lensModel;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.LensModel, out lensModel)) {
|
|
|
|
|
LensModel = lensModel.Value ?? "";
|
2023-08-03 02:29:04 +00:00
|
|
|
|
ShortLensModel = GetShortLensModel(LensModel);
|
2023-07-25 20:43:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IExifValue<Rational>? focalLength;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.FocalLength, out focalLength)) {
|
|
|
|
|
Rational r = focalLength.Value;
|
|
|
|
|
FocalLength = $"{r.Numerator / r.Denominator}mm";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IExifValue<Rational>? fNumber;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.FNumber, out fNumber)) {
|
|
|
|
|
Rational r = fNumber.Value;
|
2023-07-26 19:09:19 +00:00
|
|
|
|
if (r.Numerator % r.Denominator == 0) {
|
|
|
|
|
FNumber = $"f/{r.Numerator / r.Denominator}";
|
2023-07-25 20:43:11 +00:00
|
|
|
|
} else {
|
2023-07-26 19:09:19 +00:00
|
|
|
|
int fTimesTen = (int) Math.Round(10f * r.Numerator / r.Denominator);
|
|
|
|
|
FNumber = $"f/{fTimesTen / 10}.{fTimesTen % 10}";
|
2023-07-25 20:43:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:54:00 +00:00
|
|
|
|
// FIXME: could also show ExposureBiasValue, ExposureMode, ExposureProgram?
|
2023-07-25 20:43:11 +00:00
|
|
|
|
IExifValue<Rational>? exposureTime;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.ExposureTime, out exposureTime)) {
|
|
|
|
|
Rational r = exposureTime.Value;
|
|
|
|
|
if (r.Numerator == 1) {
|
|
|
|
|
ExposureTime = $"1/{r.Denominator}";
|
|
|
|
|
} else if (r.Numerator == 10) {
|
|
|
|
|
ExposureTime = $"1/{r.Denominator / 10}";
|
|
|
|
|
} else if (r.Denominator == 1) {
|
|
|
|
|
ExposureTime = $"{r.Numerator }\"";
|
|
|
|
|
} else if (r.Denominator == 10) {
|
|
|
|
|
ExposureTime = $"{r.Numerator / 10}.{r.Numerator % 10}\"";
|
|
|
|
|
} else {
|
|
|
|
|
Console.WriteLine($"*** WARNING: unexpected ExposureTime: {r.Numerator}/{r.Denominator}");
|
|
|
|
|
ExposureTime = r.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IExifValue<ushort[]>? isoSpeed;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.ISOSpeedRatings, out isoSpeed)) {
|
|
|
|
|
ushort[]? iso = isoSpeed.Value;
|
|
|
|
|
if (iso != null) {
|
|
|
|
|
if (iso.Length != 1) {
|
|
|
|
|
Console.WriteLine($"*** WARNING: unexpected ISOSpeedRatings array length: {iso.Length}");
|
|
|
|
|
}
|
|
|
|
|
if (iso.Length >= 1) {
|
|
|
|
|
IsoSpeed = $"ISO {iso[0]}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-26 00:25:07 +00:00
|
|
|
|
|
2023-07-28 16:21:38 +00:00
|
|
|
|
// FIXME: there is also a SubSecTimeOriginal tag we could use to get fractional seconds.
|
2023-07-26 00:25:07 +00:00
|
|
|
|
// FIXME: I think the iPhone stores time in UTC but other cameras report it in local time.
|
|
|
|
|
IExifValue<string>? dateTimeOriginal;
|
|
|
|
|
if (exifs.TryGetValue(ExifTag.DateTimeOriginal, out dateTimeOriginal)) {
|
|
|
|
|
DateTime date;
|
|
|
|
|
if (DateTime.TryParseExact(
|
|
|
|
|
dateTimeOriginal.Value ?? "",
|
|
|
|
|
"yyyy:MM:dd HH:mm:ss",
|
|
|
|
|
System.Globalization.CultureInfo.InvariantCulture,
|
|
|
|
|
System.Globalization.DateTimeStyles.AssumeLocal,
|
|
|
|
|
out date)) {
|
|
|
|
|
DateTimeOriginal = date;
|
|
|
|
|
} else {
|
|
|
|
|
Console.WriteLine($"*** WARNING: unexpected DateTimeOriginal value: {dateTimeOriginal.Value}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-25 20:43:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 02:29:04 +00:00
|
|
|
|
public string GetShortLensModel(string lensModel) {
|
|
|
|
|
// Example Canon RF lens names:
|
|
|
|
|
// RF16mm F2.8 STM
|
|
|
|
|
// RF24-105mm F4-7.1 IS STM
|
|
|
|
|
// RF35mm F1.8 MACRO IS STM
|
|
|
|
|
// RF100-400mm F5.6-8 IS USM
|
|
|
|
|
string[] tokens = lensModel.Split(' ');
|
|
|
|
|
string result = "";
|
|
|
|
|
foreach (string token in tokens) {
|
|
|
|
|
if (token == "STM" || token == "IS" || token == "USM") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
result += token + " ";
|
|
|
|
|
}
|
|
|
|
|
return result.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-17 03:45:50 +00:00
|
|
|
|
public Texture Texture() {
|
2023-07-27 01:29:26 +00:00
|
|
|
|
LastTouch = touchCounter++;
|
2023-07-23 23:29:47 +00:00
|
|
|
|
if (texture == placeholder && image != null) {
|
2023-07-25 22:26:46 +00:00
|
|
|
|
// 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
|
|
|
|
|
// image is ready to go.
|
2023-07-23 23:29:47 +00:00
|
|
|
|
texture = new Texture(image);
|
|
|
|
|
image.Dispose();
|
|
|
|
|
image = null;
|
2023-07-24 16:36:44 +00:00
|
|
|
|
Loaded = true;
|
2023-07-23 23:29:47 +00:00
|
|
|
|
}
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
2023-07-24 20:07:17 +00:00
|
|
|
|
|
|
|
|
|
public string Description() {
|
2023-07-26 00:35:12 +00:00
|
|
|
|
string date = DateTimeOriginal.ToString("yyyy-MM-dd HH:mm:ss");
|
2023-08-03 02:29:04 +00:00
|
|
|
|
return String.Format(
|
|
|
|
|
"{0,6} {1,-5} {2,-7} {3,-10} {4} {5,-20} {6}",
|
|
|
|
|
FocalLength, FNumber, ExposureTime, IsoSpeed, date, ShortLensModel, Filename);
|
2023-07-24 20:07:17 +00:00
|
|
|
|
}
|
2023-07-17 00:06:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-07-17 00:06:37 +00:00
|
|
|
|
public class Texture : IDisposable {
|
|
|
|
|
public int Handle;
|
|
|
|
|
public Vector2i Size;
|
|
|
|
|
|
2023-07-27 01:29:26 +00:00
|
|
|
|
private static int maxHandle = -1;
|
|
|
|
|
private bool disposedValue = false;
|
|
|
|
|
|
2023-07-17 00:06:37 +00:00
|
|
|
|
public Texture(Image<Rgba32> image) {
|
|
|
|
|
Size = new Vector2i(image.Width, image.Height);
|
2023-07-08 03:41:32 +00:00
|
|
|
|
byte[] pixelBytes = new byte[Size.X * Size.Y * Unsafe.SizeOf<Rgba32>()];
|
2023-06-30 02:10:24 +00:00
|
|
|
|
image.CopyPixelDataTo(pixelBytes);
|
|
|
|
|
|
|
|
|
|
Handle = GL.GenTexture();
|
2023-07-24 16:13:13 +00:00
|
|
|
|
if (Handle > maxHandle) {
|
2023-07-26 01:44:22 +00:00
|
|
|
|
// Console.WriteLine("GL.GenTexture #" + Handle);
|
2023-07-24 16:13:13 +00:00
|
|
|
|
maxHandle = Handle;
|
|
|
|
|
}
|
2023-06-30 02:10:24 +00:00
|
|
|
|
GL.ActiveTexture(TextureUnit.Texture0);
|
|
|
|
|
GL.BindTexture(TextureTarget.Texture2D, Handle);
|
2023-07-08 03:41:32 +00:00
|
|
|
|
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Size.X, Size.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixelBytes);
|
2023-07-17 06:51:15 +00:00
|
|
|
|
//GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.LinearMipmapLinear);
|
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.Linear);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Nearest);
|
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) TextureWrapMode.ClampToBorder);
|
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) TextureWrapMode.ClampToBorder);
|
|
|
|
|
float[] borderColor = { 0.0f, 0.0f, 0.0f, 1.0f };
|
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, borderColor);
|
2023-07-17 06:51:15 +00:00
|
|
|
|
// FIXME: should we use mipmaps?
|
|
|
|
|
//GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing) {
|
|
|
|
|
if (!disposedValue) {
|
|
|
|
|
GL.DeleteTexture(Handle);
|
|
|
|
|
disposedValue = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Texture() {
|
|
|
|
|
if (!disposedValue) {
|
|
|
|
|
Console.WriteLine("~Texture(): resource leak? Dispose() should be called manually.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-07-07 18:24:43 +00:00
|
|
|
|
public class UiGeometry {
|
2023-07-26 19:09:19 +00:00
|
|
|
|
public static Vector2i MIN_WINDOW_SIZE = new(1024, 768);
|
2023-07-16 23:13:08 +00:00
|
|
|
|
private static CameraInfo activeCamera = CameraInfo.CANON_EOS_R6M2;
|
2023-07-07 18:24:43 +00:00
|
|
|
|
|
|
|
|
|
public readonly Vector2i WindowSize;
|
2023-07-25 21:18:11 +00:00
|
|
|
|
public readonly Box2i ThumbnailBox;
|
2023-07-07 18:52:36 +00:00
|
|
|
|
public readonly List<Box2i> ThumbnailBoxes = new();
|
2023-07-26 19:09:19 +00:00
|
|
|
|
public readonly List<Box2i> StarBoxes = new();
|
2023-07-07 20:00:43 +00:00
|
|
|
|
public readonly Box2i PhotoBox;
|
2023-07-24 17:14:07 +00:00
|
|
|
|
public readonly Box2i StatusBox;
|
2023-07-07 18:24:43 +00:00
|
|
|
|
|
2023-07-26 19:09:19 +00:00
|
|
|
|
public UiGeometry() : this(MIN_WINDOW_SIZE, 0) {}
|
2023-07-07 18:24:43 +00:00
|
|
|
|
|
2023-07-26 19:09:19 +00:00
|
|
|
|
public UiGeometry(Vector2i windowSize, int starSize) {
|
2023-07-07 18:24:43 +00:00
|
|
|
|
WindowSize = windowSize;
|
2023-07-07 18:52:36 +00:00
|
|
|
|
|
2023-07-31 20:44:01 +00:00
|
|
|
|
int numThumbnails = Math.Max(WindowSize.Y / 100, 1);
|
2023-07-08 04:04:45 +00:00
|
|
|
|
int thumbnailHeight = WindowSize.Y / numThumbnails;
|
2023-07-07 18:52:36 +00:00
|
|
|
|
int thumbnailWidth = (int) 1.0 * thumbnailHeight * activeCamera.Resolution.X / activeCamera.Resolution.Y;
|
2023-07-28 18:36:02 +00:00
|
|
|
|
|
|
|
|
|
Console.WriteLine($"thumbnail size: {thumbnailWidth} x {thumbnailHeight}");
|
2023-07-08 04:04:45 +00:00
|
|
|
|
for (int i = 0; i < numThumbnails; i++) {
|
2023-07-24 16:43:38 +00:00
|
|
|
|
Box2i box = Util.MakeBox(WindowSize.X - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight);
|
2023-07-07 18:52:36 +00:00
|
|
|
|
ThumbnailBoxes.Add(box);
|
|
|
|
|
}
|
2023-07-07 20:00:43 +00:00
|
|
|
|
|
2023-08-02 05:05:10 +00:00
|
|
|
|
int statusBoxHeight = 40;
|
2023-07-24 17:14:07 +00:00
|
|
|
|
int statusBoxPadding = 4;
|
|
|
|
|
PhotoBox = new Box2i(0, 0, WindowSize.X - thumbnailWidth, WindowSize.Y - statusBoxHeight - statusBoxPadding);
|
|
|
|
|
StatusBox = new Box2i(0, WindowSize.Y - statusBoxHeight, WindowSize.X - thumbnailWidth, WindowSize.Y);
|
2023-07-25 21:18:11 +00:00
|
|
|
|
ThumbnailBox = new Box2i(ThumbnailBoxes[0].Min.X, ThumbnailBoxes[0].Min.Y, WindowSize.X, WindowSize.Y);
|
2023-07-26 19:09:19 +00:00
|
|
|
|
|
|
|
|
|
int starSpacing = 10;
|
|
|
|
|
int starBoxLeft = (int) (PhotoBox.Center.X - 2.5 * starSize - starSpacing * 2);
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
|
Box2i box = Util.MakeBox(starBoxLeft + i * (starSize + starSpacing), PhotoBox.Max.Y - starSize - 10, starSize, starSize);
|
|
|
|
|
StarBoxes.Add(box);
|
|
|
|
|
}
|
2023-07-07 18:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
|
public static class Util {
|
2023-07-23 22:42:08 +00:00
|
|
|
|
public const float PI = (float) Math.PI;
|
|
|
|
|
|
2023-08-01 18:12:52 +00:00
|
|
|
|
public static int Lerp(int start, int end, double fraction) {
|
|
|
|
|
return start + (int) ((end - start) * fraction);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 16:43:38 +00:00
|
|
|
|
public static Box2i MakeBox(int left, int top, int width, int height) {
|
2023-07-07 18:52:36 +00:00
|
|
|
|
return new Box2i(left, top, left + width, top + height);
|
2023-07-07 18:24:43 +00:00
|
|
|
|
}
|
2023-07-24 16:13:13 +00:00
|
|
|
|
|
2023-07-24 16:43:38 +00:00
|
|
|
|
public static Image<Rgba32> MakeImage(float width, float height) {
|
2023-07-24 16:36:44 +00:00
|
|
|
|
return new((int) Math.Ceiling(width), (int) Math.Ceiling(height));
|
2023-07-24 16:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 18:28:57 +00:00
|
|
|
|
// https://sirv.com/help/articles/rotate-photos-to-be-upright/
|
|
|
|
|
public static void RotateImageFromExif(Image<Rgba32> image, ushort orientation) {
|
2023-07-25 18:48:02 +00:00
|
|
|
|
if (orientation <= 1) {
|
2023-07-25 18:28:57 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-25 19:00:30 +00:00
|
|
|
|
// FIXME: I'm not convinced that all of these are correct, especially the
|
|
|
|
|
// cases that involve flipping (because whether you're flipping before or
|
2023-08-04 00:03:46 +00:00
|
|
|
|
// after rotation matters.)
|
2023-07-25 18:48:02 +00:00
|
|
|
|
var operations = new Dictionary<ushort, (RotateMode, FlipMode)> {
|
|
|
|
|
{ 2, (RotateMode.None, FlipMode.Horizontal) },
|
|
|
|
|
{ 3, (RotateMode.Rotate180, FlipMode.None) },
|
2023-07-25 19:02:40 +00:00
|
|
|
|
{ 4, (RotateMode.None, FlipMode.Vertical) },
|
2023-07-25 18:48:02 +00:00
|
|
|
|
{ 5, (RotateMode.Rotate90, FlipMode.Vertical) },
|
|
|
|
|
{ 6, (RotateMode.Rotate90, FlipMode.None) },
|
|
|
|
|
{ 7, (RotateMode.Rotate270, FlipMode.Vertical) },
|
|
|
|
|
{ 8, (RotateMode.Rotate270, FlipMode.None) },
|
|
|
|
|
};
|
|
|
|
|
var (rotate, flip) = operations[orientation];
|
|
|
|
|
image.Mutate(x => x.RotateFlip(rotate, flip));
|
2023-07-25 18:28:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 16:43:38 +00:00
|
|
|
|
public static Texture RenderText(string text) {
|
|
|
|
|
return RenderText(text, 16);
|
2023-07-24 16:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 16:43:38 +00:00
|
|
|
|
public static Texture RenderText(string text, int size) {
|
2023-08-04 00:03:46 +00:00
|
|
|
|
// Make sure that 0-length text doesn't end up as a 0-size texture, which
|
|
|
|
|
// might cause problems.
|
|
|
|
|
if (text.Length == 0) {
|
|
|
|
|
text = " ";
|
|
|
|
|
}
|
2023-07-24 16:36:44 +00:00
|
|
|
|
Font font = SystemFonts.CreateFont("Consolas", size, FontStyle.Bold);
|
2023-07-24 16:13:13 +00:00
|
|
|
|
TextOptions options = new(font);
|
2023-07-24 16:36:44 +00:00
|
|
|
|
FontRectangle rect = TextMeasurer.Measure(text, new TextOptions(font));
|
2023-07-24 16:43:38 +00:00
|
|
|
|
Image<Rgba32> image = MakeImage(rect.Width, rect.Height);
|
2023-07-24 16:13:13 +00:00
|
|
|
|
IBrush brush = Brushes.Solid(Color.White);
|
2023-07-24 16:36:44 +00:00
|
|
|
|
image.Mutate(x => x.DrawText(options, text, brush));
|
2023-07-24 16:13:13 +00:00
|
|
|
|
Texture texture = new Texture(image);
|
|
|
|
|
image.Dispose();
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 15:24:56 +00:00
|
|
|
|
// FIXME: make a real icon stored as a PNG...
|
2023-07-26 14:00:46 +00:00
|
|
|
|
public static OpenTK.Windowing.Common.Input.Image[] RenderAppIcon() {
|
2023-07-26 15:11:06 +00:00
|
|
|
|
int size = 64;
|
2023-07-26 15:14:23 +00:00
|
|
|
|
Font font = SystemFonts.CreateFont("MS Mincho", size, FontStyle.Bold);
|
2023-07-26 14:00:46 +00:00
|
|
|
|
TextOptions options = new(font);
|
2023-07-26 15:11:06 +00:00
|
|
|
|
Image<Rgba32> image = MakeImage(size, size);
|
2023-07-26 14:00:46 +00:00
|
|
|
|
IBrush brush = Brushes.Solid(Color.Black);
|
|
|
|
|
image.Mutate(x => x.DrawText(options, "撮", brush));
|
2023-07-26 15:11:06 +00:00
|
|
|
|
byte[] pixelBytes = new byte[size * size * 4];
|
2023-07-26 14:00:46 +00:00
|
|
|
|
image.CopyPixelDataTo(pixelBytes);
|
2023-07-26 15:11:06 +00:00
|
|
|
|
image.Dispose();
|
|
|
|
|
OpenTK.Windowing.Common.Input.Image opentkImage = new(size, size, pixelBytes);
|
2023-07-26 14:00:46 +00:00
|
|
|
|
return new OpenTK.Windowing.Common.Input.Image[]{ opentkImage };
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 16:23:58 +00:00
|
|
|
|
public static Texture RenderStar(float radius, bool filled) {
|
2023-07-26 19:09:19 +00:00
|
|
|
|
IPath path = new Star(x: radius, y: radius + 1, prongs: 5, innerRadii: radius * 0.4f, outerRadii: radius, angle: Util.PI);
|
2023-07-26 17:10:19 +00:00
|
|
|
|
// We add a little bit to the width & height because the reported
|
|
|
|
|
// path.Bounds are often a little tighter than they should be & a couple
|
|
|
|
|
// pixels end up obviously missing...
|
2023-07-26 16:23:58 +00:00
|
|
|
|
Image<Rgba32> image = MakeImage(path.Bounds.Width + 2, path.Bounds.Height + 2);
|
|
|
|
|
IBrush brush = Brushes.Solid(Color.White);
|
2023-07-26 19:09:19 +00:00
|
|
|
|
IPen white = Pens.Solid(Color.White, 1.5f);
|
|
|
|
|
IPen black = Pens.Solid(Color.Black, 3f);
|
|
|
|
|
image.Mutate(x => x.Draw(black, path));
|
2023-07-26 16:23:58 +00:00
|
|
|
|
if (filled) {
|
|
|
|
|
image.Mutate(x => x.Fill(brush, path));
|
|
|
|
|
}
|
2023-07-26 19:09:19 +00:00
|
|
|
|
image.Mutate(x => x.Draw(white, path));
|
2023-07-24 16:13:13 +00:00
|
|
|
|
Texture texture = new Texture(image);
|
|
|
|
|
image.Dispose();
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
2023-07-07 18:24:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
public class Game : GameWindow {
|
2023-08-03 22:38:21 +00:00
|
|
|
|
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) {
|
|
|
|
|
activeTool = viewTool;
|
|
|
|
|
}
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
2023-08-02 05:05:10 +00:00
|
|
|
|
private static string outputRoot = @"c:\users\colin\desktop\totte-output";
|
|
|
|
|
// private static string outputRoot = @"c:\users\colin\pictures\photos";
|
|
|
|
|
|
2023-07-08 04:33:15 +00:00
|
|
|
|
private static Texture TEXTURE_WHITE = new(new Image<Rgba32>(1, 1, new Rgba32(255, 255, 255)));
|
2023-07-24 21:13:19 +00:00
|
|
|
|
private static Texture TEXTURE_BLACK = new(new Image<Rgba32>(1, 1, new Rgba32(0, 0, 0)));
|
2023-07-26 16:23:58 +00:00
|
|
|
|
private static Texture STAR_FILLED = Util.RenderStar(20, true);
|
2023-07-26 17:10:19 +00:00
|
|
|
|
private static Texture STAR_EMPTY = Util.RenderStar(20, false);
|
|
|
|
|
private static Texture STAR_SMALL = Util.RenderStar(6, true);
|
2023-07-06 22:31:50 +00:00
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
|
UiGeometry geometry = new();
|
2023-07-26 02:19:18 +00:00
|
|
|
|
FpsCounter fpsCounter = new();
|
2023-07-07 18:24:43 +00:00
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
|
// Four points, each consisting of (x, y, z, tex_x, tex_y).
|
2023-07-07 18:24:43 +00:00
|
|
|
|
float[] vertices = new float[20];
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
|
// Indices to draw a rectangle from two triangles.
|
2023-06-30 02:10:24 +00:00
|
|
|
|
uint[] indices = {
|
|
|
|
|
0, 1, 3, // first triangle
|
|
|
|
|
1, 2, 3 // second triangle
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int VertexBufferObject;
|
|
|
|
|
int ElementBufferObject;
|
|
|
|
|
int VertexArrayObject;
|
2023-07-26 21:29:59 +00:00
|
|
|
|
List<Photo> allPhotos = new();
|
2023-07-16 23:23:03 +00:00
|
|
|
|
List<Photo> photos = new();
|
2023-07-27 01:29:26 +00:00
|
|
|
|
HashSet<Photo> loadedImages = new();
|
2023-07-28 17:07:47 +00:00
|
|
|
|
HashSet<Photo> loadingImages = new();
|
|
|
|
|
readonly object loadedImagesLock = new();
|
2023-08-03 22:38:21 +00:00
|
|
|
|
readonly ViewTool viewTool = new ViewTool();
|
|
|
|
|
ITool activeTool;
|
2023-07-16 23:25:28 +00:00
|
|
|
|
int photoIndex = 0;
|
2023-07-25 22:26:46 +00:00
|
|
|
|
int ribbonIndex = 0;
|
2023-08-02 05:05:10 +00:00
|
|
|
|
Vector2i mousePosition;
|
2023-08-02 03:14:00 +00:00
|
|
|
|
float activeScale = 1f;
|
2023-08-02 05:05:10 +00:00
|
|
|
|
Vector2i activeOffset;
|
2023-07-08 04:33:15 +00:00
|
|
|
|
Shader shader = new();
|
2023-06-30 02:10:24 +00:00
|
|
|
|
Matrix4 projection;
|
2023-07-18 05:42:59 +00:00
|
|
|
|
float zoomLevel = 0f;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnUpdateFrame(FrameEventArgs e) {
|
|
|
|
|
base.OnUpdateFrame(e);
|
|
|
|
|
|
2023-08-04 03:21:10 +00:00
|
|
|
|
Photo previousPhoto = photos[photoIndex];
|
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
KeyboardState input = KeyboardState;
|
|
|
|
|
|
2023-07-31 04:58:21 +00:00
|
|
|
|
bool shiftIsDown = input.IsKeyDown(Keys.LeftShift) || input.IsKeyDown(Keys.RightShift);
|
2023-07-31 21:01:08 +00:00
|
|
|
|
bool altIsDown = input.IsKeyDown(Keys.LeftAlt) || input.IsKeyDown(Keys.RightAlt);
|
2023-07-31 04:58:21 +00:00
|
|
|
|
bool ctrlIsDown = input.IsKeyDown(Keys.LeftControl) || input.IsKeyDown(Keys.RightControl);
|
|
|
|
|
|
2023-07-25 22:26:46 +00:00
|
|
|
|
// FIXME: add a confirm dialog before closing. (Also for the window-close button.)
|
2023-08-01 00:50:53 +00:00
|
|
|
|
// FIXME: don't quit if there's pending file-write operations.
|
2023-08-02 02:24:25 +00:00
|
|
|
|
// Close when Ctrl-Q is pressed.
|
|
|
|
|
if (input.IsKeyPressed(Keys.Q) && ctrlIsDown) {
|
2023-07-16 23:13:08 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 05:05:10 +00:00
|
|
|
|
mousePosition = (Vector2i) MouseState.Position;
|
2023-08-02 02:24:25 +00:00
|
|
|
|
|
2023-07-26 19:20:20 +00:00
|
|
|
|
// Look for mouse clicks on thumbnails or stars.
|
2023-07-25 22:38:21 +00:00
|
|
|
|
//
|
|
|
|
|
// Note that we don't bounds-check photoIndex until after all the possible
|
|
|
|
|
// inputs that might affect it. That simplifies this logic significantly.
|
|
|
|
|
if (MouseState.IsButtonPressed(MouseButton.Button1)) {
|
2023-07-26 19:20:20 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < geometry.StarBoxes.Count; i++) {
|
2023-08-02 02:24:25 +00:00
|
|
|
|
if (geometry.StarBoxes[i].ContainsInclusive(mousePosition)) {
|
2023-07-26 19:20:20 +00:00
|
|
|
|
photos[photoIndex].Rating = i + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-08 04:18:31 +00:00
|
|
|
|
for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) {
|
2023-08-02 02:24:25 +00:00
|
|
|
|
if (geometry.ThumbnailBoxes[i].ContainsInclusive(mousePosition)) {
|
2023-07-25 22:38:21 +00:00
|
|
|
|
photoIndex = ribbonIndex + i;
|
2023-07-08 04:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 22:38:21 +00:00
|
|
|
|
if (MouseState.IsButtonPressed(MouseButton.Button4)) {
|
|
|
|
|
photoIndex--;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 22:38:21 +00:00
|
|
|
|
if (MouseState.IsButtonPressed(MouseButton.Button5)) {
|
|
|
|
|
photoIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MouseState.ScrollDelta.Y < 0) {
|
|
|
|
|
photoIndex++;
|
2023-07-16 23:13:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 22:38:21 +00:00
|
|
|
|
if (MouseState.ScrollDelta.Y > 0) {
|
|
|
|
|
photoIndex--;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.Down)) {
|
2023-07-25 22:38:21 +00:00
|
|
|
|
photoIndex++;
|
|
|
|
|
}
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.Up)) {
|
2023-07-25 22:38:21 +00:00
|
|
|
|
photoIndex--;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 01:44:22 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.Home)) {
|
|
|
|
|
photoIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input.IsKeyPressed(Keys.End)) {
|
|
|
|
|
photoIndex = photos.Count - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input.IsKeyPressed(Keys.PageDown)) {
|
2023-07-26 20:57:32 +00:00
|
|
|
|
photoIndex += 5;
|
2023-07-26 01:44:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input.IsKeyPressed(Keys.PageUp)) {
|
2023-07-26 20:57:32 +00:00
|
|
|
|
photoIndex -= 5;
|
2023-07-26 01:44:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 21:01:08 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.P) && altIsDown) {
|
2023-07-28 19:52:36 +00:00
|
|
|
|
ExportPhotos();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 22:38:21 +00:00
|
|
|
|
// Make sure the photoIndex is actually valid.
|
2023-07-28 15:52:07 +00:00
|
|
|
|
if (photos.Count == 0) {
|
|
|
|
|
photoIndex = 0;
|
|
|
|
|
} else {
|
|
|
|
|
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
|
|
|
|
|
}
|
2023-07-25 22:38:21 +00:00
|
|
|
|
|
2023-07-26 21:29:59 +00:00
|
|
|
|
// Handle presses of the "rating" keys -- 0-5 and `.
|
|
|
|
|
// A normal press just sets the rating of the current photo.
|
|
|
|
|
// If the user is holding "shift", we instead filter to only show photos of that rating or higher.
|
|
|
|
|
int rating = -1;
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.D0) || input.IsKeyPressed(Keys.GraveAccent)) {
|
2023-07-26 21:29:59 +00:00
|
|
|
|
rating = 0;
|
2023-07-18 05:42:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.D1)) {
|
2023-07-26 21:29:59 +00:00
|
|
|
|
rating = 1;
|
2023-07-18 05:42:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.D2)) {
|
2023-07-26 21:29:59 +00:00
|
|
|
|
rating = 2;
|
2023-07-18 05:42:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.D3)) {
|
2023-07-26 21:29:59 +00:00
|
|
|
|
rating = 3;
|
2023-07-18 05:42:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.D4)) {
|
2023-07-26 21:29:59 +00:00
|
|
|
|
rating = 4;
|
2023-07-18 05:42:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.D5)) {
|
2023-07-26 21:29:59 +00:00
|
|
|
|
rating = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rating >= 0) {
|
2023-07-31 04:58:21 +00:00
|
|
|
|
if (shiftIsDown) {
|
2023-07-26 21:29:59 +00:00
|
|
|
|
FilterByRating(rating);
|
|
|
|
|
} else {
|
2023-07-28 15:52:07 +00:00
|
|
|
|
if (photos.Count > 0) {
|
|
|
|
|
photos[photoIndex].Rating = rating;
|
|
|
|
|
}
|
2023-07-26 21:29:59 +00:00
|
|
|
|
}
|
2023-07-26 19:41:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.Q)) {
|
2023-07-26 19:41:53 +00:00
|
|
|
|
zoomLevel = 0f;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.W)) {
|
2023-07-26 19:41:53 +00:00
|
|
|
|
zoomLevel = 1f;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.E)) {
|
2023-07-26 19:41:53 +00:00
|
|
|
|
zoomLevel = 2f;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.R)) {
|
2023-07-26 19:41:53 +00:00
|
|
|
|
zoomLevel = 4f;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.T)) {
|
2023-07-26 19:41:53 +00:00
|
|
|
|
zoomLevel = 8f;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 20:57:32 +00:00
|
|
|
|
if (input.IsKeyPressed(Keys.Y)) {
|
2023-07-18 05:42:59 +00:00
|
|
|
|
zoomLevel = 16f;
|
|
|
|
|
}
|
2023-08-03 22:14:19 +00:00
|
|
|
|
|
2023-08-03 22:38:21 +00:00
|
|
|
|
// Handle tool switching.
|
2023-08-04 03:21:10 +00:00
|
|
|
|
if (photos[photoIndex] != previousPhoto) {
|
|
|
|
|
activeTool = viewTool;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:38:21 +00:00
|
|
|
|
if (activeTool == viewTool) {
|
|
|
|
|
if (input.IsKeyPressed(Keys.C)) {
|
2023-08-04 00:03:46 +00:00
|
|
|
|
activeTool = new CropTool(photos[photoIndex]);
|
2023-08-03 22:38:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delegate input to the active tool.
|
|
|
|
|
ToolState state = activeTool.HandleInput(geometry, KeyboardState, MouseState, this);
|
|
|
|
|
|
|
|
|
|
// Change back to the default tool if the active tool is done.
|
|
|
|
|
if (state != ToolState.Active) {
|
|
|
|
|
activeTool = viewTool;
|
|
|
|
|
}
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 21:29:59 +00:00
|
|
|
|
void FilterByRating(int rating) {
|
|
|
|
|
Console.WriteLine("filter to " + rating);
|
2023-07-28 15:52:07 +00:00
|
|
|
|
Photo previouslyActive = photos.Count > 0 ? photos[photoIndex] : allPhotos[0];
|
2023-07-26 22:16:51 +00:00
|
|
|
|
photos = allPhotos.Where(p => p.Rating >= rating).ToList();
|
2023-07-27 01:56:27 +00:00
|
|
|
|
// Move photoIndex to wherever the previously active photo was, or if it
|
|
|
|
|
// was filtered out, to whichever unfiltered photo comes before it. This
|
|
|
|
|
// is O(n) in the length of allPhotos, but how bad can it be? :)
|
|
|
|
|
photoIndex = -1;
|
|
|
|
|
for (int i = 0; i < allPhotos.Count; i++) {
|
|
|
|
|
Photo candidate = allPhotos[i];
|
|
|
|
|
if (candidate.Rating >= rating) {
|
|
|
|
|
photoIndex++;
|
|
|
|
|
}
|
|
|
|
|
if (candidate == previouslyActive) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
photoIndex = Math.Max(0, photoIndex);
|
2023-07-26 21:29:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 23:32:53 +00:00
|
|
|
|
// FIXME: switch to immediate mode??
|
|
|
|
|
// https://gamedev.stackexchange.com/questions/198805/opentk-immediate-mode-on-net-core-doesnt-work
|
|
|
|
|
// https://www.youtube.com/watch?v=Q23Kf9QEaO4
|
2023-07-26 01:24:20 +00:00
|
|
|
|
protected override void OnLoad() {
|
2023-06-30 02:10:24 +00:00
|
|
|
|
base.OnLoad();
|
|
|
|
|
|
2023-07-07 05:44:51 +00:00
|
|
|
|
GL.ClearColor(0f, 0f, 0f, 1f);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
2023-07-24 16:13:13 +00:00
|
|
|
|
GL.Enable(EnableCap.Blend);
|
|
|
|
|
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
VertexArrayObject = GL.GenVertexArray();
|
|
|
|
|
GL.BindVertexArray(VertexArrayObject);
|
|
|
|
|
|
|
|
|
|
VertexBufferObject = GL.GenBuffer();
|
|
|
|
|
ElementBufferObject = GL.GenBuffer();
|
|
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
|
|
|
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
|
|
|
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
|
|
|
|
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.DynamicDraw);
|
|
|
|
|
|
2023-07-08 03:29:51 +00:00
|
|
|
|
shader.Init();
|
2023-06-30 02:10:24 +00:00
|
|
|
|
shader.Use();
|
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
|
// Because there's 5 floats between the start of the first vertex and the start of the second,
|
|
|
|
|
// the stride is 5 * sizeof(float).
|
2023-06-30 02:10:24 +00:00
|
|
|
|
// This will now pass the new vertex array to the buffer.
|
|
|
|
|
var vertexLocation = shader.GetAttribLocation("aPosition");
|
|
|
|
|
GL.EnableVertexAttribArray(vertexLocation);
|
|
|
|
|
GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float, false, 5 * sizeof(float), 0);
|
|
|
|
|
|
|
|
|
|
// Next, we also setup texture coordinates. It works in much the same way.
|
|
|
|
|
// We add an offset of 3, since the texture coordinates comes after the position data.
|
|
|
|
|
// We also change the amount of data to 2 because there's only 2 floats for texture coordinates.
|
|
|
|
|
var texCoordLocation = shader.GetAttribLocation("aTexCoord");
|
|
|
|
|
GL.EnableVertexAttribArray(texCoordLocation);
|
|
|
|
|
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
|
|
|
|
|
|
2023-07-26 01:24:20 +00:00
|
|
|
|
// Load photos from a directory.
|
2023-08-04 01:33:28 +00:00
|
|
|
|
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\");
|
2023-08-03 22:14:19 +00:00
|
|
|
|
// string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\");
|
2023-08-04 01:33:28 +00:00
|
|
|
|
string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\23\");
|
2023-08-03 23:38:53 +00:00
|
|
|
|
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\");
|
2023-08-01 00:50:53 +00:00
|
|
|
|
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\07\31");
|
2023-07-25 18:28:57 +00:00
|
|
|
|
// string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23");
|
2023-07-28 19:52:36 +00:00
|
|
|
|
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
|
2023-07-28 15:52:07 +00:00
|
|
|
|
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
|
2023-07-17 03:45:50 +00:00
|
|
|
|
|
2023-07-17 00:06:37 +00:00
|
|
|
|
for (int i = 0; i < files.Count(); i++) {
|
|
|
|
|
string file = files[i];
|
2023-06-30 02:10:24 +00:00
|
|
|
|
if (file.ToLower().EndsWith(".jpg")) {
|
2023-07-24 21:13:19 +00:00
|
|
|
|
Photo photo = new Photo(file, TEXTURE_BLACK);
|
2023-07-26 21:29:59 +00:00
|
|
|
|
allPhotos.Add(photo);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-25 20:58:41 +00:00
|
|
|
|
|
2023-07-26 21:29:59 +00:00
|
|
|
|
allPhotos.Sort(ComparePhotosByDate);
|
|
|
|
|
photos = allPhotos;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 00:25:07 +00:00
|
|
|
|
private static int ComparePhotosByDate(Photo x, Photo y) {
|
|
|
|
|
int compare = x.DateTimeOriginal.CompareTo(y.DateTimeOriginal);
|
|
|
|
|
if (compare != 0) {
|
|
|
|
|
return compare;
|
|
|
|
|
}
|
|
|
|
|
// If the photos have the same seconds value, sort by filename
|
|
|
|
|
// (since cameras usually increment the filename for successive shots.)
|
|
|
|
|
return x.Filename.CompareTo(y.Filename);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
protected override void OnUnload() {
|
|
|
|
|
base.OnUnload();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 17:07:47 +00:00
|
|
|
|
private void UnloadImages() {
|
|
|
|
|
// Unload images that haven't been touched in a while.
|
2023-07-26 02:00:43 +00:00
|
|
|
|
// FIXME: keep around thumbnail-sized textures?
|
2023-07-28 17:07:47 +00:00
|
|
|
|
lock (loadedImagesLock) {
|
2023-07-28 18:36:02 +00:00
|
|
|
|
while (loadedImages.Count > 100) {
|
2023-07-28 17:07:47 +00:00
|
|
|
|
long earliestTime = long.MaxValue;
|
|
|
|
|
Photo? earliest = null;
|
|
|
|
|
foreach (Photo photo in loadedImages) {
|
|
|
|
|
if (photo.LastTouch < earliestTime) {
|
|
|
|
|
earliest = photo;
|
|
|
|
|
earliestTime = photo.LastTouch;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (earliest != null) {
|
2023-07-28 18:36:02 +00:00
|
|
|
|
Console.WriteLine($"loadedImages.Count: {loadedImages.Count}, evicting {earliest.Filename} @ {earliestTime}");
|
2023-07-28 17:07:47 +00:00
|
|
|
|
// TODO: we have to free textures on the GL thread, but could we do that async'ly to keep the UI responsive?
|
|
|
|
|
earliest.Unload();
|
|
|
|
|
loadedImages.Remove(earliest);
|
2023-07-27 01:29:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-28 17:07:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void LoadImagesAsync() {
|
|
|
|
|
foreach (Photo p in loadingImages) {
|
|
|
|
|
if (p.Loaded) {
|
|
|
|
|
lock (loadedImagesLock) {
|
|
|
|
|
loadedImages.Add(p);
|
|
|
|
|
loadingImages.Remove(p);
|
|
|
|
|
}
|
2023-07-26 01:24:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-28 17:07:47 +00:00
|
|
|
|
// Start loading any images that are in our window but not yet loaded.
|
2023-07-28 19:52:36 +00:00
|
|
|
|
int minLoadedImage = Math.Max(0, photoIndex - 30);
|
|
|
|
|
int maxLoadedImage = Math.Min(photoIndex + 30, photos.Count - 1);
|
2023-07-28 17:07:47 +00:00
|
|
|
|
List<Photo> toLoad = new();
|
2023-07-26 01:24:20 +00:00
|
|
|
|
for (int i = minLoadedImage; i <= maxLoadedImage; i++) {
|
2023-07-28 17:07:47 +00:00
|
|
|
|
lock (loadedImagesLock) {
|
|
|
|
|
if (!loadedImages.Contains(photos[i]) && !loadingImages.Contains(photos[i])) {
|
|
|
|
|
Console.WriteLine("loading " + i);
|
|
|
|
|
loadingImages.Add(photos[i]);
|
|
|
|
|
toLoad.Add(photos[i]);
|
|
|
|
|
}
|
2023-07-26 01:24:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-28 17:07:47 +00:00
|
|
|
|
foreach (Photo p in toLoad) {
|
|
|
|
|
await Task.Run( () => { p.LoadAsync(); });
|
|
|
|
|
}
|
2023-07-26 01:24:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 19:52:36 +00:00
|
|
|
|
// To find the JPEG compression level of a file from the command line:
|
|
|
|
|
// $ identify -verbose image.jpg | grep Quality:
|
2023-07-28 20:28:18 +00:00
|
|
|
|
// FIXME: don't ExportPhotos() if another export is already active.
|
|
|
|
|
// FIXME: show a progress bar or something.
|
|
|
|
|
private async void ExportPhotos() {
|
2023-07-28 20:00:08 +00:00
|
|
|
|
JpegEncoder encoder = new JpegEncoder() { Quality = 100 };
|
2023-07-28 19:52:36 +00:00
|
|
|
|
foreach (Photo p in photos) {
|
2023-08-01 00:50:53 +00:00
|
|
|
|
await Task.Run( () => { p.SaveAsJpegAsync(outputRoot, encoder); });
|
2023-07-28 19:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e) {
|
|
|
|
|
base.OnRenderFrame(e);
|
2023-07-26 02:19:18 +00:00
|
|
|
|
fpsCounter.Update();
|
2023-07-17 03:45:50 +00:00
|
|
|
|
|
2023-07-28 17:07:47 +00:00
|
|
|
|
UnloadImages();
|
|
|
|
|
LoadImagesAsync();
|
2023-07-26 01:24:20 +00:00
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
2023-07-26 22:16:51 +00:00
|
|
|
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
2023-07-07 01:26:50 +00:00
|
|
|
|
GL.ActiveTexture(TextureUnit.Texture0);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
2023-07-28 15:52:07 +00:00
|
|
|
|
if (photos.Count > 0) {
|
|
|
|
|
DrawPhotos();
|
|
|
|
|
} else {
|
|
|
|
|
DrawText("No photos found.", 10, 10);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
activeTool.Draw(geometry, this);
|
2023-08-01 18:12:52 +00:00
|
|
|
|
|
2023-07-28 15:52:07 +00:00
|
|
|
|
SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawPhotos() {
|
2023-07-24 16:53:21 +00:00
|
|
|
|
Photo activePhoto = photos[photoIndex];
|
|
|
|
|
Texture active = activePhoto.Texture();
|
2023-06-30 02:52:52 +00:00
|
|
|
|
|
2023-07-07 20:00:43 +00:00
|
|
|
|
// FIXME: make a function for scaling & centering one box on another.
|
2023-07-08 04:30:05 +00:00
|
|
|
|
float scaleX = 1f * geometry.PhotoBox.Size.X / active.Size.X;
|
|
|
|
|
float scaleY = 1f * geometry.PhotoBox.Size.Y / active.Size.Y;
|
|
|
|
|
float scale = Math.Min(scaleX, scaleY);
|
2023-07-18 05:42:59 +00:00
|
|
|
|
if (zoomLevel > 0f) {
|
|
|
|
|
scale = zoomLevel;
|
|
|
|
|
}
|
2023-08-02 03:14:00 +00:00
|
|
|
|
activeScale = scale;
|
2023-07-08 04:30:05 +00:00
|
|
|
|
|
|
|
|
|
Vector2i renderSize = (Vector2i) (((Vector2) active.Size) * scale);
|
|
|
|
|
Vector2i center = (Vector2i) geometry.PhotoBox.Center;
|
2023-08-02 05:05:10 +00:00
|
|
|
|
Box2i photoBox = Util.MakeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y);
|
|
|
|
|
activeOffset = new(photoBox.Min.X, photoBox.Min.Y);
|
2023-07-26 16:23:58 +00:00
|
|
|
|
DrawTexture(active, photoBox);
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
|
Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY;
|
2023-07-26 19:09:19 +00:00
|
|
|
|
DrawTexture(star, geometry.StarBoxes[i].Min.X, geometry.StarBoxes[i].Min.Y);
|
2023-07-26 16:23:58 +00:00
|
|
|
|
}
|
2023-08-04 03:21:10 +00:00
|
|
|
|
bool cropActive = activeTool.GetType().Name == "CropTool";
|
|
|
|
|
DrawCropRectangle(cropActive);
|
2023-07-25 21:18:11 +00:00
|
|
|
|
|
|
|
|
|
// Draw thumbnail boxes.
|
2023-07-25 22:26:46 +00:00
|
|
|
|
ribbonIndex = Math.Clamp(photoIndex - (geometry.ThumbnailBoxes.Count - 1) / 2, 0, Math.Max(0, photos.Count - geometry.ThumbnailBoxes.Count));
|
2023-07-25 21:18:11 +00:00
|
|
|
|
DrawFilledBox(geometry.ThumbnailBox, Color4.Black);
|
2023-07-25 22:26:46 +00:00
|
|
|
|
for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) {
|
|
|
|
|
if (ribbonIndex + i >= photos.Count) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-07-26 17:10:19 +00:00
|
|
|
|
Photo photo = photos[ribbonIndex + i];
|
2023-07-07 18:52:36 +00:00
|
|
|
|
Box2i box = geometry.ThumbnailBoxes[i];
|
2023-07-26 17:10:19 +00:00
|
|
|
|
DrawTexture(photo.Texture(), box);
|
|
|
|
|
for (int j = 0; j < photo.Rating; j++) {
|
2023-07-26 17:49:48 +00:00
|
|
|
|
DrawTexture(STAR_SMALL, box.Min.X + 8 + ((STAR_SMALL.Size.X + 2) * j), box.Min.Y + 8);
|
2023-07-26 17:10:19 +00:00
|
|
|
|
}
|
2023-07-25 22:26:46 +00:00
|
|
|
|
if (ribbonIndex + i == photoIndex) {
|
2023-07-07 06:33:01 +00:00
|
|
|
|
DrawBox(box, 5, Color4.Black);
|
|
|
|
|
DrawBox(box, 3, Color4.White);
|
2023-07-07 01:26:50 +00:00
|
|
|
|
}
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
2023-07-24 16:53:21 +00:00
|
|
|
|
|
2023-07-24 17:14:07 +00:00
|
|
|
|
// Draw status box.
|
2023-07-26 15:24:56 +00:00
|
|
|
|
int statusPadding = 2;
|
2023-07-25 13:45:40 +00:00
|
|
|
|
DrawFilledBox(geometry.StatusBox, Color4.Black);
|
2023-08-02 05:05:10 +00:00
|
|
|
|
// First line.
|
|
|
|
|
int y = geometry.StatusBox.Min.Y + statusPadding;
|
2023-08-03 02:29:04 +00:00
|
|
|
|
DrawText(String.Format("{0,4}/{1,-4}", photoIndex + 1, photos.Count), geometry.StatusBox.Min.X, y);
|
|
|
|
|
DrawText(activePhoto.Description(), geometry.StatusBox.Min.X + 88, y);
|
|
|
|
|
|
2023-08-02 05:05:10 +00:00
|
|
|
|
// Second line.
|
|
|
|
|
y += 20;
|
2023-08-03 23:38:53 +00:00
|
|
|
|
DrawText(activeTool.Status(), geometry.StatusBox.Min.X, y);
|
2023-08-02 05:05:10 +00:00
|
|
|
|
DrawText(String.Format("FPS: {0,2}", fpsCounter.Fps), geometry.StatusBox.Max.X - 66, y);
|
2023-07-24 16:53:21 +00:00
|
|
|
|
if (activePhoto.Loaded) {
|
2023-08-03 23:38:53 +00:00
|
|
|
|
DrawText($"{(scale * 100):F1}%", geometry.StatusBox.Max.X - 136, y);
|
2023-07-24 16:36:44 +00:00
|
|
|
|
}
|
2023-08-02 05:05:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 03:21:10 +00:00
|
|
|
|
void DrawCropRectangle(bool active) {
|
|
|
|
|
Photo activePhoto = photos[photoIndex];
|
|
|
|
|
if (activePhoto.CropRectangle == Rectangle.Empty) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2i leftTop = ImageToScreen(activePhoto.CropRectangle.Left, activePhoto.CropRectangle.Top);
|
|
|
|
|
Vector2i rightBottom = ImageToScreen(activePhoto.CropRectangle.Right, activePhoto.CropRectangle.Bottom);
|
|
|
|
|
var (left, top) = leftTop;
|
|
|
|
|
var (right, bottom) = rightBottom;
|
|
|
|
|
|
|
|
|
|
Color4 shadeColor = new Color4(0, 0, 0, 0.75f);
|
|
|
|
|
DrawFilledBox(new Box2i(0, 0, left, geometry.PhotoBox.Max.Y), shadeColor);
|
|
|
|
|
DrawFilledBox(new Box2i(left, 0, geometry.PhotoBox.Max.X, top), shadeColor);
|
|
|
|
|
DrawFilledBox(new Box2i(left, bottom, geometry.PhotoBox.Max.X, geometry.PhotoBox.Max.Y), shadeColor);
|
|
|
|
|
DrawFilledBox(new Box2i(right, top, geometry.PhotoBox.Max.X, bottom), shadeColor);
|
|
|
|
|
DrawBox(new Box2i(left, top, right, bottom), 1, Color4.White);
|
|
|
|
|
if (active) {
|
|
|
|
|
DrawHorizontalLine(left, Util.Lerp(top, bottom, 1.0 / 3), right, Color4.White);
|
|
|
|
|
DrawHorizontalLine(left, Util.Lerp(top, bottom, 2.0 / 3), right, Color4.White);
|
|
|
|
|
DrawVerticalLine(Util.Lerp(left, right, 1.0 / 3), top, bottom, Color4.White);
|
|
|
|
|
DrawVerticalLine(Util.Lerp(left, right, 2.0 / 3), top, bottom, Color4.White);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public Vector2i ScreenToImage(int x, int y) {
|
2023-08-03 22:38:21 +00:00
|
|
|
|
int rx = (int) ((x - activeOffset.X) / activeScale);
|
2023-08-04 01:33:28 +00:00
|
|
|
|
rx = Math.Clamp(rx, 0, photos[photoIndex].Size.X);
|
2023-08-03 22:38:21 +00:00
|
|
|
|
int ry = (int) ((y - activeOffset.Y) / activeScale);
|
2023-08-04 01:33:28 +00:00
|
|
|
|
ry = Math.Clamp(ry, 0, photos[photoIndex].Size.Y);
|
2023-08-03 22:38:21 +00:00
|
|
|
|
return new(rx, ry);
|
2023-08-02 05:05:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public Vector2i ScreenToImage(Vector2i position) {
|
2023-08-02 05:05:10 +00:00
|
|
|
|
return ScreenToImage(position.X, position.Y);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
public Vector2i ImageToScreen(int x, int y) {
|
|
|
|
|
int rx = (int) ((x * activeScale) + activeOffset.X);
|
|
|
|
|
int ry = (int) ((y * activeScale) + activeOffset.Y);
|
|
|
|
|
return new(rx, ry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2i ImageToScreen(Vector2i position) {
|
|
|
|
|
return ImageToScreen(position.X, position.Y);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawTexture(Texture texture, int x, int y) {
|
2023-07-26 17:49:48 +00:00
|
|
|
|
DrawTexture(texture, Util.MakeBox(x, y, texture.Size.X, texture.Size.Y));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawTexture(Texture texture, Box2i box) {
|
2023-07-07 03:36:55 +00:00
|
|
|
|
DrawTexture(texture, box, Color4.White);
|
2023-07-07 03:14:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawTexture(Texture texture, Box2i box, Color4 color) {
|
2023-07-07 05:07:58 +00:00
|
|
|
|
GL.Uniform4(shader.GetUniformLocation("color"), color);
|
2023-07-07 03:48:12 +00:00
|
|
|
|
SetVertices(box.Min.X, box.Min.Y, box.Size.X, box.Size.Y);
|
2023-07-07 01:26:50 +00:00
|
|
|
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
|
|
|
|
GL.BindTexture(TextureTarget.Texture2D, texture.Handle);
|
|
|
|
|
GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawHorizontalLine(int left, int top, int right, Color4 color) {
|
2023-08-01 18:12:52 +00:00
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.MakeBox(left, top, right - left, 1), color);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawVerticalLine(int left, int top, int bottom, Color4 color) {
|
2023-08-01 18:12:52 +00:00
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.MakeBox(left, top, 1, bottom - top), color);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawBox(Box2i box, int thickness, Color4 color) {
|
2023-07-24 16:43:38 +00:00
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Min.X, box.Min.Y, box.Size.X, thickness), color);
|
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Min.X, box.Min.Y, thickness, box.Size.Y), color);
|
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Min.X, box.Max.Y - thickness, box.Size.X, thickness), color);
|
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color);
|
2023-07-07 01:26:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawFilledBox(Box2i box, Color4 color) {
|
2023-07-25 13:45:40 +00:00
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Min.X, box.Min.Y, box.Size.X, box.Size.Y), color);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:14:19 +00:00
|
|
|
|
public void DrawText(string text, int x, int y) {
|
2023-07-24 16:53:21 +00:00
|
|
|
|
Texture label = Util.RenderText(text);
|
2023-07-26 17:49:48 +00:00
|
|
|
|
DrawTexture(label, x, y);
|
2023-07-24 16:53:21 +00:00
|
|
|
|
label.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
protected override void OnResize(ResizeEventArgs e) {
|
|
|
|
|
base.OnResize(e);
|
|
|
|
|
Console.WriteLine($"OnResize: {e.Width}x{e.Height}");
|
|
|
|
|
|
2023-07-26 19:09:19 +00:00
|
|
|
|
geometry = new UiGeometry(e.Size, STAR_FILLED.Size.X);
|
2023-07-07 18:24:43 +00:00
|
|
|
|
|
|
|
|
|
projection = Matrix4.CreateOrthographicOffCenter(0f, e.Width, e.Height, 0f, -1f, 1f);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
GL.UniformMatrix4(shader.GetUniformLocation("projection"), true, ref projection);
|
2023-07-07 18:24:43 +00:00
|
|
|
|
GL.Viewport(0, 0, e.Width, e.Height);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 02:57:38 +00:00
|
|
|
|
private void SetVertices(float left, float top, float width, float height) {
|
2023-06-30 02:10:24 +00:00
|
|
|
|
// top left
|
|
|
|
|
vertices[0] = left;
|
|
|
|
|
vertices[1] = top;
|
|
|
|
|
vertices[2] = 0f;
|
|
|
|
|
vertices[3] = 0f;
|
|
|
|
|
vertices[4] = 0f;
|
|
|
|
|
|
|
|
|
|
// top right
|
2023-06-30 02:57:38 +00:00
|
|
|
|
vertices[5] = left + width;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
vertices[6] = top;
|
|
|
|
|
vertices[7] = 0f;
|
|
|
|
|
vertices[8] = 1f;
|
|
|
|
|
vertices[9] = 0f;
|
|
|
|
|
|
|
|
|
|
// bottom right
|
2023-06-30 02:57:38 +00:00
|
|
|
|
vertices[10] = left + width;
|
|
|
|
|
vertices[11] = top + height;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
vertices[12] = 0f;
|
|
|
|
|
vertices[13] = 1f;
|
|
|
|
|
vertices[14] = 1f;
|
|
|
|
|
|
|
|
|
|
// bottom left
|
|
|
|
|
vertices[15] = left;
|
2023-06-30 02:57:38 +00:00
|
|
|
|
vertices[16] = top + height;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
vertices[17] = 0f;
|
|
|
|
|
vertices[18] = 0f;
|
|
|
|
|
vertices[19] = 1f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 01:33:28 +00:00
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
|
static class Program {
|
|
|
|
|
static void Main(string[] args) {
|
|
|
|
|
List<MonitorInfo> monitors = Monitors.GetMonitors();
|
|
|
|
|
MonitorInfo bestMonitor = monitors[0];
|
|
|
|
|
int bestResolution = bestMonitor.HorizontalResolution * bestMonitor.VerticalResolution;
|
|
|
|
|
for (int i = 1; i < monitors.Count; i++) {
|
|
|
|
|
MonitorInfo monitor = monitors[i];
|
|
|
|
|
int resolution = monitor.HorizontalResolution * monitor.VerticalResolution;
|
|
|
|
|
if (resolution > bestResolution) {
|
|
|
|
|
bestResolution = resolution;
|
|
|
|
|
bestMonitor = monitor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine($"best monitor: {bestMonitor.HorizontalResolution}x{bestMonitor.VerticalResolution}");
|
2023-07-07 18:52:36 +00:00
|
|
|
|
GameWindowSettings gwSettings = new();
|
2023-07-26 02:19:18 +00:00
|
|
|
|
gwSettings.UpdateFrequency = 30.0;
|
|
|
|
|
gwSettings.RenderFrequency = 30.0;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
|
NativeWindowSettings nwSettings = new();
|
2023-06-30 02:10:24 +00:00
|
|
|
|
nwSettings.WindowState = WindowState.Normal;
|
|
|
|
|
nwSettings.CurrentMonitor = bestMonitor.Handle;
|
|
|
|
|
nwSettings.Location = new Vector2i(bestMonitor.WorkArea.Min.X + 1, bestMonitor.WorkArea.Min.Y + 31);
|
2023-08-01 00:50:53 +00:00
|
|
|
|
// nwSettings.Size = new Vector2i(bestMonitor.WorkArea.Size.X - 2, bestMonitor.WorkArea.Size.Y - 32);
|
|
|
|
|
nwSettings.Size = new Vector2i(1600, 900);
|
2023-07-07 18:24:43 +00:00
|
|
|
|
nwSettings.MinimumSize = UiGeometry.MIN_WINDOW_SIZE;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
nwSettings.Title = "Totte";
|
2023-07-26 14:00:46 +00:00
|
|
|
|
nwSettings.IsEventDriven = false;
|
|
|
|
|
nwSettings.Icon = new WindowIcon(Util.RenderAppIcon());
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
2023-07-08 04:33:15 +00:00
|
|
|
|
using (Game game = new(gwSettings, nwSettings)) {
|
2023-06-30 02:10:24 +00:00
|
|
|
|
game.Run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|