Compare commits

...

25 commits
master ... dev

Author SHA1 Message Date
Syping 719ff89b2e libragephoto: improve parser efficiency 2024-07-15 22:29:39 +02:00
Syping 9379595283 RagePhoto.cpp: remove unused uInt32Buffer 2024-04-22 21:26:16 +02:00
Syping bb2b98e5d8 libragephoto: use ternary operator for flags
index.dox: remove unnecessary whitespaces
2024-04-16 09:30:41 +02:00
Syping 2d59f2acf9 libragephoto: added library flags support
libragephoto: added RAGEPHOTO_FLAG_LEGACY_NULL_RETURN library flag
2024-04-15 12:40:36 +02:00
Syping bc9065e8dc libragephoto: improve documentation 2024-04-09 05:21:36 +02:00
Syping 0fa69667d0 libragephoto: put C++ wrapper in ragephoto_c namespace 2024-04-05 19:46:12 +02:00
Syping eadec52f35 libragephoto: improve serializer 2024-04-05 19:31:14 +02:00
Syping caf885d91c RagePhoto.c: fix off_t type in ragephoto_loadfile 2024-04-05 04:22:43 +02:00
Syping c8c2f65b3a libragephoto: remove offset jumping
- CMakeLists.txt: add RAGEPHOTO_DEBUG option
- RagePhoto.c: fix ragephoto_loadfile and add support for 64-Bit files
- RagePhoto.*: improve correctness
- ragephoto-*viewer: depend on ragephoto 0.6 or newer
2024-04-05 04:17:41 +02:00
Syping 1e160ee170 ragephoto_c: fix header inclusion
- CI: hardcore Emscripten version
2024-03-26 10:21:32 +01:00
Syping 18325f7c05 pyragephoto: add 'with' support 2024-03-25 13:43:10 +01:00
Syping c55b99e23f RagePhoto: dont take reference from save function 2024-03-25 13:15:26 +01:00
Syping 0611a368a6 RagePhoto: remove u8path in saveFile 2024-03-25 13:09:52 +01:00
Syping dd60f8d0b7 libragephoto: add ragephoto_getphotosigns function
- rename libragephoto.py to libragephoto_loader.py
- enforce set CXX standard for WASM build
2024-03-25 13:06:14 +01:00
Syping 1b7c95e735 CI: adjust CXX standards 2024-01-19 08:19:50 +01:00
Syping 1a80125802 CMakeLists and RagePhoto C file access improvements
- CMakeLists.txt: CMAKE_CXX_STANDARD -> RAGEPHOTO_CXX_STANDARD
- RagePhoto.c: Fix potential issues with file access
2024-01-18 19:53:47 +01:00
Syping e1cf6df258 libragephoto: add C++ namespaces (API change)
- RagePhoto::saveFile() -> use const char* instead of std::string
- RagePhoto C++ -> C API: try catch for throwable functions (to match C
impl. behaviour)
- Rename header files and classes
2024-01-15 17:05:54 +01:00
Syping b94e66624b RagePhoto.c: add windows.h for RAGEPHOTO_BENCHMARK on Windows 2023-12-24 16:19:09 +01:00
Syping e62fbacea8 RagePhoto.c: add benchmark for Windows 2023-12-23 11:14:01 +01:00
Syping 1b7b3c977b libragephoto: add benchmark to C implementation
CMakeLists.txt: update RAGEPHOTO_BENCHMARK description
RagePhoto.c: add benchmark
RagePhoto.cpp: change benchmark clock from
std::chrono::high_resolution_clock to std::chrono::steady_clock
2023-12-10 07:57:15 +01:00
Syping 6046b7213a libragephoto: use zeroBuffer to improve efficiency 2023-12-06 02:38:13 +01:00
Syping 534d978e47 pyragephoto: ship libragephoto with Python Package 2023-11-16 00:07:43 +01:00
Syping 8b8da1c1ef ragephoto.py: change format variable to photoFormat 2023-11-09 20:35:28 +01:00
Syping 0f1cfe630b libragephoto: add ragephoto Python Package
- separate RagePhoto and RagePhoto-Extract sources
2023-11-09 20:17:37 +01:00
Syping 9a5bcabf8c libragephoto: improve get and serializer reliability
- get functions do not return NULL or nullptr anymore
- serializer checks for valid references to not crash
- tight buffers do not prematurely end writing anymore
- add zeroBuffer function for future nullbyte insertions
- IconvTest.cpp: remove some C-style casts
- RagePhoto.cpp: improve initializer reliability
- RagePhotoA.hpp: throw error when instance could not be allocated
- README.md: minor markdown fix
2023-10-30 14:31:50 +01:00
44 changed files with 1736 additions and 965 deletions

View file

@ -16,7 +16,7 @@ jobs:
sudo apt-get update -qq
sudo apt-get install cmake gcc g++ ninja-build -qq
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
run: cmake -B ${{github.workspace}}/build -DRAGEPHOTO_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install

View file

@ -12,7 +12,9 @@ jobs:
with:
submodules: recursive
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
uses: mymindstorm/setup-emsdk@v14
with:
version: 3.1.47
- name: Install packages
run: |
sudo apt-get update -qq

View file

@ -12,13 +12,15 @@ jobs:
with:
submodules: recursive
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
uses: mymindstorm/setup-emsdk@v14
with:
version: 3.1.47
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake ninja-build -qq
- name: Configure CMake
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_CXX_STANDARD=11 -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload

View file

@ -21,7 +21,7 @@ jobs:
with:
arch: ${{matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_UNICODE=wincvt -GNinja
run: cmake -B ${{github.workspace}}/build -DRAGEPHOTO_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_UNICODE=wincvt -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install

View file

@ -1,6 +1,6 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2023 Syping
* Copyright (C) 2021-2024 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -17,14 +17,13 @@
****************************************************************************]]
cmake_minimum_required(VERSION 3.8)
project(ragephoto VERSION 0.5.1 LANGUAGES C CXX)
project(ragephoto VERSION 0.6.0 LANGUAGES C CXX)
include(GNUInstallDirs)
# RagePhoto CMake includes
include(cmake/cxxstd.cmake)
include(cmake/unicode.cmake)
# RagePhoto Top Level ON
# RagePhoto Top Level
if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto")
set(RPTL_ON ON)
else()
@ -35,77 +34,77 @@ endif()
option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF)
if (RAGEPHOTO_C_LIBRARY)
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
src/core/RagePhoto.h
src/core/ragephoto_c
src/core/ragephoto_c.hpp
src/core/RagePhoto
src/core/RagePhoto.hpp
src/core/RagePhotoLibrary.h
src/core/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.c
src/core/RagePhoto.c
)
else()
set(RAGEPHOTO_HEADERS
src/RagePhoto
src/RagePhoto.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
src/core/ragephoto_cxx
src/core/ragephoto_cxx.hpp
src/core/RagePhoto
src/core/RagePhoto.hpp
src/core/RagePhotoLibrary.h
src/core/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
src/core/RagePhoto.cpp
)
endif()
# RagePhoto Library Type
option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF)
if (RAGEPHOTO_STATIC)
option(RAGEPHOTO_C_API "Build libragephoto with C API support" OFF)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_STATIC)
else()
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_SHARED)
endif()
# RagePhoto Benchmark
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark (C++ only)" OFF)
if (RAGEPHOTO_BENCHMARK)
list(APPEND LIBRAGEPHOTO_DEFINES
RAGEPHOTO_BENCHMARK
)
endif()
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark" OFF)
# RagePhoto C API
# RagePhoto Debug
option(RAGEPHOTO_DEBUG "Build with libragephoto debug output" OFF)
# RagePhoto API
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
if (RAGEPHOTO_C_LIBRARY)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_ONLY)
else()
if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_C)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
src/core/RagePhoto.h
src/core/ragephoto_c
src/core/ragephoto_c.hpp
)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_ONLY)
endif()
endif()
# RagePhoto C++ Standard
set(RAGEPHOTO_CXX_STANDARD "11" CACHE STRING "libragephoto C++ standard")
# RagePhoto Win32 Shared Resources
if (WIN32)
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
configure_file(src/ragephoto.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto.rc" @ONLY)
configure_file(src/core/ragephoto.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto.rc" @ONLY)
list(APPEND RAGEPHOTO_SHARED_RESOURCES
"${ragephoto_BINARY_DIR}/resources/ragephoto.rc"
)
endif()
# RagePhoto Configures + Target + Installs
configure_file(src/ragephoto.pc.in "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" @ONLY)
configure_file(src/RagePhotoConfig.h.in "${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h" @ONLY)
configure_file(src/core/ragephoto.pc.in "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" @ONLY)
configure_file(src/core/RagePhotoConfig.h.in "${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h" @ONLY)
list(APPEND RAGEPHOTO_HEADERS
"${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h"
)
@ -119,16 +118,22 @@ else()
SOVERSION "${ragephoto_VERSION}"
)
endif()
set_target_properties(ragephoto PROPERTIES
CXX_STANDARD ${RAGEPHOTO_CXX_STANDARD}
CXX_STANDARD_REQUIRED ON
)
target_compile_definitions(ragephoto PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
$<$<BOOL:${RAGEPHOTO_BENCHMARK}>:RAGEPHOTO_BENCHMARK>
$<$<BOOL:${RAGEPHOTO_DEBUG}>:RAGEPHOTO_DEBUG>
)
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_LIBRARY)
target_compile_options(ragephoto PRIVATE "/Zc:__cplusplus")
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
target_compile_options(ragephoto PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
endif()
target_include_directories(ragephoto PUBLIC
"${ragephoto_BINARY_DIR}/include"
"${ragephoto_SOURCE_DIR}/src"
"${ragephoto_SOURCE_DIR}/src/core"
)
install(TARGETS ragephoto
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
@ -167,14 +172,14 @@ option(RAGEPHOTO_EXTRACT "Build libragephoto with ragephoto-extract" ${RPTL_ON})
if (RAGEPHOTO_EXTRACT)
# RagePhoto-Extract Source files
if (RAGEPHOTO_C_API)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
set(EXTRACT_SOURCES src/extract/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
set(EXTRACT_SOURCES src/extract/RagePhoto-Extract.cpp)
endif()
# RagePhoto-Extract Win32 Shared Resources
if (WIN32)
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
configure_file(src/ragephoto-extract.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc" @ONLY)
configure_file(src/extract/ragephoto-extract.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc" @ONLY)
list(APPEND EXTRACT_RESOURCES
"${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc"
)
@ -183,14 +188,51 @@ if (RAGEPHOTO_EXTRACT)
add_executable(ragephoto-extract ${RAGEPHOTO_HEADERS} ${EXTRACT_SOURCES} ${EXTRACT_RESOURCES})
set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
CXX_STANDARD ${RAGEPHOTO_CXX_STANDARD}
CXX_STANDARD_REQUIRED ON
)
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_API)
target_compile_options(ragephoto-extract PRIVATE "/Zc:__cplusplus")
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
target_compile_options(ragephoto-extract PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
endif()
target_link_libraries(ragephoto-extract PRIVATE ragephoto)
install(TARGETS ragephoto-extract DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
# RagePhoto Python Package
option(RAGEPHOTO_PYTHON "Create ragephoto Python Package" OFF)
if (RAGEPHOTO_PYTHON)
# Python Package Library file
if (WIN32)
set(PYRAGEPHOTO_LIBRARY "libragephoto.dll")
else()
set(PYRAGEPHOTO_LIBRARY "libragephoto.so")
endif()
# Generate Python Package Project files
configure_file(src/python/setup.py.in "${ragephoto_BINARY_DIR}/pyragephoto/setup.py" @ONLY)
configure_file(src/python/pyproject.toml.in "${ragephoto_BINARY_DIR}/pyragephoto/pyproject.toml" @ONLY)
configure_file(src/python/__version__.py.in "${ragephoto_BINARY_DIR}/pyragephoto/ragephoto/__version__.py" @ONLY)
# Python Package Source files + Target
set(PYRAGEPHOTO_SOURCES
"src/python/__init__.py"
"src/python/libragephoto_loader.py"
"src/python/ragephoto.py"
)
add_custom_target(pyragephoto SOURCES ${PYRAGEPHOTO_SOURCES})
# Copy Python Package to build directory
file(COPY ${PYRAGEPHOTO_SOURCES} DESTINATION "${ragephoto_BINARY_DIR}/pyragephoto/ragephoto")
# Python Package Bundle Settings
option(RAGEPHOTO_PYTHON_BUNDLE_LIBRARY "Bundle libragephoto with ragephoto Python Package" OFF)
if (RAGEPHOTO_PYTHON_BUNDLE_LIBRARY)
add_custom_command(
TARGET ragephoto
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:ragephoto>" "${ragephoto_BINARY_DIR}/pyragephoto/ragephoto/${PYRAGEPHOTO_LIBRARY}"
BYPRODUCTS "${ragephoto_BINARY_DIR}/pyragephoto/ragephoto/${PYRAGEPHOTO_LIBRARY}"
VERBATIM
)
endif()
endif()
# CPack Package Generation
if (RPTL_ON)
include(InstallRequiredSystemLibraries)

View file

@ -16,10 +16,11 @@ sudo cmake --install libragephoto-build
```
##### Optional CMake flags
`-DCMAKE_CXX_STANDARD=17`
`-DRAGEPHOTO_CXX_STANDARD=17`
`-DRAGEPHOTO_BENCHMARK=ON`
`-DRAGEPHOTO_C_API=OFF`
`-DRAGEPHOTO_C_LIBRARY=ON`
`-DRAGEPHOTO_DEBUG=ON`
`-DRAGEPHOTO_DOC=ON`
`-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON`
`-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON`

View file

@ -1,21 +0,0 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2023 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
****************************************************************************]]
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11 CACHE STRING "libragephoto C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON)

View file

@ -1,6 +1,6 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2023 Syping
* Copyright (C) 2023-2024 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -17,8 +17,13 @@
****************************************************************************]]
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
add_executable(ragephoto-wasm ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES})
add_executable(ragephoto-wasm
${RAGEPHOTO_HEADERS}
${RAGEPHOTO_SOURCES}
)
set_target_properties(ragephoto-wasm PROPERTIES
CXX_STANDARD ${RAGEPHOTO_CXX_STANDARD}
CXX_STANDARD_REQUIRED ON
PREFIX "lib"
OUTPUT_NAME "ragephoto"
)
@ -40,7 +45,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
)
target_include_directories(ragephoto-wasm PUBLIC
"${ragephoto_BINARY_DIR}/include"
"${ragephoto_SOURCE_DIR}/src"
"${ragephoto_SOURCE_DIR}/src/core"
)
else()
message(WARNING "A useable WebAssembly build needs at least CMake 3.13.0 or newer")

View file

@ -1,6 +1,6 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* Copyright (C) 2021-2024 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -24,12 +24,13 @@ if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @ONLY)
add_custom_target(
doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND "${DOXYGEN_EXECUTABLE}" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile"
COMMENT "Generate API documentation with Doxygen"
SOURCES "build.dox" "index.dox" "usage.dox"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
VERBATIM
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html" DESTINATION "${CMAKE_INSTALL_DOCDIR}")

View file

@ -1,16 +1,18 @@
PROJECT_NAME = "libragephoto"
PROJECT_NUMBER = "Version: @ragephoto_VERSION@"
INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/index.doc" \
"@CMAKE_CURRENT_SOURCE_DIR@/build.doc" \
"@CMAKE_CURRENT_SOURCE_DIR@/usage.doc" \
"src"
INPUT = "src/core" \
"@CMAKE_CURRENT_SOURCE_DIR@/index.dox" \
"@CMAKE_CURRENT_SOURCE_DIR@/build.dox" \
"@CMAKE_CURRENT_SOURCE_DIR@/usage.dox"
OUTPUT_DIRECTORY = "@CMAKE_CURRENT_BINARY_DIR@"
FULL_PATH_NAMES = NO
EXTRACT_PRIVATE = NO
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
EXPAND_ONLY_PREDEF = NO
PREDEFINED = "__cplusplus=201703L" \
"RAGEPHOTO_CXX_STD=17" \
"@LIBRAGEPHOTO_API@" \
"LIBRAGEPHOTO_C_PUBLIC=" \
"LIBRAGEPHOTO_CXX_PUBLIC="
"LIBRAGEPHOTO_CXX_PUBLIC=" \
"INT32_C(val)=val" \
"UINT32_C(val)=val##U"

View file

@ -17,10 +17,11 @@ To customise your libragephoto build, the following <a href="#flags">Optional CM
<h4 id="flags">Optional CMake flags</h4>
\code{.sh}
-DCMAKE_CXX_STANDARD=17
-DRAGEPHOTO_CXX_STANDARD=17
-DRAGEPHOTO_BENCHMARK=ON
-DRAGEPHOTO_C_API=OFF
-DRAGEPHOTO_C_LIBRARY=ON
-DRAGEPHOTO_DEBUG=ON
-DRAGEPHOTO_DOC=ON
-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON
-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON

View file

@ -12,9 +12,8 @@
\subpage Usage "Using libragephoto"
<b>Reference</b>
RagePhoto (C++ API)
RagePhotoA (C++ API based on C API)
RagePhoto.h (C API)
\ref RagePhotoInstance "RagePhoto C API"
\ref ragephoto::photo "RagePhoto C++ API"
RagePhotoData (Data Object Struct)
RagePhotoFormatParser (Custom Format Parser Struct)

View file

@ -2,15 +2,13 @@
<h3 id="api_cxx">C++ API</h3>
<h4 id="cxx_include_usage">Including and using RagePhoto</h4>
Include RagePhoto (C++ native), RagePhotoA (C API wrapper) or \link RagePhotoB.hpp RagePhotoB \endlink (best implementation)
<h4 id="cxx_include">Including RagePhoto</h4>
\code{.cpp}
#include <RagePhoto>
\endcode
Create a RagePhoto object
Initializing a RagePhoto object
\code{.cpp}
RagePhoto ragePhoto;
@ -21,16 +19,14 @@ RagePhoto ragePhoto;
From a file using RagePhoto::loadFile
\code{.cpp}
const char* filename = "PGTA5123456789";
const bool loaded = ragePhoto.loadFile(filename);
const bool loaded = ragePhoto.loadFile("PGTA5123456789");
\endcode
From a file using RagePhoto::load(const std::string&)
\code{.cpp}
// Reading file
const char* filename = "PGTA5123456789";
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
std::ifstream ifs("PGTA5123456789", std::ios::in | std::ios::binary);
if (!ifs.is_open())
return;
std::string sdata(std::istreambuf_iterator<char>{ifs}, {});
@ -46,7 +42,7 @@ From a char* using RagePhoto::load(const char*, size_t)
const bool loaded = ragePhoto.load(data, size);
\endcode
<h4 id="cxx_using">Using a Photo</h4>
<h4 id="cxx_using">Querying Photo data</h4>
\code{.cpp}
// Returns the Photo Format
@ -85,64 +81,21 @@ Saving the JPEG from a Photo
\code{.cpp}
// Example saveJpeg function
bool saveJpeg(RagePhoto* ragePhoto, const std::string& filename) {
bool saveJpeg(RagePhoto &ragePhoto, const std::string &filename) {
std::ofstream ofs(filename, std::ios::out | std::ios::binary | std::ios::trunc);
if (!ofs.is_open())
return false;
ofs << ragePhoto->jpeg();
ofs << ragePhoto.jpeg();
const bool saved = ofs.good();
ofs.close();
return saved;
}
// Using the saveJpeg function
const char* filename = "PGTA5123456789.jpg";
const bool saved = saveJpeg(&ragePhoto, filename);
const bool saved = saveJpeg(ragePhoto, "photo.jpg");
\endcode
Using the JPEG in GTK+ (gtkmm)
\code{.cpp}
// Writing pixbuf loader
GdkPixbufLoader* pixbuf_loader = gdk_pixbuf_loader_new();
gdk_pixbuf_loader_write(pixbuf_loader, reinterpret_cast<const guchar*>(ragePhoto.jpegData()), ragePhoto.jpegSize(), nullptr);
GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader);
gdk_pixbuf_loader_close(pixbuf_loader, nullptr);
// Set image
Gtk::Image image;
image.set(Glib::wrap(pixbuf));
\endcode
Using the JPEG in Qt
\code{.cpp}
// Returns the JPEG as QImage
const QImage image = QImage::fromData(QByteArray::fromRawData(ragePhoto.jpegData(), ragePhoto.jpegSize()), "JPEG");
// Loading the JPEG in QImage
QImage image;
const bool loaded = image.loadFromData(QByteArray::fromRawData(ragePhoto.jpegData(), ragePhoto.jpegSize()), "JPEG");
\endcode
Using the JSON in Boost.JSON
\code{.cpp}
boost::json::error_code ec;
const boost::json::value jv = boost::json::parse(ragePhoto.json(), ec);
if (ec)
return;
\endcode
Using the JSON in Qt
\code{.cpp}
const QJsonDocument jd = QJsonDocument::fromJson(ragePhoto.json());
if (jd.isNull())
return;
\endcode
<h4 id="cxx_error">Detect Photo errors</h4>
<h4 id="cxx_error">Querying last error</h4>
\code{.cpp}
const int32_t error = ragePhoto.error();
@ -164,6 +117,110 @@ default:
Available error codes: RagePhoto::Error
<h3 id="api_c">C API</h3>
<h4 id="c_include">Including RagePhoto</h4>
\code{.c}
#include <RagePhoto.h>
\endcode
Initializing a RagePhoto instance
\code{.c}
ragephoto_t instance = ragephoto_open();
\endcode
Destroying a RagePhoto instance
\code{.c}
ragephoto_close(instance);
\endcode
<h4 id="c_loading">Loading a Photo</h4>
From a file using ragephoto_loadfile(ragephoto_t, const char*)
\code{.c}
const bool loaded = ragephoto_loadfile(instance, "PGTA5123456789");
\endcode
From a char* using ragephoto_load(ragephoto_t, const char*, size_t)
\code{.c}
const bool loaded = ragephoto_load(instance, data, size);
\endcode
<h4 id="c_using">Querying Photo data</h4>
\code{.c}
// Returns the Photo Format
const uint32_t format = ragephoto_getphotoformat(instance);
// Returns the JPEG as const char*
const char* jpeg = ragephoto_getphotojpeg(instance);
const uint32_t size = ragephoto_getphotosize(instance);
// Returns the JSON
const char* json = ragephoto_getphotojson(instance);
// Returns the Title
const char* title = ragephoto_getphototitle(instance);
\endcode
Detecting if Photo is from GTA V or RDR 2
\code{.c}
switch (ragephoto_getphotoformat(instance)) {
case RAGEPHOTO_FORMAT_GTA5:
printf("GTA V format detected\n");
break;
case RAGEPHOTO_FORMAT_RDR2:
printf("RDR 2 format detected\n");
break;
default:
printf("Unknown format detected\n");
}
\endcode
Saving the JPEG from a Photo
\code{.c}
// Example saveJpeg function
bool saveJpeg(ragephoto_t instance, const char* filename) {
FILE* file = fopen(filename, "wb");
if (!file)
return false;
const uint32_t jpegSize = ragephoto_getphotosize(instance);
const size_t writeSize = fwrite(ragephoto_getphotojpeg(instance), sizeof(char), jpegSize, file);
fclose(file);
return (jpegSize == writeSize);
}
// Using the saveJpeg function
const bool saved = saveJpeg(instance, "photo.jpg");
\endcode
<h4 id="c_error">Querying last error</h4>
\code{.c}
const int32_t error = ragephoto_error(instance);
switch (error) {
case RAGEPHOTO_ERROR_NOFORMATIDENTIFIER:
printf("No format identifier\n");
break;
case RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT:
printf("Incompatible format\n");
break;
// Detect for more errors here...
case RAGEPHOTO_ERROR_NOERROR:
printf("No error detected\n");
break;
default:
printf("Unknown error detected\n");
}
\endcode
<h3 id="cmake">Including libragephoto in a CMake project</h3>
<h4 id="cmake_pkgconfig">Using PkgConfig</h4>

View file

@ -35,7 +35,7 @@ if (TARGET ragephoto)
set(RAGEPHOTO_LIBRARIES ragephoto)
set(RAGEPHOTO_LIBRARY_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
else()
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto>=0.6)
endif()
add_executable(ragephoto-gtkviewer WIN32 ${GTKVIEWER_SOURCES})

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhotoB>
#include <RagePhoto>
#include <gtkmm/application.h>
#include <gtkmm/box.h>
#include <gtkmm/button.h>
@ -36,11 +36,11 @@ bool readPhotoFile(const std::string &filename, Gtk::Window *win, Gtk::Image *im
if (ifs.is_open()) {
std::string data(std::istreambuf_iterator<char>{ifs}, {});
ifs.close();
RagePhotoB ragePhoto;
RagePhoto ragePhoto;
const bool loaded = ragePhoto.load(data);
if (!loaded) {
const int32_t error = ragePhoto.error();
if (error <= RagePhotoB::PhotoReadError) {
if (error <= RagePhoto::PhotoReadError) {
Gtk::MessageDialog msg(*win, "Failed to read photo: " + filename, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
msg.set_title("Open Photo");
msg.run();

View file

@ -41,7 +41,7 @@ if (TARGET ragephoto)
set(RAGEPHOTO_LIBRARY_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto>=0.6)
endif()
add_executable(ragephoto-qtviewer WIN32 ${QTVIEWER_SOURCES})

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhotoB>
#include <RagePhoto>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
@ -35,11 +35,11 @@ bool readPhotoFile(const QString &filename, QMainWindow *mainWindow, QLabel *pho
if (file.open(QIODevice::ReadOnly)) {
const QByteArray fileData = file.readAll();
file.close();
RagePhotoB ragePhoto;
RagePhoto ragePhoto;
const bool loaded = ragePhoto.load(fileData.data(), static_cast<size_t>(fileData.size()));
if (!loaded) {
const int32_t error = ragePhoto.error();
if (error <= RagePhotoB::PhotoReadError) {
if (error <= RagePhoto::PhotoReadError) {
QMessageBox::warning(mainWindow, "Open Photo", "Failed to read photo: " + filename);
return false;
}

View file

@ -1 +0,0 @@
#include "RagePhotoA.hpp"

View file

@ -1 +0,0 @@
#include "RagePhotoB.hpp"

View file

@ -1,143 +0,0 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2023 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef RAGEPHOTOTYPEDEFS_H
#define RAGEPHOTOTYPEDEFS_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/** RagePhoto data struct for storing internal data. */
typedef struct RagePhotoData {
char* jpeg; /**< Pointer for internal JPEG buffer */
char* description; /**< Pointer for internal Description buffer */
char* json; /**< Pointer for internal JSON buffer */
char* header; /**< Pointer for internal Header buffer */
char* title; /**< Pointer for internal Title buffer */
int32_t error; /**< RagePhoto error code */
uint32_t descBuffer; /**< Description buffer length */
uint32_t descOffset; /**< Description buffer offset */
uint32_t endOfFile; /**< End Of File offset */
uint32_t headerSum; /**< Checksum of the header 1 */
uint32_t headerSum2; /**< Checksum of the header 2 (RDR 2 only) */
uint32_t jpegBuffer; /**< JPEG buffer length */
uint32_t jpegSize; /**< Internal JPEG buffer length and size of JPEG */
uint32_t jsonBuffer; /**< JSON buffer length */
uint32_t jsonOffset; /**< JSON buffer offset */
uint32_t photoFormat; /**< Photo file format magic */
uint32_t titlBuffer; /**< Title buffer length */
uint32_t titlOffset; /**< Title buffer offset */
} RagePhotoData;
/** RagePhoto load function typedef. */
typedef bool (*ragephoto_loadfunc_t)(RagePhotoData*, const char*, size_t);
/** RagePhoto save function typedef (char* allocated by caller). */
typedef bool (*ragephoto_savefunc_t)(RagePhotoData*, char*, uint32_t);
/** RagePhoto save function typedef (char* allocated by function). */
typedef bool (*ragephoto_savepfunc_t)(RagePhotoData*, char**, uint32_t);
/** RagePhoto saveSize function typedef. */
typedef size_t (*ragephoto_saveszfunc_t)(RagePhotoData*, uint32_t);
/** RagePhoto format parser struct for registering custom formats. */
typedef struct RagePhotoFormatParser {
uint32_t photoFormat; /**< Photo file format magic */
ragephoto_loadfunc_t funcLoad; /**< Pointer to load function */
ragephoto_savefunc_t funcSave; /**< Pointer to save function */
ragephoto_savepfunc_t funcSavep; /**< Pointer to savep function */
ragephoto_saveszfunc_t funcSaveSz; /**< Pointer to saveSize function */
} RagePhotoFormatParser;
/** RagePhoto instance struct for storing data and format parser pointer. */
typedef struct RagePhotoInstance {
RagePhotoData *data; /**< Pointer for data */
RagePhotoFormatParser *parser; /**< Pointer for format parser */
} RagePhotoInstance;
/* RagePhoto default sizes */
#define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER 524288UL /**< GTA V default Photo Buffer Size */
#define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER 1048576UL /**< RDR 2 default Photo Buffer Size */
#define RAGEPHOTO_DEFAULT_DESCBUFFER 256UL /**< Default Description Buffer Size */
#define RAGEPHOTO_DEFAULT_JSONBUFFER 3072UL /**< Default JSON Buffer Size */
#define RAGEPHOTO_DEFAULT_TITLBUFFER 256UL /**< Default Title Buffer Size */
#define RAGEPHOTO_GTA5_HEADERSIZE 264UL /**< GTA V Header Size */
#define RAGEPHOTO_RDR2_HEADERSIZE 272UL /**< RDR 2 Header Size */
/* RagePhoto error codes */
#define RAGEPHOTO_ERROR_DESCBUFFERTIGHT 39L /**< Description Buffer is too tight */
#define RAGEPHOTO_ERROR_DESCMALLOCERROR 31L /**< Description Buffer can't be allocated */
#define RAGEPHOTO_ERROR_DESCREADERROR 32L /**< Description can't be read successfully */
#define RAGEPHOTO_ERROR_HEADERBUFFERTIGHT 35L /**< Header Buffer is too tight */
#define RAGEPHOTO_ERROR_HEADERMALLOCERROR 4L /**< Header Buffer can't be allocated */
#define RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT 2L /**< Format is incompatible */
#define RAGEPHOTO_ERROR_INCOMPLETECHECKSUM 7L /**< Header checksum is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER 30L /**< Description Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER 28L /**< Description Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET 11L /**< Description Offset is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEEOF 8L /**< End Of File Offset is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEHEADER 3L /**< Header is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER 33L /**< JEND Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER 12L /**< JPEG Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER 20L /**< JSON Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER 18L /**< JSON Marker incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET 9L /**< JSON Offset incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER 14L /**< Photo Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE 15L /**< Photo Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER 25L /**< Title Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER 23L /**< Title Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET 10L /**< Title Offset is incomplete */
#define RAGEPHOTO_ERROR_INCORRECTDESCMARKER 29L /**< Description Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJENDMARKER 34L /**< JEND Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJPEGMARKER 13L /**< JPEG Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJSONMARKER 19L /**< JSON Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTTITLEMARKER 24L /**< Title Marker is incorrect */
#define RAGEPHOTO_ERROR_JSONBUFFERTIGHT 37L /**< JSON Buffer is too tight */
#define RAGEPHOTO_ERROR_JSONMALLOCERROR 21L /**< JSON Buffer can't be allocated */
#define RAGEPHOTO_ERROR_JSONREADERROR 22L /**< JSON can't be read successfully */
#define RAGEPHOTO_ERROR_NOERROR 255L /**< Finished without errors */
#define RAGEPHOTO_ERROR_NOFORMATIDENTIFIER 1L /**< No format detected, empty file */
#define RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT 36L /**< Photo Buffer is too tight */
#define RAGEPHOTO_ERROR_PHOTOMALLOCERROR 16L /**< Photo Buffer can't be allocated */
#define RAGEPHOTO_ERROR_PHOTOREADERROR 17L /**< Photo can't be read */
#define RAGEPHOTO_ERROR_TITLEBUFFERTIGHT 38L /**< Title Buffer is too tight */
#define RAGEPHOTO_ERROR_TITLEMALLOCERROR 26L /**< Title Buffer can't be allocated */
#define RAGEPHOTO_ERROR_TITLEREADERROR 27L /**< Title can't be read */
#define RAGEPHOTO_ERROR_UNICODEINITERROR 5L /**< Failed to initialise Unicode decoder */
#define RAGEPHOTO_ERROR_UNICODEHEADERERROR 6L /**< Header can't be encoded/decoded successfully */
#define RAGEPHOTO_ERROR_UNINITIALISED 0L /**< Uninitialised, file access failed */
/* RagePhoto formats */
#define RAGEPHOTO_FORMAT_GTA5 0x01000000UL /**< GTA V Photo Format */
#define RAGEPHOTO_FORMAT_RDR2 0x04000000UL /**< RDR 2 Photo Format */
/* RagePhoto sign initials */
#define RAGEPHOTO_SIGNINITIAL_GTA5 0xE47AB81CUL /**< GTA V Sign Initial */
#define RAGEPHOTO_SIGNINITIAL_RDR2 0x00FEEB1EUL /**< RDR 2 Sign Initial */
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTOTYPEDEFS_H

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2023 Syping
* Copyright (C) 2021-2024 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -16,9 +16,10 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhoto.hpp"
#include "ragephoto_cxx.hpp"
#ifdef LIBRAGEPHOTO_CXX_C
#include "RagePhoto.h"
#include <cinttypes>
#endif
#include <cstdlib>
@ -27,10 +28,6 @@
#include <iostream>
#include <iterator>
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
#include <filesystem>
#endif
#ifdef RAGEPHOTO_BENCHMARK
#include <chrono>
#endif
@ -45,6 +42,13 @@
#include <stringapiset.h>
#endif
/* CLASSIC RAGEPHOTO TYPEDEF */
typedef ragephoto::photo RagePhoto;
/* RAGEPHOTO LIBRARY GLOBALS */
int libraryflags = 0;
const char* nullchar = "";
/* BEGIN OF STATIC LIBRARY FUNCTIONS */
inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t outputLen, size_t inputLen)
{
@ -72,6 +76,19 @@ inline size_t writeBuffer(const void *input, char *output, size_t *pos, size_t o
return writeLen;
}
inline size_t zeroBuffer(char *output, size_t *pos, size_t outputLen, size_t inputLen)
{
const size_t maxLen = outputLen - *pos;
size_t zeroLen = inputLen;
if (*pos >= outputLen)
return 0;
if (inputLen > maxLen)
zeroLen = maxLen;
memset(&output[*pos], 0, zeroLen);
*pos = *pos + zeroLen;
return zeroLen;
}
inline bool writeDataChar(const char *input, char **output)
{
const size_t src_s = strlen(input) + 1;
@ -117,6 +134,15 @@ inline uint32_t charToUInt32LE(char *x)
static_cast<unsigned char>(x[0]));
}
inline uint32_t swapToUInt32LE(uint32_t x)
{
unsigned char *y = reinterpret_cast<unsigned char*>(&x);
return (y[3] << 24 |
y[2] << 16 |
y[1] << 8 |
y[0]);
}
inline void uInt32ToCharLE(uint32_t x, char *y)
{
y[0] = x;
@ -130,18 +156,19 @@ inline uint32_t joaatFromInitial(const char *data, size_t size, uint32_t init_va
uint32_t val = init_val;
for (size_t i = 0; i != size; i++) {
val += data[i];
val += (val << 10);
val ^= (val >> 6);
val += val << 10;
val ^= val >> 6;
}
val += (val << 3);
val ^= (val >> 11);
val += (val << 15);
val += val << 3;
val ^= val >> 11;
val += val << 15;
return val;
}
/* END OF STATIC LIBRARY FUNCTIONS */
/* BEGIN OF RAGEPHOTO CLASS */
RagePhoto::RagePhoto()
RagePhoto::photo()
{
m_data = static_cast<RagePhotoData*>(malloc(sizeof(RagePhotoData)));
if (!m_data)
@ -154,7 +181,7 @@ RagePhoto::RagePhoto()
setBufferDefault(m_data);
}
RagePhoto::~RagePhoto()
RagePhoto::~photo()
{
free(m_data->jpeg);
free(m_data->description);
@ -178,7 +205,7 @@ void RagePhoto::addParser(RagePhotoFormatParser *rp_parser)
throw std::runtime_error("RagePhotoFormatParser array can't be expanded");
m_parser = t_parser;
memcpy(&m_parser[length], rp_parser, sizeof(RagePhotoFormatParser));
memset(&m_parser[length+1], 0, sizeof(RagePhotoFormatParser));
memset(&m_parser[length + 1], 0, sizeof(RagePhotoFormatParser));
}
}
@ -206,25 +233,22 @@ RagePhotoData* RagePhoto::data()
bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
{
#ifdef RAGEPHOTO_BENCHMARK
auto benchmark_parse_start = std::chrono::high_resolution_clock::now();
auto benchmark_parse_start = std::chrono::steady_clock::now();
#endif
// Avoid data conflicts
clear(rp_data);
size_t pos = 0;
char uInt32Buffer[4];
size_t size = readBuffer(data, uInt32Buffer, &pos, 4, length);
size_t size = readBuffer(data, &rp_data->photoFormat, &pos, 4, length);
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
rp_data->photoFormat = swapToUInt32LE(rp_data->photoFormat);
#endif
if (size != 4) {
rp_data->error = Error::NoFormatIdentifier; // 1
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
memcpy(&rp_data->photoFormat, uInt32Buffer, 4);
#else
rp_data->photoFormat = charToUInt32LE(uInt32Buffer);
#endif
if (rp_data->photoFormat == PhotoFormat::GTA5 || rp_data->photoFormat == PhotoFormat::RDR2) {
#if defined UNICODE_ICONV || defined UNICODE_CODECVT || defined UNICODE_WINCVT
char photoHeader[256];
@ -285,16 +309,14 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
}
#endif
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
size = readBuffer(data, &rp_data->headerSum, &pos, 4, length);
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
rp_data->headerSum = swapToUInt32LE(rp_data->headerSum);
#endif
if (size != 4) {
rp_data->error = Error::IncompleteChecksum; // 7
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
memcpy(&rp_data->headerSum, uInt32Buffer, 4);
#else
rp_data->headerSum = charToUInt32LE(uInt32Buffer);
#endif
if (rp_data->photoFormat == PhotoFormat::RDR2) {
char formatCheckBuffer[4];
@ -309,61 +331,50 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
size = readBuffer(data, &rp_data->headerSum2, &pos, 4, length);
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
rp_data->headerSum2 = swapToUInt32LE(rp_data->headerSum2);
#endif
if (size != 4) {
rp_data->error = Error::IncompleteChecksum; // 7
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
memcpy(&rp_data->headerSum2, uInt32Buffer, 4);
#else
rp_data->headerSum2 = charToUInt32LE(uInt32Buffer);
#endif
}
const size_t headerSize = pos;
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
size = readBuffer(data, &rp_data->endOfFile, &pos, 4, length);
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
rp_data->endOfFile = swapToUInt32LE(rp_data->endOfFile);
#endif
if (size != 4) {
rp_data->error = Error::IncompleteEOF; // 8
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
memcpy(&rp_data->endOfFile, uInt32Buffer, 4);
#else
rp_data->endOfFile = charToUInt32LE(uInt32Buffer);
#endif
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
size = readBuffer(data, &rp_data->jsonOffset, &pos, 4, length);
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
rp_data->jsonOffset = swapToUInt32LE(rp_data->jsonOffset);
#endif