C++ API
Including RagePhoto
Initializing a RagePhoto object
GTA V and RDR 2 Photo Parser.
Loading a Photo
From a file using RagePhoto::loadFile
const bool loaded = ragePhoto.
loadFile(
"PGTA5123456789");
bool loadFile(const std::string &filename)
Definition RagePhoto.cpp:592
From a file using RagePhoto::load(const std::string&)
std::ifstream ifs("PGTA5123456789", std::ios::in | std::ios::binary);
if (!ifs.is_open())
return;
std::string sdata(std::istreambuf_iterator<char>{ifs}, {});
ifs.close();
const bool loaded = ragePhoto.
load(sdata);
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
Definition RagePhoto.cpp:238
From a char* using RagePhoto::load(const char*, size_t)
const bool loaded = ragePhoto.
load(data, size);
Querying Photo data
const uint32_t format = ragePhoto.
format();
const std::string jpeg = ragePhoto.
jpeg();
const char* jpeg = ragePhoto.
jpegData();
const uint32_t size = ragePhoto.
jpegSize();
const char* json = ragePhoto.
json();
const char* title = ragePhoto.
title();
const std::string jpeg() const
Definition RagePhoto.cpp:616
const char * jpegData() const
Definition RagePhoto.cpp:632
const char * json() const
Definition RagePhoto.cpp:686
uint32_t jpegSize() const
Definition RagePhoto.cpp:665
const char * title() const
Definition RagePhoto.cpp:693
uint32_t format() const
Definition RagePhoto.cpp:611
Detecting if Photo is from GTA V or RDR 2
std::cout << "GTA V format detected" << std::endl;
break;
std::cout << "RDR 2 format detected" << std::endl;
break;
default:
std::cout << "Unknown format detected" << std::endl;
}
@ GTA5
Definition ragephoto_cxx.hpp:95
@ RDR2
Definition ragephoto_cxx.hpp:96
Saving the JPEG from a Photo
bool saveJpeg(
RagePhoto &ragePhoto,
const std::string &filename) {
std::ofstream ofs(filename, std::ios::out | std::ios::binary | std::ios::trunc);
if (!ofs.is_open())
return false;
const bool saved = ofs.good();
ofs.close();
return saved;
}
const bool saved = saveJpeg(ragePhoto, "photo.jpg");
Querying last error
const int32_t error = ragePhoto.
error();
switch (error) {
std::cout << "No format identifier" << std::endl;
break;
std::cout << "Incompatible format" << std::endl;
break;
std::cout << "No error detected" << std::endl;
break;
default:
std::cout << "Unknown error detected" << std::endl;
}
int32_t error() const
Definition RagePhoto.cpp:606
@ NoFormatIdentifier
Definition ragephoto_cxx.hpp:82
@ IncompatibleFormat
Definition ragephoto_cxx.hpp:56
@ NoError
Definition ragephoto_cxx.hpp:81
Available error codes: RagePhoto::Error
C API
Including RagePhoto
Initializing a RagePhoto instance
ragephoto_t instance = ragephoto_open();
Destroying a RagePhoto instance
ragephoto_close(instance);
Loading a Photo
From a file using ragephoto_loadfile(ragephoto_t, const char*)
const bool loaded = ragephoto_loadfile(instance, "PGTA5123456789");
From a char* using ragephoto_load(ragephoto_t, const char*, size_t)
const bool loaded = ragephoto_load(instance, data, size);
Querying Photo data
const uint32_t format = ragephoto_getphotoformat(instance);
const char* jpeg = ragephoto_getphotojpeg(instance);
const uint32_t size = ragephoto_getphotosize(instance);
const char* json = ragephoto_getphotojson(instance);
const char* title = ragephoto_getphototitle(instance);
Detecting if Photo is from GTA V or RDR 2
switch (ragephoto_getphotoformat(instance)) {
case RAGEPHOTO_FORMAT_GTA5:
printf("GTA V format detected\n");
break;
case RAGEPHOTO_FORMAT_RDR2:
printf("RDR 2 format detected\n");
break;
default:
printf("Unknown format detected\n");
}
Saving the JPEG from a Photo
bool saveJpeg(ragephoto_t instance, const char* filename) {
FILE* file = fopen(filename, "wb");
if (!file)
return false;
const uint32_t jpegSize = ragephoto_getphotosize(instance);
const size_t writeSize = fwrite(ragephoto_getphotojpeg(instance), sizeof(char), jpegSize, file);
fclose(file);
return (jpegSize == writeSize);
}
const bool saved = saveJpeg(instance, "photo.jpg");
Querying last error
const int32_t error = ragephoto_error(instance);
switch (error) {
case RAGEPHOTO_ERROR_NOFORMATIDENTIFIER:
printf("No format identifier\n");
break;
case RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT:
printf("Incompatible format\n");
break;
case RAGEPHOTO_ERROR_NOERROR:
printf("No error detected\n");
break;
default:
printf("Unknown error detected\n");
}
Including libragephoto in a CMake project
Using PkgConfig
find_package(PkgConfig REQUIRED)
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
target_compile_options(your_project PRIVATE ${RAGEPHOTO_CFLAGS})
target_link_libraries(your_project PRIVATE ${RAGEPHOTO_LIBRARIES})
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
target_link_directories(your_project PRIVATE ${RAGEPHOTO_LIBRARY_DIRS})
endif()
target_include_directories(your_project PRIVATE ${RAGEPHOTO_INCLUDE_DIRS})
Using add_subdirectory
add_subdirectory(src/libragephoto)
target_link_libraries(your_project PRIVATE ragephoto)