diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 9b512b6..f946ee9 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -21,7 +21,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v5 with: - dotnet-version: 10.0.x + dotnet-version: 11.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.gitignore b/.gitignore index d8d9a29..2ff7712 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ obj/ bin/ PublishProfiles/ Properties/ +PhotoLocator/ai/ PhotoLocator/exiftool/ PhotoLocator/ffmpeg/ PhotoLocator/jpegli/ diff --git a/Directory.Build.props b/Directory.Build.props index 81a1384..915be94 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,13 +1,16 @@ - + + 15 true + x64 + false - - true - true - true - true + + true + true + true + true \ No newline at end of file diff --git a/MapUiTools/WPF/MapUiTools.WPF.csproj b/MapUiTools/WPF/MapUiTools.WPF.csproj index 200f246..bbab847 100644 --- a/MapUiTools/WPF/MapUiTools.WPF.csproj +++ b/MapUiTools/WPF/MapUiTools.WPF.csproj @@ -9,8 +9,6 @@ Clemens Fischer Copyright © 2023 Clemens Fischer true - x64 - false diff --git a/PhotoLocator/BitmapOperations/AiDenoiseOperation.cs b/PhotoLocator/BitmapOperations/AiDenoiseOperation.cs index 564dfd6..dbf82e8 100644 --- a/PhotoLocator/BitmapOperations/AiDenoiseOperation.cs +++ b/PhotoLocator/BitmapOperations/AiDenoiseOperation.cs @@ -178,7 +178,7 @@ private static InferenceSession CreateSession(string modelPath, bool preferDirec private static void RunTileInference(InferenceSession session, FloatBitmap source, int srcLeft, int srcTop, int tileWidth, int tileHeight, int channels, FloatBitmap dstBitmap, int dstLeft, int dstTop) { var inputBuffer = new float[1 * channels * tileHeight * tileWidth]; - for (var y = 0; y < tileHeight; y++) + Parallel.For(0, tileHeight, y => { var sourceY = srcTop + y; for (var x = 0; x < tileWidth; x++) @@ -190,7 +190,7 @@ private static void RunTileInference(InferenceSession session, FloatBitmap sourc inputBuffer[index] = source.Elements[sourceY, sourceX * channels + c]; } } - } + }); var inputName = session.InputMetadata.Keys.First(); using var output = session.Run([NamedOnnxValue.CreateFromTensor(inputName, new DenseTensor(inputBuffer, [1, channels, tileHeight, tileWidth]))]); diff --git a/PhotoLocator/BitmapOperations/FloatBitmap.cs b/PhotoLocator/BitmapOperations/FloatBitmap.cs index 07842e5..41506da 100644 --- a/PhotoLocator/BitmapOperations/FloatBitmap.cs +++ b/PhotoLocator/BitmapOperations/FloatBitmap.cs @@ -3,12 +3,14 @@ using System; using System.Buffers; using System.Diagnostics; +using System.Globalization; using System.Threading.Tasks; using System.Windows.Media; using System.Windows.Media.Imaging; namespace PhotoLocator.BitmapOperations { + [DebuggerDisplay("{Width}x{Height}x{PlaneCount}")] public class FloatBitmap { public const double DefaultMonitorGamma = 2.2; @@ -32,6 +34,14 @@ public FloatBitmap(BitmapSource source, double gamma) Assign(source, gamma); } + public FloatBitmap(params float[][] elements) + { + New(elements[0].Length, elements.Length, 1); + for(int y = 0; y < elements.Length; y++) + for (int x = 0; x < elements[y].Length; x++) + Elements[y, x] = elements[y][x]; + } + public float[,] Elements { get; private set; } = null!; public float this[int x, int y] @@ -53,7 +63,20 @@ public FloatBitmap(BitmapSource source, double gamma) public override string ToString() { - return $"{Width}x{Height}x{PlaneCount}"; + if (Width> 100 || Height > 100 || PlaneCount > 1) + return $"{Width}x{Height}x{PlaneCount}"; + var sb = new System.Text.StringBuilder(); + for (int y = 0; y < Height; y++) + { + for (int x = 0; x < Width; x++) + { + sb.Append(Elements[y, x].ToString("F2", CultureInfo.InvariantCulture)); + if (x < Width - 1) + sb.Append(", "); + } + sb.AppendLine(); + } + return sb.ToString(); } public void New(int width, int height, int planes) diff --git a/PhotoLocator/MainViewModel.cs b/PhotoLocator/MainViewModel.cs index 9f4af91..0f78dae 100644 --- a/PhotoLocator/MainViewModel.cs +++ b/PhotoLocator/MainViewModel.cs @@ -24,7 +24,6 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shell; -using System.Windows.Threading; namespace PhotoLocator { diff --git a/PhotoLocator/Metadata/ExifHandler.cs b/PhotoLocator/Metadata/ExifHandler.cs index ba39e88..0101f47 100644 --- a/PhotoLocator/Metadata/ExifHandler.cs +++ b/PhotoLocator/Metadata/ExifHandler.cs @@ -210,6 +210,7 @@ void TransferValue(string query1, string query2, string? query3 = null) if (source.TryGetFormat() == "png") { + result.ApplicationName = nameof(PhotoLocator); var (exposureTime, location) = DecodePngMetadata(source); if (exposureTime is not null) { diff --git a/PhotoLocator/PhotoLocator.csproj b/PhotoLocator/PhotoLocator.csproj index f1cb8b9..1de2210 100644 --- a/PhotoLocator/PhotoLocator.csproj +++ b/PhotoLocator/PhotoLocator.csproj @@ -6,7 +6,7 @@ enable true app.manifest - 2026.10.4.0 + 2026.11.21.0 (c) 2022-2026 Michael Vinther MeeSoft Resources\PhotoLocator.ico @@ -14,13 +14,12 @@ All CA1014,CA1309,CA1515,CA1814,CA1819,IDE0017 true - x64 - false false true + True @@ -65,6 +64,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/PhotoLocator/PictureFileFormats/JpegXlFileFormatHandler.cs b/PhotoLocator/PictureFileFormats/JpegXlFileFormatHandler.cs index a3cc7aa..b2c13c8 100644 --- a/PhotoLocator/PictureFileFormats/JpegXlFileFormatHandler.cs +++ b/PhotoLocator/PictureFileFormats/JpegXlFileFormatHandler.cs @@ -39,6 +39,7 @@ public static void TranscodeToJxl(string sourcePath, string targetPath, string? { using var process = new Process(); process.StartInfo.FileName = EncoderPath; + process.StartInfo.WorkingDirectory = AppContext.BaseDirectory; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; diff --git a/PhotoLocator/PictureFileFormats/JpegliEncoder.cs b/PhotoLocator/PictureFileFormats/JpegliEncoder.cs index 21b08fe..2334e0f 100644 --- a/PhotoLocator/PictureFileFormats/JpegliEncoder.cs +++ b/PhotoLocator/PictureFileFormats/JpegliEncoder.cs @@ -33,6 +33,7 @@ internal static void Process(string executablePath, Stream srcStream, string src { using var process = new Process(); process.StartInfo.FileName = executablePath; + process.StartInfo.WorkingDirectory = AppContext.BaseDirectory; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; diff --git a/PhotoLocator/Settings/RegistrySettings.cs b/PhotoLocator/Settings/RegistrySettings.cs index 1fe10a6..8f3030e 100644 --- a/PhotoLocator/Settings/RegistrySettings.cs +++ b/PhotoLocator/Settings/RegistrySettings.cs @@ -8,7 +8,7 @@ namespace PhotoLocator.Settings { sealed class RegistrySettings : IDisposable, IRegistrySettings { - public const string DefaultPhotoFileExtensions = ".jpg, .jpeg, .png, .cr2, .cr3, .arw, .nef, .dng, .psd, .tif, .tiff, .jxr, .jxl, .fits, .mp4, .mov"; + public const string DefaultPhotoFileExtensions = ".jpg, .jpeg, .png, .cr2, .cr3, .arw, .nef, .dng, .psd, .tif, .tiff, .jxr, .jxl, .bmp, .fits, .mp4, .mov"; public RegistryKey Key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\MeeSoft\PhotoLocator"); diff --git a/PhotoLocatorSetup/Package.appxmanifest b/PhotoLocatorSetup/Package.appxmanifest index 65ed8f3..7c63101 100644 --- a/PhotoLocatorSetup/Package.appxmanifest +++ b/PhotoLocatorSetup/Package.appxmanifest @@ -9,7 +9,7 @@ + Version="2026.11.21.0" /> PhotoLocator diff --git a/PhotoLocatorTest/BitmapOperations/AiDenoiseOperationTest.cs b/PhotoLocatorTest/BitmapOperations/AiDenoiseOperationTest.cs index 3d7788b..d7044d6 100644 --- a/PhotoLocatorTest/BitmapOperations/AiDenoiseOperationTest.cs +++ b/PhotoLocatorTest/BitmapOperations/AiDenoiseOperationTest.cs @@ -6,21 +6,32 @@ namespace PhotoLocator.BitmapOperations; public class AiDenoiseOperationTest { [TestMethod] - public void Apply_ShouldRunDenoiseModel_WhenPretrainedOnnxExists() + [DataRow(8, 1, 6, 2)] + [DataRow(8, 1, 8, 0)] + [DataRow(8, 3, 6, 2)] + [DataRow(8, 3, 8, 0)] + public void Apply_ShouldRunDenoiseModel_With3Planes(int imageSize, int planes, int tileSize, int tileOverlap) { var modelPath = Path.Combine(AppContext.BaseDirectory, "TestData", "dncnn_test.onnx"); if (!File.Exists(modelPath)) Assert.Inconclusive($"Pretrained ONNX file not found: {modelPath}. Add a trained dncnn model to PhotoLocatorTest/TestData/dncnn_test.onnx to run this test."); - var bitmap = new FloatBitmap(8, 8, 3); - for (var y = 0; y < bitmap.Height; y++) + var bitmap = new FloatBitmap(imageSize, imageSize, planes); + if (planes == 1) { - for (var x = 0; x < bitmap.Width; x++) - { - bitmap.Elements[y, x * 3 + 0] = ((x * 13 + y * 7) % 17) / 16f; - bitmap.Elements[y, x * 3 + 1] = (float)(0.5 + 0.2 * Math.Sin(x * 0.7 + y * 0.9)); - bitmap.Elements[y, x * 3 + 2] = (float)(1.0 - 0.3 * Math.Cos(x * 0.5 + y * 0.4)); - } + for (var y = 0; y < bitmap.Height; y++) + for (var x = 0; x < bitmap.Width; x++) + bitmap.Elements[y, x] = ((x * 13 + y * 7) % 17) / 16f; + } + else + { + for (var y = 0; y < bitmap.Height; y++) + for (var x = 0; x < bitmap.Width; x++) + { + bitmap.Elements[y, x * 3 + 0] = ((x * 13 + y * 7) % 17) / 16f; + bitmap.Elements[y, x * 3 + 1] = (float)(0.5 + 0.2 * Math.Sin(x * 0.7 + y * 0.9)); + bitmap.Elements[y, x * 3 + 2] = (float)(1.0 - 0.3 * Math.Cos(x * 0.5 + y * 0.4)); + } } var op = new AiDenoiseOperation @@ -28,8 +39,9 @@ public void Apply_ShouldRunDenoiseModel_WhenPretrainedOnnxExists() SrcBitmap = bitmap, DstBitmap = new FloatBitmap(), ModelPath = modelPath, - TileSize = 6, - TileOverlap = 2, + ExpectColorModel = true, + TileSize = tileSize, + TileOverlap = tileOverlap, }; var sw = Stopwatch.StartNew(); diff --git a/PhotoLocatorTest/BitmapOperations/HoleClosingOperationTest.cs b/PhotoLocatorTest/BitmapOperations/HoleClosingOperationTest.cs new file mode 100644 index 0000000..f531372 --- /dev/null +++ b/PhotoLocatorTest/BitmapOperations/HoleClosingOperationTest.cs @@ -0,0 +1,72 @@ +using System.Diagnostics; + +namespace PhotoLocator.BitmapOperations; + +[TestClass] +public class HoleClosingOperationTest +{ + [TestMethod] + public void CloseHolesIteratively_FillsSingleHole() + { + int width = 3; + int height = 1; + var image = new FloatBitmap(width, height, 1); + var mask = new FloatBitmap(width, height, 1); + // set all pixel values to 1 (non-hole) + for (int x = 0; x < width; x++) + image[x, 0] = 1f; + // create a single hole at middle pixel + image[1, 0] = 0f; // non-hole pixels in mask are 0 + mask[1, 0] = 1f; // hole indicator + + HoleClosingOperation.CloseHolesIteratively(image, mask, 0.5f); + + // The center pixel should be replaced by the average of its neighbors (both 1) + Assert.AreEqual(1f, image[1, 0], 1e-6f, "Center pixel should be filled with average of neighbors"); + } + + [TestMethod] + public void CloseHolesIteratively_FillsAdjacentHoles() + { + int width = 5; + int height = 1; + var image = new FloatBitmap(width, height, 1); + var mask = new FloatBitmap(width, height, 1); + // set all pixel values to 1 (non-hole) + for (int x = 0; x < width; x++) + image[x, 0] = 1f; + // create holes at positions 1 and 3 + image[1, 0] = 0f; + image[3, 0] = 0f; + mask[1, 0] = 1f; + mask[3, 0] = 1f; + + HoleClosingOperation.CloseHolesIteratively(image, mask, 0.5f); + + Assert.AreEqual(1f, image[1, 0], 1e-6f, "Hole at position 1 should be filled"); + Assert.AreEqual(1f, image[3, 0], 1e-6f, "Hole at position 3 should be filled"); + } + + [TestMethod] + public void CloseHolesIteratively_FillsBiggerHole() + { + var image = new FloatBitmap( + [ 1, 1, 1, 1 ], + [ 0.5f, 0, 0, 0 ], + [ 0.5f, 0, 0, 0 ], + [ 0.5f, 0, 0, 0 ], + [ 1, 1, 1, 1 ]); + var mask = new FloatBitmap( + [ 0, 0, 0, 0 ], + [ 0, 1, 1, 1 ], + [ 0, 1, 1, 1 ], + [ 0, 1, 1, 1 ], + [ 0, 0, 0, 0 ]); + + HoleClosingOperation.CloseHolesIteratively(image, mask, 0.5f); + + Debug.WriteLine(image); + Assert.AreEqual(0.8f, image[1, 1], 1e-6f, "Hole at position 1 should be filled"); + Assert.AreEqual(1f, image[3, 3], 1e-6f, "Hole at position 3 should be filled"); + } +} \ No newline at end of file diff --git a/PhotoLocatorTest/Metadata/ExifHandlerTest.cs b/PhotoLocatorTest/Metadata/ExifHandlerTest.cs index 1cf25f0..dda3a75 100644 --- a/PhotoLocatorTest/Metadata/ExifHandlerTest.cs +++ b/PhotoLocatorTest/Metadata/ExifHandlerTest.cs @@ -163,6 +163,22 @@ public void SetMetadata_ShouldSetPngMetadataOnTiff() //Assert.AreEqual(ExifHandler.GetGeotag(source), ExifHandler.GetGeotag(target)); } + [TestMethod] + public void SetMetadata_ShouldSetEmptyPngMetadataOnTiff() + { + const string TestFileName = "fromEmptyPng.tif"; + + var source = new BitmapMetadata("png"); + var bitmap = BitmapSource.Create(2, 2, 96, 96, PixelFormats.Gray8, null, new byte[4], 2); + + GeneralFileFormatHandler.SaveToFile(bitmap, TestFileName, source); + + using var targetStream = File.OpenRead(TestFileName); + var target = ExifHandler.LoadMetadata(targetStream)!; + Assert.AreAllNotNull(target); + Assert.AreEqual("PhotoLocator", target.ApplicationName); + } + [TestMethod] public void SetMetadata_ShouldSetTiffMetadataOnJpeg() { diff --git a/PhotoLocatorTest/PhotoLocatorTest.csproj b/PhotoLocatorTest/PhotoLocatorTest.csproj index 5511d8e..42f98b1 100644 --- a/PhotoLocatorTest/PhotoLocatorTest.csproj +++ b/PhotoLocatorTest/PhotoLocatorTest.csproj @@ -6,8 +6,6 @@ enable PhotoLocator false - x64 - false diff --git a/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj b/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj index 24fef04..6b5735a 100644 --- a/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj +++ b/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj @@ -3,8 +3,6 @@ net10.0-windows True - x64 - false CA2022