libragephoto Version: 0.5.0
Loading...
Searching...
No Matches
RagePhotoA.hpp
1/*****************************************************************************
2* libragephoto RAGE Photo Parser
3* Copyright (C) 2021-2023 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 RAGEPHOTOA_HPP
20#define RAGEPHOTOA_HPP
21
22#ifdef __cplusplus
23#include "RagePhoto.h"
24#include <cstdlib>
25#include <iostream>
26
31{
32public:
34 enum DefaultSize : uint32_t {
42 };
44 enum Error : int32_t {
75 NoError = 255L,
86 };
88 enum PhotoFormat : uint32_t {
89 GTA5 = 0x01000000UL,
90 RDR2 = 0x04000000UL,
91 };
93 enum SignInitials : uint32_t {
94 SIGTA5 = 0xE47AB81CUL,
95 SIRDR2 = 0x00FEEB1EUL,
96 };
97 RagePhotoA() {
98 instance = ragephoto_open();
99 }
100 ~RagePhotoA() {
101 ragephoto_close(instance);
102 }
105 ragephoto_addparser(instance, rp_parser);
106 }
108 static void clear(RagePhotoData *rp_data) {
109 ragephotodata_clear(rp_data);
110 }
112 void clear() {
113 ragephoto_clear(instance);
114 }
117 return ragephoto_getphotodata(instance);
118 }
120 static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
121 return ragephotodata_load(rp_data, rp_parser, data, size);
122 }
127 bool load(const char *data, size_t size) {
128 return ragephoto_load(instance, data, size);
129 }
133 bool load(const std::string &data) {
134 return ragephoto_load(instance, data.data(), data.size());
135 }
139 bool loadFile(const char *filename) {
140 return ragephoto_loadfile(instance, filename);
141 }
143 int32_t error() const {
144 return ragephoto_error(instance);
145 }
147 uint32_t format() const {
148 return ragephoto_getphotoformat(instance);
149 }
151 const std::string jpeg() const {
152 const char *jpegData = ragephoto_getphotojpeg(instance);
153 if (jpegData)
154 return std::string(jpegData, ragephoto_getphotosize(instance));
155 else
156 return std::string();
157 }
158#if (__cplusplus >= 201703L)
160 const std::string_view jpeg_view() const {
161 const char *jpegData = ragephoto_getphotojpeg(instance);
162 if (jpegData)
163 return std::string_view(jpegData, ragephoto_getphotosize(instance));
164 else
165 return std::string_view();
166 }
167#endif
169 const char* jpegData() const {
170 return ragephoto_getphotojpeg(instance);
171 }
173 static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data) {
174 return ragephotodata_getphotosignf(rp_data, photoFormat);
175 }
177 static uint64_t jpegSign(RagePhotoData *rp_data) {
178 return ragephotodata_getphotosign(rp_data);
179 }
181 uint64_t jpegSign(uint32_t photoFormat) const {
182 return ragephoto_getphotosignf(instance, photoFormat);
183 }
185 uint64_t jpegSign() const {
186 return ragephoto_getphotosign(instance);
187 }
189 uint32_t jpegSize() const {
190 return ragephoto_getphotosize(instance);
191 }
193 const char* description() const {
194 return ragephoto_getphotodesc(instance);
195 }
197 const char* json() const {
198 return ragephoto_getphotojson(instance);
199 }
201 const char* header() const {
202 return ragephoto_getphotoheader(instance);
203 }
205 const char* title() const {
206 return ragephoto_getphototitle(instance);
207 }
209 static const char* version() {
210 return ragephoto_version();
211 }
213 static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
214 return ragephotodata_savef(rp_data, rp_parser, data, photoFormat);
215 }
217 static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
218 return ragephotodata_save(rp_data, rp_parser, data);
219 }
224 bool save(char *data, uint32_t photoFormat) {
225 return ragephoto_savef(instance, data, photoFormat);
226 }
230 bool save(char *data) {
231 return ragephoto_save(instance, data);
232 }
237 const std::string save(uint32_t photoFormat, bool *ok = nullptr) {
238 std::string sdata;
239 const size_t size = ragephoto_getsavesizef(instance, photoFormat);
240 if (size == 0) {
241 if (ok)
242 *ok = false;
243 return sdata;
244 }
245 sdata.resize(size);
246 const bool saved = ragephoto_savef(instance, &sdata[0], photoFormat);
247 if (ok)
248 *ok = saved;
249 return sdata;
250 }
254 const std::string save(bool *ok = nullptr) {
255 return save(ragephoto_getphotoformat(instance), ok);
256 }
258 bool saveFile(const char *filename, uint32_t photoFormat) {
259 return ragephoto_savefilef(instance, filename, photoFormat);
260 }
262 bool saveFile(const char *filename) {
263 return ragephoto_savefile(instance, filename);
264 }
266 static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
267 return ragephotodata_getsavesizef(rp_data, rp_parser, photoFormat);
268 }
270 static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
271 return ragephotodata_getsavesize(rp_data, rp_parser);
272 }
274 size_t saveSize(uint32_t photoFormat) {
275 return ragephoto_getsavesizef(instance, photoFormat);
276 }
278 size_t saveSize() {
279 return ragephoto_getsavesize(instance);
280 }
282 static void setBufferDefault(RagePhotoData *rp_data) {
283 ragephotodata_setbufferdefault(rp_data);
284 }
287 ragephoto_setbufferdefault(instance);
288 }
290 static void setBufferOffsets(RagePhotoData *rp_data) {
291 ragephotodata_setbufferoffsets(rp_data);
292 }
295 ragephoto_setbufferoffsets(instance);
296 }
298 bool setData(RagePhotoData *ragePhotoData, bool takeCopy = true) {
299 if (takeCopy)
300 return ragephoto_setphotodatac(instance, ragePhotoData);
301 else
302 return ragephoto_setphotodata(instance, ragePhotoData);
303 }
305 void setDescription(const char *description, uint32_t bufferSize = 0) {
306 ragephoto_setphotodesc(instance, description, bufferSize);
307 }
309 void setFormat(uint32_t photoFormat) {
310 ragephoto_setphotoformat(instance, photoFormat);
311 }
317 bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0) {
318 return ragephoto_setphotojpeg(instance, data, size, bufferSize);
319 }
324 bool setJpeg(const std::string &data, uint32_t bufferSize = 0) {
325 return ragephoto_setphotojpeg(instance, data.data(), static_cast<uint32_t>(data.size()), bufferSize);
326 }
328 void setJson(const char *json, uint32_t bufferSize = 0) {
329 ragephoto_setphotojson(instance, json, bufferSize);
330 }
332 void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
333 ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
334 }
336 void setTitle(const char *title, uint32_t bufferSize = 0) {
337 ragephoto_setphototitle(instance, title, bufferSize);
338 }
339
340private:
341 ragephoto_t instance;
342};
343#endif // __cplusplus
344
345#endif // RAGEPHOTOA_HPP
void * ragephoto_t
Definition RagePhoto.h:36
GTA V and RDR 2 Photo Parser (C API wrapper).
Definition RagePhotoA.hpp:31
const char * title() const
Definition RagePhotoA.hpp:205
bool setJpeg(const std::string &data, uint32_t bufferSize=0)
Definition RagePhotoA.hpp:324
PhotoFormat
Definition RagePhotoA.hpp:88
@ RDR2
Definition RagePhotoA.hpp:90
@ GTA5
Definition RagePhotoA.hpp:89
bool save(char *data)
Definition RagePhotoA.hpp:230
void clear()
Definition RagePhotoA.hpp:112
bool saveFile(const char *filename)
Definition RagePhotoA.hpp:262
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize=0)
Definition RagePhotoA.hpp:317
bool saveFile(const char *filename, uint32_t photoFormat)
Definition RagePhotoA.hpp:258
bool load(const std::string &data)
Definition RagePhotoA.hpp:133
SignInitials
Definition RagePhotoA.hpp:93
@ SIRDR2
Definition RagePhotoA.hpp:95
@ SIGTA5
Definition RagePhotoA.hpp:94
int32_t error() const
Definition RagePhotoA.hpp:143
uint64_t jpegSign() const
Definition RagePhotoA.hpp:185
bool load(const char *data, size_t size)
Definition RagePhotoA.hpp:127
bool save(char *data, uint32_t photoFormat)
Definition RagePhotoA.hpp:224
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition RagePhotoA.hpp:217
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data)
Definition RagePhotoA.hpp:173
const char * header() const
Definition RagePhotoA.hpp:201
static void setBufferDefault(RagePhotoData *rp_data)
Definition RagePhotoA.hpp:282
static void clear(RagePhotoData *rp_data)
Definition RagePhotoA.hpp:108
bool loadFile(const char *filename)
Definition RagePhotoA.hpp:139
DefaultSize
Definition RagePhotoA.hpp:34
@ RDR2_HEADERSIZE
Definition RagePhotoA.hpp:41
@ DEFAULT_DESCBUFFER
Definition RagePhotoA.hpp:37
@ DEFAULT_RDR2_PHOTOBUFFER
Definition RagePhotoA.hpp:36
@ DEFAULT_GTA5_PHOTOBUFFER
Definition RagePhotoA.hpp:35
@ DEFAULT_TITLBUFFER
Definition RagePhotoA.hpp:39
@ GTA5_HEADERSIZE
Definition RagePhotoA.hpp:40
@ DEFAULT_JSONBUFFER
Definition RagePhotoA.hpp:38
static const char * version()
Definition RagePhotoA.hpp:209
size_t saveSize()
Definition RagePhotoA.hpp:278
uint64_t jpegSign(uint32_t photoFormat) const
Definition RagePhotoA.hpp:181
const std::string save(uint32_t photoFormat, bool *ok=nullptr)
Definition RagePhotoA.hpp:237
void setTitle(const char *title, uint32_t bufferSize=0)
Definition RagePhotoA.hpp:336
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition RagePhotoA.hpp:120
static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition RagePhotoA.hpp:213
const std::string_view jpeg_view() const
Definition RagePhotoA.hpp:160
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition RagePhotoA.hpp:270
RagePhotoData * data()
Definition RagePhotoA.hpp:116
void setBufferDefault()
Definition RagePhotoA.hpp:286
uint32_t jpegSize() const
Definition RagePhotoA.hpp:189
const std::string save(bool *ok=nullptr)
Definition RagePhotoA.hpp:254
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2=0)
Definition RagePhotoA.hpp:332
const std::string jpeg() const
Definition RagePhotoA.hpp:151
uint32_t format() const
Definition RagePhotoA.hpp:147
void setJson(const char *json, uint32_t bufferSize=0)
Definition RagePhotoA.hpp:328
void setDescription(const char *description, uint32_t bufferSize=0)
Definition RagePhotoA.hpp:305
void setBufferOffsets()
Definition RagePhotoA.hpp:294
const char * jpegData() const
Definition RagePhotoA.hpp:169
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition RagePhotoA.hpp:266
Error
Definition RagePhotoA.hpp:44
@ UnicodeHeaderError
Definition RagePhotoA.hpp:84
@ IncompleteHeader
Definition RagePhotoA.hpp:56
@ JsonMallocError
Definition RagePhotoA.hpp:73
@ IncorrectDescMarker
Definition RagePhotoA.hpp:67
@ IncompleteTitleOffset
Definition RagePhotoA.hpp:66
@ JsonBufferTight
Definition RagePhotoA.hpp:72
@ IncompletePhotoBuffer
Definition RagePhotoA.hpp:62
@ JsonReadError
Definition RagePhotoA.hpp:74
@ IncompleteJsonOffset
Definition RagePhotoA.hpp:61
@ PhotoMallocError
Definition RagePhotoA.hpp:78
@ PhotoBufferTight
Definition RagePhotoA.hpp:77
@ IncompleteDescBuffer
Definition RagePhotoA.hpp:52
@ IncompleteJendMarker
Definition RagePhotoA.hpp:57
@ IncompleteTitleMarker
Definition RagePhotoA.hpp:65
@ TitleMallocError
Definition RagePhotoA.hpp:81
@ IncompleteEOF
Definition RagePhotoA.hpp:55
@ IncompleteJsonMarker
Definition RagePhotoA.hpp:60
@ IncompleteDescMarker
Definition RagePhotoA.hpp:53
@ IncompleteTitleBuffer
Definition RagePhotoA.hpp:64
@ IncompatibleFormat
Definition RagePhotoA.hpp:50
@ TitleBufferTight
Definition RagePhotoA.hpp:80
@ HeaderMallocError
Definition RagePhotoA.hpp:49
@ PhotoReadError
Definition RagePhotoA.hpp:79
@ DescReadError
Definition RagePhotoA.hpp:47
@ NoFormatIdentifier
Definition RagePhotoA.hpp:76
@ DescBufferTight
Definition RagePhotoA.hpp:45
@ NoError
Definition RagePhotoA.hpp:75
@ IncorrectJendMarker
Definition RagePhotoA.hpp:68
@ UnicodeInitError
Definition RagePhotoA.hpp:83
@ IncompleteJsonBuffer
Definition RagePhotoA.hpp:59
@ HeaderBufferTight
Definition RagePhotoA.hpp:48
@ IncorrectJsonMarker
Definition RagePhotoA.hpp:70
@ IncorrectJpegMarker
Definition RagePhotoA.hpp:69
@ IncompleteJpegMarker
Definition RagePhotoA.hpp:58
@ IncompleteChecksum
Definition RagePhotoA.hpp:51
@ IncorrectTitleMarker
Definition RagePhotoA.hpp:71
@ DescMallocError
Definition RagePhotoA.hpp:46
@ Uninitialised
Definition RagePhotoA.hpp:85
@ IncompletePhotoSize
Definition RagePhotoA.hpp:63
@ IncompleteDescOffset
Definition RagePhotoA.hpp:54
@ TitleReadError
Definition RagePhotoA.hpp:82
bool setData(RagePhotoData *ragePhotoData, bool takeCopy=true)
Definition RagePhotoA.hpp:298
void setFormat(uint32_t photoFormat)
Definition RagePhotoA.hpp:309
const char * description() const
Definition RagePhotoA.hpp:193
static void setBufferOffsets(RagePhotoData *rp_data)
Definition RagePhotoA.hpp:290
static uint64_t jpegSign(RagePhotoData *rp_data)
Definition RagePhotoA.hpp:177
size_t saveSize(uint32_t photoFormat)
Definition RagePhotoA.hpp:274
const char * json() const
Definition RagePhotoA.hpp:197
void addParser(RagePhotoFormatParser *rp_parser)
Definition RagePhotoA.hpp:104
Definition RagePhotoTypedefs.h:31
Definition RagePhotoTypedefs.h:65