add documentation and set functions
This commit is contained in:
parent
3479a5597c
commit
3fa0068251
5 changed files with 170 additions and 14 deletions
|
@ -402,6 +402,96 @@ const std::string RagePhoto::title()
|
|||
return p_titleString;
|
||||
}
|
||||
|
||||
void RagePhoto::setDescription(const std::string &description, uint32_t bufferSize)
|
||||
{
|
||||
p_descriptionString = description;
|
||||
if (bufferSize != 0) {
|
||||
p_descBuffer = bufferSize;
|
||||
moveOffsets();
|
||||
}
|
||||
}
|
||||
|
||||
void RagePhoto::setJson(const std::string &json, uint32_t bufferSize)
|
||||
{
|
||||
p_jsonString = json;
|
||||
if (bufferSize != 0) {
|
||||
p_jsonBuffer = bufferSize;
|
||||
moveOffsets();
|
||||
}
|
||||
}
|
||||
|
||||
void RagePhoto::setHeader(const std::string &header)
|
||||
{
|
||||
p_photoString = header;
|
||||
}
|
||||
|
||||
bool RagePhoto::setPhotoData(const char *data, uint32_t size, uint32_t bufferSize)
|
||||
{
|
||||
if (p_photoLoaded) {
|
||||
if (p_photoSize > size) {
|
||||
char *t_photoData = static_cast<char*>(realloc(p_photoData, size));
|
||||
if (!t_photoData) {
|
||||
p_error = Error::PhotoMallocError; // 15
|
||||
return false;
|
||||
}
|
||||
p_photoData = t_photoData;
|
||||
memcpy(p_photoData, data, size);
|
||||
}
|
||||
else if (p_photoSize < size) {
|
||||
free(p_photoData);
|
||||
p_photoData = static_cast<char*>(malloc(size));
|
||||
if (!p_photoData) {
|
||||
p_error = Error::PhotoMallocError; // 15
|
||||
p_photoLoaded = false;
|
||||
return false;
|
||||
}
|
||||
memcpy(p_photoData, data, size);
|
||||
}
|
||||
else {
|
||||
memcpy(p_photoData, data, size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
p_photoData = static_cast<char*>(malloc(size));
|
||||
if (!p_photoData) {
|
||||
p_error = Error::PhotoMallocError; // 15
|
||||
return false;
|
||||
}
|
||||
memcpy(p_photoData, data, size);
|
||||
p_photoLoaded = true;
|
||||
}
|
||||
|
||||
if (bufferSize != 0) {
|
||||
p_photoBuffer = bufferSize;
|
||||
moveOffsets();
|
||||
}
|
||||
|
||||
p_error = Error::NoError; // 255
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RagePhoto::setPhotoData(const std::string &data, uint32_t bufferSize)
|
||||
{
|
||||
return setPhotoData(data.data(), data.size(), bufferSize);
|
||||
}
|
||||
|
||||
void RagePhoto::setTitle(const std::string &title, uint32_t bufferSize)
|
||||
{
|
||||
p_titleString = title;
|
||||
if (bufferSize != 0) {
|
||||
p_titlBuffer = bufferSize;
|
||||
moveOffsets();
|
||||
}
|
||||
}
|
||||
|
||||
void RagePhoto::moveOffsets()
|
||||
{
|
||||
p_jsonOffset = p_photoBuffer + 28;
|
||||
p_titlOffset = p_jsonOffset + p_jsonBuffer + 8;
|
||||
p_descOffset = p_titlOffset + p_titlBuffer + 8;
|
||||
p_endOfFile = p_descOffset + p_descBuffer + 12;
|
||||
}
|
||||
|
||||
size_t RagePhoto::readBuffer(const char *input, char *output, size_t *pos, size_t len, size_t inputLen)
|
||||
{
|
||||
size_t readLen = 0;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
class LIBRAGEPHOTO_EXPORT RagePhoto
|
||||
{
|
||||
public:
|
||||
/** Parsing and set errors */
|
||||
enum class Error : uint8_t {
|
||||
DescMallocError = 30,
|
||||
DescReadError = 31,
|
||||
|
@ -64,26 +65,41 @@ public:
|
|||
UnicodeInitError = 4,
|
||||
Uninitialised = 0,
|
||||
};
|
||||
/** Photo Formats */
|
||||
enum class PhotoFormat : uint32_t {
|
||||
GTA5 = 0x01000000U,
|
||||
RDR2 = 0x04000000U,
|
||||
Undefined = 0,
|
||||
GTA5 = 0x01000000U, /**< GTA V Photo Format */
|
||||
RDR2 = 0x04000000U, /**< RDR 2 Photo Format */
|
||||
Undefined = 0, /**< Undefined Format */
|
||||
};
|
||||
RagePhoto();
|
||||
~RagePhoto();
|
||||
void clear();
|
||||
bool load(const char *data, size_t length);
|
||||
bool load(const std::string &data);
|
||||
Error error();
|
||||
PhotoFormat format();
|
||||
const char *photoData();
|
||||
const uint32_t photoSize();
|
||||
const std::string description();
|
||||
const std::string json();
|
||||
const std::string header();
|
||||
const std::string title();
|
||||
void clear(); /**< Resets the RagePhoto instance to default values. */
|
||||
bool load(const char *data, size_t length); /**< Loads a Photo stored inside a const char*. */
|
||||
bool load(const std::string &data); /**< Loads a Photo stored inside a std::string. */
|
||||
Error error(); /**< Returns the last error occurred. */
|
||||
PhotoFormat format(); /**< Returns the Photo Format (GTA V or RDR 2). */
|
||||
const char *photoData(); /**< Returns the Photo JPEG data. */
|
||||
const uint32_t photoSize(); /**< Returns the Photo JPEG data size. */
|
||||
const std::string description(); /**< Returns the Photo description. */
|
||||
const std::string json(); /**< Returns the Photo JSON data. */
|
||||
const std::string header(); /**< Returns the Photo header. */
|
||||
const std::string title(); /**< Returns the Photo title. */
|
||||
void setDescription(const std::string &description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
|
||||
void setJson(const std::string &json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
|
||||
void setHeader(const std::string &header); /**< Sets the Photo header. (expert only) */
|
||||
/** Sets the Photo JPEG data.
|
||||
* @param data JPEG data
|
||||
* @param size JPEG data size
|
||||
*/
|
||||
bool setPhotoData(const char *data, uint32_t size, uint32_t bufferSize = 0);
|
||||
/** Sets the Photo JPEG data.
|
||||
* @param data JPEG data
|
||||
*/
|
||||
bool setPhotoData(const std::string &data, uint32_t bufferSize = 0);
|
||||
void setTitle(const std::string &title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
|
||||
|
||||
protected:
|
||||
inline void moveOffsets();
|
||||
inline size_t readBuffer(const char *input, char *output, size_t *pos, size_t len, size_t inputLen);
|
||||
inline uint32_t charToUInt32BE(char *x);
|
||||
inline uint32_t charToUInt32LE(char *x);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue