C++ API
Including and using RagePhoto
Include RagePhoto (C++ native), RagePhotoA (C API wrapper) or RagePhotoB (best implementation)
Create a RagePhoto object
GTA V and RDR 2 Photo Parser.
Definition RagePhoto.hpp:34
Loading a Photo
From a file using RagePhoto::loadFile
const char* filename = "PGTA5123456789";
const bool loaded = ragePhoto.
loadFile(filename);
bool loadFile(const std::string &filename)
Definition RagePhoto.cpp:592
From a file using RagePhoto::load(const std::string&)
const char* filename = "PGTA5123456789";
std::ifstream ifs(filename, 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:206
From a char* using RagePhoto::load(const char*, size_t)
const bool loaded = ragePhoto.
load(data, size);
Using a Photo
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:620
const char * jpegData() const
Definition RagePhoto.cpp:638
const char * json() const
Definition RagePhoto.cpp:681
uint32_t jpegSize() const
Definition RagePhoto.cpp:668
const char * title() const
Definition RagePhoto.cpp:691
uint32_t format() const
Definition RagePhoto.cpp:615
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.hpp:92
@ RDR2
Definition RagePhoto.hpp:93
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;
ofs << ragePhoto->
jpeg();
const bool saved = ofs.good();
ofs.close();
return saved;
}
const char* filename = "PGTA5123456789.jpg";
const bool saved = saveJpeg(&ragePhoto, filename);
Using the JPEG in GTK+ (gtkmm)
GdkPixbufLoader* pixbuf_loader = gdk_pixbuf_loader_new();
gdk_pixbuf_loader_write(pixbuf_loader,
reinterpret_cast<const guchar*
>(ragePhoto.
jpegData()), ragePhoto.
jpegSize(),
nullptr);
GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader);
gdk_pixbuf_loader_close(pixbuf_loader, nullptr);
Gtk::Image image;
image.set(Glib::wrap(pixbuf));
Using the JPEG in Qt
const QImage image = QImage::fromData(QByteArray::fromRawData(ragePhoto.
jpegData(), ragePhoto.
jpegSize()),
"JPEG");
QImage image;
const bool loaded = image.loadFromData(QByteArray::fromRawData(ragePhoto.
jpegData(), ragePhoto.
jpegSize()),
"JPEG");
Using the JSON in Boost.JSON
boost::json::error_code ec;
const boost::json::value jv = boost::json::parse(ragePhoto.
json(), ec);
if (ec)
return;
Using the JSON in Qt
const QJsonDocument jd = QJsonDocument::fromJson(ragePhoto.
json());
if (jd.isNull())
return;
Detect Photo errors
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:610
@ NoFormatIdentifier
Definition RagePhoto.hpp:79
@ IncompatibleFormat
Definition RagePhoto.hpp:53
@ NoError
Definition RagePhoto.hpp:78
Available error codes: RagePhoto::Error
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)