libragephoto: various changes

- libragephoto_global.h seperated to RagePhotoConfig.h and
RagePhotoLibrary.h
- RagePhotoData.h renamed to RagePhotoTypedefs.h
- RagePhotoData: updated struct and documentated it
- RagePhotoC: changed ragephoto_setphotodata ABI, added
ragephoto_setphotodatac for copying
- RagePhotoA: adapted for the ABI changes
- RagePhoto: adapted for the ABI changes and updated struct
This commit is contained in:
Syping 2023-02-07 03:06:22 +01:00
parent 8e73219549
commit 45a45701f6
9 changed files with 206 additions and 173 deletions

View File

@ -17,7 +17,7 @@
****************************************************************************]] ****************************************************************************]]
cmake_minimum_required(VERSION 3.7) cmake_minimum_required(VERSION 3.7)
project(ragephoto VERSION 0.2.0 LANGUAGES CXX) project(ragephoto VERSION 0.3.0 LANGUAGES CXX)
include(GNUInstallDirs) include(GNUInstallDirs)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -27,13 +27,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# RagePhoto CMake includes # RagePhoto CMake includes
include(cmake/unicode.cmake) include(cmake/unicode.cmake)
# RagePhoto WebAssembly ON
if (EMSCRIPTEN)
set(EM_ON ON)
else()
set(EM_ON OFF)
endif()
# RagePhoto Top Level ON # RagePhoto Top Level ON
if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto") if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto")
set(RPTL_ON ON) set(RPTL_ON ON)
@ -44,16 +37,17 @@ endif()
# RagePhoto Source files # RagePhoto Source files
set(RAGEPHOTO_HEADERS set(RAGEPHOTO_HEADERS
src/RagePhoto.h src/RagePhoto.h
src/RagePhotoData.h src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
) )
set(RAGEPHOTO_SOURCES set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp src/RagePhoto.cpp
) )
# RagePhoto Library Type # RagePhoto Library Type
option(RAGEPHOTO_STATIC "Build libragephoto as static library" ${EM_ON}) option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF)
if (RAGEPHOTO_STATIC) if (RAGEPHOTO_STATIC)
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ${EM_ON}) option(RAGEPHOTO_C_API "Build libragephoto with C API support" OFF)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_STATIC) set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_STATIC)
else() else()
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON) option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
@ -90,9 +84,9 @@ endif()
# RagePhoto Configures + Target + Installs # RagePhoto Configures + Target + Installs
configure_file(src/ragephoto.pc.in "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" @ONLY) configure_file(src/ragephoto.pc.in "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" @ONLY)
configure_file(src/libragephoto_global.h.in "${ragephoto_BINARY_DIR}/include/libragephoto_global.h" @ONLY) configure_file(src/RagePhotoConfig.h.in "${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h" @ONLY)
list(APPEND RAGEPHOTO_HEADERS list(APPEND RAGEPHOTO_HEADERS
"${ragephoto_BINARY_DIR}/include/libragephoto_global.h" "${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h"
) )
if (RAGEPHOTO_STATIC) if (RAGEPHOTO_STATIC)
add_library(ragephoto STATIC ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_STATIC_RESOURCES}) add_library(ragephoto STATIC ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_STATIC_RESOURCES})
@ -100,6 +94,7 @@ else()
add_library(ragephoto SHARED ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_SHARED_RESOURCES}) add_library(ragephoto SHARED ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_SHARED_RESOURCES})
set_target_properties(ragephoto PROPERTIES set_target_properties(ragephoto PROPERTIES
PREFIX "lib" PREFIX "lib"
VERSION "${ragephoto_VERSION}"
) )
endif() endif()
target_compile_definitions(ragephoto PRIVATE target_compile_definitions(ragephoto PRIVATE
@ -130,13 +125,16 @@ if (EMSCRIPTEN)
) )
target_compile_definitions(ragephoto-wasm PRIVATE target_compile_definitions(ragephoto-wasm PRIVATE
LIBRAGEPHOTO_LIBRARY LIBRAGEPHOTO_LIBRARY
LIBRAGEPHOTO_WASM
${LIBRAGEPHOTO_DEFINES} ${LIBRAGEPHOTO_DEFINES}
) )
target_link_options(ragephoto-wasm PRIVATE target_link_options(ragephoto-wasm PRIVATE
"SHELL:-O3" "SHELL:-O3"
"SHELL:--no-entry" "SHELL:--no-entry"
"SHELL:-s WASM=1"
"SHELL:-s ALLOW_MEMORY_GROWTH=1" "SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s MODULARIZE=1"
"SHELL:-s WASM=1"
"SHELL:-s EXPORT_NAME=libragephotoModule"
"SHELL:-s EXPORTED_FUNCTIONS=_free,_malloc" "SHELL:-s EXPORTED_FUNCTIONS=_free,_malloc"
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap" "SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
) )

View File

@ -125,20 +125,7 @@ inline void uInt32ToCharLE(uint32_t x, char *y)
/* BEGIN OF RAGEPHOTO CLASS */ /* BEGIN OF RAGEPHOTO CLASS */
RagePhoto::RagePhoto() RagePhoto::RagePhoto()
{ {
#if __cplusplus >= 201707L
m_data = new RagePhotoData {
.jpeg = nullptr,
.description = nullptr,
.json = nullptr,
.title = nullptr,
.error = 0,
.photoFormat = 0,
.unnamedSum1 = 0,
.unnamedSum2 = 0
};
#else
m_data = new RagePhotoData { 0 }; m_data = new RagePhotoData { 0 };
#endif
setBufferDefault(); setBufferDefault();
} }
@ -354,9 +341,9 @@ bool RagePhoto::load(const char *data, size_t length)
return false; return false;
} }
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&m_data->photoBuffer, uInt32Buffer, 4); std::memcpy(&m_data->jpegBuffer, uInt32Buffer, 4);
#else #else
m_data->photoBuffer = charToUInt32LE(uInt32Buffer); m_data->jpegBuffer = charToUInt32LE(uInt32Buffer);
#endif #endif
size = readBuffer(data, uInt32Buffer, &pos, 4, length); size = readBuffer(data, uInt32Buffer, &pos, 4, length);
@ -510,7 +497,7 @@ bool RagePhoto::load(const char *data, size_t length)
std::cout << "headerSum: " << m_data->headerSum << std::endl; std::cout << "headerSum: " << m_data->headerSum << std::endl;
std::cout << "unnamedSum1: " << m_data->unnamedSum1 << std::endl; std::cout << "unnamedSum1: " << m_data->unnamedSum1 << std::endl;
std::cout << "unnamedSum2: " << m_data->unnamedSum2 << std::endl; std::cout << "unnamedSum2: " << m_data->unnamedSum2 << std::endl;
std::cout << "photoBuffer: " << m_data->photoBuffer << std::endl; std::cout << "photoBuffer: " << m_data->jpegBuffer << std::endl;
std::cout << "descBuffer: " << m_data->descBuffer << std::endl; std::cout << "descBuffer: " << m_data->descBuffer << std::endl;
std::cout << "descOffset: " << m_data->descOffset << std::endl; std::cout << "descOffset: " << m_data->descOffset << std::endl;
std::cout << "description: " << m_data->description << std::endl; std::cout << "description: " << m_data->description << std::endl;
@ -562,7 +549,7 @@ bool RagePhoto::loadFile(const std::string &filename)
} }
} }
uint8_t RagePhoto::error() const int32_t RagePhoto::error() const
{ {
return m_data->error; return m_data->error;
} }
@ -590,7 +577,7 @@ uint32_t RagePhoto::photoSize() const
if (m_data->jpeg) if (m_data->jpeg)
return m_data->jpegSize; return m_data->jpegSize;
else else
return 0UL; return 0;
} }
const char* RagePhoto::description() const const char* RagePhoto::description() const
@ -663,7 +650,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat)
const size_t photoHeader_size = 256; const size_t photoHeader_size = 256;
#endif #endif
if (m_data->jpegSize > m_data->photoBuffer) { if (m_data->jpegSize > m_data->jpegBuffer) {
m_data->error = Error::PhotoBufferTight; // 36 m_data->error = Error::PhotoBufferTight; // 36
return false; return false;
} }
@ -757,9 +744,9 @@ bool RagePhoto::save(char *data, uint32_t photoFormat)
writeBuffer("JPEG", data, &pos, length, 4); writeBuffer("JPEG", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &m_data->photoBuffer, 4); std::memcpy(uInt32Buffer, &m_data->jpegBuffer, 4);
#else #else
uInt32ToCharLE(m_data->photoBuffer, uInt32Buffer); uInt32ToCharLE(m_data->jpegBuffer, uInt32Buffer);
#endif #endif
writeBuffer(uInt32Buffer, data, &pos, length, 4); writeBuffer(uInt32Buffer, data, &pos, length, 4);
@ -771,7 +758,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat)
writeBuffer(uInt32Buffer, data, &pos, length, 4); writeBuffer(uInt32Buffer, data, &pos, length, 4);
writeBuffer(m_data->jpeg, data, &pos, length, m_data->jpegSize); writeBuffer(m_data->jpeg, data, &pos, length, m_data->jpegSize);
for (size_t i = m_data->jpegSize; i < m_data->photoBuffer; i++) { for (size_t i = m_data->jpegSize; i < m_data->jpegBuffer; i++) {
writeBuffer("\0", data, &pos, length, 1); writeBuffer("\0", data, &pos, length, 1);
} }
@ -889,9 +876,9 @@ bool RagePhoto::saveFile(const std::string &filename)
inline size_t RagePhoto::saveSize(RagePhotoData *ragePhotoData, uint32_t photoFormat) inline size_t RagePhoto::saveSize(RagePhotoData *ragePhotoData, uint32_t photoFormat)
{ {
if (photoFormat == PhotoFormat::GTA5) if (photoFormat == PhotoFormat::GTA5)
return (ragePhotoData->photoBuffer + ragePhotoData->jsonBuffer + ragePhotoData->titlBuffer + ragePhotoData->descBuffer + GTA5_HEADERSIZE + 56UL); return (ragePhotoData->jpegBuffer + ragePhotoData->jsonBuffer + ragePhotoData->titlBuffer + ragePhotoData->descBuffer + GTA5_HEADERSIZE + 56UL);
else if (photoFormat == PhotoFormat::RDR2) else if (photoFormat == PhotoFormat::RDR2)
return (ragePhotoData->photoBuffer + ragePhotoData->jsonBuffer + ragePhotoData->titlBuffer + ragePhotoData->descBuffer + RDR2_HEADERSIZE + 56UL); return (ragePhotoData->jpegBuffer + ragePhotoData->jsonBuffer + ragePhotoData->titlBuffer + ragePhotoData->descBuffer + RDR2_HEADERSIZE + 56UL);
else else
return 0; return 0;
} }
@ -931,7 +918,7 @@ inline void RagePhoto::setBufferOffsets()
inline void RagePhoto::setBufferOffsets(RagePhotoData *ragePhotoData) inline void RagePhoto::setBufferOffsets(RagePhotoData *ragePhotoData)
{ {
ragePhotoData->jsonOffset = ragePhotoData->photoBuffer + 28; ragePhotoData->jsonOffset = ragePhotoData->jpegBuffer + 28;
ragePhotoData->titlOffset = ragePhotoData->jsonOffset + ragePhotoData->jsonBuffer + 8; ragePhotoData->titlOffset = ragePhotoData->jsonOffset + ragePhotoData->jsonBuffer + 8;
ragePhotoData->descOffset = ragePhotoData->titlOffset + ragePhotoData->titlBuffer + 8; ragePhotoData->descOffset = ragePhotoData->titlOffset + ragePhotoData->titlBuffer + 8;
ragePhotoData->endOfFile = ragePhotoData->descOffset + ragePhotoData->descBuffer + 12; ragePhotoData->endOfFile = ragePhotoData->descOffset + ragePhotoData->descBuffer + 12;
@ -972,7 +959,7 @@ bool RagePhoto::setData(RagePhotoData *ragePhotoData, bool takeOwnership)
return false; return false;
std::memcpy(m_data->jpeg, ragePhotoData->jpeg, ragePhotoData->jpegSize); std::memcpy(m_data->jpeg, ragePhotoData->jpeg, ragePhotoData->jpegSize);
m_data->jpegSize = ragePhotoData->jpegSize; m_data->jpegSize = ragePhotoData->jpegSize;
m_data->photoBuffer = ragePhotoData->photoBuffer; m_data->jpegBuffer = ragePhotoData->jpegBuffer;
} }
if (ragePhotoData->json) { if (ragePhotoData->json) {
@ -1090,7 +1077,7 @@ bool RagePhoto::setPhoto(const char *data, uint32_t size, uint32_t bufferSize)
} }
if (bufferSize != 0) { if (bufferSize != 0) {
m_data->photoBuffer = bufferSize; m_data->jpegBuffer = bufferSize;
setBufferOffsets(); setBufferOffsets();
} }
@ -1140,7 +1127,7 @@ ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename)
return ragePhoto->loadFile(filename); return ragePhoto->loadFile(filename);
} }
uint8_t ragephoto_error(ragephoto_t instance) int32_t ragephoto_error(ragephoto_t instance)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->error(); return ragePhoto->error();
@ -1262,10 +1249,16 @@ void ragephoto_setbufferoffsets(ragephoto_t instance)
ragePhoto->setBufferOffsets(); ragePhoto->setBufferOffsets();
} }
void ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *ragePhotoData, ragephoto_bool_t takeOwnership) void ragephoto_setphotodata(ragephoto_t *instance, RagePhotoData *ragePhotoData)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(*instance);
ragePhoto->setData(ragePhotoData, true);
}
void ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *ragePhotoData)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setData(ragePhotoData, takeOwnership); ragePhoto->setData(ragePhotoData, false);
} }
void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize) void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize)

View File

@ -20,8 +20,8 @@
#define RAGEPHOTO_H #define RAGEPHOTO_H
#ifdef __cplusplus #ifdef __cplusplus
#include "libragephoto_global.h" #include "RagePhotoLibrary.h"
#include "RagePhotoData.h" #include "RagePhotoTypedefs.h"
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <cstdint> #include <cstdint>
@ -30,7 +30,7 @@
/** /**
* \brief GTA V and RDR 2 Photo Parser. * \brief GTA V and RDR 2 Photo Parser.
*/ */
class LIBRAGEPHOTO_CXX_EXPORT RagePhoto class LIBRAGEPHOTO_CXX_BINDING RagePhoto
{ {
public: public:
/** Default sizes */ /** Default sizes */
@ -44,7 +44,7 @@ public:
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */ RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
}; };
/** Parsing and set errors */ /** Parsing and set errors */
enum Error : uint8_t { enum Error : int32_t {
DescBufferTight = 39, /**< Description Buffer is too tight */ DescBufferTight = 39, /**< Description Buffer is too tight */
DescMallocError = 31, /**< Description Buffer can't be allocated */ DescMallocError = 31, /**< Description Buffer can't be allocated */
DescReadError = 32, /**< Description can't be read successfully */ DescReadError = 32, /**< Description can't be read successfully */
@ -109,7 +109,7 @@ public:
* \param filename File to load * \param filename File to load
*/ */
bool loadFile(const std::string &filename); bool loadFile(const std::string &filename);
uint8_t error() const; /**< Returns the last error occurred. */ int32_t error() const; /**< Returns the last error occurred. */
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */ uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string photo() const; /**< Returns the Photo JPEG data. */ const std::string photo() const; /**< Returns the Photo JPEG data. */
const char *photoData() const; /**< Returns the Photo JPEG data. */ const char *photoData() const; /**< Returns the Photo JPEG data. */

View File

@ -44,7 +44,7 @@ public:
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */ RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
}; };
/** Parsing and set errors */ /** Parsing and set errors */
enum Error : uint8_t { enum Error : int32_t {
DescBufferTight = 39, /**< Description Buffer is too tight */ DescBufferTight = 39, /**< Description Buffer is too tight */
DescMallocError = 31, /**< Description Buffer can't be allocated */ DescMallocError = 31, /**< Description Buffer can't be allocated */
DescReadError = 32, /**< Description can't be read successfully */ DescReadError = 32, /**< Description can't be read successfully */
@ -228,7 +228,10 @@ public:
} }
/** Sets the internal RagePhotoData object. */ /** Sets the internal RagePhotoData object. */
bool setData(RagePhotoData *ragePhotoData, bool takeOwnership = true) { bool setData(RagePhotoData *ragePhotoData, bool takeOwnership = true) {
ragephoto_setphotodata(instance, ragePhotoData, takeOwnership); if (takeOwnership)
ragephoto_setphotodata(&instance, ragePhotoData);
else
ragephoto_setphotodatac(instance, ragePhotoData);
} }
/** Sets the Photo description. */ /** Sets the Photo description. */
void setDescription(const char *description, uint32_t bufferSize = 0) { void setDescription(const char *description, uint32_t bufferSize = 0) {

View File

@ -19,8 +19,8 @@
#ifndef RAGEPHOTOC_H #ifndef RAGEPHOTOC_H
#define RAGEPHOTOC_H #define RAGEPHOTOC_H
#include "libragephoto_global.h" #include "RagePhotoLibrary.h"
#include "RagePhotoData.h" #include "RagePhotoTypedefs.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -39,136 +39,141 @@ typedef void* ragephoto_t;
typedef int32_t ragephoto_bool_t; typedef int32_t ragephoto_bool_t;
/** Opens a \p ragephoto_t instance. */ /** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_C_EXPORT ragephoto_t ragephoto_open(); LIBRAGEPHOTO_C_BINDING ragephoto_t ragephoto_open();
/** Resets the \p ragephoto_t instance to default values. /** Resets the \p ragephoto_t instance to default values.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_clear(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING void ragephoto_clear(ragephoto_t instance);
/** Loads a Photo from a const char*. /** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param data Photo data * \param data Photo data
* \param size Photo data size * \param size Photo data size
*/ */
LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size); LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a file. /** Loads a Photo from a file.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param filename File to load * \param filename File to load
*/ */
LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename); LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename);
/** Returns the last error occurred. /** Returns the last error occurred.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT uint8_t ragephoto_error(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING int32_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */ /** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_defpbuf_gta5(); LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */ /** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_defpbuf_rdr2(); LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */ /** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_format_gta5(); LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */ /** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_format_rdr2(); LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_format_rdr2();
/** Returns the internal RagePhotoData object. /** Returns the internal RagePhotoData object.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT RagePhotoData* ragephoto_getphotodata(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING RagePhotoData* ragephoto_getphotodata(ragephoto_t instance);
/** Returns the Photo description. /** Returns the Photo description.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotodesc(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotodesc(ragephoto_t instance);
/** Returns the Photo Format (GTA V or RDR 2). /** Returns the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_getphotoformat(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data. /** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotojpeg(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data. /** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotojson(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header. /** Returns the Photo header.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotoheader(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG data size. /** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_getphotosize(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title. /** Returns the Photo title.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphototitle(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size. /** Returns the Photo save file size.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT size_t ragephoto_getsavesize(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size. /** Returns the Photo save file size.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2) * \param photoFormat Photo Format (GTA V or RDR 2)
*/ */
LIBRAGEPHOTO_C_EXPORT size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat); LIBRAGEPHOTO_C_BINDING size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
/** Saves a Photo to a char*. /** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param data Photo data * \param data Photo data
*/ */
LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_save(ragephoto_t instance, char *data); LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_save(ragephoto_t instance, char *data);
/** Saves a Photo to a char*. /** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param data Photo data * \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2) * \param photoFormat Photo Format (GTA V or RDR 2)
*/ */
LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat); LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a file. /** Saves a Photo to a file.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param filename File to save * \param filename File to save
*/ */
LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_savefile(ragephoto_t instance, const char *filename); LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_savefile(ragephoto_t instance, const char *filename);
/** Saves a Photo to a file. /** Saves a Photo to a file.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param filename File to save * \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2) * \param photoFormat Photo Format (GTA V or RDR 2)
*/ */
LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat); LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size. /** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setbufferdefault(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING void ragephoto_setbufferdefault(ragephoto_t instance);
/** Moves all Buffer offsets to correct position. /** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setbufferoffsets(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Sets the internal RagePhotoData object. /** Sets the internal RagePhotoData object.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param ragePhotoData RagePhotoData object * \param ragePhotoData RagePhotoData object being set
* \param takeOwnership True takes ownership, false copies source object
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *ragePhotoData, ragephoto_bool_t takeOwnership); LIBRAGEPHOTO_C_BINDING void ragephoto_setphotodata(ragephoto_t *instance, RagePhotoData *ragePhotoData);
/** Copies RagePhotoData object to internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param ragePhotoData RagePhotoData object being copied
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *ragePhotoData);
/** Sets the Photo description. /** Sets the Photo description.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -177,13 +182,13 @@ LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotodata(ragephoto_t instance, RagePhot
* *
* Default bufferSize: 256UL * Default bufferSize: 256UL
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize); LIBRAGEPHOTO_C_BINDING void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2). /** Sets the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2) * \param photoFormat Photo Format (GTA V or RDR 2)
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat); LIBRAGEPHOTO_C_BINDING void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
/** Sets the Photo JPEG data. /** Sets the Photo JPEG data.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -193,7 +198,7 @@ LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoformat(ragephoto_t instance, uint32
* *
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2() * Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/ */
LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize); LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data. /** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -202,10 +207,10 @@ LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instan
* *
* Default bufferSize: 3072UL * Default bufferSize: 3072UL
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize); LIBRAGEPHOTO_C_BINDING void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. (EXPERT ONLY) */ /** Sets the Photo header. (EXPERT ONLY) */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum); LIBRAGEPHOTO_C_BINDING void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo title. /** Sets the Photo title.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -214,15 +219,15 @@ LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const
* *
* Default bufferSize: 256UL * Default bufferSize: 256UL
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize); LIBRAGEPHOTO_C_BINDING void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance. /** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_C_EXPORT void ragephoto_close(ragephoto_t instance); LIBRAGEPHOTO_C_BINDING void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */ /** Returns the library version. */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_version(); LIBRAGEPHOTO_C_BINDING const char* ragephoto_version();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* libragephoto RAGE Photo Parser * libragephoto RAGE Photo Parser
* Copyright (C) 2021-2022 Syping * Copyright (C) 2023 Syping
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * 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. * responsible for anything with use of the software, you are self responsible.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBRAGEPHOTO_GLOBAL_H #ifndef RAGEPHOTOCONFIG_H
#define LIBRAGEPHOTO_GLOBAL_H #define RAGEPHOTOCONFIG_H
/* CMAKE CONFIG BEGIN */ /* CMAKE CONFIG BEGIN */
#define @LIBRAGEPHOTO_API@ #define @LIBRAGEPHOTO_API@
@ -28,30 +28,4 @@
#define RAGEPHOTO_VERSION_PATCH @ragephoto_VERSION_PATCH@ #define RAGEPHOTO_VERSION_PATCH @ragephoto_VERSION_PATCH@
/* CMAKE CONFIG END */ /* CMAKE CONFIG END */
/* RAGEPHOTO LIBRARY EXPORT BEGIN */ #endif // RAGEPHOTOCONFIG_H
#ifdef _WIN32
#ifndef LIBRAGEPHOTO_STATIC
#ifdef LIBRAGEPHOTO_LIBRARY
#define LIBRAGEPHOTO_C_EXPORT __declspec(dllexport)
#define LIBRAGEPHOTO_CXX_EXPORT __declspec(dllexport)
#else
#define LIBRAGEPHOTO_C_EXPORT __declspec(dllimport)
#define LIBRAGEPHOTO_CXX_EXPORT __declspec(dllimport)
#endif // LIBRAGEPHOTO_LIBRARY
#else
#define LIBRAGEPHOTO_C_EXPORT
#define LIBRAGEPHOTO_CXX_EXPORT
#endif // LIBRAGEPHOTO_STATIC
#else
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#define LIBRAGEPHOTO_C_EXPORT EMSCRIPTEN_KEEPALIVE
#define LIBRAGEPHOTO_CXX_EXPORT
#else
#define LIBRAGEPHOTO_C_EXPORT
#define LIBRAGEPHOTO_CXX_EXPORT
#endif // __EMSCRIPTEN__
#endif // _WIN32
/* RAGEPHOTO LIBRARY EXPORT END */
#endif // LIBRAGEPHOTO_GLOBAL_H

View File

@ -1,54 +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 RAGEPHOTODATA_H
#define RAGEPHOTODATA_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef struct RagePhotoData {
char* jpeg;
char* description;
char* json;
char* header;
char* title;
uint8_t error;
uint32_t descBuffer;
uint32_t descOffset;
uint32_t endOfFile;
uint32_t headerSum;
uint32_t jpegSize;
uint32_t jsonBuffer;
uint32_t jsonOffset;
uint32_t photoBuffer;
uint32_t photoFormat;
uint32_t titlBuffer;
uint32_t titlOffset;
uint32_t unnamedSum1;
uint32_t unnamedSum2;
} RagePhotoData;
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTODATA_H

59
src/RagePhotoLibrary.h Normal file
View File

@ -0,0 +1,59 @@
/*****************************************************************************
* 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 RAGEPHOTOLIBRARY_H
#define RAGEPHOTOLIBRARY_H
#include "RagePhotoConfig.h"
/* RAGEPHOTO LIBRARY BINDING BEGIN */
#ifdef _WIN32
#ifndef LIBRAGEPHOTO_STATIC
#ifdef LIBRAGEPHOTO_LIBRARY
#define LIBRAGEPHOTO_C_BINDING __declspec(dllexport)
#define LIBRAGEPHOTO_CXX_BINDING __declspec(dllexport)
#else
#define LIBRAGEPHOTO_C_BINDING __declspec(dllimport)
#define LIBRAGEPHOTO_CXX_BINDING __declspec(dllimport)
#endif // LIBRAGEPHOTO_LIBRARY
#else
#define LIBRAGEPHOTO_C_BINDING
#define LIBRAGEPHOTO_CXX_BINDING
#endif // LIBRAGEPHOTO_STATIC
#else
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#define LIBRAGEPHOTO_C_BINDING EMSCRIPTEN_KEEPALIVE
#define LIBRAGEPHOTO_CXX_BINDING
#else
#define LIBRAGEPHOTO_C_BINDING
#define LIBRAGEPHOTO_CXX_BINDING
#endif // __EMSCRIPTEN__
#endif // _WIN32
/* RAGEPHOTO LIBRARY BINDING END */
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY BEGIN */
#ifdef LIBRAGEPHOTO_WASM
#ifdef RAGEPHOTO_C_NOAPI
#undef RAGEPHOTO_C_NOAPI
#define RAGEPHOTO_C_API
#endif // RAGEPHOTO_C_NOAPI
#endif // LIBRAGEPHOTO_WASM
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY END */
#endif // RAGEPHOTOLIBRARY_H

55
src/RagePhotoTypedefs.h Normal file
View File

@ -0,0 +1,55 @@
/*****************************************************************************
* 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 <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; /**< Photo Description buffer length */
uint32_t descOffset; /**< Photo Description buffer offset */
uint32_t endOfFile; /**< Photo End Of File offset */
uint32_t headerSum; /**< Photo Checksum of the header */
uint32_t jpegBuffer; /**< Photo JPEG buffer length */
uint32_t jpegSize; /**< Internal JPEG buffer length and size of JPEG */
uint32_t jsonBuffer; /**< Photo JSON buffer length */
uint32_t jsonOffset; /**< Photo JSON buffer offset */
uint32_t photoFormat; /**< Photo file format magic */
uint32_t titlBuffer; /**< Photo Title buffer length */
uint32_t titlOffset; /**< Photo Title buffer offset */
uint32_t unnamedSum1; /**< 1st unnamed checksum for Red Dead Redemption 2 */
uint32_t unnamedSum2; /**< 2nd unnamed checksum for Red Dead Redemption 2 */
} RagePhotoData;
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTOTYPEDEFS_H