Compare commits

...

12 commits

Author SHA1 Message Date
Syping c74b4a415f libragephoto 0.5.1 release
- ragephoto_open: fix memory leak when instance can't be allocated
- ragephoto_loadfile: fix file handle leak when data heap can't be
allocated
- ragephotodata_load: fix printf print types
- RagePhoto.cpp: remove std namespace from C functions
2023-10-25 16:33:01 +02:00
Syping 6fdc075741 libragephoto 0.5.0 release
- CMakeLists.txt: add missing RagePhotoA for C API builds
- updated README.md
2023-06-11 23:07:41 +02:00
Syping 12507be85d libragephoto: add RagePhotoB for best implementation
CMakeLists.txt: add RagePhotoB class, improve settings clarification
doc/build.doc: add RAGEPHOTO_C_LIBRARY flag
doc/index.doc: correct RagePhoto.h header
doc/usage.doc: fix minor documentation issue, clarify class differences
ragephoto-gtkviewer: use RagePhotoB class
ragephoto-qtviewer: use RagePhotoB class
RagePhoto-Extract.cpp: use RagePhotoB class
RagePhoto.cpp: LIBRAGEPHOTO_C_API -> LIBRAGEPHOTO_CXX_C
RagePhotoA.hpp: simplify brief
RagePhotoB.hpp: add best implementation detection
RagePhotoLibrary.h: fix WASM C API inclusion by default
README.md: add RAGEPHOTO_C_LIBRARY flag
2023-06-11 05:41:32 +02:00
Syping d7943e552d GitHub Actions: fix WebAssembly C build 2023-06-09 05:05:42 +02:00
Syping b838c505a4 libragephoto: C++ headers have now .hpp extension
RagePhoto.h -> RagePhoto.hpp
RagePhotoA.h -> RagePhotoA.hpp
RagePhotoC.h -> RagePhoto.h

unicode.cmake: exclude codecvt for C builds
GitHub Actions: separate C and CXX builds
2023-06-07 06:57:23 +02:00
Syping 6acf7b7338 RagePhoto.c: fix potential memory issue 2023-06-07 06:12:24 +02:00
Syping 24e0d9c03e RagePhoto.c: fix potential memory issue 2023-06-07 06:09:37 +02:00
Syping 6066d92ee9 RagePhoto.c: fix potential memory issue, fix debug code 2023-06-06 21:05:55 +02:00
Syping c3e838cecf RagePhoto.c: fix iconv code 2023-06-06 20:27:51 +02:00
Syping 8a29d8aebe GitHub Actions: use C library for WebAssembly build
RagePhoto.c: fix header includes
2023-06-06 20:22:20 +02:00
Syping 3046cbd077 libragephoto: introduce C library port
CMakeLists.txt: fixes for MSVC and C library support
RagePhoto: non C++11 support
RagePhotoC: clarify C instance support in comment
RagePhotoTypedefs: add typedefs for C library
2023-06-06 19:39:22 +02:00
Syping af3580dff4 libragephoto 0.4.1 release
RagePhotoA: fix setData() pointer passthrough
2023-05-25 23:30:26 +02:00
29 changed files with 2048 additions and 649 deletions

29
.github/workflows/ubuntu-c.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: Ubuntu C
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake gcc g++ ninja-build -qq
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install/usr/local
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Ubuntu
path: |
${{github.workspace}}/install/

View file

@ -1,4 +1,4 @@
name: Ubuntu
name: Ubuntu CXX
on: push

30
.github/workflows/webassembly-c.yml vendored Normal file
View file

@ -0,0 +1,30 @@
name: WebAssembly C
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup emsdk
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_C_LIBRARY=ON -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload
uses: actions/upload-artifact@v2
with:
name: WebAssembly
path: |
${{github.workspace}}/build/libragephoto.js
${{github.workspace}}/build/libragephoto.wasm

View file

@ -1,4 +1,4 @@
name: WebAssembly
name: WebAssembly CXX
on: push

34
.github/workflows/windows-c.yml vendored Normal file
View file

@ -0,0 +1,34 @@
name: Windows C
on: push
jobs:
Release:
runs-on: windows-latest
env:
BUILD_TYPE: Release
strategy:
matrix:
arch:
- amd64
- amd64_x86
- amd64_arm64
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -DRAGEPHOTO_UNICODE=wincvt -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Windows MSVC ${{matrix.arch}}
path: |
${{github.workspace}}/install/

View file

@ -1,4 +1,4 @@
name: Windows
name: Windows CXX
on: push

View file

@ -17,7 +17,7 @@
****************************************************************************]]
cmake_minimum_required(VERSION 3.8)
project(ragephoto VERSION 0.4.0 LANGUAGES CXX)
project(ragephoto VERSION 0.5.1 LANGUAGES C CXX)
include(GNUInstallDirs)
# RagePhoto CMake includes
@ -32,14 +32,33 @@ else()
endif()
# RagePhoto Source files
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF)
if (RAGEPHOTO_C_LIBRARY)
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.c
)
else()
set(RAGEPHOTO_HEADERS
src/RagePhoto
src/RagePhoto.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
endif()
# RagePhoto Library Type
option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF)
@ -52,7 +71,7 @@ else()
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
@ -60,14 +79,19 @@ if (RAGEPHOTO_BENCHMARK)
endif()
# RagePhoto C API
if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h
src/RagePhotoC.h
)
if (RAGEPHOTO_C_LIBRARY)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_ONLY)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI)
if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_C)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_ONLY)
endif()
endif()
# RagePhoto Win32 Shared Resources
@ -99,7 +123,7 @@ target_compile_definitions(ragephoto PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
if (MSVC)
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
@ -143,7 +167,6 @@ option(RAGEPHOTO_EXTRACT "Build libragephoto with ragephoto-extract" ${RPTL_ON})
if (RAGEPHOTO_EXTRACT)
# RagePhoto-Extract Source files
if (RAGEPHOTO_C_API)
enable_language(C)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
@ -161,7 +184,7 @@ if (RAGEPHOTO_EXTRACT)
set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
if (MSVC AND NOT RAGEPHOTO_C_API)
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)

View file

@ -19,6 +19,7 @@ sudo cmake --install libragephoto-build
`-DCMAKE_CXX_STANDARD=17`
`-DRAGEPHOTO_BENCHMARK=ON`
`-DRAGEPHOTO_C_API=OFF`
`-DRAGEPHOTO_C_LIBRARY=ON`
`-DRAGEPHOTO_DOC=ON`
`-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON`
`-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON`
@ -27,7 +28,7 @@ sudo cmake --install libragephoto-build
#### RagePhoto API
[RagePhoto C API](https://libragephoto.syping.de/doc/RagePhotoC_8h.html)
[RagePhoto C API](https://libragephoto.syping.de/doc/RagePhoto_8h.html)
[RagePhoto C++ API](https://libragephoto.syping.de/doc/classRagePhoto.html)
#### libragephoto Documentation

View file

@ -60,7 +60,7 @@ else()
"UNICODE_WINCVT"
)
message("-- UnicodeCvt - wincvt")
elseif (CODECVT_COMPAT)
elseif (CODECVT_COMPAT AND NOT RAGEPHOTO_C_LIBRARY)
list(APPEND LIBRAGEPHOTO_DEFINES
"UNICODE_CODECVT"
)
@ -70,5 +70,7 @@ else()
"UNICODE_ICONV"
)
message("-- UnicodeCvt - iconv")
else()
message("-- UnicodeCvt - none")
endif()
endif()

View file

@ -33,6 +33,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s MODULARIZE=1"
"SHELL:-s WASM=1"
"SHELL:-s WASM_BIGINT=1"
"SHELL:-s EXPORT_NAME=libragephotoModule"
"SHELL:-s EXPORTED_FUNCTIONS=_free,_malloc"
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"

View file

@ -20,6 +20,7 @@ To customise your libragephoto build, the following <a href="#flags">Optional CM
-DCMAKE_CXX_STANDARD=17
-DRAGEPHOTO_BENCHMARK=ON
-DRAGEPHOTO_C_API=OFF
-DRAGEPHOTO_C_LIBRARY=ON
-DRAGEPHOTO_DOC=ON
-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON
-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON

View file

@ -14,7 +14,7 @@
<b>Reference</b>
RagePhoto (C++ API)
RagePhotoA (C++ API based on C API)
RagePhotoC.h (C API)
RagePhoto.h (C API)
RagePhotoData (Data Object Struct)
RagePhotoFormatParser (Custom Format Parser Struct)

View file

@ -4,10 +4,10 @@
<h4 id="cxx_include_usage">Including and using RagePhoto</h4>
Include RagePhoto.h or RagePhotoA.h
Include RagePhoto (C++ native), RagePhotoA (C API wrapper) or \link RagePhotoB.hpp RagePhotoB \endlink (best implementation)
\code{.cpp}
#include <RagePhoto.h>
#include <RagePhoto>
\endcode
Create a RagePhoto object
@ -128,7 +128,7 @@ const bool loaded = image.loadFromData(QByteArray::fromRawData(ragePhoto.jpegDat
Using the JSON in Boost.JSON
\code{.cpp}
std::error_code ec;
boost::json::error_code ec;
const boost::json::value jv = boost::json::parse(ragePhoto.json(), ec);
if (ec)
return;
@ -137,8 +137,7 @@ if (ec)
Using the JSON in Qt
\code{.cpp}
const QByteArray json = ragePhoto.json();
const QJsonDocument jd = QJsonDocument::fromJson(json);
const QJsonDocument jd = QJsonDocument::fromJson(ragePhoto.json());
if (jd.isNull())
return;
\endcode

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto.h>
#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();

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto.h>
#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
src/RagePhoto Normal file
View file

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

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhotoC.h"
#include "RagePhoto.h"
#include <stdio.h>
int main(int argc, char *argv[])

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhoto.h"
#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;

1230
src/RagePhoto.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -16,9 +16,9 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhoto.hpp"
#ifdef LIBRAGEPHOTO_CXX_C
#include "RagePhoto.h"
#ifdef LIBRAGEPHOTO_C_API
#include "RagePhotoC.h"
#endif
#include <cstdlib>
@ -54,7 +54,7 @@ inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t ou
readLen = inputLen - *pos;
if (readLen > outputLen)
readLen = outputLen;
std::memcpy(output, &input[*pos], readLen);
memcpy(output, &input[*pos], readLen);
*pos = *pos + readLen;
return readLen;
}
@ -67,7 +67,7 @@ inline size_t writeBuffer(const void *input, char *output, size_t *pos, size_t o
return 0;
if (inputLen > maxLen)
writeLen = maxLen;
std::memcpy(&output[*pos], input, writeLen);
memcpy(&output[*pos], input, writeLen);
*pos = *pos + writeLen;
return writeLen;
}
@ -78,33 +78,33 @@ inline bool writeDataChar(const char *input, char **output)
if (*output) {
const size_t dst_s = strlen(*output) + 1;
if (dst_s > src_s) {
char *t_output = static_cast<char*>(std::realloc(*output, src_s));
char *t_output = static_cast<char*>(realloc(*output, src_s));
if (!t_output) {
return false;
}
*output = t_output;
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
else if (dst_s < src_s) {
char *t_output = static_cast<char*>(std::malloc(src_s));
char *t_output = static_cast<char*>(malloc(src_s));
if (!t_output) {
return false;
}
std::free(*output);
free(*output);
*output = t_output;
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
else {
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
}
else {
char *t_output = static_cast<char*>(std::malloc(src_s));
char *t_output = static_cast<char*>(malloc(src_s));
if (!t_output) {
return false;
}
*output = t_output;
std::memcpy(*output, input, src_s);
memcpy(*output, input, src_s);
}
return true;
}
@ -143,53 +143,53 @@ inline uint32_t joaatFromInitial(const char *data, size_t size, uint32_t init_va
/* BEGIN OF RAGEPHOTO CLASS */
RagePhoto::RagePhoto()
{
m_data = static_cast<RagePhotoData*>(std::malloc(sizeof(RagePhotoData)));
m_data = static_cast<RagePhotoData*>(malloc(sizeof(RagePhotoData)));
if (!m_data)
throw std::runtime_error("RagePhotoData data struct can't be allocated");
std::memset(m_data, 0, sizeof(RagePhotoData));
m_parser = static_cast<RagePhotoFormatParser*>(std::malloc(sizeof(RagePhotoFormatParser)));
memset(m_data, 0, sizeof(RagePhotoData));
m_parser = static_cast<RagePhotoFormatParser*>(malloc(sizeof(RagePhotoFormatParser)));
if (!m_parser)
throw std::runtime_error("RagePhotoFormatParser parser struct can't be allocated");
std::memset(m_parser, 0, sizeof(RagePhotoFormatParser));
memset(m_parser, 0, sizeof(RagePhotoFormatParser));
setBufferDefault(m_data);
}
RagePhoto::~RagePhoto()
{
std::free(m_data->jpeg);
std::free(m_data->description);
std::free(m_data->json);
std::free(m_data->header);
std::free(m_data->title);
std::free(m_data);
std::free(m_parser);
free(m_data->jpeg);
free(m_data->description);
free(m_data->json);
free(m_data->header);
free(m_data->title);
free(m_data);
free(m_parser);
}
void RagePhoto::addParser(RagePhotoFormatParser *rp_parser)
{
if (rp_parser) {
RagePhotoFormatParser n_parser[1]{};
if (!std::memcmp(&n_parser[0], rp_parser, sizeof(RagePhotoFormatParser)))
if (!memcmp(&n_parser[0], rp_parser, sizeof(RagePhotoFormatParser)))
return;
size_t length;
for (length = 0; std::memcmp(&n_parser[0], &m_parser[length], sizeof(RagePhotoFormatParser)); length++);
RagePhotoFormatParser *t_parser = static_cast<RagePhotoFormatParser*>(std::realloc(m_parser, (length + 2 * sizeof(RagePhotoFormatParser))));
for (length = 0; memcmp(&n_parser[0], &m_parser[length], sizeof(RagePhotoFormatParser)); length++);
RagePhotoFormatParser *t_parser = static_cast<RagePhotoFormatParser*>(realloc(m_parser, (length + 2 * sizeof(RagePhotoFormatParser))));
if (!t_parser)
throw std::runtime_error("RagePhotoFormatParser array can't be expanded");
m_parser = t_parser;
std::memcpy(&m_parser[length], rp_parser, sizeof(RagePhotoFormatParser));
std::memset(&m_parser[length+1], 0, sizeof(RagePhotoFormatParser));
memcpy(&m_parser[length], rp_parser, sizeof(RagePhotoFormatParser));
memset(&m_parser[length+1], 0, sizeof(RagePhotoFormatParser));
}
}
void RagePhoto::clear(RagePhotoData *rp_data)
{
std::free(rp_data->jpeg);
std::free(rp_data->description);
std::free(rp_data->json);
std::free(rp_data->header);
std::free(rp_data->title);
std::memset(rp_data, 0, sizeof(RagePhotoData));
free(rp_data->jpeg);
free(rp_data->description);
free(rp_data->json);
free(rp_data->header);
free(rp_data->title);
memset(rp_data, 0, sizeof(RagePhotoData));
setBufferDefault(rp_data);
}
@ -221,7 +221,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->photoFormat, uInt32Buffer, 4);
memcpy(&rp_data->photoFormat, uInt32Buffer, 4);
#else
rp_data->photoFormat = charToUInt32LE(uInt32Buffer);
#endif
@ -242,19 +242,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
const size_t photoHeader_size = photoHeader_string.size() + 1;
rp_data->header = static_cast<char*>(std::malloc(photoHeader_size));
rp_data->header = static_cast<char*>(malloc(photoHeader_size));
if (!rp_data->header) {
rp_data->error = Error::HeaderMallocError; // 4
return false;
}
std::memcpy(rp_data->header, photoHeader_string.c_str(), photoHeader_size);
memcpy(rp_data->header, photoHeader_string.c_str(), photoHeader_size);
#elif defined UNICODE_ICONV
iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE");
if (iconv_in == (iconv_t)-1) {
rp_data->error = Error::UnicodeInitError; // 4
return false;
}
rp_data->header = static_cast<char*>(std::malloc(256));
rp_data->header = static_cast<char*>(malloc(256));
if (!rp_data->header) {
rp_data->error = Error::HeaderMallocError; // 4
iconv_close(iconv_in);
@ -271,14 +271,14 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#elif defined UNICODE_WINCVT
rp_data->header = static_cast<char*>(std::malloc(256));
rp_data->header = static_cast<char*>(malloc(256));
if (!rp_data->header) {
rp_data->error = Error::HeaderMallocError; // 4
return false;
}
const int converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<wchar_t*>(photoHeader), -1, rp_data->header, 256, NULL, NULL);
if (converted == 0) {
std::free(rp_data->header);
free(rp_data->header);
rp_data->header = nullptr;
rp_data->error = Error::UnicodeHeaderError; // 6
return false;
@ -291,7 +291,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->headerSum, uInt32Buffer, 4);
memcpy(&rp_data->headerSum, uInt32Buffer, 4);
#else
rp_data->headerSum = charToUInt32LE(uInt32Buffer);
#endif
@ -304,7 +304,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
char n_formatCheckBuffer[4]{};
if (std::memcmp(formatCheckBuffer, n_formatCheckBuffer, 4)) {
if (memcmp(formatCheckBuffer, n_formatCheckBuffer, 4)) {
rp_data->error = Error::IncompatibleFormat; // 2
return false;
}
@ -315,7 +315,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->headerSum2, uInt32Buffer, 4);
memcpy(&rp_data->headerSum2, uInt32Buffer, 4);
#else
rp_data->headerSum2 = charToUInt32LE(uInt32Buffer);
#endif
@ -328,7 +328,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->endOfFile, uInt32Buffer, 4);
memcpy(&rp_data->endOfFile, uInt32Buffer, 4);
#else
rp_data->endOfFile = charToUInt32LE(uInt32Buffer);
#endif
@ -339,7 +339,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jsonOffset, uInt32Buffer, 4);
memcpy(&rp_data->jsonOffset, uInt32Buffer, 4);
#else
rp_data->jsonOffset = charToUInt32LE(uInt32Buffer);
#endif
@ -349,7 +349,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->titlOffset, uInt32Buffer, 4);
memcpy(&rp_data->titlOffset, uInt32Buffer, 4);
#else
rp_data->titlOffset = charToUInt32LE(uInt32Buffer);
#endif
@ -360,7 +360,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->descOffset, uInt32Buffer, 4);
memcpy(&rp_data->descOffset, uInt32Buffer, 4);
#else
rp_data->descOffset = charToUInt32LE(uInt32Buffer);
#endif
@ -371,7 +371,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJpegMarker; // 12
return false;
}
if (std::memcmp(markerBuffer, "JPEG", 4)) {
if (memcmp(markerBuffer, "JPEG", 4)) {
rp_data->error = Error::IncorrectJpegMarker; // 13
return false;
}
@ -382,7 +382,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jpegBuffer, uInt32Buffer, 4);
memcpy(&rp_data->jpegBuffer, uInt32Buffer, 4);
#else
rp_data->jpegBuffer = charToUInt32LE(uInt32Buffer);
#endif
@ -393,19 +393,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jpegSize, uInt32Buffer, 4);
memcpy(&rp_data->jpegSize, uInt32Buffer, 4);
#else
rp_data->jpegSize = charToUInt32LE(uInt32Buffer);
#endif
rp_data->jpeg = static_cast<char*>(std::malloc(rp_data->jpegSize));
rp_data->jpeg = static_cast<char*>(malloc(rp_data->jpegSize));
if (!rp_data->jpeg) {
rp_data->error = Error::PhotoMallocError; // 16
return false;
}
size = readBuffer(data, rp_data->jpeg, &pos, rp_data->jpegSize, length);
if (size != rp_data->jpegSize) {
std::free(rp_data->jpeg);
free(rp_data->jpeg);
rp_data->jpeg = nullptr;
rp_data->error = Error::PhotoReadError; // 17
return false;
@ -417,7 +417,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJsonMarker; // 18
return false;
}
if (std::memcmp(markerBuffer, "JSON", 4)) {
if (memcmp(markerBuffer, "JSON", 4)) {
rp_data->error = Error::IncorrectJsonMarker; // 19
return false;
}
@ -428,19 +428,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->jsonBuffer, uInt32Buffer, 4);
memcpy(&rp_data->jsonBuffer, uInt32Buffer, 4);
#else
rp_data->jsonBuffer = charToUInt32LE(uInt32Buffer);
#endif
rp_data->json = static_cast<char*>(std::malloc(rp_data->jsonBuffer));
rp_data->json = static_cast<char*>(malloc(rp_data->jsonBuffer));
if (!rp_data->json) {
rp_data->error = Error::JsonMallocError; // 21
return false;
}
size = readBuffer(data, rp_data->json, &pos, rp_data->jsonBuffer, length);
if (size != rp_data->jsonBuffer) {
std::free(rp_data->json);
free(rp_data->json);
rp_data->json = nullptr;
rp_data->error = Error::JsonReadError; // 22
return false;
@ -452,7 +452,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteTitleMarker; // 23
return false;
}
if (std::memcmp(markerBuffer, "TITL", 4)) {
if (memcmp(markerBuffer, "TITL", 4)) {
rp_data->error = Error::IncorrectTitleMarker; // 24
return false;
}
@ -463,19 +463,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->titlBuffer, uInt32Buffer, 4);
memcpy(&rp_data->titlBuffer, uInt32Buffer, 4);
#else
rp_data->titlBuffer = charToUInt32LE(uInt32Buffer);
#endif
rp_data->title = static_cast<char*>(std::malloc(rp_data->titlBuffer));
rp_data->title = static_cast<char*>(malloc(rp_data->titlBuffer));
if (!rp_data->title) {
rp_data->error = Error::TitleMallocError; // 26
return false;
}
size = readBuffer(data, rp_data->title, &pos, rp_data->titlBuffer, length);
if (size != rp_data->titlBuffer) {
std::free(rp_data->title);
free(rp_data->title);
rp_data->title = nullptr;
rp_data->error = Error::TitleReadError; // 27
return false;
@ -487,7 +487,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteDescMarker; // 28
return false;
}
if (std::memcmp(markerBuffer, "DESC", 4)) {
if (memcmp(markerBuffer, "DESC", 4)) {
rp_data->error = Error::IncorrectDescMarker; // 29
return false;
}
@ -498,19 +498,19 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->descBuffer, uInt32Buffer, 4);
memcpy(&rp_data->descBuffer, uInt32Buffer, 4);
#else
rp_data->descBuffer = charToUInt32LE(uInt32Buffer);
#endif
rp_data->description = static_cast<char*>(std::malloc(rp_data->descBuffer));
rp_data->description = static_cast<char*>(malloc(rp_data->descBuffer));
if (!rp_data->description) {
rp_data->error = Error::DescMallocError; // 31
return false;
}
size = readBuffer(data, rp_data->description, &pos, rp_data->descBuffer, length);
if (size != rp_data->descBuffer) {
std::free(rp_data->description);
free(rp_data->description);
rp_data->description = nullptr;
rp_data->error = Error::DescReadError; // 32
return false;
@ -522,7 +522,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJendMarker; // 33
return false;
}
if (std::memcmp(markerBuffer, "JEND", 4)) {
if (memcmp(markerBuffer, "JEND", 4)) {
rp_data->error = Error::IncorrectJendMarker; // 34
return false;
}
@ -569,7 +569,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
}
else if (rp_parser) {
RagePhotoFormatParser n_parser[1]{};
for (size_t i = 0; std::memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
for (size_t i = 0; memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
if (rp_data->photoFormat == rp_parser[i].photoFormat)
if (rp_parser[i].funcLoad)
return (rp_parser[i].funcLoad)(rp_data, data, length);
@ -771,7 +771,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
char uInt32Buffer[4];
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &photoFormat, 4);
memcpy(uInt32Buffer, &photoFormat, 4);
#else
uInt32ToCharLE(static_cast<uint32_t>(photoFormat), uInt32Buffer);
#endif
@ -783,7 +783,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->headerSum, 4);
memcpy(uInt32Buffer, &rp_data->headerSum, 4);
#else
uInt32ToCharLE(rp_data->headerSum, uInt32Buffer);
#endif
@ -794,7 +794,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer(n_formatCheckBuffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->headerSum2, 4);
memcpy(uInt32Buffer, &rp_data->headerSum2, 4);
#else
uInt32ToCharLE(rp_data->headerSum2, uInt32Buffer);
#endif
@ -803,28 +803,28 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
const size_t headerSize = pos;
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->endOfFile, 4);
memcpy(uInt32Buffer, &rp_data->endOfFile, 4);
#else
uInt32ToCharLE(rp_data->endOfFile, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jsonOffset, 4);
memcpy(uInt32Buffer, &rp_data->jsonOffset, 4);
#else
uInt32ToCharLE(rp_data->jsonOffset, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->titlOffset, 4);
memcpy(uInt32Buffer, &rp_data->titlOffset, 4);
#else
uInt32ToCharLE(rp_data->titlOffset, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->descOffset, 4);
memcpy(uInt32Buffer, &rp_data->descOffset, 4);
#else
uInt32ToCharLE(rp_data->descOffset, uInt32Buffer);
#endif
@ -833,14 +833,14 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("JPEG", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jpegBuffer, 4);
memcpy(uInt32Buffer, &rp_data->jpegBuffer, 4);
#else
uInt32ToCharLE(rp_data->jpegBuffer, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jpegSize, 4);
memcpy(uInt32Buffer, &rp_data->jpegSize, 4);
#else
uInt32ToCharLE(rp_data->jpegSize, uInt32Buffer);
#endif
@ -855,7 +855,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("JSON", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->jsonBuffer, 4);
memcpy(uInt32Buffer, &rp_data->jsonBuffer, 4);
#else
uInt32ToCharLE(rp_data->jsonBuffer, uInt32Buffer);
#endif
@ -870,7 +870,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("TITL", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->titlBuffer, 4);
memcpy(uInt32Buffer, &rp_data->titlBuffer, 4);
#else
uInt32ToCharLE(rp_data->titlBuffer, uInt32Buffer);
#endif
@ -885,7 +885,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer("DESC", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->descBuffer, 4);
memcpy(uInt32Buffer, &rp_data->descBuffer, 4);
#else
uInt32ToCharLE(rp_data->descBuffer, uInt32Buffer);
#endif
@ -909,7 +909,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
}
else if (rp_parser) {
RagePhotoFormatParser n_parser[1]{};
for (size_t i = 0; std::memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
for (size_t i = 0; memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
if (photoFormat == rp_parser[i].photoFormat)
if (rp_parser[i].funcSave)
return (rp_parser[i].funcSave)(rp_data, data, photoFormat);
@ -970,7 +970,11 @@ bool RagePhoto::saveFile(const std::string &filename, uint32_t photoFormat)
m_data->error = Error::Uninitialised; // 0
return false;
}
#if (RAGEPHOTO_CXX_STD >= 11) && (__cplusplus >= 201103L)
ofs << sdata;
#else
ofs.write(sdata.data(), sdata.size());
#endif
ok = ofs.good();
ofs.close();
return ok;
@ -992,7 +996,7 @@ size_t RagePhoto::saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePho
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; std::memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
for (size_t i = 0; memcmp(&n_parser[0], &rp_parser[i], sizeof(RagePhotoFormatParser)); i++) {
if (photoFormat == rp_parser[i].photoFormat)
if (rp_parser[i].funcSaveSz)
return (rp_parser[i].funcSaveSz)(rp_data, photoFormat);
@ -1053,59 +1057,59 @@ bool RagePhoto::setData(RagePhotoData *rp_data, bool takeCopy)
if (rp_data->header) {
const size_t headerSize = strlen(rp_data->header) + 1;
m_data->header = static_cast<char*>(std::malloc(headerSize));
m_data->header = static_cast<char*>(malloc(headerSize));
if (!m_data->header)
return false;
std::memcpy(m_data->header, rp_data->header, headerSize);
memcpy(m_data->header, rp_data->header, headerSize);
m_data->headerSum = rp_data->headerSum;
m_data->headerSum2 = rp_data->headerSum2;
}
if (rp_data->jpeg) {
m_data->jpeg = static_cast<char*>(std::malloc(rp_data->jpegSize));
m_data->jpeg = static_cast<char*>(malloc(rp_data->jpegSize));
if (!m_data->jpeg)
return false;
std::memcpy(m_data->jpeg, rp_data->jpeg, rp_data->jpegSize);
memcpy(m_data->jpeg, rp_data->jpeg, rp_data->jpegSize);
m_data->jpegSize = rp_data->jpegSize;
m_data->jpegBuffer = rp_data->jpegBuffer;
}
if (rp_data->json) {
const size_t jsonSize = strlen(rp_data->json) + 1;
m_data->json = static_cast<char*>(std::malloc(jsonSize));
m_data->json = static_cast<char*>(malloc(jsonSize));
if (!m_data->json)
return false;
std::memcpy(m_data->json, rp_data->json, jsonSize);
memcpy(m_data->json, rp_data->json, jsonSize);
m_data->jsonBuffer = rp_data->jsonBuffer;
}
if (rp_data->title) {
const size_t titleSize = strlen(rp_data->title) + 1;
m_data->title = static_cast<char*>(std::malloc(titleSize));
m_data->title = static_cast<char*>(malloc(titleSize));
if (!m_data->title)
return false;
std::memcpy(m_data->title, rp_data->title, titleSize);
memcpy(m_data->title, rp_data->title, titleSize);
m_data->titlBuffer = rp_data->titlBuffer;
}
if (rp_data->description) {
const size_t descriptionSize = strlen(rp_data->description) + 1;
m_data->description = static_cast<char*>(std::malloc(descriptionSize));
m_data->description = static_cast<char*>(malloc(descriptionSize));
if (!m_data->description)
return false;
std::memcpy(m_data->description, rp_data->description, descriptionSize);
memcpy(m_data->description, rp_data->description, descriptionSize);
m_data->descBuffer = rp_data->descBuffer;
}
setBufferOffsets(m_data);
}
else {
std::free(m_data->jpeg);
std::free(m_data->description);
std::free(m_data->json);
std::free(m_data->header);
std::free(m_data->title);
std::free(m_data);
free(m_data->jpeg);
free(m_data->description);
free(m_data->json);
free(m_data->header);
free(m_data->title);
free(m_data);
m_data = rp_data;
}
@ -1135,36 +1139,36 @@ bool RagePhoto::setJpeg(const char *data, uint32_t size, uint32_t bufferSize)
{
if (m_data->jpeg) {
if (m_data->jpegSize > size) {
char *t_photoData = static_cast<char*>(std::realloc(m_data->jpeg, size));
char *t_photoData = static_cast<char*>(realloc(m_data->jpeg, size));
if (!t_photoData) {
m_data->error = Error::PhotoMallocError; // 16
return false;
}
m_data->jpeg = t_photoData;
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
m_data->jpegSize = size;
}
else if (m_data->jpegSize < size) {
std::free(m_data->jpeg);
m_data->jpeg = static_cast<char*>(std::malloc(size));
free(m_data->jpeg);
m_data->jpeg = static_cast<char*>(malloc(size));
if (!m_data->jpeg) {
m_data->error = Error::PhotoMallocError; // 16
return false;
}
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
m_data->jpegSize = size;
}
else {
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
}
}
else {
m_data->jpeg = static_cast<char*>(std::malloc(size));
m_data->jpeg = static_cast<char*>(malloc(size));
if (!m_data->jpeg) {
m_data->error = Error::PhotoMallocError; // 16
return false;
}
std::memcpy(m_data->jpeg, data, size);
memcpy(m_data->jpeg, data, size);
m_data->jpegSize = size;
}
@ -1219,7 +1223,7 @@ void RagePhoto::setTitle(const char *title, uint32_t bufferSize)
m_data->error = Error::NoError; // 255
}
#ifdef LIBRAGEPHOTO_C_API
#ifdef LIBRAGEPHOTO_CXX_C
ragephoto_t ragephoto_open()
{
return static_cast<ragephoto_t>(new RagePhoto);

View file

@ -19,175 +19,297 @@
#ifndef RAGEPHOTO_H
#define RAGEPHOTO_H
#ifdef __cplusplus
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <iostream>
#include <cstdlib>
#include <cstdint>
#include <cstdio>
#include <stddef.h>
#include <stdint.h>
/**
* \brief GTA V and RDR 2 Photo Parser.
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/** C API for RagePhoto.
* \file RagePhoto.h
*/
class LIBRAGEPHOTO_CXX_PUBLIC RagePhoto
{
public:
/** Default sizes */
enum DefaultSize : uint32_t {
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 = 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 = 0x01000000UL, /**< GTA V Photo Format */
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
};
/** Sign Initials */
enum SignInitials : uint32_t {
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
};
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. */
RagePhotoData* data(); /**< Returns the internal RagePhotoData object. */
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Loads a Photo from a const char*. */
/** Loads a Photo from a const char*.
* \param data Photo data
* \param size Photo data size
*/
bool load(const char *data, size_t size);
/** Loads a Photo from a std::string.
* \param data Photo data
*/
bool load(const std::string &data);
/** Loads a Photo from a file.
* \param filename File to load
*/
bool loadFile(const std::string &filename);
int32_t error() const; /**< Returns the last error occurred. */
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string jpeg() const; /**< Returns the Photo JPEG data. */
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
const std::string_view jpeg_view() const; /**< Returns the Photo JPEG data. */
#endif
const char* jpegData() const; /**< Returns the Photo JPEG data. */
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
static uint64_t jpegSign(RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
uint64_t jpegSign(uint32_t photoFormat) const; /**< Returns the Photo JPEG sign. */
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* 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*. */
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
bool save(char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param data Photo data
*/
bool save(char *data);
/** Saves a Photo to a std::string.
* \param photoFormat Photo Format (GTA V or RDR 2)
* \param ok \p true when saved successfully
*/
const std::string save(uint32_t photoFormat, bool *ok = nullptr);
/** Saves a Photo to a std::string.
* \param ok \p true when saved successfully
*/
const std::string save(bool *ok = nullptr);
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. */
size_t saveSize(); /**< Returns the Photo save file size. */
static void setBufferDefault(RagePhotoData *rp_data); /**< Sets all cross-format Buffer to default size. */
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
static void setBufferOffsets(RagePhotoData *rp_data); /**< Moves all Buffer offsets to correct position. */
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
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). */
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
void setJson(const char *json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
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;
};
#else
#include "RagePhotoC.h"
/** RagePhoto C instance/C++ class typedef. */
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_C_PUBLIC ragephoto_t ragephoto_open();
/** Add a custom defined RagePhotoFormatParser.
* \param instance \p ragephoto_t instance
* \param rp_parser RagePhotoFormatParser parser to add
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser);
/** Resets the RagePhotoData object to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_clear(ragephoto_t instance);
/** 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*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a const char*.
* \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.
* \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.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC int32_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_rdr2();
/** Returns the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC RagePhotoData* ragephoto_getphotodata(ragephoto_t instance);
/** Returns the Photo description.
* \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).
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosign(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \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.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data);
/** Returns the Photo JPEG sign.
* \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.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size.
* \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.
* \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.
* \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*.
* \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*.
* \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*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \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.
* \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.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferdefault(ragephoto_t instance);
/** Sets all cross-format Buffer to default size.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferdefault(RagePhotoData *rp_data);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);
/** Sets the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \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.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being copied
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
* \param description Description
* \param bufferSize Description buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2).
* \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.
* \param instance \p ragephoto_t instance
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance
* \param json JSON data
* \param bufferSize JSON data buffer size
*
* Default bufferSize: 3072UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** 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) */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
* \param title Title
* \param bufferSize Title buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_version();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTO_H

191
src/RagePhoto.hpp Normal file
View file

@ -0,0 +1,191 @@
/*****************************************************************************
* 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 RAGEPHOTO_HPP
#define RAGEPHOTO_HPP
#ifdef __cplusplus
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <iostream>
#include <cstdlib>
#include <cstdint>
#include <cstdio>
/**
* \brief GTA V and RDR 2 Photo Parser.
*/
class LIBRAGEPHOTO_CXX_PUBLIC RagePhoto
{
public:
/** Default sizes */
enum DefaultSize : uint32_t {
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 = 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 = 0x01000000UL, /**< GTA V Photo Format */
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
};
/** Sign Initials */
enum SignInitials : uint32_t {
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
};
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. */
RagePhotoData* data(); /**< Returns the internal RagePhotoData object. */
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Loads a Photo from a const char*. */
/** Loads a Photo from a const char*.
* \param data Photo data
* \param size Photo data size
*/
bool load(const char *data, size_t size);
/** Loads a Photo from a std::string.
* \param data Photo data
*/
bool load(const std::string &data);
/** Loads a Photo from a file.
* \param filename File to load
*/
bool loadFile(const std::string &filename);
int32_t error() const; /**< Returns the last error occurred. */
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string jpeg() const; /**< Returns the Photo JPEG data. */
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
const std::string_view jpeg_view() const; /**< Returns the Photo JPEG data. */
#endif
const char* jpegData() const; /**< Returns the Photo JPEG data. */
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
static uint64_t jpegSign(RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
uint64_t jpegSign(uint32_t photoFormat) const; /**< Returns the Photo JPEG sign. */
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* 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*. */
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
bool save(char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param data Photo data
*/
bool save(char *data);
/** Saves a Photo to a std::string.
* \param photoFormat Photo Format (GTA V or RDR 2)
* \param ok \p true when saved successfully
*/
const std::string save(uint32_t photoFormat, bool *ok = nullptr);
/** Saves a Photo to a std::string.
* \param ok \p true when saved successfully
*/
const std::string save(bool *ok = nullptr);
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. */
size_t saveSize(); /**< Returns the Photo save file size. */
static void setBufferDefault(RagePhotoData *rp_data); /**< Sets all cross-format Buffer to default size. */
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
static void setBufferOffsets(RagePhotoData *rp_data); /**< Moves all Buffer offsets to correct position. */
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
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). */
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
void setJson(const char *json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
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;
};
#endif // __cplusplus
#endif // RAGEPHOTO_HPP

1
src/RagePhotoA Normal file
View file

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

View file

@ -16,19 +16,16 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef RAGEPHOTOA_H
#define RAGEPHOTOA_H
#ifndef RAGEPHOTOA_HPP
#define RAGEPHOTOA_HPP
#ifdef __cplusplus
#include "RagePhotoC.h"
#include "RagePhoto.h"
#include <cstdlib>
#include <iostream>
/**
* \brief ABI Stable Wrapper for RagePhoto.
*
* Using RagePhotoA instead of RagePhoto allows your library or application to survive more changes in the RagePhoto class,
* disadvantages include that it doesn't always include the newest features, performance is about the same.
* \brief GTA V and RDR 2 Photo Parser (C API wrapper).
*/
class RagePhotoA
{
@ -302,7 +299,7 @@ public:
if (takeCopy)
return ragephoto_setphotodatac(instance, ragePhotoData);
else
return ragephoto_setphotodata(&instance, ragePhotoData);
return ragephoto_setphotodata(instance, ragePhotoData);
}
/** Sets the Photo description. */
void setDescription(const char *description, uint32_t bufferSize = 0) {
@ -343,8 +340,6 @@ public:
private:
ragephoto_t instance;
};
#else
#include "RagePhotoC.h"
#endif // __cplusplus
#endif // RAGEPHOTOA_H
#endif // RAGEPHOTOA_HPP

1
src/RagePhotoB Normal file
View file

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

43
src/RagePhotoB.hpp Normal file
View file

@ -0,0 +1,43 @@
/*****************************************************************************
* 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.
*****************************************************************************/
#ifndef RAGEPHOTOB_HPP
#define RAGEPHOTOB_HPP
#ifdef __cplusplus
#include "RagePhotoLibrary.h"
#ifdef LIBRAGEPHOTO_CXX_ONLY
#include "RagePhoto.hpp"
typedef RagePhoto RagePhotoB;
#elif defined LIBRAGEPHOTO_CXX_C
#ifdef LIBRAGEPHOTO_STATIC
#include "RagePhoto.hpp"
typedef RagePhoto RagePhotoB;
#else
#include "RagePhotoA.hpp"
typedef RagePhotoA RagePhotoB;
#endif // LIBRAGEPHOTO_STATIC
#elif defined LIBRAGEPHOTO_C_ONLY
#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 // RAGEPHOTOB_HPP

View file

@ -1,319 +0,0 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2023 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef RAGEPHOTOC_H
#define RAGEPHOTOC_H
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <stddef.h>
#include <stdint.h>
#ifdef LIBRAGEPHOTO_C_NOAPI
#error "libragephoto was built without C API"
#endif // LIBRAGEPHOTO_C_NOAPI
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/** C API for RagePhoto.
* \file RagePhotoC.h
*/
/** RagePhoto C++ class typedef for C API. */
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_C_PUBLIC ragephoto_t ragephoto_open();
/** Add a custom defined RagePhotoFormatParser.
* \param instance \p ragephoto_t instance
* \param rp_parser RagePhotoFormatParser parser to add
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser);
/** Resets the RagePhotoData object to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_clear(ragephoto_t instance);
/** 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*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a const char*.
* \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.
* \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.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC int32_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_rdr2();
/** Returns the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC RagePhotoData* ragephoto_getphotodata(ragephoto_t instance);
/** Returns the Photo description.
* \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).
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosign(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \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.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data);
/** Returns the Photo JPEG sign.
* \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.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size.
* \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.
* \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.
* \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*.
* \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*.
* \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*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \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.
* \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.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferdefault(ragephoto_t instance);
/** Sets all cross-format Buffer to default size.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferdefault(RagePhotoData *rp_data);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);
/** Sets the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \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.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being copied
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
* \param description Description
* \param bufferSize Description buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2).
* \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.
* \param instance \p ragephoto_t instance
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance
* \param json JSON data
* \param bufferSize JSON data buffer size
*
* Default bufferSize: 3072UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** 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) */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
* \param title Title
* \param bufferSize Title buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_version();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTOC_H

View file

@ -57,13 +57,13 @@
#endif // _WIN32
/* RAGEPHOTO LIBRARY BINDING END */
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY BEGIN */
/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY BEGIN */
#ifdef LIBRAGEPHOTO_WASM
#ifdef RAGEPHOTO_C_NOAPI
#undef RAGEPHOTO_C_NOAPI
#define RAGEPHOTO_C_API
#endif // RAGEPHOTO_C_NOAPI
#ifdef LIBRAGEPHOTO_CXX_ONLY
#undef LIBRAGEPHOTO_CXX_ONLY
#define LIBRAGEPHOTO_CXX_C
#endif // LIBRAGEPHOTO_CXX_ONLY
#endif // LIBRAGEPHOTO_WASM
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY END */
/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY END */
#endif // RAGEPHOTOLIBRARY_H

View file

@ -70,6 +70,12 @@ typedef struct RagePhotoFormatParser {
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 */
@ -126,6 +132,10 @@ typedef struct RagePhotoFormatParser {
#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