Skip to content

Commit

Permalink
libragephoto: update C API
Browse files Browse the repository at this point in the history
RagePhotoA: add new C API functions
RagePhotoC: add ragephotodata_clear(), ragephotodata_load(),
ragephotodata_getsavesize(), ragephotodata_getsavesizef(),
ragephotodata_setbufferdefault(), ragephotodata_setbufferoffsets()
  • Loading branch information
Syping committed Feb 20, 2023
1 parent e51d50f commit 9807f0d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/RagePhoto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,12 +1171,22 @@ void ragephoto_clear(ragephoto_t instance)
ragePhoto->clear();
}

void ragephotodata_clear(RagePhotoData *rp_data)
{
RagePhoto::clear(rp_data);
}

ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->load(data, size);
}

ragephoto_bool_t ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size)
{
return RagePhoto::load(rp_data, rp_parser, data, size);
}

ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
Expand Down Expand Up @@ -1263,12 +1273,22 @@ size_t ragephoto_getsavesize(ragephoto_t instance)
return ragePhoto->saveSize();
}

size_t ragephotodata_getsavesize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
{
return RagePhoto::saveSize(rp_data, rp_parser);
}

size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->saveSize(photoFormat);
}

size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat)
{
return RagePhoto::saveSize(rp_data, rp_parser, photoFormat);
}

ragephoto_bool_t ragephoto_save(ragephoto_t instance, char *data)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
Expand Down Expand Up @@ -1299,12 +1319,22 @@ void ragephoto_setbufferdefault(ragephoto_t instance)
ragePhoto->setBufferDefault();
}

void ragephotodata_setbufferdefault(RagePhotoData *rp_data)
{
RagePhoto::setBufferDefault(rp_data);
}

void ragephoto_setbufferoffsets(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setBufferOffsets();
}

void ragephotodata_setbufferoffsets(RagePhotoData *rp_data)
{
RagePhoto::setBufferOffsets(rp_data);
}

ragephoto_bool_t ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
Expand Down
30 changes: 29 additions & 1 deletion src/RagePhotoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,26 @@ class RagePhotoA
~RagePhotoA() {
ragephoto_close(instance);
}
/** Resets the RagePhoto instance to default values. */
/** Add a custom defined RagePhotoFormatParser. */
void addParser(RagePhotoFormatParser *rp_parser) {
ragephoto_addparser(instance, rp_parser);
}
/** Resets the RagePhotoData object to default values. */
static void clear(RagePhotoData *rp_data) {
ragephotodata_clear(rp_data);
}
/** Resets the RagePhotoData object to default values. */
void clear() {
ragephoto_clear(instance);
}
/** Returns the internal RagePhotoData object. */
RagePhotoData* data() {
return ragephoto_getphotodata(instance);
}
/** Loads a Photo from a const char*. */
static bool load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size) {
return ragephotodata_load(rp_data, rp_parser, data, size);
}
/** Loads a Photo from a const char*.
* \param data Photo data
* \param size Photo data size
Expand Down Expand Up @@ -211,6 +223,14 @@ class RagePhotoA
return ragephoto_savefile(instance, filename);
}
/** Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat) {
return ragephotodata_getsavesizef(rp_data, rp_parser, photoFormat);
}
/** Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
return ragephotodata_getsavesize(rp_data, rp_parser);
}
/** Returns the Photo save file size. */
size_t saveSize(uint32_t photoFormat) {
return ragephoto_getsavesizef(instance, photoFormat);
}
Expand All @@ -219,10 +239,18 @@ class RagePhotoA
return ragephoto_getsavesize(instance);
}
/** Sets all cross-format Buffer to default size. */
static void setBufferDefault(RagePhotoData *rp_data) {
ragephotodata_setbufferdefault(rp_data);
}
/** Sets all cross-format Buffer to default size. */
void setBufferDefault() {
ragephoto_setbufferdefault(instance);
}
/** Moves all Buffer offsets to correct position. */
static void setBufferOffsets(RagePhotoData *rp_data) {
ragephotodata_setbufferoffsets(rp_data);
}
/** Moves all Buffer offsets to correct position. */
void setBufferOffsets() {
ragephoto_setbufferoffsets(instance);
}
Expand Down
38 changes: 37 additions & 1 deletion src/RagePhotoC.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,31 @@ LIBRAGEPHOTO_C_BINDING ragephoto_t ragephoto_open();
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser);

/** Resets the \p ragephoto_t instance to default values.
/** Resets the RagePhotoData object to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_clear(ragephoto_t instance);

/** Resets the RagePhotoData object to default values.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_BINDING void ragephotodata_clear(RagePhotoData *rp_data);

/** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size);

/** Loads a Photo from a const char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size);

/** Loads a Photo from a file.
* \param instance \p ragephoto_t instance
* \param filename File to load
Expand Down Expand Up @@ -125,12 +138,25 @@ LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphototitle(ragephoto_t instance)
*/
LIBRAGEPHOTO_C_BINDING size_t ragephoto_getsavesize(ragephoto_t instance);

/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
*/
LIBRAGEPHOTO_C_BINDING size_t ragephotodata_getsavesize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);

/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);

/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_BINDING size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat);

/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
Expand Down Expand Up @@ -162,11 +188,21 @@ LIBRAGEPHOTO_C_BINDING ragephoto_bool_t ragephoto_savefilef(ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setbufferdefault(ragephoto_t instance);

/** Sets all cross-format Buffer to default size.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_BINDING void ragephotodata_setbufferdefault(RagePhotoData *rp_data);

/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_BINDING void ragephoto_setbufferoffsets(ragephoto_t instance);

/** Moves all Buffer offsets to correct position.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_BINDING void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);

/** Sets the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being set
Expand Down

0 comments on commit 9807f0d

Please sign in to comment.