Skip to content

Commit

Permalink
libragephoto: add new ragephotodata functions and improvements
Browse files Browse the repository at this point in the history
RagePhoto: changed photo(), photoData(), photoSize() and setPhoto() to
jpeg(), jpegData(), jpegSize() and setJpeg()
RagePhoto: setData() now takes takeCopy instead of takeOwnership
RagePhoto: changed static member argument order for easier coding
RagePhotoA: changed photo(), photoData(), photoSize() and setPhoto() to
jpeg(), jpegData(), jpegSize() and setJpeg()
RagePhotoA: setData() now takes takeCopy instead of takeOwnership
RagePhotoA: changed static member argument order for easier coding
RagePhotoA: add new C API functions
RagePhotoC: add ragephotodata_save() and ragephotodata_savef()
RagePhoto-Extract: update for API changes, stop assuming RDR 2 when GTA
V format not found
ragephoto-gtkviewer: update for API changes
ragephoto-qtviewer: update for API changes
  • Loading branch information
Syping committed Feb 23, 2023
1 parent 9807f0d commit d75eba2
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 177 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ if (EMSCRIPTEN)
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
)
target_include_directories(ragephoto-wasm PUBLIC
${ragephoto_BINARY_DIR}/include
${ragephoto_SOURCE_DIR}/src
"${ragephoto_BINARY_DIR}/include"
"${ragephoto_SOURCE_DIR}/src"
)
else()
message(WARNING "A useable WebAssembly build needs at least CMake 3.13.0 or newer")
Expand Down
4 changes: 2 additions & 2 deletions examples/ragephoto-gtkviewer/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2022 Syping
* Copyright (C) 2021-2023 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -48,7 +48,7 @@ bool readPhotoFile(const std::string &filename, Gtk::Window *win, Gtk::Image *im
}
}
GdkPixbufLoader *pixbuf_loader = gdk_pixbuf_loader_new();
gdk_pixbuf_loader_write(pixbuf_loader, reinterpret_cast<const guchar*>(ragePhoto.photoData()), ragePhoto.photoSize(), NULL);
gdk_pixbuf_loader_write(pixbuf_loader, reinterpret_cast<const guchar*>(ragePhoto.jpegData()), ragePhoto.jpegSize(), NULL);
GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader);
gdk_pixbuf_loader_close(pixbuf_loader, NULL);
image->set(Glib::wrap(pixbuf));
Expand Down
6 changes: 3 additions & 3 deletions examples/ragephoto-qtviewer/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2022 Syping
* Copyright (C) 2021-2023 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -44,8 +44,8 @@ bool readPhotoFile(const QString &filename, QMainWindow *mainWindow, QLabel *pho
return false;
}
}
const QByteArray photoData = QByteArray::fromRawData(ragePhoto.photoData(), ragePhoto.photoSize());
const QImage image = QImage::fromData(photoData, "JPEG");
const QByteArray jpegData = QByteArray::fromRawData(ragePhoto.jpegData(), ragePhoto.jpegSize());
const QImage image = QImage::fromData(jpegData, "JPEG");
photoLabel->setPixmap(QPixmap::fromImage(image));
mainWindow->setWindowTitle(QStringLiteral("RagePhoto Qt Photo Viewer - ") + QString::fromUtf8(ragePhoto.title()));
return true;
Expand Down
16 changes: 12 additions & 4 deletions src/RagePhoto-Extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ int main(int argc, char *argv[])
if (loaded != 1) {
if (ragephoto_error(ragephoto_in) == 0) {
printf("Failed to open file: %s\n", argv[1]);
ragephoto_close(ragephoto_in);
return 1;
}
else if (ragephoto_getphotosize(ragephoto_in) <= 0) {
printf("Failed to load photo\n");
ragephoto_close(ragephoto_in);
return 1;
}
}
Expand All @@ -52,20 +54,26 @@ int main(int argc, char *argv[])
#endif
if (!file) {
printf("Failed to write file: %s\n", argv[2]);
ragephoto_close(ragephoto_in);
return 1;
}
const size_t size = fwrite(ragephoto_getphotojpeg(ragephoto_in), sizeof(char), ragephoto_getphotosize(ragephoto_in), file);
const size_t jpegSize = ragephoto_getphotosize(ragephoto_in);
const size_t fileSize = fwrite(ragephoto_getphotojpeg(ragephoto_in), sizeof(char), jpegSize, file);
fclose(file);

if (size != ragephoto_getphotosize(ragephoto_in)) {
if (fileSize != jpegSize) {
printf("Failed to write file: %s\n", argv[2]);
ragephoto_close(ragephoto_in);
return 1;
}

if (ragephoto_getphotoformat(ragephoto_in) == ragephoto_format_gta5())
const uint32_t photoFormat = ragephoto_getphotoformat(ragephoto_in);
if (photoFormat == ragephoto_format_gta5())
printf("GTA V Photo successfully exported\n");
else
else if (photoFormat == ragephoto_format_rdr2())
printf("RDR 2 Photo successfully exported\n");
else
printf("Photo successfully exported\n");

ragephoto_close(ragephoto_in);

Expand Down
14 changes: 9 additions & 5 deletions src/RagePhoto-Extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ int main(int argc, char *argv[])
const bool loaded = ragePhoto.loadFile(argv[1]);

if (!loaded) {
if (ragePhoto.error() == RagePhoto::Uninitialised) {
const int32_t error = ragePhoto.error();
if (error == RagePhoto::Uninitialised) {
std::cout << "Failed to open file: " << argv[1] << std::endl;
return 1;
}
else if (ragePhoto.error() <= RagePhoto::PhotoReadError) {
else if (error <= RagePhoto::PhotoReadError) {
std::cout << "Failed to load photo" << std::endl;
return 1;
}
Expand All @@ -49,7 +50,7 @@ int main(int argc, char *argv[])
std::cout << "Failed to write file: " << argv[2] << std::endl;
return 1;
}
ofs << ragePhoto.photo();
ofs << ragePhoto.jpeg();
const bool ok = ofs.good();
ofs.close();

Expand All @@ -58,10 +59,13 @@ int main(int argc, char *argv[])
return 1;
}

if (ragePhoto.format() == RagePhoto::GTA5)
const uint32_t photoFormat = ragePhoto.format();
if (photoFormat == RagePhoto::GTA5)
std::cout << "GTA V Photo successfully exported" << std::endl;
else
else if (photoFormat == RagePhoto::RDR2)
std::cout << "RDR 2 Photo successfully exported" << std::endl;
else
std::cout << "Photo successfully exported" << std::endl;

return 0;
}

0 comments on commit d75eba2

Please sign in to comment.