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)
project(ragephoto VERSION 0.2.0 LANGUAGES CXX)
project(ragephoto VERSION 0.3.0 LANGUAGES CXX)
include(GNUInstallDirs)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -27,13 +27,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# RagePhoto CMake includes
include(cmake/unicode.cmake)
# RagePhoto WebAssembly ON
if (EMSCRIPTEN)
set(EM_ON ON)
else()
set(EM_ON OFF)
endif()
# RagePhoto Top Level ON
if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto")
set(RPTL_ON ON)
@ -44,16 +37,17 @@ endif()
# RagePhoto Source files
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoData.h
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
# 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)
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)
else()
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
@ -90,9 +84,9 @@ endif()
# RagePhoto Configures + Target + Installs
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
"${ragephoto_BINARY_DIR}/include/libragephoto_global.h"
"${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h"
)
if (RAGEPHOTO_STATIC)
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})
set_target_properties(ragephoto PROPERTIES
PREFIX "lib"
VERSION "${ragephoto_VERSION}"
)
endif()
target_compile_definitions(ragephoto PRIVATE
@ -130,13 +125,16 @@ if (EMSCRIPTEN)
)
target_compile_definitions(ragephoto-wasm PRIVATE
LIBRAGEPHOTO_LIBRARY
LIBRAGEPHOTO_WASM
${LIBRAGEPHOTO_DEFINES}
)
target_link_options(ragephoto-wasm PRIVATE
"SHELL:-O3"
"SHELL:--no-entry"
"SHELL:-s WASM=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_RUNTIME_METHODS=ccall,cwrap"
)

View file

@ -125,20 +125,7 @@ inline void uInt32ToCharLE(uint32_t x, char *y)
/* BEGIN OF RAGEPHOTO CLASS */
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 };
#endif
setBufferDefault();
}
@ -354,9 +341,9 @@ bool RagePhoto::load(const char *data, size_t length)
return false;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&m_data->photoBuffer, uInt32Buffer, 4);
std::memcpy(&m_data->jpegBuffer, uInt32Buffer, 4);
#else
m_data->photoBuffer = charToUInt32LE(uInt32Buffer);
m_data->jpegBuffer = charToUInt32LE(uInt32Buffer);
#endif
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 << "unnamedSum1: " << m_data->unnamedSum1 << 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 << "descOffset: " << m_data->descOffset << 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;
}
@ -590,7 +577,7 @@ uint32_t RagePhoto::photoSize() const
if (m_data->jpeg)
return m_data->jpegSize;
else
return 0UL;
return 0;
}
const char* RagePhoto::description() const
@ -663,7 +650,7 @@ bool RagePhoto::save(char *data, uint32_t photoFormat)
const size_t photoHeader_size = 256;
#endif
if (m_data->jpegSize > m_data->photoBuffer) {
if (m_data->jpegSize > m_data->jpegBuffer) {
m_data->error = Error::PhotoBufferTight; // 36
return false;
}
@ -757,9 +744,9 @@ bool RagePhoto::save(char *data, uint32_t photoFormat)
writeBuffer("JPEG", data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &m_data->photoBuffer, 4);
std::memcpy(uInt32Buffer, &m_data->jpegBuffer, 4);
#else
uInt32ToCharLE(m_data->photoBuffer, uInt32Buffer);
uInt32ToCharLE(m_data->jpegBuffer, uInt32Buffer);
#endif
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(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);
}
@ -889,9 +876,9 @@ bool RagePhoto::saveFile(const std::string &filename)
inline size_t RagePhoto::saveSize(RagePhotoData *ragePhotoData, uint32_t photoFormat)
{
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)
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
return 0;
}
@ -931,7 +918,7 @@ inline void RagePhoto::setBufferOffsets()
inline void RagePhoto::setBufferOffsets(RagePhotoData *ragePhotoData)
{
ragePhotoData->jsonOffset = ragePhotoData->photoBuffer + 28;
ragePhotoData->jsonOffset = ragePhotoData->jpegBuffer + 28;
ragePhotoData->titlOffset = ragePhotoData->jsonOffset + ragePhotoData->jsonBuffer + 8;
ragePhotoData->descOffset = ragePhotoData->titlOffset + ragePhotoData->titlBuffer + 8;
ragePhotoData->endOfFile = ragePhotoData->descOffset + ragePhotoData->descBuffer + 12;
@ -972,7 +959,7 @@ bool RagePhoto::setData(RagePhotoData *ragePhotoData, bool takeOwnership)
return false;
std::memcpy(m_data->jpeg, ragePhotoData->jpeg, ragePhotoData->jpegSize);
m_data->jpegSize = ragePhotoData->jpegSize;
m_data->photoBuffer = ragePhotoData->photoBuffer;
m_data->jpegBuffer = ragePhotoData->jpegBuffer;
}
if (ragePhotoData->json) {
@ -1090,7 +1077,7 @@ bool RagePhoto::setPhoto(const char *data, uint32_t size, uint32_t bufferSize)
}
if (bufferSize != 0) {
m_data->photoBuffer = bufferSize;
m_data->jpegBuffer = bufferSize;
setBufferOffsets();
}
@ -1140,7 +1127,7 @@ ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *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);
return ragePhoto->error();
@ -1262,10 +1249,16 @@ void ragephoto_setbufferoffsets(ragephoto_t instance)
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->setData(ragePhotoData, takeOwnership);
ragePhoto->setData(ragePhotoData, false);
}
void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize)

View file

@ -20,8 +20,8 @@
#define RAGEPHOTO_H
#ifdef __cplusplus
#include "libragephoto_global.h"
#include "RagePhotoData.h"
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <iostream>
#include <cstdlib>
#include <cstdint>
@ -30,7 +30,7 @@
/**
* \brief GTA V and RDR 2 Photo Parser.
*/
class LIBRAGEPHOTO_CXX_EXPORT RagePhoto
class LIBRAGEPHOTO_CXX_BINDING RagePhoto
{
public:
/** Default sizes */
@ -44,7 +44,7 @@ public:
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
};
/** Parsing and set errors */
enum Error : uint8_t {
enum Error : int32_t {
DescBufferTight = 39, /**< Description Buffer is too tight */
DescMallocError = 31, /**< Description Buffer can't be allocated */
DescReadError = 32, /**< Description can't be read successfully */
@ -109,7 +109,7 @@ public:
* \param filename File to load
*/
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). */
const std::string photo() 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 */
};
/** Parsing and set errors */
enum Error : uint8_t {
enum Error : int32_t {
DescBufferTight = 39, /**< Description Buffer is too tight */
DescMallocError = 31, /**< Description Buffer can't be allocated */
DescReadError = 32, /**< Description can't be read successfully */
@ -228,7 +228,10 @@ public:
}
/** Sets the internal RagePhotoData object. */
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. */
void setDescription(const char *description, uint32_t bufferSize = 0) {

View file

@ -19,8 +19,8 @@
#ifndef RAGEPHOTOC_H
#define RAGEPHOTOC_H
#include "libragephoto_global.h"
#include "RagePhotoData.h"
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <stdint.h>
#include <stdio.h>
@ -39,136 +39,141 @@ typedef void* ragephoto_t;
typedef int32_t ragephoto_bool_t;
/** 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.
* \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*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \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.
* \param instance \p ragephoto_t instance
* \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.
* \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. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_defpbuf_gta5();
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_defpbuf_gta5();
/** 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. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_format_gta5();
LIBRAGEPHOTO_C_BINDING uint32_t ragephoto_format_gta5();
/** 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.
* \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.
* \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).
* \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.
* \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.
* \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.
* \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.
* \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.
* \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.
* \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.
* \param instance \p ragephoto_t instance
* \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*.
* \param instance \p ragephoto_t instance
* \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*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \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.
* \param instance \p ragephoto_t instance
* \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.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \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.
* \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.
* \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.
* \param instance \p ragephoto_t instance
* \param ragePhotoData RagePhotoData object
* \param takeOwnership True takes ownership, false copies source object
* \param ragePhotoData RagePhotoData object being set
*/
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.
* \param instance \p ragephoto_t instance
@ -177,13 +182,13 @@ LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotodata(ragephoto_t instance, RagePhot
*
* 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).
* \param instance \p ragephoto_t instance
* \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.
* \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()
*/
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.
* \param instance \p ragephoto_t instance
@ -202,10 +207,10 @@ LIBRAGEPHOTO_C_EXPORT ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instan
*
* 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) */
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.
* \param instance \p ragephoto_t instance
@ -214,15 +219,15 @@ LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const
*
* 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.
* \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. */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_version();
LIBRAGEPHOTO_C_BINDING const char* ragephoto_version();
#ifdef __cplusplus
}

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* 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,
* are permitted provided that the following conditions are met:
@ -16,8 +16,8 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef LIBRAGEPHOTO_GLOBAL_H
#define LIBRAGEPHOTO_GLOBAL_H
#ifndef RAGEPHOTOCONFIG_H
#define RAGEPHOTOCONFIG_H
/* CMAKE CONFIG BEGIN */
#define @LIBRAGEPHOTO_API@
@ -28,30 +28,4 @@
#define RAGEPHOTO_VERSION_PATCH @ragephoto_VERSION_PATCH@
/* CMAKE CONFIG END */
/* RAGEPHOTO LIBRARY EXPORT BEGIN */
#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
#endif // RAGEPHOTOCONFIG_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