libragephoto 0.4.0 release

- CMakeLists.txt: bump version to 0.4.0
- RagePhoto(A): add headerSum2 for RDR 2
- RagePhotoC: add ragephoto_setphotoheader2() for RDR 2
- RagePhotoTypedefs: remove unnamedSum1, rename unnamedSum2 ->
headerSum2
- RagePhotoTypedefs: remove ragephoto_bool_t for bool
This commit is contained in:
Syping 2023-05-14 11:44:59 +02:00
parent 3d9d632d7b
commit 4aedd8b869
6 changed files with 157 additions and 155 deletions

View File

@ -17,7 +17,7 @@
****************************************************************************]] ****************************************************************************]]
cmake_minimum_required(VERSION 3.8) cmake_minimum_required(VERSION 3.8)
project(ragephoto VERSION 0.3.0 LANGUAGES CXX) project(ragephoto VERSION 0.4.0 LANGUAGES CXX)
include(GNUInstallDirs) include(GNUInstallDirs)
# RagePhoto CMake includes # RagePhoto CMake includes

View File

@ -297,16 +297,17 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
#endif #endif
if (rp_data->photoFormat == PhotoFormat::RDR2) { if (rp_data->photoFormat == PhotoFormat::RDR2) {
size = readBuffer(data, uInt32Buffer, &pos, 4, length); char formatCheckBuffer[4];
size = readBuffer(data, formatCheckBuffer, &pos, 4, length);
if (size != 4) { if (size != 4) {
rp_data->error = Error::IncompleteChecksum; // 7 rp_data->error = Error::IncompleteChecksum; // 7
return false; return false;
} }
#if __BYTE_ORDER == __LITTLE_ENDIAN char n_formatCheckBuffer[4]{};
std::memcpy(&rp_data->unnamedSum1, uInt32Buffer, 4); if (std::memcmp(formatCheckBuffer, n_formatCheckBuffer, 4)) {
#else rp_data->error = Error::IncompatibleFormat; // 2
rp_data->unnamedSum1 = charToUInt32LE(uInt32Buffer); return false;
#endif }
size = readBuffer(data, uInt32Buffer, &pos, 4, length); size = readBuffer(data, uInt32Buffer, &pos, 4, length);
if (size != 4) { if (size != 4) {
@ -314,9 +315,9 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
return false; return false;
} }
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(&rp_data->unnamedSum2, uInt32Buffer, 4); std::memcpy(&rp_data->headerSum2, uInt32Buffer, 4);
#else #else
rp_data->unnamedSum2 = charToUInt32LE(uInt32Buffer); rp_data->headerSum2 = charToUInt32LE(uInt32Buffer);
#endif #endif
} }
const size_t headerSize = pos; const size_t headerSize = pos;
@ -370,7 +371,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJpegMarker; // 12 rp_data->error = Error::IncompleteJpegMarker; // 12
return false; return false;
} }
if (std::memcmp(markerBuffer, "JPEG", 4) != 0) { if (std::memcmp(markerBuffer, "JPEG", 4)) {
rp_data->error = Error::IncorrectJpegMarker; // 13 rp_data->error = Error::IncorrectJpegMarker; // 13
return false; return false;
} }
@ -416,7 +417,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJsonMarker; // 18 rp_data->error = Error::IncompleteJsonMarker; // 18
return false; return false;
} }
if (std::memcmp(markerBuffer, "JSON", 4) != 0) { if (std::memcmp(markerBuffer, "JSON", 4)) {
rp_data->error = Error::IncorrectJsonMarker; // 19 rp_data->error = Error::IncorrectJsonMarker; // 19
return false; return false;
} }
@ -451,7 +452,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteTitleMarker; // 23 rp_data->error = Error::IncompleteTitleMarker; // 23
return false; return false;
} }
if (std::memcmp(markerBuffer, "TITL", 4) != 0) { if (std::memcmp(markerBuffer, "TITL", 4)) {
rp_data->error = Error::IncorrectTitleMarker; // 24 rp_data->error = Error::IncorrectTitleMarker; // 24
return false; return false;
} }
@ -486,7 +487,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteDescMarker; // 28 rp_data->error = Error::IncompleteDescMarker; // 28
return false; return false;
} }
if (std::memcmp(markerBuffer, "DESC", 4) != 0) { if (std::memcmp(markerBuffer, "DESC", 4)) {
rp_data->error = Error::IncorrectDescMarker; // 29 rp_data->error = Error::IncorrectDescMarker; // 29
return false; return false;
} }
@ -521,7 +522,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
rp_data->error = Error::IncompleteJendMarker; // 33 rp_data->error = Error::IncompleteJendMarker; // 33
return false; return false;
} }
if (std::memcmp(markerBuffer, "JEND", 4) != 0) { if (std::memcmp(markerBuffer, "JEND", 4)) {
rp_data->error = Error::IncorrectJendMarker; // 34 rp_data->error = Error::IncorrectJendMarker; // 34
return false; return false;
} }
@ -535,8 +536,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
#ifdef RAGEPHOTO_DEBUG #ifdef RAGEPHOTO_DEBUG
std::cout << "header: " << rp_data->header << std::endl; std::cout << "header: " << rp_data->header << std::endl;
std::cout << "headerSum: " << rp_data->headerSum << std::endl; std::cout << "headerSum: " << rp_data->headerSum << std::endl;
std::cout << "unnamedSum1: " << rp_data->unnamedSum1 << std::endl; std::cout << "headerSum2: " << rp_data->headerSum2 << std::endl;
std::cout << "unnamedSum2: " << rp_data->unnamedSum2 << std::endl;
std::cout << "photoBuffer: " << rp_data->jpegBuffer << std::endl; std::cout << "photoBuffer: " << rp_data->jpegBuffer << std::endl;
std::cout << "descBuffer: " << rp_data->descBuffer << std::endl; std::cout << "descBuffer: " << rp_data->descBuffer << std::endl;
std::cout << "descOffset: " << rp_data->descOffset << std::endl; std::cout << "descOffset: " << rp_data->descOffset << std::endl;
@ -790,17 +790,13 @@ bool RagePhoto::save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, R
writeBuffer(uInt32Buffer, data, &pos, length, 4); writeBuffer(uInt32Buffer, data, &pos, length, 4);
if (photoFormat == PhotoFormat::RDR2) { if (photoFormat == PhotoFormat::RDR2) {
#if __BYTE_ORDER == __LITTLE_ENDIAN char n_formatCheckBuffer[4]{};
std::memcpy(uInt32Buffer, &rp_data->unnamedSum1, 4); writeBuffer(n_formatCheckBuffer, data, &pos, length, 4);
#else
uInt32ToCharLE(rp_data->unnamedSum1, uInt32Buffer);
#endif
writeBuffer(uInt32Buffer, data, &pos, length, 4);
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
std::memcpy(uInt32Buffer, &rp_data->unnamedSum2, 4); std::memcpy(uInt32Buffer, &rp_data->headerSum2, 4);
#else #else
uInt32ToCharLE(rp_data->unnamedSum2, uInt32Buffer); uInt32ToCharLE(rp_data->headerSum2, uInt32Buffer);
#endif #endif
writeBuffer(uInt32Buffer, data, &pos, length, 4); writeBuffer(uInt32Buffer, data, &pos, length, 4);
} }
@ -1062,6 +1058,7 @@ bool RagePhoto::setData(RagePhotoData *rp_data, bool takeCopy)
return false; return false;
std::memcpy(m_data->header, rp_data->header, headerSize); std::memcpy(m_data->header, rp_data->header, headerSize);
m_data->headerSum = rp_data->headerSum; m_data->headerSum = rp_data->headerSum;
m_data->headerSum2 = rp_data->headerSum2;
} }
if (rp_data->jpeg) { if (rp_data->jpeg) {
@ -1100,8 +1097,6 @@ bool RagePhoto::setData(RagePhotoData *rp_data, bool takeCopy)
m_data->descBuffer = rp_data->descBuffer; m_data->descBuffer = rp_data->descBuffer;
} }
m_data->unnamedSum1 = rp_data->unnamedSum1;
m_data->unnamedSum2 = rp_data->unnamedSum2;
setBufferOffsets(m_data); setBufferOffsets(m_data);
} }
else { else {
@ -1200,13 +1195,14 @@ 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) void RagePhoto::setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2)
{ {
if (!writeDataChar(header, &m_data->header)) { if (!writeDataChar(header, &m_data->header)) {
m_data->error = Error::HeaderMallocError; // 4 m_data->error = Error::HeaderMallocError; // 4
return; return;
} }
m_data->headerSum = headerSum; m_data->headerSum = headerSum;
m_data->headerSum2 = headerSum2;
m_data->error = Error::NoError; // 255 m_data->error = Error::NoError; // 255
} }
@ -1246,18 +1242,18 @@ void ragephotodata_clear(RagePhotoData *rp_data)
RagePhoto::clear(rp_data); RagePhoto::clear(rp_data);
} }
ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size) bool ragephoto_load(ragephoto_t instance, const char *data, size_t size)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->load(data, size); return ragePhoto->load(data, size);
} }
ragephoto_bool_t ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size) bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size)
{ {
return RagePhoto::load(data, size, rp_data, rp_parser); return RagePhoto::load(data, size, rp_data, rp_parser);
} }
ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename) bool ragephoto_loadfile(ragephoto_t instance, const char *filename)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->loadFile(filename); return ragePhoto->loadFile(filename);
@ -1381,35 +1377,35 @@ size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser
return RagePhoto::saveSize(photoFormat, rp_data, rp_parser); return RagePhoto::saveSize(photoFormat, rp_data, rp_parser);
} }
ragephoto_bool_t ragephoto_save(ragephoto_t instance, char *data) bool ragephoto_save(ragephoto_t instance, char *data)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->save(data); return ragePhoto->save(data);
} }
ragephoto_bool_t ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data) bool ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data)
{ {
return RagePhoto::save(data, rp_data->photoFormat, rp_data, rp_parser); return RagePhoto::save(data, rp_data->photoFormat, rp_data, rp_parser);
} }
ragephoto_bool_t ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat) bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->save(data, photoFormat); return ragePhoto->save(data, photoFormat);
} }
ragephoto_bool_t ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat) bool ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat)
{ {
return RagePhoto::save(data, photoFormat, rp_data, rp_parser); return RagePhoto::save(data, photoFormat, rp_data, rp_parser);
} }
ragephoto_bool_t ragephoto_savefile(ragephoto_t instance, const char *filename) bool ragephoto_savefile(ragephoto_t instance, const char *filename)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->saveFile(filename); return ragePhoto->saveFile(filename);
} }
ragephoto_bool_t ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat) bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->saveFile(filename, photoFormat); return ragePhoto->saveFile(filename, photoFormat);
@ -1437,13 +1433,13 @@ void ragephotodata_setbufferoffsets(RagePhotoData *rp_data)
RagePhoto::setBufferOffsets(rp_data); RagePhoto::setBufferOffsets(rp_data);
} }
ragephoto_bool_t 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);
return ragePhoto->setData(rp_data, false); return ragePhoto->setData(rp_data, false);
} }
ragephoto_bool_t ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data) bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->setData(rp_data, true); return ragePhoto->setData(rp_data, true);
@ -1461,7 +1457,7 @@ void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat)
ragePhoto->setFormat(photoFormat); ragePhoto->setFormat(photoFormat);
} }
ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize) bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->setJpeg(data, size, bufferSize); return ragePhoto->setJpeg(data, size, bufferSize);
@ -1479,6 +1475,12 @@ void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t
ragePhoto->setHeader(header, headerSum); ragePhoto->setHeader(header, headerSum);
} }
void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
ragePhoto->setHeader(header, headerSum, headerSum2);
}
void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize) void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);

View File

@ -45,47 +45,47 @@ public:
}; };
/** Parsing and set errors */ /** Parsing and set errors */
enum Error : int32_t { enum Error : int32_t {
DescBufferTight = 39, /**< Description Buffer is too tight */ DescBufferTight = 39L, /**< Description Buffer is too tight */
DescMallocError = 31, /**< Description Buffer can't be allocated */ DescMallocError = 31L, /**< Description Buffer can't be allocated */
DescReadError = 32, /**< Description can't be read successfully */ DescReadError = 32L, /**< Description can't be read successfully */
HeaderBufferTight = 35, /**< Header Buffer is too tight */ HeaderBufferTight = 35L, /**< Header Buffer is too tight */
HeaderMallocError = 4, /**< Header Buffer can't be allocated */ HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
IncompatibleFormat = 2, /**< Format is incompatible */ IncompatibleFormat = 2L, /**< Format is incompatible */
IncompleteChecksum = 7, /**< Header checksum is incomplete */ IncompleteChecksum = 7L, /**< Header checksum is incomplete */
IncompleteDescBuffer = 30, /**< Description Buffer Size is incomplete */ IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
IncompleteDescMarker = 28, /**< Description Marker is incomplete */ IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
IncompleteDescOffset = 11, /**< Description Offset is incomplete */ IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
IncompleteEOF = 8, /**< End Of File Offset is incomplete */ IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
IncompleteHeader = 3, /**< Header is incomplete */ IncompleteHeader = 3L, /**< Header is incomplete */
IncompleteJendMarker = 33, /**< JEND Marker is incomplete */ IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
IncompleteJpegMarker = 12, /**< JPEG Marker is incomplete */ IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
IncompleteJsonBuffer = 20, /**< JSON Buffer Size is incomplete */ IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
IncompleteJsonMarker = 18, /**< JSON Marker incomplete */ IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
IncompleteJsonOffset = 9, /**< JSON Offset incomplete */ IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
IncompletePhotoBuffer = 14, /**< Photo Buffer Size is incomplete */ IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
IncompletePhotoSize = 15, /**< Photo Size is incomplete */ IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
IncompleteTitleBuffer = 25, /**< Title Buffer Size is incomplete */ IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
IncompleteTitleMarker = 23, /**< Title Marker is incomplete */ IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
IncompleteTitleOffset = 10, /**< Title Offset is incomplete */ IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
IncorrectDescMarker = 29, /**< Description Marker is incorrect */ IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
IncorrectJendMarker = 34, /**< JEND Marker is incorrect */ IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
IncorrectJpegMarker = 13, /**< JPEG Marker is incorrect */ IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
IncorrectJsonMarker = 19, /**< JSON Marker is incorrect */ IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
IncorrectTitleMarker = 24, /**< Title Marker is incorrect */ IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
JsonBufferTight = 37, /**< JSON Buffer is too tight */ JsonBufferTight = 37L, /**< JSON Buffer is too tight */
JsonMallocError = 21, /**< JSON Buffer can't be allocated */ JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
JsonReadError = 22, /**< JSON can't be read successfully */ JsonReadError = 22L, /**< JSON can't be read successfully */
NoError = 255, /**< Finished without errors */ NoError = 255L, /**< Finished without errors */
NoFormatIdentifier = 1, /**< No format detected, empty file */ NoFormatIdentifier = 1L, /**< No format detected, empty file */
PhotoBufferTight = 36, /**< Photo Buffer is too tight */ PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
PhotoMallocError = 16, /**< Photo Buffer can't be allocated */ PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
PhotoReadError = 17, /**< Photo can't be read */ PhotoReadError = 17L, /**< Photo can't be read */
TitleBufferTight = 38, /**< Title Buffer is too tight */ TitleBufferTight = 38L, /**< Title Buffer is too tight */
TitleMallocError = 26, /**< Title Buffer can't be allocated */ TitleMallocError = 26L, /**< Title Buffer can't be allocated */
TitleReadError = 27, /**< Title can't be read */ TitleReadError = 27L, /**< Title can't be read */
UnicodeInitError = 5, /**< Failed to initialise Unicode decoder */ UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
UnicodeHeaderError = 6, /**< Header can't be encoded/decoded successfully */ UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
Uninitialised = 0, /**< Uninitialised, file access failed */ Uninitialised = 0L, /**< Uninitialised, file access failed */
}; };
/** Photo Formats */ /** Photo Formats */
enum PhotoFormat : uint32_t { enum PhotoFormat : uint32_t {
@ -179,7 +179,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); /**< Sets the Photo header. (EXPERT ONLY) */ void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0); /**< Sets the Photo header. */
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:

View File

@ -45,47 +45,47 @@ public:
}; };
/** Parsing and set errors */ /** Parsing and set errors */
enum Error : int32_t { enum Error : int32_t {
DescBufferTight = 39, /**< Description Buffer is too tight */ DescBufferTight = 39L, /**< Description Buffer is too tight */
DescMallocError = 31, /**< Description Buffer can't be allocated */ DescMallocError = 31L, /**< Description Buffer can't be allocated */
DescReadError = 32, /**< Description can't be read successfully */ DescReadError = 32L, /**< Description can't be read successfully */
HeaderBufferTight = 35, /**< Header Buffer is too tight */ HeaderBufferTight = 35L, /**< Header Buffer is too tight */
HeaderMallocError = 4, /**< Header Buffer can't be allocated */ HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
IncompatibleFormat = 2, /**< Format is incompatible */ IncompatibleFormat = 2L, /**< Format is incompatible */
IncompleteChecksum = 7, /**< Header checksum is incomplete */ IncompleteChecksum = 7L, /**< Header checksum is incomplete */
IncompleteDescBuffer = 30, /**< Description Buffer Size is incomplete */ IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
IncompleteDescMarker = 28, /**< Description Marker is incomplete */ IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
IncompleteDescOffset = 11, /**< Description Offset is incomplete */ IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
IncompleteEOF = 8, /**< End Of File Offset is incomplete */ IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
IncompleteHeader = 3, /**< Header is incomplete */ IncompleteHeader = 3L, /**< Header is incomplete */
IncompleteJendMarker = 33, /**< JEND Marker is incomplete */ IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
IncompleteJpegMarker = 12, /**< JPEG Marker is incomplete */ IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
IncompleteJsonBuffer = 20, /**< JSON Buffer Size is incomplete */ IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
IncompleteJsonMarker = 18, /**< JSON Marker incomplete */ IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
IncompleteJsonOffset = 9, /**< JSON Offset incomplete */ IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
IncompletePhotoBuffer = 14, /**< Photo Buffer Size is incomplete */ IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
IncompletePhotoSize = 15, /**< Photo Size is incomplete */ IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
IncompleteTitleBuffer = 25, /**< Title Buffer Size is incomplete */ IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
IncompleteTitleMarker = 23, /**< Title Marker is incomplete */ IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
IncompleteTitleOffset = 10, /**< Title Offset is incomplete */ IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
IncorrectDescMarker = 29, /**< Description Marker is incorrect */ IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
IncorrectJendMarker = 34, /**< JEND Marker is incorrect */ IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
IncorrectJpegMarker = 13, /**< JPEG Marker is incorrect */ IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
IncorrectJsonMarker = 19, /**< JSON Marker is incorrect */ IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
IncorrectTitleMarker = 24, /**< Title Marker is incorrect */ IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
JsonBufferTight = 37, /**< JSON Buffer is too tight */ JsonBufferTight = 37L, /**< JSON Buffer is too tight */
JsonMallocError = 21, /**< JSON Buffer can't be allocated */ JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
JsonReadError = 22, /**< JSON can't be read successfully */ JsonReadError = 22L, /**< JSON can't be read successfully */
NoError = 255, /**< Finished without errors */ NoError = 255L, /**< Finished without errors */
NoFormatIdentifier = 1, /**< No format detected, empty file */ NoFormatIdentifier = 1L, /**< No format detected, empty file */
PhotoBufferTight = 36, /**< Photo Buffer is too tight */ PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
PhotoMallocError = 16, /**< Photo Buffer can't be allocated */ PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
PhotoReadError = 17, /**< Photo can't be read */ PhotoReadError = 17L, /**< Photo can't be read */
TitleBufferTight = 38, /**< Title Buffer is too tight */ TitleBufferTight = 38L, /**< Title Buffer is too tight */
TitleMallocError = 26, /**< Title Buffer can't be allocated */ TitleMallocError = 26L, /**< Title Buffer can't be allocated */
TitleReadError = 27, /**< Title can't be read */ TitleReadError = 27L, /**< Title can't be read */
UnicodeInitError = 5, /**< Failed to initialise Unicode decoder */ UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
UnicodeHeaderError = 6, /**< Header can't be encoded/decoded successfully */ UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
Uninitialised = 0, /**< Uninitialised, file access failed */ Uninitialised = 0L, /**< Uninitialised, file access failed */
}; };
/** Photo Formats */ /** Photo Formats */
enum PhotoFormat : uint32_t { enum PhotoFormat : uint32_t {
@ -331,9 +331,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. (EXPERT ONLY) */ /** Sets the Photo header. */
void setHeader(const char *header, uint32_t headerSum) { void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
ragephoto_setphotoheader(instance, header, headerSum); ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
} }
/** 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

@ -63,7 +63,7 @@ LIBRAGEPHOTO_C_PUBLIC void ragephotodata_clear(RagePhotoData *rp_data);
* \param data Photo data * \param data Photo data
* \param size Photo data size * \param size Photo data size
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_load(ragephoto_t instance, const char *data, size_t size); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a const char*. /** Loads a Photo from a const char*.
* \param rp_data RagePhotoData object * \param rp_data RagePhotoData object
@ -71,13 +71,13 @@ LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_load(ragephoto_t instance, cons
* \param data Photo data * \param data Photo data
* \param size Photo data size * \param size Photo data size
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size); LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size);
/** Loads a Photo from a file. /** Loads a Photo from a file.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param filename File to load * \param filename File to load
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_loadfile(ragephoto_t instance, const char *filename); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_loadfile(ragephoto_t instance, const char *filename);
/** Returns the last error occurred. /** Returns the last error occurred.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -186,21 +186,21 @@ LIBRAGEPHOTO_C_PUBLIC size_t ragephotodata_getsavesizef(RagePhotoData *rp_data,
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param data Photo data * \param data Photo data
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_save(ragephoto_t instance, char *data); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_save(ragephoto_t instance, char *data);
/** Saves a Photo to a char*. /** Saves a Photo to a char*.
* \param rp_data RagePhotoData object * \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array * \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data * \param data Photo data
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data); LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data);
/** Saves a Photo to a char*. /** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param data Photo data * \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2) * \param photoFormat Photo Format (GTA V or RDR 2)
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a char*. /** Saves a Photo to a char*.
* \param rp_data RagePhotoData object * \param rp_data RagePhotoData object
@ -208,20 +208,20 @@ LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_savef(ragephoto_t instance, cha
* \param data Photo data * \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2) * \param photoFormat Photo Format (GTA V or RDR 2)
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat); LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat);
/** Saves a Photo to a file. /** Saves a Photo to a file.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param filename File to save * \param filename File to save
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_savefile(ragephoto_t instance, const char *filename); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefile(ragephoto_t instance, const char *filename);
/** Saves a Photo to a file. /** Saves a Photo to a file.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param filename File to save * \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2) * \param photoFormat Photo Format (GTA V or RDR 2)
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size. /** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -247,13 +247,13 @@ LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being set * \param rp_data RagePhotoData object being set
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data);
/** Copies RagePhotoData object to internal RagePhotoData object. /** Copies RagePhotoData object to internal RagePhotoData object.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being copied * \param rp_data RagePhotoData object being copied
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data);
/** Sets the Photo description. /** Sets the Photo description.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -278,7 +278,7 @@ LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoformat(ragephoto_t instance, uint32
* *
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2() * Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/ */
LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize); LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data. /** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
@ -289,9 +289,12 @@ LIBRAGEPHOTO_C_PUBLIC ragephoto_bool_t ragephoto_setphotojpeg(ragephoto_t instan
*/ */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize); LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. (EXPERT ONLY) */ /** Sets the Photo header. */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum); LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo header. (RDR 2) */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2);
/** Sets the Photo title. /** Sets the Photo title.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
* \param title Title * \param title Title

View File

@ -19,6 +19,7 @@
#ifndef RAGEPHOTOTYPEDEFS_H #ifndef RAGEPHOTOTYPEDEFS_H
#define RAGEPHOTOTYPEDEFS_H #define RAGEPHOTOTYPEDEFS_H
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -34,32 +35,28 @@ typedef struct RagePhotoData {
char* header; /**< Pointer for internal Header buffer */ char* header; /**< Pointer for internal Header buffer */
char* title; /**< Pointer for internal Title buffer */ char* title; /**< Pointer for internal Title buffer */
int32_t error; /**< RagePhoto error code */ int32_t error; /**< RagePhoto error code */
uint32_t descBuffer; /**< Photo Description buffer length */ uint32_t descBuffer; /**< Description buffer length */
uint32_t descOffset; /**< Photo Description buffer offset */ uint32_t descOffset; /**< Description buffer offset */
uint32_t endOfFile; /**< Photo End Of File offset */ uint32_t endOfFile; /**< End Of File offset */
uint32_t headerSum; /**< Photo Checksum of the header */ uint32_t headerSum; /**< Checksum of the header 1 */
uint32_t jpegBuffer; /**< Photo JPEG buffer length */ uint32_t headerSum2; /**< Checksum of the header 2 (RDR 2 only) */
uint32_t jpegBuffer; /**< JPEG buffer length */
uint32_t jpegSize; /**< Internal JPEG buffer length and size of JPEG */ uint32_t jpegSize; /**< Internal JPEG buffer length and size of JPEG */
uint32_t jsonBuffer; /**< Photo JSON buffer length */ uint32_t jsonBuffer; /**< JSON buffer length */
uint32_t jsonOffset; /**< Photo JSON buffer offset */ uint32_t jsonOffset; /**< JSON buffer offset */
uint32_t photoFormat; /**< Photo file format magic */ uint32_t photoFormat; /**< Photo file format magic */
uint32_t titlBuffer; /**< Photo Title buffer length */ uint32_t titlBuffer; /**< Title buffer length */
uint32_t titlOffset; /**< Photo Title buffer offset */ uint32_t titlOffset; /**< Title buffer offset */
uint32_t unnamedSum1; /**< 1st unnamed checksum for Red Dead Redemption 2 */
uint32_t unnamedSum2; /**< 2nd unnamed checksum for Red Dead Redemption 2 */
} RagePhotoData; } RagePhotoData;
/** RagePhoto bool typedef. */
typedef int32_t ragephoto_bool_t;
/** RagePhoto load function typedef. */ /** RagePhoto load function typedef. */
typedef ragephoto_bool_t (*ragephoto_loadfunc_t)(RagePhotoData*, const char*, size_t); typedef bool (*ragephoto_loadfunc_t)(RagePhotoData*, const char*, size_t);
/** RagePhoto save function typedef (char* allocated by caller). */ /** RagePhoto save function typedef (char* allocated by caller). */
typedef ragephoto_bool_t (*ragephoto_savefunc_t)(RagePhotoData*, char*, uint32_t); typedef bool (*ragephoto_savefunc_t)(RagePhotoData*, char*, uint32_t);
/** RagePhoto save function typedef (char* allocated by function). */ /** RagePhoto save function typedef (char* allocated by function). */
typedef ragephoto_bool_t (*ragephoto_savepfunc_t)(RagePhotoData*, char**, uint32_t); typedef bool (*ragephoto_savepfunc_t)(RagePhotoData*, char**, uint32_t);
/** RagePhoto saveSize function typedef. */ /** RagePhoto saveSize function typedef. */
typedef size_t (*ragephoto_saveszfunc_t)(RagePhotoData*, uint32_t); typedef size_t (*ragephoto_saveszfunc_t)(RagePhotoData*, uint32_t);