libragephoto Version: 0.7.1
Loading...
Searching...
No Matches
ragephoto_cxx.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_CXX_HPP
20#define RAGEPHOTO_CXX_HPP
21
22#ifdef __cplusplus
23#include "RagePhotoLibrary.h"
24#include "RagePhotoTypedefs.h"
25#include <iostream>
26#include <cstdlib>
27#include <cstdint>
28#include <cstdio>
29
30namespace ragephoto {
31
36class LIBRAGEPHOTO_CXX_PUBLIC photo
37{
38public:
40 enum DefaultSize : uint32_t {
41 DEFAULT_GTA5_PHOTOBUFFER = RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER,
42 DEFAULT_RDR2_PHOTOBUFFER = RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER,
43 DEFAULT_DESCBUFFER = RAGEPHOTO_DEFAULT_DESCBUFFER,
44 DEFAULT_JSONBUFFER = RAGEPHOTO_DEFAULT_JSONBUFFER,
45 DEFAULT_TITLBUFFER = RAGEPHOTO_DEFAULT_TITLBUFFER,
46 GTA5_HEADERSIZE = RAGEPHOTO_GTA5_HEADERSIZE,
47 RDR2_HEADERSIZE = RAGEPHOTO_RDR2_HEADERSIZE
48 };
49
50 enum Error : int32_t {
51 DescBufferTight = RAGEPHOTO_ERROR_DESCBUFFERTIGHT,
52 DescMallocError = RAGEPHOTO_ERROR_DESCMALLOCERROR,
53 DescReadError = RAGEPHOTO_ERROR_DESCREADERROR,
54 HeaderBufferTight = RAGEPHOTO_ERROR_HEADERBUFFERTIGHT,
55 HeaderMallocError = RAGEPHOTO_ERROR_HEADERMALLOCERROR,
56 IncompatibleFormat = RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT,
57 IncompleteChecksum = RAGEPHOTO_ERROR_INCOMPLETECHECKSUM,
58 IncompleteDescBuffer = RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER,
59 IncompleteDescMarker = RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER,
60 IncompleteDescOffset = RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET,
61 IncompleteEOF = RAGEPHOTO_ERROR_INCOMPLETEEOF,
62 IncompleteHeader = RAGEPHOTO_ERROR_INCOMPLETEHEADER,
63 IncompleteJendMarker = RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER,
64 IncompleteJpegMarker = RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER,
65 IncompleteJsonBuffer = RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER,
66 IncompleteJsonMarker = RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER,
67 IncompleteJsonOffset = RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET,
68 IncompletePhotoBuffer = RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER,
69 IncompletePhotoSize = RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE,
70 IncompleteTitleBuffer = RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER,
71 IncompleteTitleMarker = RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER,
72 IncompleteTitleOffset = RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET,
73 IncorrectDescMarker = RAGEPHOTO_ERROR_INCORRECTDESCMARKER,
74 IncorrectJendMarker = RAGEPHOTO_ERROR_INCORRECTJENDMARKER,
75 IncorrectJpegMarker = RAGEPHOTO_ERROR_INCORRECTJPEGMARKER,
76 IncorrectJsonMarker = RAGEPHOTO_ERROR_INCORRECTJSONMARKER,
77 IncorrectTitleMarker = RAGEPHOTO_ERROR_INCORRECTTITLEMARKER,
78 JsonBufferTight = RAGEPHOTO_ERROR_JSONBUFFERTIGHT,
79 JsonMallocError = RAGEPHOTO_ERROR_JSONMALLOCERROR,
80 JsonReadError = RAGEPHOTO_ERROR_JSONREADERROR,
81 NoError = RAGEPHOTO_ERROR_NOERROR,
82 NoFormatIdentifier = RAGEPHOTO_ERROR_NOFORMATIDENTIFIER,
83 PhotoBufferTight = RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT,
84 PhotoMallocError = RAGEPHOTO_ERROR_PHOTOMALLOCERROR,
85 PhotoReadError = RAGEPHOTO_ERROR_PHOTOREADERROR,
86 TitleBufferTight = RAGEPHOTO_ERROR_TITLEBUFFERTIGHT,
87 TitleMallocError = RAGEPHOTO_ERROR_TITLEMALLOCERROR,
88 TitleReadError = RAGEPHOTO_ERROR_TITLEREADERROR,
89 UnicodeInitError = RAGEPHOTO_ERROR_UNICODEINITERROR,
90 UnicodeHeaderError = RAGEPHOTO_ERROR_UNICODEHEADERERROR,
91 Uninitialised = RAGEPHOTO_ERROR_UNINITIALISED
92 };
93
94 enum PhotoFormat : uint32_t {
95 JPEG = RAGEPHOTO_FORMAT_JPEG,
96 GTA5 = RAGEPHOTO_FORMAT_GTA5,
97 RDR2 = RAGEPHOTO_FORMAT_RDR2
98 };
99
100 enum SignInitials : uint32_t {
101 SIGTA5 = RAGEPHOTO_SIGNINITIAL_GTA5,
102 SIRDR2 = RAGEPHOTO_SIGNINITIAL_RDR2
103 };
104 photo();
105 ~photo();
106 void addParser(RagePhotoFormatParser *rp_parser);
107 static void clear(RagePhotoData *rp_data);
108 void clear();
109 RagePhotoData* data();
110 static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
115 bool load(const char *data, size_t size);
119 bool load(const std::string &data);
123 bool loadFile(const char *filename);
124 int32_t error() const;
125 uint32_t format() const;
126 const std::string jpeg() const;
127#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
128 const std::string_view jpeg_view() const;
129#endif
130 const char* jpegData() const;
131 static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data);
132 static uint64_t jpegSign(RagePhotoData *rp_data);
133 uint64_t jpegSign(uint32_t photoFormat) const;
134 uint64_t jpegSign() const;
135 uint32_t jpegSize() const;
136 const char* description() const;
137 const char* header() const;
138 const char* json() const;
139 const char* title() const;
140 static const char* version();
141 static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
142 static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
147 bool save(char *data, uint32_t photoFormat);
151 bool save(char *data);
156 const std::string save(uint32_t photoFormat, bool *ok = nullptr);
160 const std::string save(bool *ok = nullptr);
161 bool saveFile(const char *filename, uint32_t photoFormat);
162 bool saveFile(const char *filename);
163 static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
164 static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
165 size_t saveSize(uint32_t photoFormat);
166 size_t saveSize();
167 static void setBufferDefault(RagePhotoData *rp_data);
168 void setBufferDefault();
169 static void setBufferOffsets(RagePhotoData *rp_data);
170 void setBufferOffsets();
171 bool setData(RagePhotoData *rp_data, bool takeCopy = true);
172 void setDescription(const char *description, uint32_t bufferSize = 0);
173 void setFormat(uint32_t photoFormat);
174 void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0);
180 bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
185 bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
186 void setJson(const char *json, uint32_t bufferSize = 0);
187 static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true);
188 void setTitle(const char *title, uint32_t bufferSize = 0);
189
190private:
191 RagePhotoData *m_data;
192 RagePhotoFormatParser *m_parser;
193};
194
195} // ragephoto
196#endif // __cplusplus
197
198#endif // RAGEPHOTO_CXX_HPP
GTA V and RDR 2 Photo Parser.
Definition ragephoto_cxx.hpp:37
SignInitials
Definition ragephoto_cxx.hpp:100
@ SIGTA5
Definition ragephoto_cxx.hpp:101
@ SIRDR2
Definition ragephoto_cxx.hpp:102
DefaultSize
Definition ragephoto_cxx.hpp:40
@ GTA5_HEADERSIZE
Definition ragephoto_cxx.hpp:46
@ RDR2_HEADERSIZE
Definition ragephoto_cxx.hpp:47
@ DEFAULT_RDR2_PHOTOBUFFER
Definition ragephoto_cxx.hpp:42
@ DEFAULT_GTA5_PHOTOBUFFER
Definition ragephoto_cxx.hpp:41
@ DEFAULT_DESCBUFFER
Definition ragephoto_cxx.hpp:43
@ DEFAULT_TITLBUFFER
Definition ragephoto_cxx.hpp:45
@ DEFAULT_JSONBUFFER
Definition ragephoto_cxx.hpp:44
Error
Definition ragephoto_cxx.hpp:50
@ DescBufferTight
Definition ragephoto_cxx.hpp:51
@ IncompleteJendMarker
Definition ragephoto_cxx.hpp:63
@ NoFormatIdentifier
Definition ragephoto_cxx.hpp:82
@ HeaderBufferTight
Definition ragephoto_cxx.hpp:54
@ IncorrectJpegMarker
Definition ragephoto_cxx.hpp:75
@ JsonReadError
Definition ragephoto_cxx.hpp:80
@ IncompleteJpegMarker
Definition ragephoto_cxx.hpp:64
@ HeaderMallocError
Definition ragephoto_cxx.hpp:55
@ JsonBufferTight
Definition ragephoto_cxx.hpp:78
@ UnicodeInitError
Definition ragephoto_cxx.hpp:89
@ IncorrectDescMarker
Definition ragephoto_cxx.hpp:73
@ IncompleteDescMarker
Definition ragephoto_cxx.hpp:59
@ TitleBufferTight
Definition ragephoto_cxx.hpp:86
@ DescReadError
Definition ragephoto_cxx.hpp:53
@ IncorrectJendMarker
Definition ragephoto_cxx.hpp:74
@ TitleMallocError
Definition ragephoto_cxx.hpp:87
@ IncompleteTitleMarker
Definition ragephoto_cxx.hpp:71
@ IncompleteEOF
Definition ragephoto_cxx.hpp:61
@ IncorrectTitleMarker
Definition ragephoto_cxx.hpp:77
@ IncompleteDescOffset
Definition ragephoto_cxx.hpp:60
@ IncompleteDescBuffer
Definition ragephoto_cxx.hpp:58
@ Uninitialised
Definition ragephoto_cxx.hpp:91
@ IncompatibleFormat
Definition ragephoto_cxx.hpp:56
@ IncompletePhotoSize
Definition ragephoto_cxx.hpp:69
@ TitleReadError
Definition ragephoto_cxx.hpp:88
@ JsonMallocError
Definition ragephoto_cxx.hpp:79
@ NoError
Definition ragephoto_cxx.hpp:81
@ PhotoReadError
Definition ragephoto_cxx.hpp:85
@ IncompleteJsonMarker
Definition ragephoto_cxx.hpp:66
@ UnicodeHeaderError
Definition ragephoto_cxx.hpp:90
@ DescMallocError
Definition ragephoto_cxx.hpp:52
@ IncompleteTitleBuffer
Definition ragephoto_cxx.hpp:70
@ PhotoBufferTight
Definition ragephoto_cxx.hpp:83
@ PhotoMallocError
Definition ragephoto_cxx.hpp:84
@ IncorrectJsonMarker
Definition ragephoto_cxx.hpp:76
@ IncompleteHeader
Definition ragephoto_cxx.hpp:62
@ IncompleteJsonOffset
Definition ragephoto_cxx.hpp:67
@ IncompletePhotoBuffer
Definition ragephoto_cxx.hpp:68
@ IncompleteJsonBuffer
Definition ragephoto_cxx.hpp:65
@ IncompleteChecksum
Definition ragephoto_cxx.hpp:57
@ IncompleteTitleOffset
Definition ragephoto_cxx.hpp:72
PhotoFormat
Definition ragephoto_cxx.hpp:94
@ GTA5
Definition ragephoto_cxx.hpp:96
@ RDR2
Definition ragephoto_cxx.hpp:97
@ JPEG
Definition ragephoto_cxx.hpp:95
Definition RagePhotoTypedefs.h:31
Definition RagePhotoTypedefs.h:65