libragephoto: added library flags support

libragephoto: added RAGEPHOTO_FLAG_LEGACY_NULL_RETURN library flag
This commit is contained in:
Syping 2024-04-15 12:40:36 +02:00
parent bc9065e8dc
commit 2d59f2acf9
6 changed files with 99 additions and 33 deletions

View file

@ -38,6 +38,10 @@
#include <stringapiset.h> #include <stringapiset.h>
#endif #endif
/* RAGEPHOTO LIBRARY GLOBALS */
int libraryflags = 0;
const char* nullchar = "";
/* BEGIN OF STATIC LIBRARY FUNCTIONS */ /* BEGIN OF STATIC LIBRARY FUNCTIONS */
inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t outputLen, size_t inputLen) inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t outputLen, size_t inputLen)
{ {
@ -677,7 +681,9 @@ const char* ragephoto_getphotojpeg(ragephoto_t instance_t)
RagePhotoInstance *instance = (RagePhotoInstance*)instance_t; RagePhotoInstance *instance = (RagePhotoInstance*)instance_t;
if (instance->data->jpeg) if (instance->data->jpeg)
return instance->data->jpeg; return instance->data->jpeg;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return NULL;
return nullchar;
} }
uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat) uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat)
@ -731,7 +737,9 @@ const char* ragephoto_getphotodesc(ragephoto_t instance_t)
RagePhotoInstance *instance = (RagePhotoInstance*)instance_t; RagePhotoInstance *instance = (RagePhotoInstance*)instance_t;
if (instance->data->description) if (instance->data->description)
return instance->data->description; return instance->data->description;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return NULL;
return nullchar;
} }
const char* ragephoto_getphotojson(ragephoto_t instance_t) const char* ragephoto_getphotojson(ragephoto_t instance_t)
@ -739,7 +747,9 @@ const char* ragephoto_getphotojson(ragephoto_t instance_t)
RagePhotoInstance *instance = (RagePhotoInstance*)instance_t; RagePhotoInstance *instance = (RagePhotoInstance*)instance_t;
if (instance->data->json) if (instance->data->json)
return instance->data->json; return instance->data->json;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return NULL;
return nullchar;
} }
const char* ragephoto_getphotoheader(ragephoto_t instance_t) const char* ragephoto_getphotoheader(ragephoto_t instance_t)
@ -747,7 +757,9 @@ const char* ragephoto_getphotoheader(ragephoto_t instance_t)
RagePhotoInstance *instance = (RagePhotoInstance*)instance_t; RagePhotoInstance *instance = (RagePhotoInstance*)instance_t;
if (instance->data->header) if (instance->data->header)
return instance->data->header; return instance->data->header;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return NULL;
return nullchar;
} }
const char* ragephoto_getphototitle(ragephoto_t instance_t) const char* ragephoto_getphototitle(ragephoto_t instance_t)
@ -755,7 +767,9 @@ const char* ragephoto_getphototitle(ragephoto_t instance_t)
RagePhotoInstance *instance = (RagePhotoInstance*)instance_t; RagePhotoInstance *instance = (RagePhotoInstance*)instance_t;
if (instance->data->title) if (instance->data->title)
return instance->data->title; return instance->data->title;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return NULL;
return nullchar;
} }
const char* ragephoto_version() const char* ragephoto_version()
@ -1097,6 +1111,14 @@ void ragephoto_setbufferoffsets(ragephoto_t instance_t)
ragephotodata_setbufferoffsets(instance->data); ragephotodata_setbufferoffsets(instance->data);
} }
void ragephoto_setlibraryflag(RagePhotoLibraryFlag flag, bool state)
{
if (state)
libraryflags |= flag;
else
libraryflags &= ~flag;
}
bool ragephoto_setphotodata(ragephoto_t instance_t, RagePhotoData *rp_data) bool ragephoto_setphotodata(ragephoto_t instance_t, RagePhotoData *rp_data)
{ {
RagePhotoInstance *instance = (RagePhotoInstance*)instance_t; RagePhotoInstance *instance = (RagePhotoInstance*)instance_t;

View file

@ -45,6 +45,10 @@
/* CLASSIC RAGEPHOTO TYPEDEF */ /* CLASSIC RAGEPHOTO TYPEDEF */
typedef ragephoto::photo RagePhoto; typedef ragephoto::photo RagePhoto;
/* RAGEPHOTO LIBRARY GLOBALS */
int libraryflags = 0;
const char* nullchar = "";
/* BEGIN OF STATIC LIBRARY FUNCTIONS */ /* BEGIN OF STATIC LIBRARY FUNCTIONS */
inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t outputLen, size_t inputLen) inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t outputLen, size_t inputLen)
{ {
@ -639,7 +643,9 @@ const char* RagePhoto::jpegData() const
{ {
if (m_data->jpeg) if (m_data->jpeg)
return m_data->jpeg; return m_data->jpeg;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return nullptr;
return nullchar;
} }
uint64_t RagePhoto::jpegSign(uint32_t photoFormat, RagePhotoData *rp_data) uint64_t RagePhoto::jpegSign(uint32_t photoFormat, RagePhotoData *rp_data)
@ -679,28 +685,36 @@ const char* RagePhoto::description() const
{ {
if (m_data->description) if (m_data->description)
return m_data->description; return m_data->description;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
} return nullptr;
return nullchar;
const char* RagePhoto::json() const
{
if (m_data->json)
return m_data->json;
return "";
} }
const char* RagePhoto::header() const const char* RagePhoto::header() const
{ {
if (m_data->header) if (m_data->header)
return m_data->header; return m_data->header;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return nullptr;
return nullchar;
}
const char* RagePhoto::json() const
{
if (m_data->json)
return m_data->json;
if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return nullptr;
return nullchar;
} }
const char* RagePhoto::title() const const char* RagePhoto::title() const
{ {
if (m_data->title) if (m_data->title)
return m_data->title; return m_data->title;
return ""; if (libraryflags & RAGEPHOTO_FLAG_LEGACY_NULL_RETURN)
return nullptr;
return nullchar;
} }
const char* RagePhoto::version() const char* RagePhoto::version()
@ -1151,6 +1165,17 @@ void RagePhoto::setFormat(uint32_t photoFormat)
m_data->photoFormat = photoFormat; m_data->photoFormat = photoFormat;
} }
void RagePhoto::setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2)
{
if (!writeDataChar(header, &m_data->header)) {
m_data->error = Error::HeaderMallocError; // 4
return;
}
m_data->headerSum = headerSum;
m_data->headerSum2 = headerSum2;
m_data->error = Error::NoError; // 255
}
bool RagePhoto::setJpeg(const char *data, uint32_t size, uint32_t bufferSize) bool RagePhoto::setJpeg(const char *data, uint32_t size, uint32_t bufferSize)
{ {
if (m_data->jpeg) { if (m_data->jpeg) {
@ -1215,15 +1240,12 @@ void RagePhoto::setJson(const char *json, uint32_t bufferSize)
m_data->error = Error::NoError; // 255 m_data->error = Error::NoError; // 255
} }
void RagePhoto::setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2) void RagePhoto::setLibraryFlag(RagePhotoLibraryFlag flag, bool state)
{ {
if (!writeDataChar(header, &m_data->header)) { if (state)
m_data->error = Error::HeaderMallocError; // 4 libraryflags |= flag;
return; else
} libraryflags &= ~flag;
m_data->headerSum = headerSum;
m_data->headerSum2 = headerSum2;
m_data->error = Error::NoError; // 255
} }
void RagePhoto::setTitle(const char *title, uint32_t bufferSize) void RagePhoto::setTitle(const char *title, uint32_t bufferSize)
@ -1476,6 +1498,11 @@ void ragephotodata_setbufferoffsets(RagePhotoData *rp_data)
RagePhoto::setBufferOffsets(rp_data); RagePhoto::setBufferOffsets(rp_data);
} }
void ragephoto_setlibraryflag(RagePhotoLibraryFlag flag, bool state)
{
RagePhoto::setLibraryFlag(flag, state);
}
bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data) bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);

View file

@ -301,6 +301,13 @@ LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferoffsets(ragephoto_t instance);
*/ */
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data); LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);
/** Sets a library flag.
* \relates RagePhotoInstance
* \param flag Library flag
* \param state Flag state
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setlibraryflag(RagePhotoLibraryFlag flag, bool state);
/** Sets the internal RagePhotoData object. /** Sets the internal RagePhotoData object.
* \memberof RagePhotoInstance * \memberof RagePhotoInstance
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance

View file

@ -78,6 +78,11 @@ typedef struct RagePhotoInstance {
RagePhotoFormatParser *parser; /**< Pointer for internal format parser */ RagePhotoFormatParser *parser; /**< Pointer for internal format parser */
} RagePhotoInstance; } RagePhotoInstance;
/** RagePhoto library flags. */
typedef enum RagePhotoLibraryFlag {
RAGEPHOTO_FLAG_LEGACY_NULL_RETURN = 1 << 0 /**< Flag to enable legacy NULL return */
} RagePhotoLibraryFlag;
/* RagePhoto default sizes */ /* RagePhoto default sizes */
#define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER UINT32_C(524288) /**< GTA V default Photo Buffer Size */ #define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER UINT32_C(524288) /**< GTA V default Photo Buffer Size */
#define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER UINT32_C(1048576) /**< RDR 2 default Photo Buffer Size */ #define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER UINT32_C(1048576) /**< RDR 2 default Photo Buffer Size */

View file

@ -198,14 +198,14 @@ public:
const char* description() const { const char* description() const {
return ragephoto_getphotodesc(instance); return ragephoto_getphotodesc(instance);
} }
/** Returns the Photo JSON data. */
const char* json() const {
return ragephoto_getphotojson(instance);
}
/** Returns the Photo header. */ /** Returns the Photo header. */
const char* header() const { const char* header() const {
return ragephoto_getphotoheader(instance); return ragephoto_getphotoheader(instance);
} }
/** Returns the Photo JSON data. */
const char* json() const {
return ragephoto_getphotojson(instance);
}
/** Returns the Photo title. */ /** Returns the Photo title. */
const char* title() const { const char* title() const {
return ragephoto_getphototitle(instance); return ragephoto_getphototitle(instance);
@ -314,6 +314,10 @@ public:
void setFormat(uint32_t photoFormat) { void setFormat(uint32_t photoFormat) {
ragephoto_setphotoformat(instance, photoFormat); ragephoto_setphotoformat(instance, photoFormat);
} }
/** Sets the Photo header. */
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
}
/** Sets the Photo JPEG data. /** Sets the Photo JPEG data.
* \param data JPEG data * \param data JPEG data
* \param size JPEG data size * \param size JPEG data size
@ -333,9 +337,9 @@ public:
void setJson(const char *json, uint32_t bufferSize = 0) { void setJson(const char *json, uint32_t bufferSize = 0) {
ragephoto_setphotojson(instance, json, bufferSize); ragephoto_setphotojson(instance, json, bufferSize);
} }
/** Sets the Photo header. */ /** Sets a library flag. */
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) { static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true) {
ragephoto_setphotoheader2(instance, header, headerSum, headerSum2); ragephoto_setlibraryflag(flag, state);
} }
/** Sets the Photo title. */ /** Sets the Photo title. */
void setTitle(const char *title, uint32_t bufferSize = 0) { void setTitle(const char *title, uint32_t bufferSize = 0) {

View file

@ -133,8 +133,8 @@ public:
uint64_t jpegSign() 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. */ uint32_t jpegSize() const; /**< Returns the Photo JPEG data size. */
const char* description() const; /**< Returns the Photo description. */ 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* header() const; /**< Returns the Photo header. */
const char* json() const; /**< Returns the Photo JSON data. */
const char* title() const; /**< Returns the Photo title. */ const char* title() const; /**< Returns the Photo title. */
static const char* version(); /**< Returns the library version. */ 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, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
@ -170,6 +170,7 @@ public:
bool setData(RagePhotoData *rp_data, bool takeCopy = true); /**< Sets the internal RagePhotoData object. */ 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 setDescription(const char *description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */ void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0); /**< Sets the Photo header. */
/** Sets the Photo JPEG data. /** Sets the Photo JPEG data.
* \param data JPEG data * \param data JPEG data
* \param size JPEG data size * \param size JPEG data size
@ -182,7 +183,7 @@ public:
*/ */
bool setJpeg(const std::string &data, uint32_t bufferSize = 0); 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 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. */ static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true); /**< Sets a library flag. */
void setTitle(const char *title, uint32_t bufferSize = 0); /**< Sets the Photo title. */ void setTitle(const char *title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
private: private: