libragephoto Version: 0.7.1
Loading...
Searching...
No Matches
ragephoto_c.hpp
1/*****************************************************************************
2* libragephoto RAGE Photo Parser
3* Copyright (C) 2021-2025 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 };
46
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 };
90
91 enum PhotoFormat : uint32_t {
92 JPEG = RAGEPHOTO_FORMAT_JPEG,
93 GTA5 = RAGEPHOTO_FORMAT_GTA5,
94 RDR2 = RAGEPHOTO_FORMAT_RDR2
95 };
96
97 enum SignInitials : uint32_t {
98 SIGTA5 = RAGEPHOTO_SIGNINITIAL_GTA5,
99 SIRDR2 = RAGEPHOTO_SIGNINITIAL_RDR2
100 };
101 photo() {
102 instance = ragephoto_open();
103 if (!instance)
104 throw std::runtime_error("ragephoto_t instance can't be allocated");
105 }
106 ~photo() {
107 ragephoto_close(instance);
108 }
111 ragephoto_addparser(instance, rp_parser);
112 }
113
114 static void clear(RagePhotoData *rp_data) {
115 ragephotodata_clear(rp_data);
116 }
117
118 void clear() {
119 ragephoto_clear(instance);
120 }
121
123 return ragephoto_getphotodata(instance);
124 }
125
126 static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
127 return ragephotodata_load(rp_data, rp_parser, data, size);
128 }
129
133 bool load(const char *data, size_t size) {
134 return ragephoto_load(instance, data, size);
135 }
136
139 bool load(const std::string &data) {
140 return ragephoto_load(instance, data.data(), data.size());
141 }
142
145 bool loadFile(const char *filename) {
146 return ragephoto_loadfile(instance, filename);
147 }
148
149 int32_t error() const {
150 return ragephoto_error(instance);
151 }
152
153 uint32_t format() const {
154 return ragephoto_getphotoformat(instance);
155 }
156
157 const std::string jpeg() const {
158 const char *jpegData = ragephoto_getphotojpeg(instance);
159 if (jpegData)
160 return std::string(jpegData, ragephoto_getphotosize(instance));
161 else
162 return std::string();
163 }
164#if (__cplusplus >= 201703L)
166 const std::string_view jpeg_view() const {
167 const char *jpegData = ragephoto_getphotojpeg(instance);
168 if (jpegData)
169 return std::string_view(jpegData, ragephoto_getphotosize(instance));
170 else
171 return std::string_view();
172 }
173#endif
175 const char* jpegData() const {
176 return ragephoto_getphotojpeg(instance);
177 }
178
179 static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data) {
180 return ragephotodata_getphotosignf(rp_data, photoFormat);
181 }
182
183 static uint64_t jpegSign(RagePhotoData *rp_data) {
184 return ragephotodata_getphotosign(rp_data);
185 }
186
187 uint64_t jpegSign(uint32_t photoFormat) const {
188 return ragephoto_getphotosignf(instance, photoFormat);
189 }
190
191 uint64_t jpegSign() const {
192 return ragephoto_getphotosign(instance);
193 }
194
195 uint32_t jpegSize() const {
196 return ragephoto_getphotosize(instance);
197 }
198
199 const char* description() const {
200 return ragephoto_getphotodesc(instance);
201 }
202
203 const char* header() const {
204 return ragephoto_getphotoheader(instance);
205 }
206
207 const char* json() const {
208 return ragephoto_getphotojson(instance);
209 }
210
211 const char* title() const {
212 return ragephoto_getphototitle(instance);
213 }
214
215 static const char* version() {
216 return ragephoto_version();
217 }
218
219 static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
220 return ragephotodata_savef(rp_data, rp_parser, data, photoFormat);
221 }
222
223 static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
224 return ragephotodata_save(rp_data, rp_parser, data);
225 }
226
230 bool save(char *data, uint32_t photoFormat) {
231 return ragephoto_savef(instance, data, photoFormat);
232 }
233
236 bool save(char *data) {
237 return ragephoto_save(instance, data);
238 }
239
243 const std::string save(uint32_t photoFormat, bool *ok = nullptr) {
244 std::string sdata;
245 const size_t size = ragephoto_getsavesizef(instance, photoFormat);
246 if (size == 0) {
247 if (ok)
248 *ok = false;
249 return sdata;
250 }
251 sdata.resize(size);
252 const bool saved = ragephoto_savef(instance, &sdata[0], photoFormat);
253 if (ok)
254 *ok = saved;
255 return sdata;
256 }
257
260 const std::string save(bool *ok = nullptr) {
261 return save(ragephoto_getphotoformat(instance), ok);
262 }
263
264 bool saveFile(const char *filename, uint32_t photoFormat) {
265 return ragephoto_savefilef(instance, filename, photoFormat);
266 }
267
268 bool saveFile(const char *filename) {
269 return ragephoto_savefile(instance, filename);
270 }
271
272 static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
273 return ragephotodata_getsavesizef(rp_data, rp_parser, photoFormat);
274 }
275
276 static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
277 return ragephotodata_getsavesize(rp_data, rp_parser);
278 }
279
280 size_t saveSize(uint32_t photoFormat) {
281 return ragephoto_getsavesizef(instance, photoFormat);
282 }
283
284 size_t saveSize() {
285 return ragephoto_getsavesize(instance);
286 }
287
288 static void setBufferDefault(RagePhotoData *rp_data) {
289 ragephotodata_setbufferdefault(rp_data);
290 }
291
293 ragephoto_setbufferdefault(instance);
294 }
295
296 static void setBufferOffsets(RagePhotoData *rp_data) {
297 ragephotodata_setbufferoffsets(rp_data);
298 }
299
301 ragephoto_setbufferoffsets(instance);
302 }
303
304 bool setData(RagePhotoData *ragePhotoData, bool takeCopy = true) {
305 if (takeCopy)
306 return ragephoto_setphotodatac(instance, ragePhotoData);
307 else
308 return ragephoto_setphotodata(instance, ragePhotoData);
309 }
310
311 void setDescription(const char *description, uint32_t bufferSize = 0) {
312 ragephoto_setphotodesc(instance, description, bufferSize);
313 }
314
315 void setFormat(uint32_t photoFormat) {
316 ragephoto_setphotoformat(instance, photoFormat);
317 }
318
319 void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
320 ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
321 }
322
327 bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0) {
328 return ragephoto_setphotojpeg(instance, data, size, bufferSize);
329 }
330
334 bool setJpeg(const std::string &data, uint32_t bufferSize = 0) {
335 return ragephoto_setphotojpeg(instance, data.data(), static_cast<uint32_t>(data.size()), bufferSize);
336 }
337
338 void setJson(const char *json, uint32_t bufferSize = 0) {
339 ragephoto_setphotojson(instance, json, bufferSize);
340 }
341
342 static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true) {
343 ragephoto_setlibraryflag(flag, state);
344 }
345
346 void setTitle(const char *title, uint32_t bufferSize = 0) {
347 ragephoto_setphototitle(instance, title, bufferSize);
348 }
349
350private:
351 ragephoto_t instance;
352};
353
354} // ragephoto_c
355#endif // __cplusplus
356
357#endif // RAGEPHOTO_C_HPP
GTA V and RDR 2 Photo Parser (C API wrapper).
Definition ragephoto_c.hpp:34
const char * json() const
Definition ragephoto_c.hpp:207
bool load(const char *data, size_t size)
Definition ragephoto_c.hpp:133
void setTitle(const char *title, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:346
static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state=true)
Definition ragephoto_c.hpp:342
bool loadFile(const char *filename)
Definition ragephoto_c.hpp:145
bool save(char *data, uint32_t photoFormat)
Definition ragephoto_c.hpp:230
size_t saveSize(uint32_t photoFormat)
Definition ragephoto_c.hpp:280
uint64_t jpegSign(uint32_t photoFormat) const
Definition ragephoto_c.hpp:187
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:272
void setDescription(const char *description, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:311
static void setBufferOffsets(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:296
static const char * version()
Definition ragephoto_c.hpp:215
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:327
static uint64_t jpegSign(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:183
static void clear(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:114
void setFormat(uint32_t photoFormat)
Definition ragephoto_c.hpp:315
void setBufferDefault()
Definition ragephoto_c.hpp:292
bool save(char *data)
Definition ragephoto_c.hpp:236
uint32_t jpegSize() const
Definition ragephoto_c.hpp:195
const std::string save(uint32_t photoFormat, bool *ok=nullptr)
Definition ragephoto_c.hpp:243
bool load(const std::string &data)
Definition ragephoto_c.hpp:139
bool saveFile(const char *filename, uint32_t photoFormat)
Definition ragephoto_c.hpp:264
static void setBufferDefault(RagePhotoData *rp_data)
Definition ragephoto_c.hpp:288
const std::string_view jpeg_view() const
Definition ragephoto_c.hpp:166
size_t saveSize()
Definition ragephoto_c.hpp:284
const std::string jpeg() const
Definition ragephoto_c.hpp:157
bool setJpeg(const std::string &data, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:334
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:126
void setBufferOffsets()
Definition ragephoto_c.hpp:300
SignInitials
Definition ragephoto_c.hpp:97
@ SIGTA5
Definition ragephoto_c.hpp:98
@ SIRDR2
Definition ragephoto_c.hpp:99
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2=0)
Definition ragephoto_c.hpp:319
PhotoFormat
Definition ragephoto_c.hpp:91
@ GTA5
Definition ragephoto_c.hpp:93
@ JPEG
Definition ragephoto_c.hpp:92
@ RDR2
Definition ragephoto_c.hpp:94
const std::string save(bool *ok=nullptr)
Definition ragephoto_c.hpp:260
bool saveFile(const char *filename)
Definition ragephoto_c.hpp:268
const char * header() const
Definition ragephoto_c.hpp:203
const char * jpegData() const
Definition ragephoto_c.hpp:175
const char * description() const
Definition ragephoto_c.hpp:199
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data)
Definition ragephoto_c.hpp:179
void setJson(const char *json, uint32_t bufferSize=0)
Definition ragephoto_c.hpp:338
int32_t error() const
Definition ragephoto_c.hpp:149
RagePhotoData * data()
Definition ragephoto_c.hpp:122
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:304
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:276
const char * title() const
Definition ragephoto_c.hpp:211
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:223
void addParser(RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:110
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:191
uint32_t format() const
Definition ragephoto_c.hpp:153
static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition ragephoto_c.hpp:219
void clear()
Definition ragephoto_c.hpp:118
Definition RagePhotoTypedefs.h:31
Definition RagePhotoTypedefs.h:65