Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ obj/
bin/
PublishProfiles/
Properties/
PhotoLocator/ai/
PhotoLocator/exiftool/
PhotoLocator/ffmpeg/
PhotoLocator/jpegli/
Expand Down
15 changes: 9 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project>
<PropertyGroup>


<LangVersion>15</LangVersion>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<Platforms>x64</Platforms>
<AppendPlatformToOutputPath>false</AppendPlatformToOutputPath>

<!-- Use hard links to speed up build -->
<CreateHardLinksForAdditionalFilesIfPossible>true</CreateHardLinksForAdditionalFilesIfPossible>
<CreateHardLinksForCopyLocalIfPossible>true</CreateHardLinksForCopyLocalIfPossible>
<CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>true</CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>
<CreateHardLinksForPublishFilesIfPossible>true</CreateHardLinksForPublishFilesIfPossible>
<!-- Use hard links to speed up build -->
<CreateHardLinksForAdditionalFilesIfPossible>true</CreateHardLinksForAdditionalFilesIfPossible>
<CreateHardLinksForCopyLocalIfPossible>true</CreateHardLinksForCopyLocalIfPossible>
<CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>true</CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>
<CreateHardLinksForPublishFilesIfPossible>true</CreateHardLinksForPublishFilesIfPossible>

</PropertyGroup>
</Project>
2 changes: 0 additions & 2 deletions MapUiTools/WPF/MapUiTools.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<Authors>Clemens Fischer</Authors>
<Copyright>Copyright © 2023 Clemens Fischer</Copyright>
<SignAssembly>true</SignAssembly>
<Platforms>x64</Platforms>
<AppendPlatformToOutputPath>false</AppendPlatformToOutputPath>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions PhotoLocator/BitmapOperations/AiDenoiseOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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<float>(inputBuffer, [1, channels, tileHeight, tileWidth]))]);
Expand Down
25 changes: 24 additions & 1 deletion PhotoLocator/BitmapOperations/FloatBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion PhotoLocator/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shell;
using System.Windows.Threading;

namespace PhotoLocator
{
Expand Down
1 change: 1 addition & 0 deletions PhotoLocator/Metadata/ExifHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void TransferValue(string query1, string query2, string? query3 = null)

if (source.TryGetFormat() == "png")
{
result.ApplicationName = nameof(PhotoLocator);
Comment thread
meesoft marked this conversation as resolved.
Resolved
var (exposureTime, location) = DecodePngMetadata(source);
if (exposureTime is not null)
{
Expand Down
8 changes: 5 additions & 3 deletions PhotoLocator/PhotoLocator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>2026.10.4.0</Version>
<Version>2026.11.21.0</Version>
<Copyright>(c) 2022-2026 Michael Vinther</Copyright>
<Company>MeeSoft</Company>
<ApplicationIcon>Resources\PhotoLocator.ico</ApplicationIcon>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>All</AnalysisMode>
<NoWarn>CA1014,CA1309,CA1515,CA1814,CA1819,IDE0017</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>x64</Platforms>
<AppendPlatformToOutputPath>false</AppendPlatformToOutputPath>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Microsoft_AI_DirectML_SkipDebugLayerCopy>True</Microsoft_AI_DirectML_SkipDebugLayerCopy>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -65,6 +64,9 @@
<None Include="..\JpegTransform\JpegTransform.exe" Link="JpegTransform.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ai\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="exiftool\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
1 change: 1 addition & 0 deletions PhotoLocator/PictureFileFormats/JpegXlFileFormatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
meesoft marked this conversation as resolved.
Resolved
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
Expand Down
1 change: 1 addition & 0 deletions PhotoLocator/PictureFileFormats/JpegliEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PhotoLocator/Settings/RegistrySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion PhotoLocatorSetup/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="14699MeeSoft.PhotoLocator"
Publisher="CN=7909BF9A-F4C6-49C5-995F-BEDA3E7BAD48"
Version="2026.10.4.0" />
Version="2026.11.21.0" />

<Properties>
<DisplayName>PhotoLocator</DisplayName>
Expand Down
34 changes: 23 additions & 11 deletions PhotoLocatorTest/BitmapOperations/AiDenoiseOperationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,42 @@ 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
{
SrcBitmap = bitmap,
DstBitmap = new FloatBitmap(),
ModelPath = modelPath,
TileSize = 6,
TileOverlap = 2,
ExpectColorModel = true,
TileSize = tileSize,
TileOverlap = tileOverlap,
};

var sw = Stopwatch.StartNew();
Expand Down
72 changes: 72 additions & 0 deletions PhotoLocatorTest/BitmapOperations/HoleClosingOperationTest.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
16 changes: 16 additions & 0 deletions PhotoLocatorTest/Metadata/ExifHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 0 additions & 2 deletions PhotoLocatorTest/PhotoLocatorTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<Nullable>enable</Nullable>
<RootNamespace>PhotoLocator</RootNamespace>
<IsPackable>false</IsPackable>
<Platforms>x64</Platforms>
<AppendPlatformToOutputPath>false</AppendPlatformToOutputPath>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<PropertyGroup>
<TargetFramework>net10.0-windows</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Platforms>x64</Platforms>
<AppendPlatformToOutputPath>false</AppendPlatformToOutputPath>
<NoWarn>CA2022</NoWarn>
</PropertyGroup>

Expand Down
Loading