From c8cd8112f0584202086c5a01dc043751ed9256c8 Mon Sep 17 00:00:00 2001 From: Syping Date: Mon, 10 Nov 2025 17:58:06 +0100 Subject: [PATCH] libragephoto 0.8.0 release - CMakeLists.txt: update version to 0.8.0 - src/dotnet: add .NET 8.0 target - src/dotnet: add README.md - src/dotnet: fix .targets file for .NET Framework 4.7 - src/dotnet: simplify exception string handling - src/dotnet: update version to 0.8.0 --- CMakeLists.txt | 2 +- src/dotnet/README.md | 21 ++++++++ src/dotnet/RagePhoto.Core.csproj | 27 +++++----- src/dotnet/RagePhoto.cs | 52 +++++++++---------- src/dotnet/RagePhotoException.cs | 2 +- src/dotnet/{ => net47}/RagePhoto.Core.targets | 19 ++++--- 6 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 src/dotnet/README.md rename src/dotnet/{ => net47}/RagePhoto.Core.targets (65%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02e262c..10258be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ cmake_minimum_required(VERSION 3.16) cmake_policy(VERSION 3.16...3.28) -project(ragephoto VERSION 0.7.1 LANGUAGES C CXX) +project(ragephoto VERSION 0.8.0 LANGUAGES C CXX) include(GNUInstallDirs) # RagePhoto CMake includes diff --git a/src/dotnet/README.md b/src/dotnet/README.md new file mode 100644 index 0000000..a4198e4 --- /dev/null +++ b/src/dotnet/README.md @@ -0,0 +1,21 @@ +## RagePhoto.Core +Open Source RAGE Photo Parser for GTA V and RDR 2 + +- Read/Write RAGE Photos error free and correct +- Support for metadata stored in RAGE Photos +- Simple .NET API +- Based on libragephoto + +#### How to Use RagePhoto.Core + +```c# +using RagePhoto; + +/* Get Image from Photo */ +static Image GetImageFromPhoto(String inputFile) { + using Photo photo = new(); + photo.LoadFile(inputFile); + using MemoryStream jpegStream = new(photo.Jpeg); + return Image.FromStream(jpegStream); +} +``` diff --git a/src/dotnet/RagePhoto.Core.csproj b/src/dotnet/RagePhoto.Core.csproj index 0cb99f7..05b3401 100644 --- a/src/dotnet/RagePhoto.Core.csproj +++ b/src/dotnet/RagePhoto.Core.csproj @@ -1,16 +1,17 @@  - netstandard2.1;net47 + netstandard2.1;net47;net8.0 RagePhoto.Core RagePhoto - 0.7.1 - 0.7.1 - 0.7.1 + 0.8.0 + 0.8.0 + 0.8.0 Syping Copyright © 2025 Syping Open Source RAGE Photo Parser for GTA V and RDR 2 BSD-2-Clause + README.md https://github.com/Syping/libragephoto disable @@ -20,16 +21,14 @@ - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - + + + + + + + + diff --git a/src/dotnet/RagePhoto.cs b/src/dotnet/RagePhoto.cs index d70f26e..033db5c 100644 --- a/src/dotnet/RagePhoto.cs +++ b/src/dotnet/RagePhoto.cs @@ -98,7 +98,7 @@ namespace RagePhoto { if (_instance == IntPtr.Zero) throw new RagePhotoException("Failed to initialize libragephoto"); if (!ragephoto_setphotodatac(_instance, ragephoto_getphotodata(photo._instance))) - throw new RagePhotoException(this, String.Format("Failed to copy Photo: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to copy Photo", Error); } catch (Exception exception) { throw new RagePhotoException("Failed to initialize libragephoto", exception); @@ -127,12 +127,12 @@ namespace RagePhoto { public void Load(Byte[] data) { if (!ragephoto_load(_instance, data, (UIntPtr)data.LongLength)) - throw new RagePhotoException(this, String.Format("Failed to load Photo: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to load Photo", Error); } public void LoadFile(String path) { if (!ragephoto_loadfile(_instance, path)) - throw new RagePhotoException(this, String.Format("Failed to load Photo: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to load Photo", Error); } public String Description { @@ -159,7 +159,16 @@ namespace RagePhoto { Marshal.Copy(ptr, buffer, 0, (Int32)size); return buffer; } - set => SetJpeg(value); + set { + UInt32 size = (UInt32)value.Length; + UInt32 bufferSize = Format switch { + PhotoFormat.GTA5 => size > (UInt32)DefaultSize.DEFAULT_GTA5_PHOTOBUFFER ? size : (UInt32)DefaultSize.DEFAULT_GTA5_PHOTOBUFFER, + PhotoFormat.RDR2 => size > (UInt32)DefaultSize.DEFAULT_RDR2_PHOTOBUFFER ? size : (UInt32)DefaultSize.DEFAULT_RDR2_PHOTOBUFFER, + _ => size + }; + if (!ragephoto_setphotojpeg(_instance, value, size, bufferSize)) + throw new RagePhotoException(this, "Failed to set Jpeg", Error); + } } public UInt32 JpegSize { @@ -199,25 +208,25 @@ namespace RagePhoto { public Byte[] Save() { Byte[] photo = new Byte[Environment.Is64BitProcess ? (UInt64)GetSaveSize() : (UInt32)GetSaveSize()]; if (!ragephoto_save(_instance, photo)) - throw new RagePhotoException(this, string.Format("Failed to save Photo: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to save Photo", Error); return photo; } public Byte[] Save(PhotoFormat photoFormat) { Byte[] photo = new Byte[Environment.Is64BitProcess ? (UInt64)GetSaveSize(photoFormat) : (UInt32)GetSaveSize(photoFormat)]; if (!ragephoto_savef(_instance, photo, (UInt32)photoFormat)) - throw new RagePhotoException(this, string.Format("Failed to save Photo: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to save Photo", Error); return photo; } public void SaveFile(String path) { if (!ragephoto_savefile(_instance, path)) - throw new RagePhotoException(this, string.Format("Failed to save Photo: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to save Photo", Error); } public void SaveFile(String path, PhotoFormat photoFormat) { if (!ragephoto_savefilef(_instance, path, (UInt32)photoFormat)) - throw new RagePhotoException(this, string.Format("Failed to save Photo: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to save Photo", Error); } public void SetBufferDefault() { @@ -241,32 +250,19 @@ namespace RagePhoto { } public void SetJpeg(Byte[] jpeg) { - UInt32 bufferSize; UInt32 size = (UInt32)jpeg.Length; - switch (Format) { - case PhotoFormat.GTA5: - if (size > (UInt32)DefaultSize.DEFAULT_GTA5_PHOTOBUFFER) - bufferSize = size; - else - bufferSize = (UInt32)DefaultSize.DEFAULT_GTA5_PHOTOBUFFER; - break; - case PhotoFormat.RDR2: - if (size > (UInt32)DefaultSize.DEFAULT_RDR2_PHOTOBUFFER) - bufferSize = size; - else - bufferSize = (UInt32)DefaultSize.DEFAULT_RDR2_PHOTOBUFFER; - break; - default: - bufferSize = size; - break; - } + UInt32 bufferSize = Format switch { + PhotoFormat.GTA5 => size > (UInt32)DefaultSize.DEFAULT_GTA5_PHOTOBUFFER ? size : (UInt32)DefaultSize.DEFAULT_GTA5_PHOTOBUFFER, + PhotoFormat.RDR2 => size > (UInt32)DefaultSize.DEFAULT_RDR2_PHOTOBUFFER ? size : (UInt32)DefaultSize.DEFAULT_RDR2_PHOTOBUFFER, + _ => size + }; if (!ragephoto_setphotojpeg(_instance, jpeg, size, bufferSize)) - throw new RagePhotoException(this, String.Format("Failed to set Jpeg: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to set Jpeg", Error); } public void SetJpeg(Byte[] jpeg, UInt32 bufferSize) { if (!ragephoto_setphotojpeg(_instance, jpeg, (UInt32)jpeg.Length, bufferSize)) - throw new RagePhotoException(this, String.Format("Failed to set Jpeg: {0}", Error), Error); + throw new RagePhotoException(this, "Failed to set Jpeg", Error); } public void SetJson(String json) { diff --git a/src/dotnet/RagePhotoException.cs b/src/dotnet/RagePhotoException.cs index 4f8fdf6..7aeb2e1 100644 --- a/src/dotnet/RagePhotoException.cs +++ b/src/dotnet/RagePhotoException.cs @@ -15,7 +15,7 @@ namespace RagePhoto { _error = PhotoError.Uninitialised; } - public RagePhotoException(Photo photo, String message, PhotoError error) : base(message) { + public RagePhotoException(Photo photo, String message, PhotoError error) : base(String.Format("{0}: {1}", message, error)) { _error = error; _photo = photo; } diff --git a/src/dotnet/RagePhoto.Core.targets b/src/dotnet/net47/RagePhoto.Core.targets similarity index 65% rename from src/dotnet/RagePhoto.Core.targets rename to src/dotnet/net47/RagePhoto.Core.targets index 9e84d18..25e9065 100644 --- a/src/dotnet/RagePhoto.Core.targets +++ b/src/dotnet/net47/RagePhoto.Core.targets @@ -1,21 +1,28 @@ - + + + + libragephoto.dll PreserveNewest - false - + + + + libragephoto.dll PreserveNewest - false - + + + + libragephoto.dll PreserveNewest - false +