Skip to content

Commit

Permalink
update packages and add altitude
Browse files Browse the repository at this point in the history
  • Loading branch information
gosha20777 committed Apr 18, 2024
1 parent 947490e commit 2d4e6fb
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 42 deletions.
16 changes: 8 additions & 8 deletions src/LacmusApp.Avalonia/LacmusApp.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifiers>linux-x64;win-x64;osx-x64</RuntimeIdentifiers>
<Company>Lacmus Foundation</Company>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down Expand Up @@ -64,7 +64,7 @@
<PackageReference Include="HarfBuzzSharp.NativeAssets.Win32" Version="2.8.2.5" />
<PackageReference Include="LacmusPlugin" Version="2.0.3" />
<PackageReference Include="MessageBox.Avalonia" Version="2.0.2" />
<PackageReference Include="MetadataExtractor" Version="2.7.2" />
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="6.0.7" />
<PackageReference Include="NewtonSoft.Json" Version="13.0.1" />
<PackageReference Include="Octokit" Version="2.0.0" />
Expand All @@ -76,12 +76,12 @@
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="2.88.6" />
<PackageReference Include="SkiaSharp.QrCode" Version="0.6.0" />
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="2.88.8" />
<PackageReference Include="SkiaSharp.QrCode" Version="0.7.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 6 additions & 3 deletions src/LacmusApp.Avalonia/Services/PhotoLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<PhotoViewModel[]> ReadAllFromDirByPhoto(LoadType loadType = Lo
using (var stream = File.OpenRead(path))
{
var (brush, height, width) = await reader.Read(stream);
var (metadata, latitude, longitude) = ExifConvertor.ConvertExif(
var (metadata, latitude, longitude, altitude) = ExifConvertor.ConvertExif(
ImageMetadataReader.ReadMetadata(path));
var photoViewModel = new PhotoViewModel(index)
{
Expand All @@ -63,6 +63,7 @@ public async Task<PhotoViewModel[]> ReadAllFromDirByPhoto(LoadType loadType = Lo
Name = GetNameFromPath(path),
Latitude = latitude,
Longitude = longitude,
Altitude = altitude,
ExifDataCollection = metadata
};
photoList.Add(photoViewModel);
Expand Down Expand Up @@ -109,7 +110,7 @@ public async Task<PhotoViewModel[]> ReadAllFromDirByAnnotation(LoadType loadType
using (var photoStream = File.OpenRead(photoPath))
{
var (brush, height, width) = await reader.Read(photoStream);
var (metadata, latitude, longitude) = ExifConvertor.ConvertExif(
var (metadata, latitude, longitude, altitude) = ExifConvertor.ConvertExif(
ImageMetadataReader.ReadMetadata(photoPath));
var photoViewModel = new PhotoViewModel(index)
{
Expand All @@ -121,6 +122,7 @@ public async Task<PhotoViewModel[]> ReadAllFromDirByAnnotation(LoadType loadType
Name = GetNameFromPath(photoPath),
Latitude = latitude,
Longitude = longitude,
Altitude = altitude,
ExifDataCollection = metadata
};
photoList.Add(photoViewModel);
Expand All @@ -147,7 +149,7 @@ public async Task<PhotoViewModel> LoadFromFile(string path, int index, IEnumerab
using (var photoStream = File.OpenRead(path))
{
var (brush, height, width) = await reader.ReadFromStream(photoStream);
var (metadata, latitude, longitude) = ExifConvertor.ConvertExif(
var (metadata, latitude, longitude, altitude) = ExifConvertor.ConvertExif(
ImageMetadataReader.ReadMetadata(path));
return new PhotoViewModel(index)
{
Expand All @@ -159,6 +161,7 @@ public async Task<PhotoViewModel> LoadFromFile(string path, int index, IEnumerab
Name = GetNameFromPath(path),
Latitude = latitude,
Longitude = longitude,
Altitude = altitude,
ExifDataCollection = metadata
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/LacmusApp.Avalonia/ViewModels/FourthWizardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task OpenFile(string inputPath)
await using (var stream = File.OpenRead(path))
{
var (brush, height, width) = await reader.Read(stream);
var (metadata, latitude, longitude) = ExifConvertor.ConvertExif(
var (metadata, latitude, longitude, altitude) = ExifConvertor.ConvertExif(
ImageMetadataReader.ReadMetadata(path));
var photoViewModel = new PhotoViewModel(id)
{
Expand All @@ -96,6 +96,7 @@ public async Task OpenFile(string inputPath)
Path = path,
Latitude = latitude,
Longitude = longitude,
Altitude = altitude,
ExifDataCollection = metadata
};

Expand Down
31 changes: 7 additions & 24 deletions src/LacmusApp.Avalonia/ViewModels/MetadataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public class MetadataViewModel : ReactiveValidationObject
public ReadOnlyObservableCollection<ExifData> MetaDataCollection => _metaDataCollection;
[Reactive] public string Latitude { get; set; } = "N/A";
[Reactive] public string Longitude { get; set; } = "N/A";
[Reactive] public string Altitude { get; set; } = "N/A";
[Reactive] public ImageBrush QrImage { get; set; }
[Reactive] public LocalizationContext LocalizationContext { get; set; }
public MetadataViewModel(Window window, PhotoViewModel photoViewModel, LocalizationContext localizationContext)
{
Latitude = $"{photoViewModel.Latitude}";
Longitude = $"{photoViewModel.Longitude}";
Altitude = $"{photoViewModel.Altitude} m";

_metaDataList.AddRange(photoViewModel.ExifDataCollection);

Expand All @@ -53,6 +55,10 @@ public MetadataViewModel(Window window, PhotoViewModel photoViewModel, Localizat
viewModel => viewModel.Longitude,
x => x != "N/A",
path => $"Cannot parse gps longitude");
this.ValidationRule(
viewModel => viewModel.Altitude,
x => x != "N/A",
path => $"Cannot parse gps altitude");

OpenYandexCommand = ReactiveCommand.Create(OpenYandex, this.IsValid());
OpenGoogleCommand = ReactiveCommand.Create(OpenGoogle, this.IsValid());
Expand Down Expand Up @@ -82,30 +88,6 @@ public void OpenOSM()
$"#map=15/{Latitude.Replace(',', '.')}/{Longitude.Replace(',', '.')}");
}

private string TranslateGeoTag(string tag)
{
try
{
if (!tag.Contains('°'))
return tag;
tag = tag.Replace('°', ';');
tag = tag.Replace('\'', ';');
tag = tag.Replace('"', ';');
tag = tag.Replace(" ", "");

var splitTag = tag.Split(';');
var grad = float.Parse(splitTag[0]);
var min = float.Parse(splitTag[1]);
var sec = float.Parse(splitTag[2]);

var result = grad + min / 60 + sec / 3600;
return $"{result}";
}
catch
{
return "N/A";
}
}
private void OpenUrl(string url)
{
try
Expand Down Expand Up @@ -134,6 +116,7 @@ private void OpenUrl(string url)
}
}

[Obsolete("Obsolete")]
private void RenderQr()
{
using (var generator = new QRCodeGenerator())
Expand Down
5 changes: 5 additions & 0 deletions src/LacmusApp.Avalonia/Views/MetadataWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<TextBlock FontWeight="Heavy" Text="{Binding LocalizationContext.MetadataLongitude}" />
<TextBlock Text="{Binding Longitude}" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Heavy" Text="{Binding LocalizationContext.MetadataAltitude}" />
<TextBlock Text="{Binding Altitude}" />
</StackPanel>
</StackPanel>
<Canvas Grid.Column="1"
Width="128"
Expand Down
1 change: 1 addition & 0 deletions src/LacmusApp/Image/Models/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Image()
public int Width { get; set; }
public float Latitude { get; set; }
public float Longitude { get; set; }
public float Altitude { get; set; }
public IEnumerable<ExifData> ExifDataCollection { get; set; }
public TBrush Brush { get; set; }
public string Path { get; set; }
Expand Down
25 changes: 23 additions & 2 deletions src/LacmusApp/Image/Services/ExifConvertor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using LacmusApp.Image.Models;
using MetadataExtractor;
using Serilog;
Expand All @@ -8,11 +10,12 @@ namespace LacmusApp.Image.Services
{
public static class ExifConvertor
{
public static (IEnumerable<ExifData>, float, float) ConvertExif(IReadOnlyList<Directory> directories)
public static (IEnumerable<ExifData>, float, float, float) ConvertExif(IReadOnlyList<Directory> directories)
{
var list = new List<ExifData>();
var latitude = 0f;
var longitude = 0f;
var altitude = 0f;

foreach (var directory in directories)
{
Expand All @@ -22,6 +25,8 @@ public static (IEnumerable<ExifData>, float, float) ConvertExif(IReadOnlyList<Di
latitude = GetGrad(tag.Description);
if (tag.Name.ToLower() == "gps longitude")
longitude = GetGrad(tag.Description);
if (tag.Name.ToLower() == "gps altitude")
altitude = GetAlt(tag.Description);

list.Add(new ExifData()
{
Expand All @@ -32,7 +37,7 @@ public static (IEnumerable<ExifData>, float, float) ConvertExif(IReadOnlyList<Di
}
}

return (list, latitude, longitude);
return (list, latitude, longitude, altitude);
}

private static float GetGrad(string tag)
Expand All @@ -58,5 +63,21 @@ private static float GetGrad(string tag)

return 0f;
}

private static float GetAlt(string tag)
{
try
{
var splitTag = tag.Split(' ').First();
var alt = float.Parse(splitTag);
return alt;
}
catch
{
Log.Warning("Unable to parse geotag");
}

return 0f;
}
}
}
3 changes: 2 additions & 1 deletion src/LacmusApp/Image/Services/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<IImage<TBrush>> LoadFromFile(string path)

await using (var stream = File.OpenRead(path))
{
var (metadata, latitude, longitude) = ExifConvertor.ConvertExif(
var (metadata, latitude, longitude, altitude) = ExifConvertor.ConvertExif(
ImageMetadataReader.ReadMetadata(stream));
var (imageBrush, width, height) = await _brushReader.Read(stream);

Expand All @@ -43,6 +43,7 @@ public async Task<IImage<TBrush>> LoadFromFile(string path)
IsWatched = false,
Latitude = latitude,
Longitude = longitude,
Altitude = altitude,
Path = path
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/LacmusApp/LacmusApp.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Flurl" Version="3.0.6" />
<PackageReference Include="LacmusPlugin" Version="2.0.3" />
<PackageReference Include="MetadataExtractor" Version="2.7.2" />
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ReactiveUI" Version="18.3.1" />
<PackageReference Include="ReactiveUI.Fody" Version="18.3.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/LacmusApp/Screens/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AboutViewModel(IVersionViewModel versionViewModel)
});
OpenSiteCommand = ReactiveCommand.Create(() =>
{
manager.OpenLink("https://lacmus-foundation.github.io/");
manager.OpenLink("https://lacmus.ml/");
});
}

Expand Down

0 comments on commit 2d4e6fb

Please sign in to comment.