Compare commits
No commits in common. "dev" and "master" have entirely different histories.
44 changed files with 1005 additions and 1776 deletions
2
.github/workflows/ubuntu-cxx.yml
vendored
2
.github/workflows/ubuntu-cxx.yml
vendored
|
@ -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 -DRAGEPHOTO_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||
- name: Install
|
||||
|
|
4
.github/workflows/webassembly-c.yml
vendored
4
.github/workflows/webassembly-c.yml
vendored
|
@ -12,9 +12,7 @@ jobs:
|
|||
with:
|
||||
submodules: recursive
|
||||
- name: Setup emsdk
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: 3.1.47
|
||||
uses: mymindstorm/setup-emsdk@v11
|
||||
- name: Install packages
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
|
|
6
.github/workflows/webassembly-cxx.yml
vendored
6
.github/workflows/webassembly-cxx.yml
vendored
|
@ -12,15 +12,13 @@ jobs:
|
|||
with:
|
||||
submodules: recursive
|
||||
- name: Setup emsdk
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: 3.1.47
|
||||
uses: mymindstorm/setup-emsdk@v11
|
||||
- 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}} -DRAGEPHOTO_CXX_STANDARD=11 -GNinja
|
||||
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||
- name: Upload
|
||||
|
|
2
.github/workflows/windows-cxx.yml
vendored
2
.github/workflows/windows-cxx.yml
vendored
|
@ -21,7 +21,7 @@ jobs:
|
|||
with:
|
||||
arch: ${{matrix.arch}}
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}/build -DRAGEPHOTO_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_UNICODE=wincvt -GNinja
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_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
|
||||
|
|
126
CMakeLists.txt
126
CMakeLists.txt
|
@ -1,6 +1,6 @@
|
|||
#[[**************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* 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:
|
||||
|
@ -17,13 +17,14 @@
|
|||
****************************************************************************]]
|
||||
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(ragephoto VERSION 0.6.0 LANGUAGES C CXX)
|
||||
project(ragephoto VERSION 0.5.1 LANGUAGES C CXX)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# RagePhoto CMake includes
|
||||
include(cmake/cxxstd.cmake)
|
||||
include(cmake/unicode.cmake)
|
||||
|
||||
# RagePhoto Top Level
|
||||
# RagePhoto Top Level ON
|
||||
if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto")
|
||||
set(RPTL_ON ON)
|
||||
else()
|
||||
|
@ -34,77 +35,77 @@ endif()
|
|||
option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF)
|
||||
if (RAGEPHOTO_C_LIBRARY)
|
||||
set(RAGEPHOTO_HEADERS
|
||||
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
|
||||
src/RagePhoto.h
|
||||
src/RagePhotoA
|
||||
src/RagePhotoA.hpp
|
||||
src/RagePhotoB
|
||||
src/RagePhotoB.hpp
|
||||
src/RagePhotoLibrary.h
|
||||
src/RagePhotoTypedefs.h
|
||||
)
|
||||
set(RAGEPHOTO_SOURCES
|
||||
src/core/RagePhoto.c
|
||||
src/RagePhoto.c
|
||||
)
|
||||
else()
|
||||
set(RAGEPHOTO_HEADERS
|
||||
src/core/ragephoto_cxx
|
||||
src/core/ragephoto_cxx.hpp
|
||||
src/core/RagePhoto
|
||||
src/core/RagePhoto.hpp
|
||||
src/core/RagePhotoLibrary.h
|
||||
src/core/RagePhotoTypedefs.h
|
||||
src/RagePhoto
|
||||
src/RagePhoto.hpp
|
||||
src/RagePhotoB
|
||||
src/RagePhotoB.hpp
|
||||
src/RagePhotoLibrary.h
|
||||
src/RagePhotoTypedefs.h
|
||||
)
|
||||
set(RAGEPHOTO_SOURCES
|
||||
src/core/RagePhoto.cpp
|
||||
src/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" OFF)
|
||||
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark (C++ only)" OFF)
|
||||
if (RAGEPHOTO_BENCHMARK)
|
||||
list(APPEND LIBRAGEPHOTO_DEFINES
|
||||
RAGEPHOTO_BENCHMARK
|
||||
)
|
||||
endif()
|
||||
|
||||
# RagePhoto Debug
|
||||
option(RAGEPHOTO_DEBUG "Build with libragephoto debug output" OFF)
|
||||
|
||||
# RagePhoto API
|
||||
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
|
||||
# RagePhoto C API
|
||||
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/core/RagePhoto.h
|
||||
src/core/ragephoto_c
|
||||
src/core/ragephoto_c.hpp
|
||||
src/RagePhoto.h
|
||||
src/RagePhotoA
|
||||
src/RagePhotoA.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/core/ragephoto.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto.rc" @ONLY)
|
||||
configure_file(src/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/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)
|
||||
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)
|
||||
list(APPEND RAGEPHOTO_HEADERS
|
||||
"${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h"
|
||||
)
|
||||
|
@ -118,22 +119,16 @@ 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)
|
||||
target_compile_options(ragephoto PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
|
||||
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_LIBRARY)
|
||||
target_compile_options(ragephoto PRIVATE "/Zc:__cplusplus")
|
||||
endif()
|
||||
target_include_directories(ragephoto PUBLIC
|
||||
"${ragephoto_BINARY_DIR}/include"
|
||||
"${ragephoto_SOURCE_DIR}/src/core"
|
||||
"${ragephoto_SOURCE_DIR}/src"
|
||||
)
|
||||
install(TARGETS ragephoto
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
|
@ -172,14 +167,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/extract/RagePhoto-Extract.c)
|
||||
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
|
||||
else()
|
||||
set(EXTRACT_SOURCES src/extract/RagePhoto-Extract.cpp)
|
||||
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
|
||||
endif()
|
||||
# RagePhoto-Extract Win32 Shared Resources
|
||||
if (WIN32)
|
||||
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
|
||||
configure_file(src/extract/ragephoto-extract.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc" @ONLY)
|
||||
configure_file(src/ragephoto-extract.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc" @ONLY)
|
||||
list(APPEND EXTRACT_RESOURCES
|
||||
"${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc"
|
||||
)
|
||||
|
@ -188,51 +183,14 @@ 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)
|
||||
target_compile_options(ragephoto-extract PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
|
||||
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_API)
|
||||
target_compile_options(ragephoto-extract PRIVATE "/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)
|
||||
|
|
|
@ -16,11 +16,10 @@ sudo cmake --install libragephoto-build
|
|||
```
|
||||
|
||||
##### Optional CMake flags
|
||||
`-DRAGEPHOTO_CXX_STANDARD=17`
|
||||
`-DCMAKE_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`
|
||||
|
|
21
cmake/cxxstd.cmake
Normal file
21
cmake/cxxstd.cmake
Normal file
|
@ -0,0 +1,21 @@
|
|||
#[[**************************************************************************
|
||||
* 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)
|
|
@ -1,6 +1,6 @@
|
|||
#[[**************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2023-2024 Syping
|
||||
* 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:
|
||||
|
@ -17,13 +17,8 @@
|
|||
****************************************************************************]]
|
||||
|
||||
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"
|
||||
)
|
||||
|
@ -45,7 +40,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
|
|||
)
|
||||
target_include_directories(ragephoto-wasm PUBLIC
|
||||
"${ragephoto_BINARY_DIR}/include"
|
||||
"${ragephoto_SOURCE_DIR}/src/core"
|
||||
"${ragephoto_SOURCE_DIR}/src"
|
||||
)
|
||||
else()
|
||||
message(WARNING "A useable WebAssembly build needs at least CMake 3.13.0 or newer")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#[[**************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* Copyright (C) 2021 Syping
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
|
@ -24,13 +24,12 @@ 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"
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
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})
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
PROJECT_NAME = "libragephoto"
|
||||
PROJECT_NUMBER = "Version: @ragephoto_VERSION@"
|
||||
INPUT = "src/core" \
|
||||
"@CMAKE_CURRENT_SOURCE_DIR@/index.dox" \
|
||||
"@CMAKE_CURRENT_SOURCE_DIR@/build.dox" \
|
||||
"@CMAKE_CURRENT_SOURCE_DIR@/usage.dox"
|
||||
INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/index.doc" \
|
||||
"@CMAKE_CURRENT_SOURCE_DIR@/build.doc" \
|
||||
"@CMAKE_CURRENT_SOURCE_DIR@/usage.doc" \
|
||||
"src"
|
||||
OUTPUT_DIRECTORY = "@CMAKE_CURRENT_BINARY_DIR@"
|
||||
FULL_PATH_NAMES = NO
|
||||
EXTRACT_PRIVATE = NO
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = YES
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
EXPAND_ONLY_PREDEF = YES
|
||||
PREDEFINED = "__cplusplus=201703L" \
|
||||
"RAGEPHOTO_CXX_STD=17" \
|
||||
"@LIBRAGEPHOTO_API@" \
|
||||
"LIBRAGEPHOTO_C_PUBLIC=" \
|
||||
"LIBRAGEPHOTO_CXX_PUBLIC=" \
|
||||
"INT32_C(val)=val" \
|
||||
"UINT32_C(val)=val##U"
|
||||
"LIBRAGEPHOTO_CXX_PUBLIC="
|
||||
|
|
|
@ -17,11 +17,10 @@ To customise your libragephoto build, the following <a href="#flags">Optional CM
|
|||
|
||||
<h4 id="flags">Optional CMake flags</h4>
|
||||
\code{.sh}
|
||||
-DRAGEPHOTO_CXX_STANDARD=17
|
||||
-DCMAKE_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
|
|
@ -12,8 +12,9 @@
|
|||
\subpage Usage "Using libragephoto"
|
||||
|
||||
<b>Reference</b>
|
||||
\ref RagePhotoInstance "RagePhoto C API"
|
||||
\ref ragephoto::photo "RagePhoto C++ API"
|
||||
RagePhoto (C++ API)
|
||||
RagePhotoA (C++ API based on C API)
|
||||
RagePhoto.h (C API)
|
||||
RagePhotoData (Data Object Struct)
|
||||
RagePhotoFormatParser (Custom Format Parser Struct)
|
||||
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
<h3 id="api_cxx">C++ API</h3>
|
||||
|
||||
<h4 id="cxx_include">Including RagePhoto</h4>
|
||||
<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)
|
||||
|
||||
\code{.cpp}
|
||||
#include <RagePhoto>
|
||||
\endcode
|
||||
|
||||
Initializing a RagePhoto object
|
||||
Create a RagePhoto object
|
||||
|
||||
\code{.cpp}
|
||||
RagePhoto ragePhoto;
|
||||
|
@ -19,14 +21,16 @@ RagePhoto ragePhoto;
|
|||
From a file using RagePhoto::loadFile
|
||||
|
||||
\code{.cpp}
|
||||
const bool loaded = ragePhoto.loadFile("PGTA5123456789");
|
||||
const char* filename = "PGTA5123456789";
|
||||
const bool loaded = ragePhoto.loadFile(filename);
|
||||
\endcode
|
||||
|
||||
From a file using RagePhoto::load(const std::string&)
|
||||
|
||||
\code{.cpp}
|
||||
// Reading file
|
||||
std::ifstream ifs("PGTA5123456789", std::ios::in | std::ios::binary);
|
||||
const char* filename = "PGTA5123456789";
|
||||
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
|
||||
if (!ifs.is_open())
|
||||
return;
|
||||
std::string sdata(std::istreambuf_iterator<char>{ifs}, {});
|
||||
|
@ -42,7 +46,7 @@ From a char* using RagePhoto::load(const char*, size_t)
|
|||
const bool loaded = ragePhoto.load(data, size);
|
||||
\endcode
|
||||
|
||||
<h4 id="cxx_using">Querying Photo data</h4>
|
||||
<h4 id="cxx_using">Using a Photo</h4>
|
||||
|
||||
\code{.cpp}
|
||||
// Returns the Photo Format
|
||||
|
@ -81,21 +85,64 @@ 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 bool saved = saveJpeg(ragePhoto, "photo.jpg");
|
||||
const char* filename = "PGTA5123456789.jpg";
|
||||
const bool saved = saveJpeg(&ragePhoto, filename);
|
||||
\endcode
|
||||
|
||||
<h4 id="cxx_error">Querying last error</h4>
|
||||
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>
|
||||
|
||||
\code{.cpp}
|
||||
const int32_t error = ragePhoto.error();
|
||||
|
@ -117,110 +164,6 @@ 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>
|
|
@ -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>=0.6)
|
||||
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
|
||||
endif()
|
||||
|
||||
add_executable(ragephoto-gtkviewer WIN32 ${GTKVIEWER_SOURCES})
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <RagePhoto>
|
||||
#include <RagePhotoB>
|
||||
#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();
|
||||
RagePhoto ragePhoto;
|
||||
RagePhotoB ragePhoto;
|
||||
const bool loaded = ragePhoto.load(data);
|
||||
if (!loaded) {
|
||||
const int32_t error = ragePhoto.error();
|
||||
if (error <= RagePhoto::PhotoReadError) {
|
||||
if (error <= RagePhotoB::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();
|
||||
|
|
|
@ -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>=0.6)
|
||||
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
|
||||
endif()
|
||||
|
||||
add_executable(ragephoto-qtviewer WIN32 ${QTVIEWER_SOURCES})
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <RagePhoto>
|
||||
#include <RagePhotoB>
|
||||
#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();
|
||||
RagePhoto ragePhoto;
|
||||
RagePhotoB ragePhoto;
|
||||
const bool loaded = ragePhoto.load(fileData.data(), static_cast<size_t>(fileData.size()));
|
||||
if (!loaded) {
|
||||
const int32_t error = ragePhoto.error();
|
||||
if (error <= RagePhoto::PhotoReadError) {
|
||||
if (error <= RagePhotoB::PhotoReadError) {
|
||||
QMessageBox::warning(mainWindow, "Open Photo", "Failed to read photo: " + filename);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* 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:
|
||||
|
@ -16,7 +16,7 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <RagePhoto>
|
||||
#include <RagePhotoB>
|
||||
#include <fstream>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -27,18 +27,18 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Initialise RagePhoto
|
||||
RagePhoto ragePhoto;
|
||||
RagePhotoB ragePhoto;
|
||||
|
||||
// Load Photo
|
||||
const bool loaded = ragePhoto.loadFile(argv[1]);
|
||||
|
||||
if (!loaded) {
|
||||
const int32_t error = ragePhoto.error();
|
||||
if (error == RagePhoto::Uninitialised) {
|
||||
if (error == RagePhotoB::Uninitialised) {
|
||||
std::cout << "Failed to open file: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
else if (error <= RagePhoto::PhotoReadError) {
|
||||
else if (error <= RagePhotoB::PhotoReadError) {
|
||||
std::cout << "Failed to load photo" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
const uint32_t photoFormat = ragePhoto.format();
|
||||
if (photoFormat == RagePhoto::GTA5)
|
||||
if (photoFormat == RagePhotoB::GTA5)
|
||||
std::cout << "GTA V Photo successfully exported" << std::endl;
|
||||
else if (photoFormat == RagePhoto::RDR2)
|
||||
else if (photoFormat == RagePhotoB::RDR2)
|
||||
std::cout << "RDR 2 Photo successfully exported" << std::endl;
|
||||
else
|
||||
std::cout << "Photo successfully exported" << std::endl;
|
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* 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:
|
||||
|
@ -16,10 +16,9 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "ragephoto_cxx.hpp"
|
||||
#include "RagePhoto.hpp"
|
||||
#ifdef LIBRAGEPHOTO_CXX_C
|
||||
#include "RagePhoto.h"
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -28,6 +27,10 @@
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
#ifdef RAGEPHOTO_BENCHMARK
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
@ -42,13 +45,6 @@
|
|||
#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)
|
||||
{
|
||||
|
@ -76,19 +72,6 @@ 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;
|
||||
|
@ -134,15 +117,6 @@ 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;
|
||||
|
@ -156,19 +130,18 @@ 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::photo()
|
||||
RagePhoto::RagePhoto()
|
||||
{
|
||||
m_data = static_cast<RagePhotoData*>(malloc(sizeof(RagePhotoData)));
|
||||
if (!m_data)
|
||||
|
@ -181,7 +154,7 @@ RagePhoto::photo()
|
|||
setBufferDefault(m_data);
|
||||
}
|
||||
|
||||
RagePhoto::~photo()
|
||||
RagePhoto::~RagePhoto()
|
||||
{
|
||||
free(m_data->jpeg);
|
||||
free(m_data->description);
|
||||
|
@ -205,7 +178,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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,22 +206,25 @@ 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::steady_clock::now();
|
||||
auto benchmark_parse_start = std::chrono::high_resolution_clock::now();
|
||||
#endif
|
||||
|
||||
// Avoid data conflicts
|
||||
clear(rp_data);
|
||||
|
||||
size_t pos = 0;
|
||||
size_t size = readBuffer(data, &rp_data->photoFormat, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->photoFormat = swapToUInt32LE(rp_data->photoFormat);
|
||||
#endif
|
||||
char uInt32Buffer[4];
|
||||
size_t size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
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];
|
||||
|
@ -309,14 +285,16 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
}
|
||||
#endif
|
||||
|
||||
size = readBuffer(data, &rp_data->headerSum, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->headerSum = swapToUInt32LE(rp_data->headerSum);
|
||||
#endif
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
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];
|
||||
|
@ -331,50 +309,61 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->headerSum2, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->headerSum2 = swapToUInt32LE(rp_data->headerSum2);
|
||||
#endif
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteChecksum; // 7
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->endOfFile, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->endOfFile = swapToUInt32LE(rp_data->endOfFile);
|
||||
#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);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteEOF; // 8
|
||||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->jsonOffset, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->jsonOffset = swapToUInt32LE(rp_data->jsonOffset);
|
||||
#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);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteJsonOffset; // 9
|
||||
return false;
|
||||
}
|
||||
size = readBuffer(data, &rp_data->titlOffset, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->titlOffset = swapToUInt32LE(rp_data->titlOffset);
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->jsonOffset, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->jsonOffset = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteTitleOffset; // 10
|
||||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->descOffset, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->descOffset = swapToUInt32LE(rp_data->descOffset);
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->titlOffset, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->titlOffset = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteDescOffset; // 11
|
||||
return false;
|
||||
}
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->descOffset, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->descOffset = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
|
||||
char markerBuffer[4];
|
||||
size = readBuffer(data, markerBuffer, &pos, 4, length);
|
||||
|
@ -387,23 +376,27 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->jpegBuffer, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->jpegBuffer = swapToUInt32LE(rp_data->jpegBuffer);
|
||||
#endif
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompletePhotoBuffer; // 14
|
||||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->jpegSize, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->jpegSize = swapToUInt32LE(rp_data->jpegSize);
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->jpegBuffer, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->jpegBuffer = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompletePhotoSize; // 15
|
||||
return false;
|
||||
}
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->jpegSize, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->jpegSize = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
|
||||
rp_data->jpeg = static_cast<char*>(malloc(rp_data->jpegSize));
|
||||
if (!rp_data->jpeg) {
|
||||
|
@ -418,7 +411,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
pos += rp_data->jpegBuffer - rp_data->jpegSize;
|
||||
pos = rp_data->jsonOffset + headerSize;
|
||||
size = readBuffer(data, markerBuffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteJsonMarker; // 18
|
||||
|
@ -429,14 +422,16 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->jsonBuffer, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->jsonBuffer = swapToUInt32LE(rp_data->jsonBuffer);
|
||||
#endif
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteJsonBuffer; // 20
|
||||
return false;
|
||||
}
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->jsonBuffer, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->jsonBuffer = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
|
||||
rp_data->json = static_cast<char*>(malloc(rp_data->jsonBuffer));
|
||||
if (!rp_data->json) {
|
||||
|
@ -451,6 +446,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
pos = rp_data->titlOffset + headerSize;
|
||||
size = readBuffer(data, markerBuffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteTitleMarker; // 23
|
||||
|
@ -461,14 +457,16 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->titlBuffer, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->titlBuffer = swapToUInt32LE(rp_data->titlBuffer);
|
||||
#endif
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteTitleBuffer; // 25
|
||||
return false;
|
||||
}
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->titlBuffer, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->titlBuffer = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
|
||||
rp_data->title = static_cast<char*>(malloc(rp_data->titlBuffer));
|
||||
if (!rp_data->title) {
|
||||
|
@ -483,6 +481,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
pos = rp_data->descOffset + headerSize;
|
||||
size = readBuffer(data, markerBuffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteDescMarker; // 28
|
||||
|
@ -493,14 +492,16 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
size = readBuffer(data, &rp_data->descBuffer, &pos, 4, length);
|
||||
#ifndef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
rp_data->descBuffer = swapToUInt32LE(rp_data->descBuffer);
|
||||
#endif
|
||||
size = readBuffer(data, uInt32Buffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteDescBuffer; // 30
|
||||
return false;
|
||||
}
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(&rp_data->descBuffer, uInt32Buffer, 4);
|
||||
#else
|
||||
rp_data->descBuffer = charToUInt32LE(uInt32Buffer);
|
||||
#endif
|
||||
|
||||
rp_data->description = static_cast<char*>(malloc(rp_data->descBuffer));
|
||||
if (!rp_data->description) {
|
||||
|
@ -515,6 +516,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
return false;
|
||||
}
|
||||
|
||||
pos = rp_data->endOfFile + headerSize - 4;
|
||||
size = readBuffer(data, markerBuffer, &pos, 4, length);
|
||||
if (size != 4) {
|
||||
rp_data->error = Error::IncompleteJendMarker; // 33
|
||||
|
@ -526,32 +528,35 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
|||
}
|
||||
|
||||
#ifdef RAGEPHOTO_BENCHMARK
|
||||
auto benchmark_parse_end = std::chrono::steady_clock::now();
|
||||
auto benchmark_parse_end = std::chrono::high_resolution_clock::now();
|
||||
auto benchmark_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark_parse_end - benchmark_parse_start);
|
||||
std::cout << "Benchmark: " << benchmark_ns.count() << "ns" << std::endl;
|
||||
#endif
|
||||
|
||||
#ifdef RAGEPHOTO_DEBUG
|
||||
const uint32_t jsonOffset = rp_data->jpegBuffer + UINT32_C(28);
|
||||
const uint32_t titlOffset = jsonOffset + rp_data->jsonBuffer + UINT32_C(8);
|
||||
const uint32_t descOffset = titlOffset + rp_data->titlBuffer + UINT32_C(8);
|
||||
const uint32_t endOfFile = descOffset + rp_data->descBuffer + UINT32_C(12);
|
||||
std::cout << "header: " << rp_data->header << std::endl;
|
||||
std::cout << "headerSum: " << rp_data->headerSum << std::endl;
|
||||
std::cout << "headerSum2: " << rp_data->headerSum2 << std::endl;
|
||||
std::cout << "photoBuffer: " << rp_data->jpegBuffer << std::endl;
|
||||
std::cout << "descBuffer: " << rp_data->descBuffer << std::endl;
|
||||
std::cout << "descOffset: " << rp_data->descOffset << " (" << descOffset << ")" << std::endl;
|
||||
std::cout << "descOffset: " << rp_data->descOffset << std::endl;
|
||||
std::cout << "description: " << rp_data->description << std::endl;
|
||||
std::cout << "jsonBuffer: " << rp_data->jsonBuffer << std::endl;
|
||||
std::cout << "jsonOffset: " << rp_data->jsonOffset << " (" << jsonOffset << ")" << std::endl;
|
||||
std::cout << "jsonOffset: " << rp_data->jsonOffset << std::endl;
|
||||
std::cout << "json: " << rp_data->json << std::endl;
|
||||
std::cout << "sign: " << jpegSign(rp_data) << std::endl;
|
||||
std::cout << "titlBuffer: " << rp_data->titlBuffer << std::endl;
|
||||
std::cout << "titlOffset: " << rp_data->titlOffset << " (" << titlOffset << ")" << std::endl;
|
||||
std::cout << "titlOffset: " << rp_data->titlOffset << std::endl;
|
||||
std::cout << "title: " << rp_data->title << std::endl;
|
||||
std::cout << "eofOffset: " << rp_data->endOfFile << " (" << endOfFile << ")" << std::endl;
|
||||
std::cout << "size: " << length << " (" << saveSize(rp_data, nullptr) << ")" << std::endl;
|
||||
std::cout << "eofOffset: " << rp_data->endOfFile << std::endl;
|
||||
std::cout << "setBufferOffsets()" << std::endl;
|
||||
setBufferOffsets(rp_data);
|
||||
std::cout << "descOffset: " << rp_data->descOffset << std::endl;
|
||||
std::cout << "jsonOffset: " << rp_data->jsonOffset << std::endl;
|
||||
std::cout << "titlOffset: " << rp_data->titlOffset << std::endl;
|
||||
std::cout << "eofOffset: " << rp_data->endOfFile << std::endl;
|
||||
std::cout << "calc size: " << saveSize(rp_data, rp_parser) << std::endl;
|
||||
std::cout << "real size: " << length << std::endl;
|
||||
#endif
|
||||
|
||||
rp_data->error = Error::NoError; // 255
|
||||
|
@ -586,7 +591,11 @@ bool RagePhoto::load(const std::string &data)
|
|||
|
||||
bool RagePhoto::loadFile(const std::string &filename)
|
||||
{
|
||||
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
|
||||
std::ifstream ifs(std::filesystem::u8path(filename), std::ios::in | std::ios::binary);
|
||||
#else
|
||||
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
|
||||
#endif
|
||||
if (ifs.is_open()) {
|
||||
std::string sdata(std::istreambuf_iterator<char>{ifs}, {});
|
||||
ifs.close();
|
||||
|
@ -612,6 +621,7 @@ const std::string RagePhoto::jpeg() const
|
|||
{
|
||||
if (m_data->jpeg)
|
||||
return std::string(m_data->jpeg, m_data->jpegSize);
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
|
@ -620,25 +630,23 @@ const std::string_view RagePhoto::jpeg_view() const
|
|||
{
|
||||
if (m_data->jpeg)
|
||||
return std::string_view(m_data->jpeg, m_data->jpegSize);
|
||||
else
|
||||
return std::string_view();
|
||||
}
|
||||
#endif
|
||||
|
||||
const char* RagePhoto::jpegData() const
|
||||
{
|
||||
if (m_data->jpeg)
|
||||
return m_data->jpeg;
|
||||
return (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN) ? nullptr : nullchar;
|
||||
}
|
||||
|
||||
uint64_t RagePhoto::jpegSign(uint32_t photoFormat, RagePhotoData *rp_data)
|
||||
{
|
||||
if (rp_data->jpeg) {
|
||||
if (photoFormat == PhotoFormat::GTA5)
|
||||
return (UINT64_C(0x100000000000000) | joaatFromInitial(rp_data->jpeg, rp_data->jpegSize, SignInitials::SIGTA5));
|
||||
return (0x100000000000000ULL | joaatFromInitial(rp_data->jpeg, rp_data->jpegSize, SignInitials::SIGTA5));
|
||||
else if (photoFormat == PhotoFormat::RDR2)
|
||||
return (UINT64_C(0x100000000000000) | joaatFromInitial(rp_data->jpeg, rp_data->jpegSize, SignInitials::SIRDR2));
|
||||
}
|
||||
return (0x100000000000000ULL | joaatFromInitial(rp_data->jpeg, rp_data->jpegSize, SignInitials::SIRDR2));
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -661,35 +669,28 @@ uint32_t RagePhoto::jpegSize() const
|
|||
{
|
||||
if (m_data->jpeg)
|
||||
return m_data->jpegSize;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* RagePhoto::description() const
|
||||
{
|
||||
if (m_data->description)
|
||||
return m_data->description;
|
||||
return (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN) ? nullptr : nullchar;
|
||||
}
|
||||
|
||||
const char* RagePhoto::header() const
|
||||
{
|
||||
if (m_data->header)
|
||||
return m_data->header;
|
||||
return (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN) ? nullptr : nullchar;
|
||||
}
|
||||
|
||||
const char* RagePhoto::json() const
|
||||
{
|
||||
if (m_data->json)
|
||||
return m_data->json;
|
||||
return (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN) ? nullptr : nullchar;
|
||||
}
|
||||
|
||||
const char* RagePhoto::header() const
|
||||
{
|
||||
return m_data->header;
|
||||
}
|
||||
|
||||
const char* RagePhoto::title() const
|
||||
{
|
||||
if (m_data->title)
|
||||
return m_data->title;
|
||||
return (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN) ? nullptr : nullchar;
|
||||
}
|
||||
|
||||
const char* RagePhoto::version()
|
||||
|
@ -700,10 +701,6 @@ const char* RagePhoto::version()
|
|||
bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
|
||||
{
|
||||
if (photoFormat == PhotoFormat::GTA5 || photoFormat == PhotoFormat::RDR2) {
|
||||
if (!rp_data->header) {
|
||||
rp_data->error = Error::IncompleteHeader; // 3
|
||||
return false;
|
||||
}
|
||||
#if defined UNICODE_ICONV || defined UNICODE_CODECVT || defined UNICODE_WINCVT
|
||||
#if defined UNICODE_CODECVT
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
|
||||
|
@ -712,7 +709,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
|
|||
rp_data->error = Error::UnicodeHeaderError; // 6
|
||||
return false;
|
||||
}
|
||||
const size_t photoHeader_size = photoHeader_string.size() * sizeof(char16_t);
|
||||
const size_t photoHeader_size = photoHeader_string.size() * 2;
|
||||
if (photoHeader_size > 256) {
|
||||
rp_data->error = Error::HeaderBufferTight; // 35
|
||||
return false;
|
||||
|
@ -746,165 +743,160 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
|
|||
const size_t photoHeader_size = 256;
|
||||
#endif
|
||||
|
||||
const size_t length = saveSize(photoFormat, rp_data, nullptr);
|
||||
size_t pos = 0;
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&photoFormat, data, &pos, length, 4);
|
||||
#else
|
||||
char uInt32Buffer[4];
|
||||
uInt32ToCharLE(photoFormat, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
writeBuffer(photoHeader, data, &pos, length, photoHeader_size);
|
||||
zeroBuffer(data, &pos, length, 256 - photoHeader_size);
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&rp_data->headerSum, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->headerSum, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
if (photoFormat == PhotoFormat::RDR2) {
|
||||
zeroBuffer(data, &pos, length, 4);
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&rp_data->headerSum2, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->headerSum2, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
const uint32_t jsonOffset = rp_data->jpegBuffer + UINT32_C(28);
|
||||
const uint32_t titlOffset = jsonOffset + rp_data->jsonBuffer + UINT32_C(8);
|
||||
const uint32_t descOffset = titlOffset + rp_data->titlBuffer + UINT32_C(8);
|
||||
const uint32_t endOfFile = descOffset + rp_data->descBuffer + UINT32_C(12);
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&endOfFile, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(endOfFile, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&jsonOffset, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(jsonOffset, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&titlOffset, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(titlOffset, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&descOffset, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(descOffset, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
writeBuffer("JPEG", data, &pos, length, 4);
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&rp_data->jpegBuffer, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->jpegBuffer, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&rp_data->jpegSize, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->jpegSize, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
if (rp_data->jpeg) {
|
||||
if (rp_data->jpegSize > rp_data->jpegBuffer) {
|
||||
rp_data->error = Error::PhotoBufferTight; // 36
|
||||
return false;
|
||||
}
|
||||
writeBuffer(rp_data->jpeg, data, &pos, length, rp_data->jpegSize);
|
||||
zeroBuffer(data, &pos, length, rp_data->jpegBuffer - rp_data->jpegSize);
|
||||
}
|
||||
else {
|
||||
zeroBuffer(data, &pos, length, rp_data->jpegBuffer);
|
||||
}
|
||||
|
||||
writeBuffer("JSON", data, &pos, length, 4);
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&rp_data->jsonBuffer, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->jsonBuffer, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
if (rp_data->json) {
|
||||
const size_t jsonString_size = strlen(rp_data->json) + 1;
|
||||
if (jsonString_size > rp_data->jsonBuffer) {
|
||||
rp_data->error = Error::JsonBufferTight; // 37
|
||||
return false;
|
||||
}
|
||||
writeBuffer(rp_data->json, data, &pos, length, jsonString_size);
|
||||
zeroBuffer(data, &pos, length, rp_data->jsonBuffer - jsonString_size);
|
||||
}
|
||||
else {
|
||||
zeroBuffer(data, &pos, length, rp_data->jsonBuffer);
|
||||
}
|
||||
|
||||
writeBuffer("TITL", data, &pos, length, 4);
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&rp_data->titlBuffer, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->titlBuffer, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
if (rp_data->title) {
|
||||
const size_t titlString_size = strlen(rp_data->title) + 1;
|
||||
if (titlString_size > rp_data->titlBuffer) {
|
||||
rp_data->error = Error::TitleBufferTight; // 38
|
||||
return false;
|
||||
}
|
||||
writeBuffer(rp_data->title, data, &pos, length, titlString_size);
|
||||
zeroBuffer(data, &pos, length, rp_data->titlBuffer - titlString_size);
|
||||
}
|
||||
else {
|
||||
zeroBuffer(data, &pos, length, rp_data->titlBuffer);
|
||||
}
|
||||
|
||||
writeBuffer("DESC", data, &pos, length, 4);
|
||||
|
||||
#ifdef LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
writeBuffer(&rp_data->descBuffer, data, &pos, length, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->descBuffer, uInt32Buffer);
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
#endif
|
||||
|
||||
if (rp_data->description) {
|
||||
const size_t descString_size = strlen(rp_data->description) + 1;
|
||||
if (descString_size > rp_data->descBuffer) {
|
||||
rp_data->error = Error::DescBufferTight; // 39
|
||||
return false;
|
||||
}
|
||||
writeBuffer(rp_data->description, data, &pos, length, descString_size);
|
||||
zeroBuffer(data, &pos, length, rp_data->descBuffer - descString_size);
|
||||
}
|
||||
else {
|
||||
zeroBuffer(data, &pos, length, rp_data->descBuffer);
|
||||
|
||||
const size_t length = saveSize(photoFormat, rp_data, rp_parser);
|
||||
size_t pos = 0;
|
||||
char uInt32Buffer[4];
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &photoFormat, 4);
|
||||
#else
|
||||
uInt32ToCharLE(static_cast<uint32_t>(photoFormat), uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
writeBuffer(photoHeader, data, &pos, length, photoHeader_size);
|
||||
for (size_t i = photoHeader_size; i < 256; i++) {
|
||||
writeBuffer("\0", data, &pos, length, 1);
|
||||
}
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->headerSum, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->headerSum, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
if (photoFormat == PhotoFormat::RDR2) {
|
||||
char n_formatCheckBuffer[4]{};
|
||||
writeBuffer(n_formatCheckBuffer, data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->headerSum2, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->headerSum2, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
}
|
||||
const size_t headerSize = pos;
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->endOfFile, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->endOfFile, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->jsonOffset, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->jsonOffset, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->titlOffset, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->titlOffset, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->descOffset, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->descOffset, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
writeBuffer("JPEG", data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->jpegBuffer, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->jpegBuffer, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->jpegSize, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->jpegSize, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
writeBuffer(rp_data->jpeg, data, &pos, length, rp_data->jpegSize);
|
||||
for (size_t i = rp_data->jpegSize; i < rp_data->jpegBuffer; i++) {
|
||||
writeBuffer("\0", data, &pos, length, 1);
|
||||
}
|
||||
|
||||
pos = rp_data->jsonOffset + headerSize;
|
||||
writeBuffer("JSON", data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->jsonBuffer, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->jsonBuffer, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
writeBuffer(rp_data->json, data, &pos, length, jsonString_size);
|
||||
for (size_t i = jsonString_size; i < rp_data->jsonBuffer; i++) {
|
||||
writeBuffer("\0", data, &pos, length, 1);
|
||||
}
|
||||
|
||||
pos = rp_data->titlOffset + headerSize;
|
||||
writeBuffer("TITL", data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->titlBuffer, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->titlBuffer, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
writeBuffer(rp_data->title, data, &pos, length, titlString_size);
|
||||
for (size_t i = titlString_size; i < rp_data->titlBuffer; i++) {
|
||||
writeBuffer("\0", data, &pos, length, 1);
|
||||
}
|
||||
|
||||
pos = rp_data->descOffset + headerSize;
|
||||
writeBuffer("DESC", data, &pos, length, 4);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
memcpy(uInt32Buffer, &rp_data->descBuffer, 4);
|
||||
#else
|
||||
uInt32ToCharLE(rp_data->descBuffer, uInt32Buffer);
|
||||
#endif
|
||||
writeBuffer(uInt32Buffer, data, &pos, length, 4);
|
||||
|
||||
writeBuffer(rp_data->description, data, &pos, length, descString_size);
|
||||
for (size_t i = descString_size; i < rp_data->descBuffer; i++) {
|
||||
writeBuffer("\0", data, &pos, length, 1);
|
||||
}
|
||||
|
||||
pos = rp_data->endOfFile + headerSize - 4;
|
||||
writeBuffer("JEND", data, &pos, length, 4);
|
||||
|
||||
rp_data->error = Error::NoError; // 255
|
||||
|
@ -964,12 +956,16 @@ const std::string RagePhoto::save(bool *ok)
|
|||
return save(m_data->photoFormat, ok);
|
||||
}
|
||||
|
||||
bool RagePhoto::saveFile(const char *filename, uint32_t photoFormat)
|
||||
bool RagePhoto::saveFile(const std::string &filename, uint32_t photoFormat)
|
||||
{
|
||||
bool ok;
|
||||
const std::string sdata = save(photoFormat, &ok);
|
||||
const std::string &sdata = save(photoFormat, &ok);
|
||||
if (ok) {
|
||||
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
|
||||
std::ofstream ofs(std::filesystem::u8path(filename), std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
#else
|
||||
std::ofstream ofs(filename, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
#endif
|
||||
if (!ofs.is_open()) {
|
||||
m_data->error = Error::Uninitialised; // 0
|
||||
return false;
|
||||
|
@ -987,7 +983,7 @@ bool RagePhoto::saveFile(const char *filename, uint32_t photoFormat)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool RagePhoto::saveFile(const char *filename)
|
||||
bool RagePhoto::saveFile(const std::string &filename)
|
||||
{
|
||||
return saveFile(filename, m_data->photoFormat);
|
||||
}
|
||||
|
@ -995,9 +991,9 @@ bool RagePhoto::saveFile(const char *filename)
|
|||
size_t RagePhoto::saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
|
||||
{
|
||||
if (photoFormat == PhotoFormat::GTA5)
|
||||
return (rp_data->jpegBuffer + rp_data->jsonBuffer + rp_data->titlBuffer + rp_data->descBuffer + GTA5_HEADERSIZE + UINT32_C(56));
|
||||
return (rp_data->jpegBuffer + rp_data->jsonBuffer + rp_data->titlBuffer + rp_data->descBuffer + GTA5_HEADERSIZE + 56UL);
|
||||
else if (photoFormat == PhotoFormat::RDR2)
|
||||
return (rp_data->jpegBuffer + rp_data->jsonBuffer + rp_data->titlBuffer + rp_data->descBuffer + RDR2_HEADERSIZE + UINT32_C(56));
|
||||
return (rp_data->jpegBuffer + rp_data->jsonBuffer + rp_data->titlBuffer + rp_data->descBuffer + RDR2_HEADERSIZE + 56UL);
|
||||
else if (rp_parser) {
|
||||
RagePhotoFormatParser n_parser[1]{};
|
||||
for (size_t i = 0; memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
|
||||
|
@ -1139,17 +1135,6 @@ void RagePhoto::setFormat(uint32_t photoFormat)
|
|||
m_data->photoFormat = photoFormat;
|
||||
}
|
||||
|
||||
void RagePhoto::setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2)
|
||||
{
|
||||
if (!writeDataChar(header, &m_data->header)) {
|
||||
m_data->error = Error::HeaderMallocError; // 4
|
||||
return;
|
||||
}
|
||||
m_data->headerSum = headerSum;
|
||||
m_data->headerSum2 = headerSum2;
|
||||
m_data->error = Error::NoError; // 255
|
||||
}
|
||||
|
||||
bool RagePhoto::setJpeg(const char *data, uint32_t size, uint32_t bufferSize)
|
||||
{
|
||||
if (m_data->jpeg) {
|
||||
|
@ -1214,9 +1199,15 @@ void RagePhoto::setJson(const char *json, uint32_t bufferSize)
|
|||
m_data->error = Error::NoError; // 255
|
||||
}
|
||||
|
||||
void RagePhoto::setLibraryFlag(RagePhotoLibraryFlag flag, bool state)
|
||||
void RagePhoto::setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2)
|
||||
{
|
||||
state ? (libraryflags |= flag) : (libraryflags &= ~flag);
|
||||
if (!writeDataChar(header, &m_data->header)) {
|
||||
m_data->error = Error::HeaderMallocError; // 4
|
||||
return;
|
||||
}
|
||||
m_data->headerSum = headerSum;
|
||||
m_data->headerSum2 = headerSum2;
|
||||
m_data->error = Error::NoError; // 255
|
||||
}
|
||||
|
||||
void RagePhoto::setTitle(const char *title, uint32_t bufferSize)
|
||||
|
@ -1235,24 +1226,13 @@ void RagePhoto::setTitle(const char *title, uint32_t bufferSize)
|
|||
#ifdef LIBRAGEPHOTO_CXX_C
|
||||
ragephoto_t ragephoto_open()
|
||||
{
|
||||
try {
|
||||
return static_cast<ragephoto_t>(new RagePhoto);
|
||||
}
|
||||
catch (const std::exception &exception) {
|
||||
std::cerr << "[libragephoto] Exception thrown at ragephoto_open: " << exception.what() << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser)
|
||||
{
|
||||
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
|
||||
try {
|
||||
ragePhoto->addParser(rp_parser);
|
||||
}
|
||||
catch (const std::exception &exception) {
|
||||
std::cerr << "[libragephoto] Exception thrown at ragephoto_addparser: " << exception.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ragephoto_clear(ragephoto_t instance)
|
||||
|
@ -1357,18 +1337,6 @@ uint64_t ragephoto_getphotosignf(ragephoto_t instance, uint32_t photoFormat)
|
|||
return ragePhoto->jpegSign(photoFormat);
|
||||
}
|
||||
|
||||
void ragephoto_getphotosigns(ragephoto_t instance, char *data, size_t size)
|
||||
{
|
||||
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
|
||||
snprintf(data, size, "%" PRIu64, ragePhoto->jpegSign());
|
||||
}
|
||||
|
||||
void ragephoto_getphotosignsf(ragephoto_t instance, char *data, size_t size, uint32_t photoFormat)
|
||||
{
|
||||
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
|
||||
snprintf(data, size, "%" PRIu64, ragePhoto->jpegSign(photoFormat));
|
||||
}
|
||||
|
||||
uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data)
|
||||
{
|
||||
return RagePhoto::jpegSign(rp_data);
|
||||
|
@ -1469,11 +1437,6 @@ void ragephotodata_setbufferoffsets(RagePhotoData *rp_data)
|
|||
RagePhoto::setBufferOffsets(rp_data);
|
||||
}
|
||||
|
||||
void ragephoto_setlibraryflag(RagePhotoLibraryFlag flag, bool state)
|
||||
{
|
||||
RagePhoto::setLibraryFlag(flag, state);
|
||||
}
|
||||
|
||||
bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data)
|
||||
{
|
||||
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* 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:
|
||||
|
@ -16,10 +16,6 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
/** RagePhoto C API header file
|
||||
* \file RagePhoto.h
|
||||
*/
|
||||
|
||||
#ifndef RAGEPHOTO_H
|
||||
#define RAGEPHOTO_H
|
||||
|
||||
|
@ -32,37 +28,33 @@
|
|||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
/** RagePhoto typedef for C instance/C++ object.
|
||||
* \memberof RagePhotoInstance
|
||||
/** C API for RagePhoto.
|
||||
* \file RagePhoto.h
|
||||
*/
|
||||
|
||||
/** RagePhoto C instance/C++ class typedef. */
|
||||
typedef void* ragephoto_t;
|
||||
|
||||
/** Opens a \p ragephoto_t instance.
|
||||
* \memberof RagePhotoInstance
|
||||
*/
|
||||
/** Opens a \p ragephoto_t instance. */
|
||||
LIBRAGEPHOTO_C_PUBLIC ragephoto_t ragephoto_open();
|
||||
|
||||
/** Add a custom defined RagePhotoFormatParser.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param rp_parser Parser to add
|
||||
* \param rp_parser RagePhotoFormatParser parser to add
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser);
|
||||
|
||||
/** Resets the Data object to default values.
|
||||
* \memberof RagePhotoInstance
|
||||
/** Resets the RagePhotoData object to default values.
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_clear(ragephoto_t instance);
|
||||
|
||||
/** Resets the Data object to default values.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
/** Resets the RagePhotoData object to default values.
|
||||
* \param rp_data RagePhotoData object
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_clear(RagePhotoData *rp_data);
|
||||
|
||||
/** Loads a Photo from a const char*.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param data Photo data
|
||||
* \param size Photo data size
|
||||
|
@ -70,183 +62,136 @@ LIBRAGEPHOTO_C_PUBLIC void ragephotodata_clear(RagePhotoData *rp_data);
|
|||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_load(ragephoto_t instance, const char *data, size_t size);
|
||||
|
||||
/** Loads a Photo from a const char*.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_parser Parser array
|
||||
* \param rp_data RagePhotoData object
|
||||
* \param rp_parser RagePhotoFormatParser parser array
|
||||
* \param data Photo data
|
||||
* \param size Photo data size
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size);
|
||||
|
||||
/** Loads a Photo from a file.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param filename File to load
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_loadfile(ragephoto_t instance, const char *filename);
|
||||
|
||||
/** Returns the last error occurred.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC int32_t ragephoto_error(ragephoto_t instance);
|
||||
|
||||
/** Returns the GTA V default Photo Buffer Size.
|
||||
* \relates RagePhotoInstance
|
||||
*/
|
||||
/** Returns the GTA V default Photo Buffer Size. */
|
||||
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_gta5();
|
||||
|
||||
/** Returns the RDR 2 default Photo Buffer Size.
|
||||
* \relates RagePhotoInstance
|
||||
*/
|
||||
/** Returns the RDR 2 default Photo Buffer Size. */
|
||||
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_rdr2();
|
||||
|
||||
/** Returns the GTA V Photo Format.
|
||||
* \relates RagePhotoInstance
|
||||
*/
|
||||
/** Returns the GTA V Photo Format. */
|
||||
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_gta5();
|
||||
|
||||
/** Returns the RDR 2 Photo Format.
|
||||
* \relates RagePhotoInstance
|
||||
*/
|
||||
/** Returns the RDR 2 Photo Format. */
|
||||
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_rdr2();
|
||||
|
||||
/** Returns the internal Data object.
|
||||
* \memberof RagePhotoInstance
|
||||
/** Returns the internal RagePhotoData object.
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC RagePhotoData* ragephoto_getphotodata(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo description.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotodesc(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo Format (GTA V or RDR 2).
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotoformat(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo JPEG data.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojpeg(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo JSON data.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojson(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo header.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotoheader(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo JPEG sign.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosign(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo JPEG sign.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosignf(ragephoto_t instance, uint32_t photoFormat);
|
||||
|
||||
/** Returns the Photo JPEG sign as string.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param data String data
|
||||
* \param size String size
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_getphotosigns(ragephoto_t instance, char *data, size_t size);
|
||||
|
||||
/** Returns the Photo JPEG sign as string.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param data String data
|
||||
* \param size String size
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_getphotosignsf(ragephoto_t instance, char *data, size_t size, uint32_t photoFormat);
|
||||
|
||||
/** Returns the Photo JPEG sign.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_data RagePhotoData object
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data);
|
||||
|
||||
/** Returns the Photo JPEG sign.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_data RagePhotoData object
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat);
|
||||
|
||||
/** Returns the Photo JPEG data size.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotosize(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo title.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphototitle(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo save file size.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesize(ragephoto_t instance);
|
||||
|
||||
/** Returns the Photo save file size.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_parser Parser array
|
||||
* \param rp_data RagePhotoData object
|
||||
* \param rp_parser RagePhotoFormatParser parser array
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC size_t ragephotodata_getsavesize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
|
||||
|
||||
/** Returns the Photo save file size.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
|
||||
|
||||
/** Returns the Photo save file size.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_parser Parser array
|
||||
* \param rp_data RagePhotoData object
|
||||
* \param rp_parser RagePhotoFormatParser parser array
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat);
|
||||
|
||||
/** Saves a Photo to a char*.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param data Photo data
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_save(ragephoto_t instance, char *data);
|
||||
|
||||
/** Saves a Photo to a char*.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_parser Parser array
|
||||
* \param rp_data RagePhotoData object
|
||||
* \param rp_parser RagePhotoFormatParser parser array
|
||||
* \param data Photo data
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data);
|
||||
|
||||
/** Saves a Photo to a char*.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param data Photo data
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
|
@ -254,23 +199,20 @@ LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_save(RagePhotoData *rp_data, RagePhotoF
|
|||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
|
||||
|
||||
/** Saves a Photo to a char*.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_parser Parser array
|
||||
* \param rp_data RagePhotoData object
|
||||
* \param rp_parser RagePhotoFormatParser parser array
|
||||
* \param data Photo data
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat);
|
||||
|
||||
/** Saves a Photo to a file.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param filename File to save
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefile(ragephoto_t instance, const char *filename);
|
||||
|
||||
/** Saves a Photo to a file.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param filename File to save
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
|
@ -278,52 +220,38 @@ LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefile(ragephoto_t instance, const char *
|
|||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
|
||||
|
||||
/** Sets all cross-format Buffer to default size.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferdefault(ragephoto_t instance);
|
||||
|
||||
/** Sets all cross-format Buffer to default size.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_data RagePhotoData object
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferdefault(RagePhotoData *rp_data);
|
||||
|
||||
/** Moves all Buffer offsets to correct position.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferoffsets(ragephoto_t instance);
|
||||
|
||||
/** Moves all Buffer offsets to correct position.
|
||||
* \memberof RagePhotoData
|
||||
* \param rp_data Data object
|
||||
* \param rp_data RagePhotoData object
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);
|
||||
|
||||
/** Sets a library flag.
|
||||
* \relates RagePhotoInstance
|
||||
* \param flag Library flag
|
||||
* \param state Flag state
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setlibraryflag(RagePhotoLibraryFlag flag, bool state);
|
||||
|
||||
/** Sets the internal RagePhotoData object.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param rp_data Data object used to replace
|
||||
* \param rp_data RagePhotoData object being set
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data);
|
||||
|
||||
/** Copies RagePhotoData object to internal RagePhotoData object.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param rp_data Data object used to copy
|
||||
* \param rp_data RagePhotoData object being copied
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data);
|
||||
|
||||
/** Sets the Photo description.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param description Description
|
||||
* \param bufferSize Description buffer size
|
||||
|
@ -333,14 +261,12 @@ LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodatac(ragephoto_t instance, RagePho
|
|||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
|
||||
|
||||
/** Sets the Photo Format (GTA V or RDR 2).
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param photoFormat Photo Format (GTA V or RDR 2)
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
|
||||
|
||||
/** Sets the Photo JPEG data.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param data JPEG data
|
||||
* \param size JPEG data size
|
||||
|
@ -351,7 +277,6 @@ LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoformat(ragephoto_t instance, uint32
|
|||
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
|
||||
|
||||
/** Sets the Photo JSON data.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param json JSON data
|
||||
* \param bufferSize JSON data buffer size
|
||||
|
@ -360,18 +285,13 @@ LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotojpeg(ragephoto_t instance, const ch
|
|||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
|
||||
|
||||
/** Sets the Photo header.
|
||||
* \memberof RagePhotoInstance
|
||||
*/
|
||||
/** Sets the Photo header. */
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
|
||||
|
||||
/** Sets the Photo header. (RDR 2)
|
||||
* \memberof RagePhotoInstance
|
||||
*/
|
||||
/** Sets the Photo header. (RDR 2) */
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2);
|
||||
|
||||
/** Sets the Photo title.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
* \param title Title
|
||||
* \param bufferSize Title buffer size
|
||||
|
@ -381,14 +301,11 @@ LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader2(ragephoto_t instance, const
|
|||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
|
||||
|
||||
/** Closes a \p ragephoto_t instance.
|
||||
* \memberof RagePhotoInstance
|
||||
* \param instance \p ragephoto_t instance
|
||||
*/
|
||||
LIBRAGEPHOTO_C_PUBLIC void ragephoto_close(ragephoto_t instance);
|
||||
|
||||
/** Returns the library version.
|
||||
* \relates RagePhotoInstance
|
||||
*/
|
||||
/** Returns the library version. */
|
||||
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_version();
|
||||
|
||||
#ifdef __cplusplus
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* 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:
|
||||
|
@ -16,8 +16,8 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef RAGEPHOTO_CXX_HPP
|
||||
#define RAGEPHOTO_CXX_HPP
|
||||
#ifndef RAGEPHOTO_HPP
|
||||
#define RAGEPHOTO_HPP
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "RagePhotoLibrary.h"
|
||||
|
@ -27,81 +27,78 @@
|
|||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
namespace ragephoto {
|
||||
|
||||
/**
|
||||
* \brief GTA V and RDR 2 Photo Parser.
|
||||
* \class ragephoto::photo RagePhoto.hpp RagePhoto
|
||||
*/
|
||||
class LIBRAGEPHOTO_CXX_PUBLIC photo
|
||||
class LIBRAGEPHOTO_CXX_PUBLIC RagePhoto
|
||||
{
|
||||
public:
|
||||
/** Default sizes */
|
||||
enum DefaultSize : uint32_t {
|
||||
DEFAULT_GTA5_PHOTOBUFFER = RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER, /**< GTA V default Photo Buffer Size */
|
||||
DEFAULT_RDR2_PHOTOBUFFER = RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER, /**< RDR 2 default Photo Buffer Size */
|
||||
DEFAULT_DESCBUFFER = RAGEPHOTO_DEFAULT_DESCBUFFER, /**< Default Description Buffer Size */
|
||||
DEFAULT_JSONBUFFER = RAGEPHOTO_DEFAULT_JSONBUFFER, /**< Default JSON Buffer Size */
|
||||
DEFAULT_TITLBUFFER = RAGEPHOTO_DEFAULT_TITLBUFFER, /**< Default Title Buffer Size */
|
||||
GTA5_HEADERSIZE = RAGEPHOTO_GTA5_HEADERSIZE, /**< GTA V Header Size */
|
||||
RDR2_HEADERSIZE = RAGEPHOTO_RDR2_HEADERSIZE, /**< RDR 2 Header Size */
|
||||
DEFAULT_GTA5_PHOTOBUFFER = 524288UL, /**< GTA V default Photo Buffer Size */
|
||||
DEFAULT_RDR2_PHOTOBUFFER = 1048576UL, /**< RDR 2 default Photo Buffer Size */
|
||||
DEFAULT_DESCBUFFER = 256UL, /**< Default Description Buffer Size */
|
||||
DEFAULT_JSONBUFFER = 3072UL, /**< Default JSON Buffer Size */
|
||||
DEFAULT_TITLBUFFER = 256UL, /**< Default Title Buffer Size */
|
||||
GTA5_HEADERSIZE = 264UL, /**< GTA V Header Size */
|
||||
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
|
||||
};
|
||||
/** Parsing and set errors */
|
||||
enum Error : int32_t {
|
||||
DescBufferTight = RAGEPHOTO_ERROR_DESCBUFFERTIGHT, /**< Description Buffer is too tight */
|
||||
DescMallocError = RAGEPHOTO_ERROR_DESCMALLOCERROR, /**< Description Buffer can't be allocated */
|
||||
DescReadError = RAGEPHOTO_ERROR_DESCREADERROR, /**< Description can't be read successfully */
|
||||
HeaderBufferTight = RAGEPHOTO_ERROR_HEADERBUFFERTIGHT, /**< Header Buffer is too tight */
|
||||
HeaderMallocError = RAGEPHOTO_ERROR_HEADERMALLOCERROR, /**< Header Buffer can't be allocated */
|
||||
IncompatibleFormat = RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT, /**< Format is incompatible */
|
||||
IncompleteChecksum = RAGEPHOTO_ERROR_INCOMPLETECHECKSUM, /**< Header checksum is incomplete */
|
||||
IncompleteDescBuffer = RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER, /**< Description Buffer Size is incomplete */
|
||||
IncompleteDescMarker = RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER, /**< Description Marker is incomplete */
|
||||
IncompleteDescOffset = RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET, /**< Description Offset is incomplete */
|
||||
IncompleteEOF = RAGEPHOTO_ERROR_INCOMPLETEEOF, /**< End Of File Offset is incomplete */
|
||||
IncompleteHeader = RAGEPHOTO_ERROR_INCOMPLETEHEADER, /**< Header is incomplete */
|
||||
IncompleteJendMarker = RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER, /**< JEND Marker is incomplete */
|
||||
IncompleteJpegMarker = RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER, /**< JPEG Marker is incomplete */
|
||||
IncompleteJsonBuffer = RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER, /**< JSON Buffer Size is incomplete */
|
||||
IncompleteJsonMarker = RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER, /**< JSON Marker incomplete */
|
||||
IncompleteJsonOffset = RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET, /**< JSON Offset incomplete */
|
||||
IncompletePhotoBuffer = RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER, /**< Photo Buffer Size is incomplete */
|
||||
IncompletePhotoSize = RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE, /**< Photo Size is incomplete */
|
||||
IncompleteTitleBuffer = RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER, /**< Title Buffer Size is incomplete */
|
||||
IncompleteTitleMarker = RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER, /**< Title Marker is incomplete */
|
||||
IncompleteTitleOffset = RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET, /**< Title Offset is incomplete */
|
||||
IncorrectDescMarker = RAGEPHOTO_ERROR_INCORRECTDESCMARKER, /**< Description Marker is incorrect */
|
||||
IncorrectJendMarker = RAGEPHOTO_ERROR_INCORRECTJENDMARKER, /**< JEND Marker is incorrect */
|
||||
IncorrectJpegMarker = RAGEPHOTO_ERROR_INCORRECTJPEGMARKER, /**< JPEG Marker is incorrect */
|
||||
IncorrectJsonMarker = RAGEPHOTO_ERROR_INCORRECTJSONMARKER, /**< JSON Marker is incorrect */
|
||||
IncorrectTitleMarker = RAGEPHOTO_ERROR_INCORRECTTITLEMARKER, /**< Title Marker is incorrect */
|
||||
JsonBufferTight = RAGEPHOTO_ERROR_JSONBUFFERTIGHT, /**< JSON Buffer is too tight */
|
||||
JsonMallocError = RAGEPHOTO_ERROR_JSONMALLOCERROR, /**< JSON Buffer can't be allocated */
|
||||
JsonReadError = RAGEPHOTO_ERROR_JSONREADERROR, /**< JSON can't be read successfully */
|
||||
NoError = RAGEPHOTO_ERROR_NOERROR, /**< Finished without errors */
|
||||
NoFormatIdentifier = RAGEPHOTO_ERROR_NOFORMATIDENTIFIER, /**< No format detected, empty file */
|
||||
PhotoBufferTight = RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT, /**< Photo Buffer is too tight */
|
||||
PhotoMallocError = RAGEPHOTO_ERROR_PHOTOMALLOCERROR, /**< Photo Buffer can't be allocated */
|
||||
PhotoReadError = RAGEPHOTO_ERROR_PHOTOREADERROR, /**< Photo can't be read */
|
||||
TitleBufferTight = RAGEPHOTO_ERROR_TITLEBUFFERTIGHT, /**< Title Buffer is too tight */
|
||||
TitleMallocError = RAGEPHOTO_ERROR_TITLEMALLOCERROR, /**< Title Buffer can't be allocated */
|
||||
TitleReadError = RAGEPHOTO_ERROR_TITLEREADERROR, /**< Title can't be read */
|
||||
UnicodeInitError = RAGEPHOTO_ERROR_UNICODEINITERROR, /**< Failed to initialise Unicode decoder */
|
||||
UnicodeHeaderError = RAGEPHOTO_ERROR_UNICODEHEADERERROR, /**< Header can't be encoded/decoded successfully */
|
||||
Uninitialised = RAGEPHOTO_ERROR_UNINITIALISED, /**< Uninitialised, file access failed */
|
||||
DescBufferTight = 39L, /**< Description Buffer is too tight */
|
||||
DescMallocError = 31L, /**< Description Buffer can't be allocated */
|
||||
DescReadError = 32L, /**< Description can't be read successfully */
|
||||
HeaderBufferTight = 35L, /**< Header Buffer is too tight */
|
||||
HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
|
||||
IncompatibleFormat = 2L, /**< Format is incompatible */
|
||||
IncompleteChecksum = 7L, /**< Header checksum is incomplete */
|
||||
IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
|
||||
IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
|
||||
IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
|
||||
IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
|
||||
IncompleteHeader = 3L, /**< Header is incomplete */
|
||||
IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
|
||||
IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
|
||||
IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
|
||||
IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
|
||||
IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
|
||||
IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
|
||||
IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
|
||||
IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
|
||||
IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
|
||||
IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
|
||||
IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
|
||||
IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
|
||||
IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
|
||||
IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
|
||||
IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
|
||||
JsonBufferTight = 37L, /**< JSON Buffer is too tight */
|
||||
JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
|
||||
JsonReadError = 22L, /**< JSON can't be read successfully */
|
||||
NoError = 255L, /**< Finished without errors */
|
||||
NoFormatIdentifier = 1L, /**< No format detected, empty file */
|
||||
PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
|
||||
PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
|
||||
PhotoReadError = 17L, /**< Photo can't be read */
|
||||
TitleBufferTight = 38L, /**< Title Buffer is too tight */
|
||||
TitleMallocError = 26L, /**< Title Buffer can't be allocated */
|
||||
TitleReadError = 27L, /**< Title can't be read */
|
||||
UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
|
||||
UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
|
||||
Uninitialised = 0L, /**< Uninitialised, file access failed */
|
||||
};
|
||||
/** Photo Formats */
|
||||
enum PhotoFormat : uint32_t {
|
||||
GTA5 = RAGEPHOTO_FORMAT_GTA5, /**< GTA V Photo Format */
|
||||
RDR2 = RAGEPHOTO_FORMAT_RDR2, /**< RDR 2 Photo Format */
|
||||
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
|
||||
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
|
||||
};
|
||||
/** Sign Initials */
|
||||
enum SignInitials : uint32_t {
|
||||
SIGTA5 = RAGEPHOTO_SIGNINITIAL_GTA5, /**< GTA V Sign Initial */
|
||||
SIRDR2 = RAGEPHOTO_SIGNINITIAL_RDR2, /**< RDR 2 Sign Initial */
|
||||
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
|
||||
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
|
||||
};
|
||||
photo();
|
||||
~photo();
|
||||
RagePhoto();
|
||||
~RagePhoto();
|
||||
void addParser(RagePhotoFormatParser *rp_parser); /**< Add a custom defined RagePhotoFormatParser. */
|
||||
static void clear(RagePhotoData *rp_data); /**< Resets the RagePhotoData object to default values. */
|
||||
void clear(); /**< Resets the RagePhotoData object to default values. */
|
||||
|
@ -133,8 +130,8 @@ public:
|
|||
uint64_t jpegSign() const; /**< Returns the Photo JPEG sign. */
|
||||
uint32_t jpegSize() const; /**< Returns the Photo JPEG data size. */
|
||||
const char* description() const; /**< Returns the Photo description. */
|
||||
const char* header() const; /**< Returns the Photo header. */
|
||||
const char* json() const; /**< Returns the Photo JSON data. */
|
||||
const char* header() const; /**< Returns the Photo header. */
|
||||
const char* title() const; /**< Returns the Photo title. */
|
||||
static const char* version(); /**< Returns the library version. */
|
||||
static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
|
||||
|
@ -157,8 +154,8 @@ public:
|
|||
* \param ok \p true when saved successfully
|
||||
*/
|
||||
const std::string save(bool *ok = nullptr);
|
||||
bool saveFile(const char *filename, uint32_t photoFormat); /**< Saves a Photo to a file. */
|
||||
bool saveFile(const char *filename); /**< Saves a Photo to a file. */
|
||||
bool saveFile(const std::string &filename, uint32_t photoFormat); /**< Saves a Photo to a file. */
|
||||
bool saveFile(const std::string &filename); /**< Saves a Photo to a file. */
|
||||
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
|
||||
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
|
||||
size_t saveSize(uint32_t photoFormat); /**< Returns the Photo save file size. */
|
||||
|
@ -170,7 +167,6 @@ public:
|
|||
bool setData(RagePhotoData *rp_data, bool takeCopy = true); /**< Sets the internal RagePhotoData object. */
|
||||
void setDescription(const char *description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
|
||||
void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */
|
||||
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0); /**< Sets the Photo header. */
|
||||
/** Sets the Photo JPEG data.
|
||||
* \param data JPEG data
|
||||
* \param size JPEG data size
|
||||
|
@ -183,15 +179,13 @@ public:
|
|||
*/
|
||||
bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
|
||||
void setJson(const char *json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
|
||||
static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true); /**< Sets a library flag. */
|
||||
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0); /**< Sets the Photo header. */
|
||||
void setTitle(const char *title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
|
||||
|
||||
private:
|
||||
RagePhotoData *m_data;
|
||||
RagePhotoFormatParser *m_parser;
|
||||
};
|
||||
|
||||
} // ragephoto
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // RAGEPHOTO_CXX_HPP
|
||||
#endif // RAGEPHOTO_HPP
|
1
src/RagePhotoA
Normal file
1
src/RagePhotoA
Normal file
|
@ -0,0 +1 @@
|
|||
#include "RagePhotoA.hpp"
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* 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:
|
||||
|
@ -16,93 +16,88 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef RAGEPHOTO_C_HPP
|
||||
#define RAGEPHOTO_C_HPP
|
||||
#ifndef RAGEPHOTOA_HPP
|
||||
#define RAGEPHOTOA_HPP
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "RagePhoto.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
namespace ragephoto_c {
|
||||
|
||||
/**
|
||||
* \brief GTA V and RDR 2 Photo Parser (C API wrapper).
|
||||
* \class ragephoto_c::photo RagePhoto.hpp RagePhoto
|
||||
*/
|
||||
class photo
|
||||
class RagePhotoA
|
||||
{
|
||||
public:
|
||||
/** Default sizes */
|
||||
enum DefaultSize : uint32_t {
|
||||
DEFAULT_GTA5_PHOTOBUFFER = RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER, /**< GTA V default Photo Buffer Size */
|
||||
DEFAULT_RDR2_PHOTOBUFFER = RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER, /**< RDR 2 default Photo Buffer Size */
|
||||
DEFAULT_DESCBUFFER = RAGEPHOTO_DEFAULT_DESCBUFFER, /**< Default Description Buffer Size */
|
||||
DEFAULT_JSONBUFFER = RAGEPHOTO_DEFAULT_JSONBUFFER, /**< Default JSON Buffer Size */
|
||||
DEFAULT_TITLBUFFER = RAGEPHOTO_DEFAULT_TITLBUFFER, /**< Default Title Buffer Size */
|
||||
GTA5_HEADERSIZE = RAGEPHOTO_GTA5_HEADERSIZE, /**< GTA V Header Size */
|
||||
RDR2_HEADERSIZE = RAGEPHOTO_RDR2_HEADERSIZE, /**< RDR 2 Header Size */
|
||||
DEFAULT_GTA5_PHOTOBUFFER = 524288UL, /**< GTA V default Photo Buffer Size */
|
||||
DEFAULT_RDR2_PHOTOBUFFER = 1048576UL, /**< RDR 2 default Photo Buffer Size */
|
||||
DEFAULT_DESCBUFFER = 256UL, /**< Default Description Buffer Size */
|
||||
DEFAULT_JSONBUFFER = 3072UL, /**< Default JSON Buffer Size */
|
||||
DEFAULT_TITLBUFFER = 256UL, /**< Default Title Buffer Size */
|
||||
GTA5_HEADERSIZE = 264UL, /**< GTA V Header Size */
|
||||
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
|
||||
};
|
||||
/** Parsing and set errors */
|
||||
enum Error : int32_t {
|
||||
DescBufferTight = RAGEPHOTO_ERROR_DESCBUFFERTIGHT, /**< Description Buffer is too tight */
|
||||
DescMallocError = RAGEPHOTO_ERROR_DESCMALLOCERROR, /**< Description Buffer can't be allocated */
|
||||
DescReadError = RAGEPHOTO_ERROR_DESCREADERROR, /**< Description can't be read successfully */
|
||||
HeaderBufferTight = RAGEPHOTO_ERROR_HEADERBUFFERTIGHT, /**< Header Buffer is too tight */
|
||||
HeaderMallocError = RAGEPHOTO_ERROR_HEADERMALLOCERROR, /**< Header Buffer can't be allocated */
|
||||
IncompatibleFormat = RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT, /**< Format is incompatible */
|
||||
IncompleteChecksum = RAGEPHOTO_ERROR_INCOMPLETECHECKSUM, /**< Header checksum is incomplete */
|
||||
IncompleteDescBuffer = RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER, /**< Description Buffer Size is incomplete */
|
||||
IncompleteDescMarker = RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER, /**< Description Marker is incomplete */
|
||||
IncompleteDescOffset = RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET, /**< Description Offset is incomplete */
|
||||
IncompleteEOF = RAGEPHOTO_ERROR_INCOMPLETEEOF, /**< End Of File Offset is incomplete */
|
||||
IncompleteHeader = RAGEPHOTO_ERROR_INCOMPLETEHEADER, /**< Header is incomplete */
|
||||
IncompleteJendMarker = RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER, /**< JEND Marker is incomplete */
|
||||
IncompleteJpegMarker = RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER, /**< JPEG Marker is incomplete */
|
||||
IncompleteJsonBuffer = RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER, /**< JSON Buffer Size is incomplete */
|
||||
IncompleteJsonMarker = RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER, /**< JSON Marker incomplete */
|
||||
IncompleteJsonOffset = RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET, /**< JSON Offset incomplete */
|
||||
IncompletePhotoBuffer = RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER, /**< Photo Buffer Size is incomplete */
|
||||
IncompletePhotoSize = RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE, /**< Photo Size is incomplete */
|
||||
IncompleteTitleBuffer = RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER, /**< Title Buffer Size is incomplete */
|
||||
IncompleteTitleMarker = RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER, /**< Title Marker is incomplete */
|
||||
IncompleteTitleOffset = RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET, /**< Title Offset is incomplete */
|
||||
IncorrectDescMarker = RAGEPHOTO_ERROR_INCORRECTDESCMARKER, /**< Description Marker is incorrect */
|
||||
IncorrectJendMarker = RAGEPHOTO_ERROR_INCORRECTJENDMARKER, /**< JEND Marker is incorrect */
|
||||
IncorrectJpegMarker = RAGEPHOTO_ERROR_INCORRECTJPEGMARKER, /**< JPEG Marker is incorrect */
|
||||
IncorrectJsonMarker = RAGEPHOTO_ERROR_INCORRECTJSONMARKER, /**< JSON Marker is incorrect */
|
||||
IncorrectTitleMarker = RAGEPHOTO_ERROR_INCORRECTTITLEMARKER, /**< Title Marker is incorrect */
|
||||
JsonBufferTight = RAGEPHOTO_ERROR_JSONBUFFERTIGHT, /**< JSON Buffer is too tight */
|
||||
JsonMallocError = RAGEPHOTO_ERROR_JSONMALLOCERROR, /**< JSON Buffer can't be allocated */
|
||||
JsonReadError = RAGEPHOTO_ERROR_JSONREADERROR, /**< JSON can't be read successfully */
|
||||
NoError = RAGEPHOTO_ERROR_NOERROR, /**< Finished without errors */
|
||||
NoFormatIdentifier = RAGEPHOTO_ERROR_NOFORMATIDENTIFIER, /**< No format detected, empty file */
|
||||
PhotoBufferTight = RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT, /**< Photo Buffer is too tight */
|
||||
PhotoMallocError = RAGEPHOTO_ERROR_PHOTOMALLOCERROR, /**< Photo Buffer can't be allocated */
|
||||
PhotoReadError = RAGEPHOTO_ERROR_PHOTOREADERROR, /**< Photo can't be read */
|
||||
TitleBufferTight = RAGEPHOTO_ERROR_TITLEBUFFERTIGHT, /**< Title Buffer is too tight */
|
||||
TitleMallocError = RAGEPHOTO_ERROR_TITLEMALLOCERROR, /**< Title Buffer can't be allocated */
|
||||
TitleReadError = RAGEPHOTO_ERROR_TITLEREADERROR, /**< Title can't be read */
|
||||
UnicodeInitError = RAGEPHOTO_ERROR_UNICODEINITERROR, /**< Failed to initialise Unicode decoder */
|
||||
UnicodeHeaderError = RAGEPHOTO_ERROR_UNICODEHEADERERROR, /**< Header can't be encoded/decoded successfully */
|
||||
Uninitialised = RAGEPHOTO_ERROR_UNINITIALISED, /**< Uninitialised, file access failed */
|
||||
DescBufferTight = 39L, /**< Description Buffer is too tight */
|
||||
DescMallocError = 31L, /**< Description Buffer can't be allocated */
|
||||
DescReadError = 32L, /**< Description can't be read successfully */
|
||||
HeaderBufferTight = 35L, /**< Header Buffer is too tight */
|
||||
HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
|
||||
IncompatibleFormat = 2L, /**< Format is incompatible */
|
||||
IncompleteChecksum = 7L, /**< Header checksum is incomplete */
|
||||
IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
|
||||
IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
|
||||
IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
|
||||
IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
|
||||
IncompleteHeader = 3L, /**< Header is incomplete */
|
||||
IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
|
||||
IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
|
||||
IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
|
||||
IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
|
||||
IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
|
||||
IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
|
||||
IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
|
||||
IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
|
||||
IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
|
||||
IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
|
||||
IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
|
||||
IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
|
||||
IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
|
||||
IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
|
||||
IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
|
||||
JsonBufferTight = 37L, /**< JSON Buffer is too tight */
|
||||
JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
|
||||
JsonReadError = 22L, /**< JSON can't be read successfully */
|
||||
NoError = 255L, /**< Finished without errors */
|
||||
NoFormatIdentifier = 1L, /**< No format detected, empty file */
|
||||
PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
|
||||
PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
|
||||
PhotoReadError = 17L, /**< Photo can't be read */
|
||||
TitleBufferTight = 38L, /**< Title Buffer is too tight */
|
||||
TitleMallocError = 26L, /**< Title Buffer can't be allocated */
|
||||
TitleReadError = 27L, /**< Title can't be read */
|
||||
UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
|
||||
UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
|
||||
Uninitialised = 0L, /**< Uninitialised, file access failed */
|
||||
};
|
||||
/** Photo Formats */
|
||||
enum PhotoFormat : uint32_t {
|
||||
GTA5 = RAGEPHOTO_FORMAT_GTA5, /**< GTA V Photo Format */
|
||||
RDR2 = RAGEPHOTO_FORMAT_RDR2, /**< RDR 2 Photo Format */
|
||||
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
|
||||
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
|
||||
};
|
||||
/** Sign Initials */
|
||||
enum SignInitials : uint32_t {
|
||||
SIGTA5 = RAGEPHOTO_SIGNINITIAL_GTA5, /**< GTA V Sign Initial */
|
||||
SIRDR2 = RAGEPHOTO_SIGNINITIAL_RDR2, /**< RDR 2 Sign Initial */
|
||||
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
|
||||
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
|
||||
};
|
||||
photo() {
|
||||
RagePhotoA() {
|
||||
instance = ragephoto_open();
|
||||
if (!instance)
|
||||
throw std::runtime_error("ragephoto_t instance can't be allocated");
|
||||
}
|
||||
~photo() {
|
||||
~RagePhotoA() {
|
||||
ragephoto_close(instance);
|
||||
}
|
||||
/** Add a custom defined RagePhotoFormatParser. */
|
||||
|
@ -198,14 +193,14 @@ public:
|
|||
const char* description() const {
|
||||
return ragephoto_getphotodesc(instance);
|
||||
}
|
||||
/** Returns the Photo header. */
|
||||
const char* header() const {
|
||||
return ragephoto_getphotoheader(instance);
|
||||
}
|
||||
/** Returns the Photo JSON data. */
|
||||
const char* json() const {
|
||||
return ragephoto_getphotojson(instance);
|
||||
}
|
||||
/** Returns the Photo header. */
|
||||
const char* header() const {
|
||||
return ragephoto_getphotoheader(instance);
|
||||
}
|
||||
/** Returns the Photo title. */
|
||||
const char* title() const {
|
||||
return ragephoto_getphototitle(instance);
|
||||
|
@ -314,10 +309,6 @@ public:
|
|||
void setFormat(uint32_t photoFormat) {
|
||||
ragephoto_setphotoformat(instance, photoFormat);
|
||||
}
|
||||
/** Sets the Photo header. */
|
||||
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
|
||||
ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
|
||||
}
|
||||
/** Sets the Photo JPEG data.
|
||||
* \param data JPEG data
|
||||
* \param size JPEG data size
|
||||
|
@ -337,9 +328,9 @@ public:
|
|||
void setJson(const char *json, uint32_t bufferSize = 0) {
|
||||
ragephoto_setphotojson(instance, json, bufferSize);
|
||||
}
|
||||
/** Sets a library flag. */
|
||||
static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true) {
|
||||
ragephoto_setlibraryflag(flag, state);
|
||||
/** Sets the Photo header. */
|
||||
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
|
||||
ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
|
||||
}
|
||||
/** Sets the Photo title. */
|
||||
void setTitle(const char *title, uint32_t bufferSize = 0) {
|
||||
|
@ -349,8 +340,6 @@ public:
|
|||
private:
|
||||
ragephoto_t instance;
|
||||
};
|
||||
|
||||
} // ragephoto_c
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // RAGEPHOTO_C_HPP
|
||||
#endif // RAGEPHOTOA_HPP
|
1
src/RagePhotoB
Normal file
1
src/RagePhotoB
Normal file
|
@ -0,0 +1 @@
|
|||
#include "RagePhotoB.hpp"
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2023-2024 Syping
|
||||
* 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:
|
||||
|
@ -16,33 +16,28 @@
|
|||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef RAGEPHOTO_HPP
|
||||
#define RAGEPHOTO_HPP
|
||||
#ifndef RAGEPHOTOB_HPP
|
||||
#define RAGEPHOTOB_HPP
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "RagePhotoLibrary.h"
|
||||
#ifdef LIBRAGEPHOTO_CXX_ONLY
|
||||
#include "ragephoto_cxx.hpp"
|
||||
typedef ragephoto::photo RagePhoto;
|
||||
#include "RagePhoto.hpp"
|
||||
typedef RagePhoto RagePhotoB;
|
||||
#elif defined LIBRAGEPHOTO_CXX_C
|
||||
#ifdef LIBRAGEPHOTO_STATIC
|
||||
#include "ragephoto_cxx.hpp"
|
||||
typedef ragephoto::photo RagePhoto;
|
||||
#include "RagePhoto.hpp"
|
||||
typedef RagePhoto RagePhotoB;
|
||||
#else
|
||||
#ifdef LIBRAGEPHOTO_PREFER_NATIVE
|
||||
#include "ragephoto_cxx.hpp"
|
||||
typedef ragephoto::photo RagePhoto;
|
||||
#else
|
||||
#include "ragephoto_c.hpp"
|
||||
typedef ragephoto_c::photo RagePhoto;
|
||||
#endif // LIBRAGEPHOTO_PREFER_NATIVE
|
||||
#include "RagePhotoA.hpp"
|
||||
typedef RagePhotoA RagePhotoB;
|
||||
#endif // LIBRAGEPHOTO_STATIC
|
||||
#elif defined LIBRAGEPHOTO_C_ONLY
|
||||
#include "ragephoto_c.hpp"
|
||||
typedef ragephoto_c::photo RagePhoto;
|
||||
#include "RagePhotoA.hpp"
|
||||
typedef RagePhotoA RagePhotoB;
|
||||
#else
|
||||
#error "Could not determine best RagePhoto implementation, libragephoto installation might be corrupt!"
|
||||
#endif // LIBRAGEPHOTO_CXX_ONLY
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // RAGEPHOTO_HPP
|
||||
#endif // RAGEPHOTOB_HPP
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2023-2024 Syping
|
||||
* 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:
|
||||
|
@ -22,7 +22,7 @@
|
|||
/* CMAKE CONFIG BEGIN */
|
||||
#define @LIBRAGEPHOTO_API@
|
||||
#define @LIBRAGEPHOTO_LIBTYPE@
|
||||
#define RAGEPHOTO_CXX_STD @RAGEPHOTO_CXX_STANDARD@
|
||||
#define RAGEPHOTO_CXX_STD @CMAKE_CXX_STANDARD@
|
||||
#define RAGEPHOTO_VERSION "@ragephoto_VERSION@"
|
||||
#define RAGEPHOTO_VERSION_MAJOR @ragephoto_VERSION_MAJOR@
|
||||
#define RAGEPHOTO_VERSION_MINOR @ragephoto_VERSION_MINOR@
|
|
@ -57,18 +57,6 @@
|
|||
#endif // _WIN32
|
||||
/* RAGEPHOTO LIBRARY BINDING END */
|
||||
|
||||
/* RAGEPHOTO LIBRARY ENDIAN START */
|
||||
#ifdef _WIN32
|
||||
#define LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
#else
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
#elif _BYTE_ORDER == _LITTLE_ENDIAN
|
||||
#define LIBRAGEPHOTO_LITTLE_ENDIAN
|
||||
#endif
|
||||
#endif // _WIN32
|
||||
/* RAGEPHOTO LIBRARY ENDIAN END */
|
||||
|
||||
/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY BEGIN */
|
||||
#ifdef LIBRAGEPHOTO_WASM
|
||||
#ifdef LIBRAGEPHOTO_CXX_ONLY
|
143
src/RagePhotoTypedefs.h
Normal file
143
src/RagePhotoTypedefs.h
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*****************************************************************************
|
||||
* 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
|
|
@ -1,150 +0,0 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* \struct RagePhotoInstance RagePhoto.h
|
||||
*/
|
||||
typedef struct RagePhotoInstance {
|
||||
RagePhotoData *data; /**< Pointer for internal data */
|
||||
RagePhotoFormatParser *parser; /**< Pointer for internal format parser */
|
||||
} RagePhotoInstance;
|
||||
|
||||
/** RagePhoto library flags. */
|
||||
typedef enum RagePhotoLibraryFlag {
|
||||
RAGEPHOTO_FLAG_LEGACY_NULL_RETURN = 1 << 0 /**< Flag to enable legacy NULL return */
|
||||
} RagePhotoLibraryFlag;
|
||||
|
||||
/* RagePhoto default sizes */
|
||||
#define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER UINT32_C(524288) /**< GTA V default Photo Buffer Size */
|
||||
#define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER UINT32_C(1048576) /**< RDR 2 default Photo Buffer Size */
|
||||
#define RAGEPHOTO_DEFAULT_DESCBUFFER UINT32_C(256) /**< Default Description Buffer Size */
|
||||
#define RAGEPHOTO_DEFAULT_JSONBUFFER UINT32_C(3072) /**< Default JSON Buffer Size */
|
||||
#define RAGEPHOTO_DEFAULT_TITLBUFFER UINT32_C(256) /**< Default Title Buffer Size */
|
||||
#define RAGEPHOTO_GTA5_HEADERSIZE UINT32_C(264) /**< GTA V Header Size */
|
||||
#define RAGEPHOTO_RDR2_HEADERSIZE UINT32_C(272) /**< RDR 2 Header Size */
|
||||
|
||||
/* RagePhoto error codes */
|
||||
#define RAGEPHOTO_ERROR_DESCBUFFERTIGHT INT32_C(39) /**< Description Buffer is too tight */
|
||||
#define RAGEPHOTO_ERROR_DESCMALLOCERROR INT32_C(31) /**< Description Buffer can't be allocated */
|
||||
#define RAGEPHOTO_ERROR_DESCREADERROR INT32_C(32) /**< Description can't be read successfully */
|
||||
#define RAGEPHOTO_ERROR_HEADERBUFFERTIGHT INT32_C(35) /**< Header Buffer is too tight */
|
||||
#define RAGEPHOTO_ERROR_HEADERMALLOCERROR INT32_C(4) /**< Header Buffer can't be allocated */
|
||||
#define RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT INT32_C(2) /**< Format is incompatible */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETECHECKSUM INT32_C(7) /**< Header checksum is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER INT32_C(30) /**< Description Buffer Size is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER INT32_C(28) /**< Description Marker is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET INT32_C(11) /**< Description Offset is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEEOF INT32_C(8) /**< End Of File Offset is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEHEADER INT32_C(3) /**< Header is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER INT32_C(33) /**< JEND Marker is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER INT32_C(12) /**< JPEG Marker is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER INT32_C(20) /**< JSON Buffer Size is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER INT32_C(18) /**< JSON Marker incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET INT32_C(9) /**< JSON Offset incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER INT32_C(14) /**< Photo Buffer Size is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE INT32_C(15) /**< Photo Size is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER INT32_C(25) /**< Title Buffer Size is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER INT32_C(23) /**< Title Marker is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET INT32_C(10) /**< Title Offset is incomplete */
|
||||
#define RAGEPHOTO_ERROR_INCORRECTDESCMARKER INT32_C(29) /**< Description Marker is incorrect */
|
||||
#define RAGEPHOTO_ERROR_INCORRECTJENDMARKER INT32_C(34) /**< JEND Marker is incorrect */
|
||||
#define RAGEPHOTO_ERROR_INCORRECTJPEGMARKER INT32_C(13) /**< JPEG Marker is incorrect */
|
||||
#define RAGEPHOTO_ERROR_INCORRECTJSONMARKER INT32_C(19) /**< JSON Marker is incorrect */
|
||||
#define RAGEPHOTO_ERROR_INCORRECTTITLEMARKER INT32_C(24) /**< Title Marker is incorrect */
|
||||
#define RAGEPHOTO_ERROR_JSONBUFFERTIGHT INT32_C(37) /**< JSON Buffer is too tight */
|
||||
#define RAGEPHOTO_ERROR_JSONMALLOCERROR INT32_C(21) /**< JSON Buffer can't be allocated */
|
||||
#define RAGEPHOTO_ERROR_JSONREADERROR INT32_C(22) /**< JSON can't be read successfully */
|
||||
#define RAGEPHOTO_ERROR_NOERROR INT32_C(255) /**< Finished without errors */
|
||||
#define RAGEPHOTO_ERROR_NOFORMATIDENTIFIER INT32_C(1) /**< No format detected, empty file */
|
||||
#define RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT INT32_C(36) /**< Photo Buffer is too tight */
|
||||
#define RAGEPHOTO_ERROR_PHOTOMALLOCERROR INT32_C(16) /**< Photo Buffer can't be allocated */
|
||||
#define RAGEPHOTO_ERROR_PHOTOREADERROR INT32_C(17) /**< Photo can't be read */
|
||||
#define RAGEPHOTO_ERROR_TITLEBUFFERTIGHT INT32_C(38) /**< Title Buffer is too tight */
|
||||
#define RAGEPHOTO_ERROR_TITLEMALLOCERROR INT32_C(26) /**< Title Buffer can't be allocated */
|
||||
#define RAGEPHOTO_ERROR_TITLEREADERROR INT32_C(27) /**< Title can't be read */
|
||||
#define RAGEPHOTO_ERROR_UNICODEINITERROR INT32_C(5) /**< Failed to initialise Unicode decoder */
|
||||
#define RAGEPHOTO_ERROR_UNICODEHEADERERROR INT32_C(6) /**< Header can't be encoded/decoded successfully */
|
||||
#define RAGEPHOTO_ERROR_UNINITIALISED INT32_C(0) /**< Uninitialised, file access failed */
|
||||
|
||||
/* RagePhoto formats */
|
||||
#define RAGEPHOTO_FORMAT_GTA5 UINT32_C(0x01000000) /**< GTA V Photo Format */
|
||||
#define RAGEPHOTO_FORMAT_RDR2 UINT32_C(0x04000000) /**< RDR 2 Photo Format */
|
||||
|
||||
/* RagePhoto sign initials */
|
||||
#define RAGEPHOTO_SIGNINITIAL_GTA5 UINT32_C(0xE47AB81C) /**< GTA V Sign Initial */
|
||||
#define RAGEPHOTO_SIGNINITIAL_RDR2 UINT32_C(0x00FEEB1E) /**< RDR 2 Sign Initial */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // RAGEPHOTOTYPEDEFS_H
|
|
@ -1 +0,0 @@
|
|||
#include "ragephoto_c.hpp"
|
|
@ -1 +0,0 @@
|
|||
#include "ragephoto_cxx.hpp"
|
|
@ -1,25 +0,0 @@
|
|||
##############################################################################
|
||||
# libragephoto for Python
|
||||
# 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:
|
||||
#
|
||||
# 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.
|
||||
##############################################################################
|
||||
|
||||
from .ragephoto import RagePhoto
|
||||
|
||||
__all__ = [
|
||||
"libragephoto_loader", # libragephoto Loader Module
|
||||
"ragephoto", # RagePhoto Module
|
||||
"RagePhoto" # RagePhoto API
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
##############################################################################
|
||||
# libragephoto for Python
|
||||
# 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.
|
||||
##############################################################################
|
||||
|
||||
VERSION = (@ragephoto_VERSION_MAJOR@, @ragephoto_VERSION_MINOR@, @ragephoto_VERSION_PATCH@)
|
||||
__version__ = "@ragephoto_VERSION@"
|
|
@ -1,88 +0,0 @@
|
|||
##############################################################################
|
||||
# libragephoto for Python
|
||||
# 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:
|
||||
#
|
||||
# 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.
|
||||
##############################################################################
|
||||
|
||||
from ctypes import *
|
||||
from ctypes.util import find_library
|
||||
from pathlib import Path
|
||||
from platform import system
|
||||
|
||||
if system() == "Windows":
|
||||
bundle_library_path = Path(__file__).parent.resolve() / "libragephoto.dll"
|
||||
if bundle_library_path.is_file():
|
||||
library_path = str(bundle_library_path)
|
||||
else:
|
||||
bundle_library_path = Path(__file__).parent.resolve() / "libragephoto.so"
|
||||
if bundle_library_path.is_file():
|
||||
library_path = str(bundle_library_path)
|
||||
else:
|
||||
library_path = find_library("ragephoto")
|
||||
|
||||
if not library_path:
|
||||
raise ImportError("libragephoto is required.")
|
||||
|
||||
libragephoto = cdll.LoadLibrary(library_path)
|
||||
libragephoto.ragephoto_open.restype = c_void_p
|
||||
libragephoto.ragephoto_clear.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_close.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_load.argtypes = [c_void_p, POINTER(c_char), c_size_t]
|
||||
libragephoto.ragephoto_load.restype = c_bool
|
||||
libragephoto.ragephoto_loadfile.argtypes = [c_void_p, c_char_p]
|
||||
libragephoto.ragephoto_loadfile.restype = c_bool
|
||||
libragephoto.ragephoto_error.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_error.restype = c_int32
|
||||
libragephoto.ragephoto_getphotodesc.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphotodesc.restype = c_char_p
|
||||
libragephoto.ragephoto_getphotoformat.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphotoformat.restype = c_uint32
|
||||
libragephoto.ragephoto_getphotojpeg.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphotojpeg.restype = POINTER(c_char)
|
||||
libragephoto.ragephoto_getphotojson.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphotojson.restype = c_char_p
|
||||
libragephoto.ragephoto_getphotoheader.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphotoheader.restype = c_char_p
|
||||
libragephoto.ragephoto_getphotosign.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphotosign.restype = c_uint64
|
||||
libragephoto.ragephoto_getphotosignf.argtypes = [c_void_p, c_uint32]
|
||||
libragephoto.ragephoto_getphotosignf.restype = c_uint64
|
||||
libragephoto.ragephoto_getphotosize.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphotosize.restype = c_uint32
|
||||
libragephoto.ragephoto_getphototitle.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getphototitle.restype = c_char_p
|
||||
libragephoto.ragephoto_getsavesize.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_getsavesize.restype = c_size_t
|
||||
libragephoto.ragephoto_getsavesizef.argtypes = [c_void_p, c_uint32]
|
||||
libragephoto.ragephoto_getsavesizef.restype = c_size_t
|
||||
libragephoto.ragephoto_save.argtypes = [c_void_p, POINTER(c_char)]
|
||||
libragephoto.ragephoto_save.restype = c_bool
|
||||
libragephoto.ragephoto_savef.argtypes = [c_void_p, POINTER(c_char), c_uint32]
|
||||
libragephoto.ragephoto_savef.restype = c_bool
|
||||
libragephoto.ragephoto_savefile.argtypes = [c_void_p, c_char_p]
|
||||
libragephoto.ragephoto_savefile.restype = c_bool
|
||||
libragephoto.ragephoto_savefilef.argtypes = [c_void_p, c_char_p, c_uint32]
|
||||
libragephoto.ragephoto_savefilef.restype = c_bool
|
||||
libragephoto.ragephoto_setbufferdefault.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_setbufferoffsets.argtypes = [c_void_p]
|
||||
libragephoto.ragephoto_setphotodesc.argtypes = [c_void_p, c_char_p, c_uint32]
|
||||
libragephoto.ragephoto_setphotoformat.argtypes = [c_void_p, c_uint32]
|
||||
libragephoto.ragephoto_setphotojpeg.argtypes = [c_void_p, POINTER(c_char), c_uint32, c_uint32]
|
||||
libragephoto.ragephoto_setphotojpeg.restype = c_bool
|
||||
libragephoto.ragephoto_setphotojson.argtypes = [c_void_p, c_char_p, c_uint32]
|
||||
libragephoto.ragephoto_setphotoheader.argtypes = [c_void_p, c_char_p, c_uint32]
|
||||
libragephoto.ragephoto_setphotoheader2.argtypes = [c_void_p, c_char_p, c_uint32, c_uint32]
|
||||
libragephoto.ragephoto_setphototitle.argtypes = [c_void_p, c_char_p, c_uint32]
|
||||
libragephoto.ragephoto_version.restype = c_char_p
|
|
@ -1,24 +0,0 @@
|
|||
[project]
|
||||
name = "ragephoto"
|
||||
version = "@ragephoto_VERSION@"
|
||||
authors = [
|
||||
{ name = "Syping" },
|
||||
]
|
||||
description = "libragephoto for Python"
|
||||
requires-python = ">=3.6"
|
||||
classifiers = [
|
||||
"License :: OSI Approved :: BSD-2-Clause",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project.urls]
|
||||
"Homepage" = "https://libragephoto.syping.de/"
|
||||
|
||||
[tool.setuptools]
|
||||
include-package-data = true
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
ragephoto = ["*.dll", "*.so"]
|
|
@ -1,251 +0,0 @@
|
|||
##############################################################################
|
||||
# libragephoto for Python
|
||||
# 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:
|
||||
#
|
||||
# 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.
|
||||
##############################################################################
|
||||
|
||||
from .libragephoto_loader import *
|
||||
from enum import IntEnum
|
||||
from json import loads as parseJson
|
||||
from json import dumps as serializeJson
|
||||
|
||||
class RagePhoto:
|
||||
class DefaultSize(IntEnum):
|
||||
DEFAULT_GTA5_PHOTOBUFFER = 524288
|
||||
DEFAULT_RDR2_PHOTOBUFFER = 1048576
|
||||
DEFAULT_DESCBUFFER = 256
|
||||
DEFAULT_JSONBUFFER = 3072
|
||||
DEFAULT_TITLBUFFER = 256
|
||||
|
||||
class Error(IntEnum):
|
||||
DescBufferTight = 39
|
||||
DescMallocError = 31
|
||||
DescReadError = 32
|
||||
HeaderBufferTight = 35
|
||||
HeaderMallocError = 4
|
||||
IncompatibleFormat = 2
|
||||
IncompleteChecksum = 7
|
||||
IncompleteDescBuffer = 30
|
||||
IncompleteDescMarker = 28
|
||||
IncompleteDescOffset = 11
|
||||
IncompleteEOF = 8
|
||||
IncompleteHeader = 3
|
||||
IncompleteJendMarker = 33
|
||||
IncompleteJpegMarker = 12
|
||||
IncompleteJsonBuffer = 20
|
||||
IncompleteJsonMarker = 18
|
||||
IncompleteJsonOffset = 9
|
||||
IncompletePhotoBuffer = 14
|
||||
IncompletePhotoSize = 15
|
||||
IncompleteTitleBuffer = 25
|
||||
IncompleteTitleMarker = 23
|
||||
IncompleteTitleOffset = 10
|
||||
IncorrectDescMarker = 29
|
||||
IncorrectJendMarker = 34
|
||||
IncorrectJpegMarker = 13
|
||||
IncorrectJsonMarker = 19
|
||||
IncorrectTitleMarker = 24
|
||||
JsonBufferTight = 37
|
||||
JsonMallocError = 21
|
||||
JsonReadError = 22
|
||||
NoError = 255
|
||||
NoFormatIdentifier = 1
|
||||
PhotoBufferTight = 36
|
||||
PhotoMallocError = 16
|
||||
PhotoReadError = 17
|
||||
TitleBufferTight = 38
|
||||
TitleMallocError = 26
|
||||
TitleReadError = 27
|
||||
UnicodeInitError = 5
|
||||
UnicodeHeaderError = 6
|
||||
Uninitialised = 0
|
||||
|
||||
class PhotoFormat(IntEnum):
|
||||
GTA5 = 0x01000000
|
||||
RDR2 = 0x04000000
|
||||
|
||||
def __init__(self):
|
||||
self.__instance = libragephoto.ragephoto_open()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
libragephoto.ragephoto_close(self.__instance)
|
||||
self.__instance = None
|
||||
|
||||
def __del__(self):
|
||||
if self.__instance is not None:
|
||||
libragephoto.ragephoto_close(self.__instance)
|
||||
|
||||
def clear(self):
|
||||
libragephoto.ragephoto_clear(self.__instance)
|
||||
|
||||
def load(self, data):
|
||||
return libragephoto.ragephoto_load(self.__instance, data, len(data))
|
||||
|
||||
def loadFile(self, file):
|
||||
if isinstance(file, str):
|
||||
return libragephoto.ragephoto_loadfile(self.__instance, file.encode())
|
||||
else:
|
||||
return libragephoto.ragephoto_loadfile(self.__instance, file)
|
||||
|
||||
def error(self):
|
||||
return libragephoto.ragephoto_error(self.__instance)
|
||||
|
||||
def description(self):
|
||||
_desc = libragephoto.ragephoto_getphotodesc(self.__instance)
|
||||
if _desc:
|
||||
return _desc
|
||||
else:
|
||||
return b""
|
||||
|
||||
def format(self):
|
||||
return libragephoto.ragephoto_getphotoformat(self.__instance)
|
||||
|
||||
def jpeg(self):
|
||||
_jpeg = libragephoto.ragephoto_getphotojpeg(self.__instance)
|
||||
if _jpeg:
|
||||
return _jpeg[:self.jpegSize()]
|
||||
else:
|
||||
return b""
|
||||
|
||||
def jpegSign(self, photoFormat = None):
|
||||
if photoFormat is None:
|
||||
return libragephoto.ragephoto_getphotosign(self.__instance)
|
||||
else:
|
||||
return libragephoto.ragephoto_getphotosignf(self.__instance, photoFormat)
|
||||
|
||||
def jpegSize(self):
|
||||
return libragephoto.ragephoto_getphotosize(self.__instance)
|
||||
|
||||
def json(self):
|
||||
_json = libragephoto.ragephoto_getphotojson(self.__instance)
|
||||
if _json:
|
||||
return _json
|
||||
else:
|
||||
return b""
|
||||
|
||||
def header(self):
|
||||
_header = libragephoto.ragephoto_getphotoheader(self.__instance)
|
||||
if _header:
|
||||
return _header
|
||||
else:
|
||||
return b""
|
||||
|
||||
def save(self, photoFormat = None):
|
||||
_data = bytearray(self.saveSize(photoFormat))
|
||||
_ptr = (c_char * len(_data)).from_buffer(_data)
|
||||
if photoFormat is None:
|
||||
_ret = libragephoto.ragephoto_save(self.__instance, _ptr)
|
||||
else:
|
||||
_ret = libragephoto.ragephoto_savef(self.__instance, _ptr, photoFormat)
|
||||
if _ret:
|
||||
return _data
|
||||
else:
|
||||
return None
|
||||
|
||||
def saveFile(self, file, photoFormat = None):
|
||||
if isinstance(file, str):
|
||||
_file = file.encode()
|
||||
else:
|
||||
_file = file
|
||||
if photoFormat is None:
|
||||
return libragephoto.ragephoto_savefile(self.__instance, _file)
|
||||
else:
|
||||
return libragephoto.ragephoto_savefilef(self.__instance, _file, photoFormat)
|
||||
|
||||
def saveSize(self, photoFormat = None):
|
||||
if photoFormat is None:
|
||||
return libragephoto.ragephoto_getsavesize(self.__instance)
|
||||
else:
|
||||
return libragephoto.ragephoto_getsavesizef(self.__instance, photoFormat)
|
||||
|
||||
def setBufferDefault(self):
|
||||
return libragephoto.ragephoto_setbufferdefault(self.__instance)
|
||||
|
||||
def setBufferOffsets(self):
|
||||
return libragephoto.ragephoto_setbufferoffsets(self.__instance)
|
||||
|
||||
def setDescription(self, desc, buffer = None):
|
||||
if isinstance(desc, str):
|
||||
_desc = desc.encode()
|
||||
else:
|
||||
_desc = desc
|
||||
if buffer is None:
|
||||
libragephoto.ragephoto_setphotodesc(self.__instance, _desc, self.DefaultSize.DEFAULT_DESCBUFFER)
|
||||
else:
|
||||
libragephoto.ragephoto_setphotodesc(self.__instance, _desc, buffer)
|
||||
|
||||
def setFormat(self, photoFormat):
|
||||
libragephoto.ragephoto_setphotoformat(self.__instance, photoFormat)
|
||||
|
||||
def setJpeg(self, jpeg, buffer = None):
|
||||
_buffer = 0
|
||||
if buffer is None:
|
||||
_format = self.format()
|
||||
if _format == self.PhotoFormat.GTA5:
|
||||
_buffer = self.DefaultSize.DEFAULT_GTA5_PHOTOBUFFER
|
||||
elif _format == self.PhotoFormat.RDR2:
|
||||
_buffer = self.DefaultSize.DEFAULT_RDR2_PHOTOBUFFER
|
||||
if _buffer < len(jpeg):
|
||||
_buffer = len(jpeg)
|
||||
return libragephoto.ragephoto_setphotojpeg(self.__instance, jpeg, len(jpeg), _buffer)
|
||||
|
||||
def setJson(self, json, buffer = None):
|
||||
if isinstance(json, str):
|
||||
_json = json.encode()
|
||||
else:
|
||||
_json = json
|
||||
if buffer is None:
|
||||
libragephoto.ragephoto_setphotojson(self.__instance, _json, self.DefaultSize.DEFAULT_JSONBUFFER)
|
||||
else:
|
||||
libragephoto.ragephoto_setphotojson(self.__instance, _json, buffer)
|
||||
|
||||
def setHeader(self, header, headerSum1, headerSum2 = 0):
|
||||
if isinstance(header, str):
|
||||
_header = header.encode()
|
||||
else:
|
||||
_header = header
|
||||
libragephoto.ragephoto_setphotoheader2(self.__instance, _header, headerSum1, headerSum2)
|
||||
|
||||
def setTitle(self, title, buffer = None):
|
||||
if isinstance(title, str):
|
||||
_title = title.encode()
|
||||
else:
|
||||
_title = title
|
||||
if buffer is None:
|
||||
libragephoto.ragephoto_setphototitle(self.__instance, _title, self.DefaultSize.DEFAULT_TITLBUFFER)
|
||||
else:
|
||||
libragephoto.ragephoto_setphototitle(self.__instance, _title, buffer)
|
||||
|
||||
def title(self):
|
||||
_title = libragephoto.ragephoto_getphototitle(self.__instance)
|
||||
if _title:
|
||||
return _title
|
||||
else:
|
||||
return b""
|
||||
|
||||
def updateSign(self):
|
||||
try:
|
||||
_json = parseJson(self.json())
|
||||
except JSONDecodeError:
|
||||
return False
|
||||
_json["sign"] = self.jpegSign()
|
||||
self.setJson(serializeJson(_json, separators=(',', ':')))
|
||||
return True
|
||||
|
||||
def version(self):
|
||||
return libragephoto.ragephoto_version()
|
|
@ -1,34 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
##############################################################################
|
||||
# libragephoto for Python
|
||||
# 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.
|
||||
##############################################################################
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="ragephoto",
|
||||
version="@ragephoto_VERSION@",
|
||||
author="Syping",
|
||||
packages=["ragephoto"],
|
||||
package_data={"ragephoto":["*.dll","*.so"]},
|
||||
include_package_data=True,
|
||||
url="https://libragephoto.syping.de/",
|
||||
description="libragephoto for Python",
|
||||
classifiers=[
|
||||
"License :: OSI Approved :: BSD-2-Clause",
|
||||
]
|
||||
)
|
|
@ -206,7 +206,7 @@ int main(int argc, char *argv[])
|
|||
// English
|
||||
src_s = sizeof(photoHeader_english);
|
||||
dst_s = sizeof(photoString);
|
||||
char *src_english = reinterpret_cast<char*>(photoHeader_english);
|
||||
char *src_english = (char*)photoHeader_english;
|
||||
char *dst_english = photoString;
|
||||
ret = iconv(iconv_in, &src_english, &src_s, &dst_english, &dst_s);
|
||||
if (ret == static_cast<size_t>(-1))
|
||||
|
@ -217,7 +217,7 @@ int main(int argc, char *argv[])
|
|||
// Japanese
|
||||
src_s = sizeof(photoHeader_japanese);
|
||||
dst_s = sizeof(photoString);
|
||||
char *src_japanese = reinterpret_cast<char*>(photoHeader_japanese);
|
||||
char *src_japanese = (char*)photoHeader_japanese;
|
||||
char *dst_japanese = photoString;
|
||||
ret = iconv(iconv_in, &src_japanese, &src_s, &dst_japanese, &dst_s);
|
||||
if (ret == static_cast<size_t>(-1))
|
||||
|
@ -228,7 +228,7 @@ int main(int argc, char *argv[])
|
|||
// Korean
|
||||
src_s = sizeof(photoHeader_korean);
|
||||
dst_s = sizeof(photoString);
|
||||
char *src_korean = reinterpret_cast<char*>(photoHeader_korean);
|
||||
char *src_korean = (char*)photoHeader_korean;
|
||||
char *dst_korean = photoString;
|
||||
ret = iconv(iconv_in, &src_korean, &src_s, &dst_korean, &dst_s);
|
||||
if (ret == static_cast<size_t>(-1))
|
||||
|
@ -239,7 +239,7 @@ int main(int argc, char *argv[])
|
|||
// Russian
|
||||
src_s = sizeof(photoHeader_russian);
|
||||
dst_s = sizeof(photoString);
|
||||
char *src_russian = reinterpret_cast<char*>(photoHeader_russian);
|
||||
char *src_russian = (char*)photoHeader_russian;
|
||||
char *dst_russian = photoString;
|
||||
ret = iconv(iconv_in, &src_russian, &src_s, &dst_russian, &dst_s);
|
||||
if (ret == static_cast<size_t>(-1))
|
||||
|
@ -250,7 +250,7 @@ int main(int argc, char *argv[])
|
|||
// Taiwanese
|
||||
src_s = sizeof(photoHeader_taiwanese);
|
||||
dst_s = sizeof(photoString);
|
||||
char *src_taiwanese = reinterpret_cast<char*>(photoHeader_taiwanese);
|
||||
char *src_taiwanese = (char*)photoHeader_taiwanese;
|
||||
char *dst_taiwanese = photoString;
|
||||
ret = iconv(iconv_in, &src_taiwanese, &src_s, &dst_taiwanese, &dst_s);
|
||||
if (ret == static_cast<size_t>(-1))
|
||||
|
|
Loading…
Reference in a new issue