added a Simple C API

This commit is contained in:
Syping 2021-10-29 11:52:59 +02:00
parent 4785fafd67
commit 18b92c24f2
6 changed files with 100 additions and 6 deletions

View file

@ -864,3 +864,34 @@ inline void RagePhoto::uInt32ToCharLE(uint32_t x, char *y)
y[2] = x >> 16;
y[3] = x >> 24;
}
// C API
ragephoto_t ragephoto_open()
{
return new RagePhoto;
}
bool ragephoto_load(ragephoto_t instance, const char *data, size_t size)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->load(data, size);
}
const char* ragephoto_getphotodata(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->photoData();
}
uint32_t ragephoto_getphotosize(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->photoSize();
}
void ragephoto_close(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
delete ragePhoto;
}

View file

@ -16,9 +16,12 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
/** \file RagePhoto.h */
#ifndef RAGEPHOTO_H
#define RAGEPHOTO_H
#ifdef __cplusplus
#include "libragephoto_data.h"
#include "libragephoto_global.h"
#include <unordered_map>
@ -27,7 +30,9 @@
#include <cstdint>
#include <cstdio>
#ifndef LIBRAGEPHOTO_DOXYGEN
typedef std::function<bool(const char*, size_t, RagePhotoData*)> RagePhotoLoadFunc;
#endif
class LIBRAGEPHOTO_EXPORT RagePhoto
{
@ -163,5 +168,48 @@ protected:
std::unordered_map<uint8_t, RagePhotoLoadFunc> m_loadFuncs;
RagePhotoData m_data;
};
#endif
#ifdef __cplusplus
extern "C" {
#else
#include "libragephoto_global.h"
#include <stdint.h>
#endif
#ifdef LIBRAGEPHOTO_C_API
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT ragephoto_t ragephoto_open();
/** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_EXPORT bool ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotodata(ragephoto_t instance);
/** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT void ragephoto_close(ragephoto_t instance);
#endif
#ifdef __cplusplus
}
#endif
#endif // RAGEPHOTO_H

View file

@ -27,7 +27,7 @@
#define LIBRAGEPHOTO_EXPORT __declspec(dllimport)
#endif
#else
#define LIBRAGEPHOTO_EXPORT __attribute__((visibility("default")))
#define LIBRAGEPHOTO_EXPORT
#endif
#else
#define LIBRAGEPHOTO_EXPORT __attribute__((visibility("default")))

View file

@ -6,4 +6,4 @@ Name: libragephoto
Description: Open Source RAGE Photo Parser for GTA V
Version: @PROJECT_VERSION@
Libs: -L${libdir} -lragephoto
Cflags: -I${includedir} @LIBRAGEPHOTO_LIBTYPE@
Cflags: -I${includedir} -D@LIBRAGEPHOTO_API@ -D@LIBRAGEPHOTO_LIBTYPE@