libragephoto Version: 0.6.0
Loading...
Searching...
No Matches
ragephoto_cxx.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_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 };
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 };
94 enum PhotoFormat : uint32_t {
95 GTA5 = RAGEPHOTO_FORMAT_GTA5,
96 RDR2 = RAGEPHOTO_FORMAT_RDR2,
97 };
99 enum SignInitials : uint32_t {
100 SIGTA5 = RAGEPHOTO_SIGNINITIAL_GTA5,
101 SIRDR2 = RAGEPHOTO_SIGNINITIAL_RDR2,
102 };
103 photo();
104 ~photo();
105 void addParser(RagePhotoFormatParser *rp_parser);
106 static void clear(RagePhotoData *rp_data);
107 void clear();
108 RagePhotoData* data();
109 static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
114 bool load(const char *data, size_t size);
118 bool load(const std::string &data);
122 bool loadFile(const std::string &filename);
123 int32_t error() const;
124 uint32_t format() const;
125 const std::string jpeg() const;
126#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
127 const std::string_view jpeg_view() const;
128#endif
129 const char* jpegData() const;
130 static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data);
131 static uint64_t jpegSign(RagePhotoData *rp_data);
132 uint64_t jpegSign(uint32_t photoFormat) const;
133 uint64_t jpegSign() const;
134 uint32_t jpegSize() const;
135 const char* description() const;
136 const char* header() const;
137 const char* json() const;
138 const char* title() const;
139 static const char* version();
140 static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
141 static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
146 bool save(char *data, uint32_t photoFormat);
150 bool save(char *data);
155 const std::string save(uint32_t photoFormat, bool *ok = nullptr);
159 const std::string save(bool *ok = nullptr);
160 bool saveFile(const char *filename, uint32_t photoFormat);
161 bool saveFile(const char *filename);
162 static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
163 static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
164 size_t saveSize(uint32_t photoFormat);
165 size_t saveSize();
166 static void setBufferDefault(RagePhotoData *rp_data);
167 void setBufferDefault();
168 static void setBufferOffsets(RagePhotoData *rp_data);
169 void setBufferOffsets();
170 bool setData(RagePhotoData *rp_data, bool takeCopy = true);
171 void setDescription(const char *description, uint32_t bufferSize = 0);
172 void setFormat(uint32_t photoFormat);
173 void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0);
179 bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
184 bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
185 void setJson(const char *json, uint32_t bufferSize = 0);
186 static void setLibraryFlag(RagePhotoLibraryFlag flag, bool state = true);
187 void setTitle(const char *title, uint32_t bufferSize = 0);
189private:
190 RagePhotoData *m_data;
191 RagePhotoFormatParser *m_parser;
192};
193
194} // ragephoto
195#endif // __cplusplus
196
197#endif // RAGEPHOTO_CXX_HPP
GTA V and RDR 2 Photo Parser.
SignInitials
Definition ragephoto_cxx.hpp:99
DefaultSize
Definition ragephoto_cxx.hpp:40
Error
Definition ragephoto_cxx.hpp:50
PhotoFormat
Definition ragephoto_cxx.hpp:94
Definition RagePhotoTypedefs.h:31
Definition RagePhotoTypedefs.h:65