libragephoto Version: 0.6.0
Loading...
Searching...
No Matches
ragephoto_c.hpp
1/*****************************************************************************
2* libragephoto RAGE Photo Parser
3* Copyright (C) 2021-2024 Syping
4*
5* Redistribution and use in source and binary forms, with or without modification,
6* are permitted provided that the following conditions are met:
7*
8* 1. Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10*
11* 2. Redistributions in binary form must reproduce the above copyright notice,
12* this list of conditions and the following disclaimer in the documentation
13* and/or other materials provided with the distribution.
14*
15* This software is provided as-is, no warranties are given to you, we are not
16* responsible for anything with use of the software, you are self responsible.
17*****************************************************************************/
18
19#ifndef RAGEPHOTO_C_HPP
20#define RAGEPHOTO_C_HPP
21
22#ifdef __cplusplus
23#include "RagePhoto.h"
24#include <cstdlib>
25#include <iostream>
26
27namespace ragephoto_c {
28
33class photo
34{
35public:
37 enum DefaultSize : uint32_t {
38 DEFAULT_GTA5_PHOTOBUFFER = RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER,
39 DEFAULT_RDR2_PHOTOBUFFER = RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER,
40 DEFAULT_DESCBUFFER = RAGEPHOTO_DEFAULT_DESCBUFFER,
41 DEFAULT_JSONBUFFER = RAGEPHOTO_DEFAULT_JSONBUFFER,
42 DEFAULT_TITLBUFFER = RAGEPHOTO_DEFAULT_TITLBUFFER,
43 GTA5_HEADERSIZE = RAGEPHOTO_GTA5_HEADERSIZE,
44 RDR2_HEADERSIZE = RAGEPHOTO_RDR2_HEADERSIZE,
45 };
47 enum Error : int32_t {
48 DescBufferTight = RAGEPHOTO_ERROR_DESCBUFFERTIGHT,
49 DescMallocError = RAGEPHOTO_ERROR_DESCMALLOCERROR,
50 DescReadError = RAGEPHOTO_ERROR_DESCREADERROR,
51 HeaderBufferTight = RAGEPHOTO_ERROR_HEADERBUFFERTIGHT,
52 HeaderMallocError = RAGEPHOTO_ERROR_HEADERMALLOCERROR,
53 IncompatibleFormat = RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT,
54 IncompleteChecksum = RAGEPHOTO_ERROR_INCOMPLETECHECKSUM,
55 IncompleteDescBuffer = RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER,
56 IncompleteDescMarker = RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER,
57 IncompleteDescOffset = RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET,
58 IncompleteEOF = RAGEPHOTO_ERROR_INCOMPLETEEOF,
59 IncompleteHeader = RAGEPHOTO_ERROR_INCOMPLETEHEADER,
60 IncompleteJendMarker = RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER,
61 IncompleteJpegMarker = RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER,
62 IncompleteJsonBuffer = RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER,
63 IncompleteJsonMarker = RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER,
64 IncompleteJsonOffset = RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET,
65 IncompletePhotoBuffer = RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER,
66 IncompletePhotoSize = RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE,
67 IncompleteTitleBuffer = RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER,
68 IncompleteTitleMarker = RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER,
69 IncompleteTitleOffset = RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET,
70 IncorrectDescMarker = RAGEPHOTO_ERROR_INCORRECTDESCMARKER,
71 IncorrectJendMarker = RAGEPHOTO_ERROR_INCORRECTJENDMARKER,
72 IncorrectJpegMarker = RAGEPHOTO_ERROR_INCORRECTJPEGMARKER,
73 IncorrectJsonMarker = RAGEPHOTO_ERROR_INCORRECTJSONMARKER,
74 IncorrectTitleMarker = RAGEPHOTO_ERROR_INCORRECTTITLEMARKER,
75 JsonBufferTight = RAGEPHOTO_ERROR_JSONBUFFERTIGHT,
76 JsonMallocError = RAGEPHOTO_ERROR_JSONMALLOCERROR,
77 JsonReadError = RAGEPHOTO_ERROR_JSONREADERROR,
78 NoError = RAGEPHOTO_ERROR_NOERROR,
79 NoFormatIdentifier = RAGEPHOTO_ERROR_NOFORMATIDENTIFIER,
80 PhotoBufferTight = RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT,
81 PhotoMallocError = RAGEPHOTO_ERROR_PHOTOMALLOCERROR,
82 PhotoReadError = RAGEPHOTO_ERROR_PHOTOREADERROR,
83 TitleBufferTight = RAGEPHOTO_ERROR_TITLEBUFFERTIGHT,
84 TitleMallocError = RAGEPHOTO_ERROR_TITLEMALLOCERROR,
85 TitleReadError = RAGEPHOTO_ERROR_TITLEREADERROR,
86 UnicodeInitError = RAGEPHOTO_ERROR_UNICODEINITERROR,
87 UnicodeHeaderError = RAGEPHOTO_ERROR_UNICODEHEADERERROR,
88 Uninitialised = RAGEPHOTO_ERROR_UNINITIALISED,
89 };
91 enum PhotoFormat : uint32_t {
92 GTA5 = RAGEPHOTO_FORMAT_GTA5,
93 RDR2 = RAGEPHOTO_FORMAT_RDR2,
94 };
96 enum SignInitials : uint32_t {
97 SIGTA5 = RAGEPHOTO_SIGNINITIAL_GTA5,
98 SIRDR2 = RAGEPHOTO_SIGNINITIAL_RDR2,
99 };
100 photo() {
101 instance = ragephoto_open();
102 if (!instance)
103 throw std::runtime_error("ragephoto_t instance can't be allocated");
104 }
105 ~photo() {
106 ragephoto_close(instance);
107 }
110 ragephoto_addparser(instance, rp_parser);
111 }
113 static void clear(RagePhotoData *rp_data) {
114 ragephotodata_clear(rp_data);
115 }
117 void clear() {
118 ragephoto_clear(instance);
119 }
122 return ragephoto_getphotodata(instance);
123 }
125 static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
126 return ragephotodata_load(rp_data, rp_parser, data, size);
127 }
132 bool load(const char *data, size_t size) {
133 return ragephoto_load(instance, data, size);
134 }
138 bool load(const std::string &data) {
139 return ragephoto_load(instance, data.data(), data.size());
140 }
144 bool loadFile(const char *filename) {
145 return ragephoto_loadfile(instance, filename);
146 }
148 int32_t error() const {
149 return ragephoto_error(instance);
150 }
152 uint32_t format() const {
153 return ragephoto_getphotoformat(instance);
154 }
156 const std::string jpeg() const {
157 const char *jpegData = ragephoto_getphotojpeg(instance);
158 if (jpegData)
159 return std::string(jpegData, ragephoto_getphotosize(instance));
160 else
161 return std::string();
162 }
163#if (__cplusplus >= 201703L)
165 const std::string_view jpeg_view() const {
166 const char *jpegData = ragephoto_getphotojpeg(instance);
167 if (jpegData)
168 return std::string_view(jpegData, ragephoto_getphotosize(instance));
169 else
170 return std::string_view();
171 }
172#endif
174 const char* jpegData() const {
175 return ragephoto_getphotojpeg(instance);
176 }
178 static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data) {
179 return ragephotodata_getphotosignf(rp_data, photoFormat);
180 }
182 static uint64_t jpegSign(RagePhotoData *rp_data) {
183 return ragephotodata_getphotosign(rp_data);
184 }
186 uint64_t jpegSign(uint32_t photoFormat) const {
187 return ragephoto_getphotosignf(instance, photoFormat);
188 }
190 uint64_t jpegSign() const {
191 return ragephoto_getphotosign(instance);
192 }
194 uint32_t jpegSize() const {
195 return ragephoto_getphotosize(instance);
196 }
198 const char* description() const {
199 return ragephoto_getphotodesc(instance);
200 }
202 const char* header() const {
203 return ragephoto_getphotoheader(instance);
204 }
206 const char* json() const {
207 return ragephoto_getphotojson(instance);
208 }
210 const char* title() const {
211 return ragephoto_getphototitle(instance);
212 }
214 static const char* version() {
215 return ragephoto_version();
216 }
218 static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
219 return ragephotodata_savef(rp_data, rp_parser, data, photoFormat);
220 }
222 static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
223 return ragephotodata_save(rp_data, rp_parser, data);
224 }
229 bool save(char *data, uint32_t photoFormat) {
230 return ragephoto_savef(instance, data, photoFormat);
231 }
235 bool save(char *data) {
236 return ragephoto_save(instance, data);
237 }
242 const std::string save(uint32_t photoFormat, bool *ok = nullptr) {
243 std::string sdata;
244 const size_t size = ragephoto_getsavesizef(instance, photoFormat);
245 if (size == 0) {
246 if (ok)
247 *ok = false;
248 return sdata;
249 }
250 sdata.resize(size);
251 const bool saved = ragephoto_savef(instance, &sdata[0], photoFormat);
252 if (ok)
253 *ok = saved;
254 return sdata;
255 }
259 const std::string save(bool *ok = nullptr) {
260 return save(ragephoto_getphotoformat(instance), ok);
261 }
263 bool saveFile(const char *filename, uint32_t photoFormat) {
264 return ragephoto_savefilef(instance, filename, photoFormat);
265 }
267 bool saveFile(const char *filename) {
268 return ragephoto_savefile(instance, filename);
269 }
271 static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
272 return ragephotodata_getsavesizef(rp_data, rp_parser, photoFormat);
273 }
275 static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
276 return ragephotodata_getsavesize(rp_data, rp_parser);
277 }
279 size_t saveSize(uint32_t photoFormat) {
280 return ragephoto_getsavesizef(instance, photoFormat);
281 }
283 size_t saveSize() {
284 return ragephoto_getsavesize(instance);
285 }
287 static void setBufferDefault(RagePhotoData *rp_data) {
289 }
292 ragephoto_setbufferdefault(instance);
293 }
295 static void setBufferOffsets(RagePhotoData *rp_data) {
296 ragephotodata_setbufferoffsets(rp_data);
297 }
300 ragephoto_setbufferoffsets(instance);
301 }
303 bool setData(RagePhotoData *ragePhotoData, bool takeCopy = true) {
304 if (takeCopy)
305 return ragephoto_setphotodatac(instance, ragePhotoData);
306 else
307 return ragephoto_setphotodata(instance, ragePhotoData);
308 }
310 void setDescription(const char *description, uint32_t bufferSize = 0) {
311 ragephoto_setphotodesc(instance, description, bufferSize);
312 }
314 void setFormat(uint32_t photoFormat) {
315 ragephoto_setphotoformat(instance, photoFormat);
316 }
318 void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
319 ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
320 }
326 bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0) {
327 return ragephoto_setphotojpeg(instance, data, size, bufferSize);
328 }
333 bool setJpeg(const std::string &data, uint32_t bufferSize = 0) {
334 return ragephoto_setphotojpeg(instance, data.data(), static_cast<uint32_t>(data.size()), bufferSize);
335 }
337 void setJson(const char *json, uint32_t bufferSize = 0) {
338 ragephoto_setphotojson(instance, json, bufferSize);
339 }
341 static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true) {
342 ragephoto_setlibraryflag(flag, state);
343 }
345 void setTitle(const char *title, uint32_t bufferSize = 0) {
346 ragephoto_setphototitle(instance, title, bufferSize);
347 }
348
349private:
350 ragephoto_t instance;
351};
352
353} // ragephoto_c
354#endif // __cplusplus
355
356#endif // RAGEPHOTO_C_HPP
size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat)
Definition RagePhoto.c:1035
uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat)
Definition RagePhoto.c:681
void ragephotodata_setbufferdefault(RagePhotoData *rp_data)
Definition RagePhoto.c:1070
bool ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat)
Definition RagePhoto.c:764
bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t length)
Definition RagePhoto.c:250
GTA V and RDR 2 Photo Parser (C API wrapper).
const char * json() const
Definition ragephoto_c.hpp:206
bool load(const char *data, size_t size)
Definition ragephoto_c.hpp:132
void setTitle(const char *title, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:345
static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state=true)
Definition ragephoto_c.hpp:341
bool loadFile(const char *filename)
Definition ragephoto_c.hpp:144
bool save(char *data, uint32_t photoFormat)
Definition ragephoto_c.hpp:229
size_t saveSize(uint32_t photoFormat)
Definition ragephoto_c.hpp:279
uint64_t jpegSign(uint32_t photoFormat) const
Definition ragephoto_c.hpp:186
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:271
void setDescription(const char *description, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:310
static void setBufferOffsets(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:295
static const char * version()
Definition ragephoto_c.hpp:214
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:326
static uint64_t jpegSign(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:182
static void clear(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:113
void setFormat(uint32_t photoFormat)
Definition ragephoto_c.hpp:314
void setBufferDefault()
Definition ragephoto_c.hpp:291
bool save(char *data)
Definition ragephoto_c.hpp:235
uint32_t jpegSize() const
Definition ragephoto_c.hpp:194
const std::string save(uint32_t photoFormat, bool *ok=nullptr)
Definition ragephoto_c.hpp:242
bool load(const std::string &data)
Definition ragephoto_c.hpp:138
bool saveFile(const char *filename, uint32_t photoFormat)
Definition ragephoto_c.hpp:263
static void setBufferDefault(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:287
const std::string_view jpeg_view() const
Definition ragephoto_c.hpp:165
size_t saveSize()
Definition ragephoto_c.hpp:283
const std::string jpeg() const
Definition ragephoto_c.hpp:156
bool setJpeg(const std::string &data, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:333
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:125
void setBufferOffsets()
Definition ragephoto_c.hpp:299
SignInitials
Definition ragephoto_c.hpp:96
@ SIGTA5
Definition ragephoto_c.hpp:97
@ SIRDR2
Definition ragephoto_c.hpp:98
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2=0)
Definition ragephoto_c.hpp:318
PhotoFormat
Definition ragephoto_c.hpp:91
@ GTA5
Definition ragephoto_c.hpp:92
@ RDR2
Definition ragephoto_c.hpp:93
const std::string save(bool *ok=nullptr)
Definition ragephoto_c.hpp:259
bool saveFile(const char *filename)
Definition ragephoto_c.hpp:267
const char * header() const
Definition ragephoto_c.hpp:202
const char * jpegData() const
Definition ragephoto_c.hpp:174
const char * description() const
Definition ragephoto_c.hpp:198
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data)
Definition ragephoto_c.hpp:178
void setJson(const char *json, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:337
int32_t error() const
Definition ragephoto_c.hpp:148
RagePhotoData * data()
Definition ragephoto_c.hpp:121
DefaultSize
Definition ragephoto_c.hpp:37
@ DEFAULT_DESCBUFFER
Definition ragephoto_c.hpp:40
@ DEFAULT_JSONBUFFER
Definition ragephoto_c.hpp:41
@ GTA5_HEADERSIZE
Definition ragephoto_c.hpp:43
@ DEFAULT_GTA5_PHOTOBUFFER
Definition ragephoto_c.hpp:38
@ DEFAULT_TITLBUFFER
Definition ragephoto_c.hpp:42
@ RDR2_HEADERSIZE
Definition ragephoto_c.hpp:44
@ DEFAULT_RDR2_PHOTOBUFFER
Definition ragephoto_c.hpp:39
bool setData(RagePhotoData *ragePhotoData, bool takeCopy=true)
Definition ragephoto_c.hpp:303
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:275
const char * title() const
Definition ragephoto_c.hpp:210
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:222
void addParser(RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:109
Error
Definition ragephoto_c.hpp:47
@ IncompleteDescBuffer
Definition ragephoto_c.hpp:55
@ JsonMallocError
Definition ragephoto_c.hpp:76
@ IncompatibleFormat
Definition ragephoto_c.hpp:53
@ IncompleteJsonBuffer
Definition ragephoto_c.hpp:62
@ IncompleteJendMarker
Definition ragephoto_c.hpp:60
@ Uninitialised
Definition ragephoto_c.hpp:88
@ UnicodeHeaderError
Definition ragephoto_c.hpp:87
@ IncompleteTitleBuffer
Definition ragephoto_c.hpp:67
@ PhotoReadError
Definition ragephoto_c.hpp:82
@ IncorrectJendMarker
Definition ragephoto_c.hpp:71
@ IncompleteJsonOffset
Definition ragephoto_c.hpp:64
@ IncorrectJsonMarker
Definition ragephoto_c.hpp:73
@ TitleReadError
Definition ragephoto_c.hpp:85
@ IncompleteDescMarker
Definition ragephoto_c.hpp:56
@ UnicodeInitError
Definition ragephoto_c.hpp:86
@ DescBufferTight
Definition ragephoto_c.hpp:48
@ HeaderMallocError
Definition ragephoto_c.hpp:52
@ IncompleteTitleMarker
Definition ragephoto_c.hpp:68
@ IncompleteTitleOffset
Definition ragephoto_c.hpp:69
@ PhotoMallocError
Definition ragephoto_c.hpp:81
@ IncompleteHeader
Definition ragephoto_c.hpp:59
@ IncompleteChecksum
Definition ragephoto_c.hpp:54
@ IncompletePhotoSize
Definition ragephoto_c.hpp:66
@ IncompleteDescOffset
Definition ragephoto_c.hpp:57
@ PhotoBufferTight
Definition ragephoto_c.hpp:80
@ DescMallocError
Definition ragephoto_c.hpp:49
@ TitleBufferTight
Definition ragephoto_c.hpp:83
@ IncorrectDescMarker
Definition ragephoto_c.hpp:70
@ IncompleteEOF
Definition ragephoto_c.hpp:58
@ IncorrectJpegMarker
Definition ragephoto_c.hpp:72
@ IncompletePhotoBuffer
Definition ragephoto_c.hpp:65
@ DescReadError
Definition ragephoto_c.hpp:50
@ JsonBufferTight
Definition ragephoto_c.hpp:75
@ TitleMallocError
Definition ragephoto_c.hpp:84
@ HeaderBufferTight
Definition ragephoto_c.hpp:51
@ IncorrectTitleMarker
Definition ragephoto_c.hpp:74
@ IncompleteJpegMarker
Definition ragephoto_c.hpp:61
@ NoError
Definition ragephoto_c.hpp:78
@ JsonReadError
Definition ragephoto_c.hpp:77
@ NoFormatIdentifier
Definition ragephoto_c.hpp:79
@ IncompleteJsonMarker
Definition ragephoto_c.hpp:63
uint64_t jpegSign() const
Definition ragephoto_c.hpp:190
uint32_t format() const
Definition ragephoto_c.hpp:152
static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:218
void clear()
Definition ragephoto_c.hpp:117
Definition RagePhotoTypedefs.h:31
Definition RagePhotoTypedefs.h:65