C API: improvements and saving added

This commit is contained in:
Syping 2021-11-02 09:26:56 +01:00
parent 4e06444e40
commit af547bd89f
3 changed files with 182 additions and 21 deletions

View File

@ -883,16 +883,30 @@ uint8_t ragephoto_error(ragephoto_t instance)
return static_cast<uint8_t>(ragePhoto->error()); return static_cast<uint8_t>(ragePhoto->error());
} }
const char* ragephoto_getphotodata(ragephoto_t instance) uint32_t ragephoto_defpbuf_gta5()
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); return RagePhoto::DEFAULT_GTA5_PHOTOBUFFER;
return ragePhoto->photoData(); }
uint32_t ragephoto_defpbuf_rdr2()
{
return RagePhoto::DEFAULT_RDR2_PHOTOBUFFER;
}
uint32_t ragephoto_format_gta5()
{
return RagePhoto::GTA5;
}
uint32_t ragephoto_format_rdr2()
{
return RagePhoto::RDR2;
} }
const char* ragephoto_getphotodesc(ragephoto_t instance) const char* ragephoto_getphotodesc(ragephoto_t instance)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->description().data(); return ragePhoto->description().c_str();
} }
uint32_t ragephoto_getphotoformat(ragephoto_t instance) uint32_t ragephoto_getphotoformat(ragephoto_t instance)
@ -901,10 +915,22 @@ uint32_t ragephoto_getphotoformat(ragephoto_t instance)
return ragePhoto->format(); return ragePhoto->format();
} }
const char* ragephoto_getphotojpeg(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->photoData();
}
const char* ragephoto_getphotojson(ragephoto_t instance) const char* ragephoto_getphotojson(ragephoto_t instance)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->json().data(); return ragePhoto->json().c_str();
}
const char* ragephoto_getphotoheader(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->header().c_str();
} }
uint32_t ragephoto_getphotosize(ragephoto_t instance) uint32_t ragephoto_getphotosize(ragephoto_t instance)
@ -916,7 +942,67 @@ uint32_t ragephoto_getphotosize(ragephoto_t instance)
const char* ragephoto_getphototitle(ragephoto_t instance) const char* ragephoto_getphototitle(ragephoto_t instance)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->title().data(); return ragePhoto->title().c_str();
}
size_t ragephoto_getsavesize(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->saveSize();
}
int ragephoto_save(ragephoto_t instance, char *data)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->save(data);
}
void ragephoto_setbufferdefault(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setBufferDefault();
}
void ragephoto_setbufferoffsets(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setBufferOffsets();
}
void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setDescription(description, bufferSize);
}
void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setFormat(photoFormat);
}
int ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->setPhoto(data, size, bufferSize);
}
void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setJson(json, bufferSize);
}
void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setHeader(header, headerSum);
}
void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setTitle(title, bufferSize);
} }
void ragephoto_close(ragephoto_t instance) void ragephoto_close(ragephoto_t instance)

View File

@ -30,9 +30,7 @@
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#ifndef LIBRAGEPHOTO_DOXYGEN
typedef std::function<bool(const char*, size_t, RagePhotoData*)> RagePhotoLoadFunc; typedef std::function<bool(const char*, size_t, RagePhotoData*)> RagePhotoLoadFunc;
#endif
class LIBRAGEPHOTO_EXPORT RagePhoto class LIBRAGEPHOTO_EXPORT RagePhoto
{ {
@ -134,10 +132,10 @@ public:
* \param ok \p true when saved successfully * \param ok \p true when saved successfully
*/ */
const std::string save(bool *ok = nullptr); const std::string save(bool *ok = nullptr);
static size_t saveSize(RagePhotoData *ragePhotoData, uint32_t photoFormat); /**< Returns the save file size. */ static size_t saveSize(RagePhotoData *ragePhotoData, uint32_t photoFormat); /**< Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *ragePhotoData); /**< Returns the save file size. */ static size_t saveSize(RagePhotoData *ragePhotoData); /**< Returns the Photo save file size. */
size_t saveSize(uint32_t photoFormat); /**< Returns the save file size. */ size_t saveSize(uint32_t photoFormat); /**< Returns the Photo save file size. */
size_t saveSize(); /**< Returns the save file size. */ size_t saveSize(); /**< Returns the Photo save file size. */
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */ void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
static void setBufferDefault(RagePhotoData *ragePhotoData); /**< Sets all cross-format Buffer to default size. */ static void setBufferDefault(RagePhotoData *ragePhotoData); /**< Sets all cross-format Buffer to default size. */
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */ void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
@ -146,7 +144,7 @@ public:
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 setFormatLoadFunction(uint32_t photoFormat, RagePhotoLoadFunc func); /**< Sets a custom Photo Format load function. */ void setFormatLoadFunction(uint32_t photoFormat, RagePhotoLoadFunc func); /**< Sets a custom Photo Format load function. */
void setJson(const std::string &json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */ void setJson(const std::string &json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
void setHeader(const std::string &header, uint32_t headerSum); /**< Sets the Photo header. (expert only) */ void setHeader(const std::string &header, uint32_t headerSum); /**< Sets the Photo header. (EXPERT ONLY) */
/** 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
@ -168,6 +166,8 @@ protected:
std::unordered_map<uint8_t, RagePhotoLoadFunc> m_loadFuncs; std::unordered_map<uint8_t, RagePhotoLoadFunc> m_loadFuncs;
RagePhotoData m_data; RagePhotoData m_data;
}; };
#else
#define LIBRAGEPHOTO_C_API
#endif #endif
#ifdef LIBRAGEPHOTO_C_API #ifdef LIBRAGEPHOTO_C_API
@ -178,11 +178,10 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#endif #endif
/** RagePhoto C++ class typedef for C API. */
typedef void* ragephoto_t; typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. /** Opens a \p ragephoto_t instance. */
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT ragephoto_t ragephoto_open(); LIBRAGEPHOTO_EXPORT ragephoto_t ragephoto_open();
/** Loads a Photo from a const char*. /** Loads a Photo from a const char*.
@ -197,10 +196,17 @@ LIBRAGEPHOTO_EXPORT int ragephoto_load(ragephoto_t instance, const char *data, s
*/ */
LIBRAGEPHOTO_EXPORT uint8_t ragephoto_error(ragephoto_t instance); LIBRAGEPHOTO_EXPORT uint8_t ragephoto_error(ragephoto_t instance);
/** Returns the Photo JPEG data. /** Returns the GTA V default Photo Buffer Size. */
* \param instance \p ragephoto_t instance LIBRAGEPHOTO_EXPORT uint32_t ragephoto_defpbuf_gta5();
*/
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotodata(ragephoto_t instance); /** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_format_rdr2();
/** Returns the Photo description. /** Returns the Photo description.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -212,11 +218,21 @@ LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotodesc(ragephoto_t instance);
*/ */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotoformat(ragephoto_t instance); LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT 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_EXPORT const char* ragephoto_getphotojson(ragephoto_t instance); LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT 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
*/ */
@ -227,6 +243,65 @@ LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotosize(ragephoto_t instance);
*/ */
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphototitle(ragephoto_t instance); LIBRAGEPHOTO_EXPORT const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT size_t ragephoto_getsavesize(ragephoto_t instance);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
*/
LIBRAGEPHOTO_EXPORT int ragephoto_save(ragephoto_t instance, char *data);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setbufferdefault(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
* \param description Description
* \param bufferSize Description buffer size \p USE \p 0
*/
LIBRAGEPHOTO_EXPORT 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_EXPORT 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
*/
LIBRAGEPHOTO_EXPORT int 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 \p USE \p 0
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. (EXPERT ONLY) */
LIBRAGEPHOTO_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
* \param title Title
* \param bufferSize Title buffer size \p USE \p 0
*/
LIBRAGEPHOTO_EXPORT 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
*/ */

View File

@ -30,7 +30,7 @@
#define LIBRAGEPHOTO_EXPORT #define LIBRAGEPHOTO_EXPORT
#endif #endif
#else #else
#define LIBRAGEPHOTO_EXPORT __attribute__((visibility("default"))) #define LIBRAGEPHOTO_EXPORT
#endif #endif
#endif // LIBRAGEPHOTO_GLOBAL_H #endif // LIBRAGEPHOTO_GLOBAL_H