From 12507be85dcf12b847b62c7e8bb6ef9db4a32de1 Mon Sep 17 00:00:00 2001 From: Syping Date: Sun, 11 Jun 2023 05:41:32 +0200 Subject: [PATCH] libragephoto: add RagePhotoB for best implementation CMakeLists.txt: add RagePhotoB class, improve settings clarification doc/build.doc: add RAGEPHOTO_C_LIBRARY flag doc/index.doc: correct RagePhoto.h header doc/usage.doc: fix minor documentation issue, clarify class differences ragephoto-gtkviewer: use RagePhotoB class ragephoto-qtviewer: use RagePhotoB class RagePhoto-Extract.cpp: use RagePhotoB class RagePhoto.cpp: LIBRAGEPHOTO_C_API -> LIBRAGEPHOTO_CXX_C RagePhotoA.hpp: simplify brief RagePhotoB.hpp: add best implementation detection RagePhotoLibrary.h: fix WASM C API inclusion by default README.md: add RAGEPHOTO_C_LIBRARY flag --- CMakeLists.txt | 18 +++++----- README.md | 1 + doc/build.doc | 1 + doc/index.doc | 2 +- doc/usage.doc | 9 +++-- examples/ragephoto-gtkviewer/src/main.cpp | 6 ++-- examples/ragephoto-qtviewer/src/main.cpp | 6 ++-- src/RagePhoto-Extract.cpp | 12 +++---- src/RagePhoto.cpp | 4 +-- src/RagePhotoA.hpp | 5 +-- src/RagePhotoB | 1 + src/RagePhotoB.hpp | 43 +++++++++++++++++++++++ src/RagePhotoLibrary.h | 11 +++--- 13 files changed, 81 insertions(+), 38 deletions(-) create mode 100644 src/RagePhotoB create mode 100644 src/RagePhotoB.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 297f1ca..cdae2bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,10 @@ option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF) if (RAGEPHOTO_C_LIBRARY) set(RAGEPHOTO_HEADERS src/RagePhoto.h + src/RagePhotoA + src/RagePhotoA.hpp + src/RagePhotoB + src/RagePhotoB.hpp src/RagePhotoLibrary.h src/RagePhotoTypedefs.h ) @@ -46,6 +50,8 @@ else() set(RAGEPHOTO_HEADERS src/RagePhoto src/RagePhoto.hpp + src/RagePhotoB + src/RagePhotoB.hpp src/RagePhotoLibrary.h src/RagePhotoTypedefs.h ) @@ -65,7 +71,7 @@ else() endif() # RagePhoto Benchmark -option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark" OFF) +option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark (C++ only)" OFF) if (RAGEPHOTO_BENCHMARK) list(APPEND LIBRAGEPHOTO_DEFINES RAGEPHOTO_BENCHMARK @@ -74,18 +80,12 @@ endif() # RagePhoto C API if (RAGEPHOTO_C_LIBRARY) - set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API) - list(APPEND RAGEPHOTO_HEADERS - src/RagePhotoA - src/RagePhotoA.hpp - ) + set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_ONLY) else() if (RAGEPHOTO_C_API) - set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API) + set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_C) list(APPEND RAGEPHOTO_HEADERS src/RagePhoto.h - src/RagePhotoA - src/RagePhotoA.hpp ) else() set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_ONLY) diff --git a/README.md b/README.md index 98482b7..52132da 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ sudo cmake --install libragephoto-build `-DCMAKE_CXX_STANDARD=17` `-DRAGEPHOTO_BENCHMARK=ON` `-DRAGEPHOTO_C_API=OFF` +`-DRAGEPHOTO_C_LIBRARY=ON` `-DRAGEPHOTO_DOC=ON` `-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON` `-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON` diff --git a/doc/build.doc b/doc/build.doc index 809d092..0f68da9 100644 --- a/doc/build.doc +++ b/doc/build.doc @@ -20,6 +20,7 @@ To customise your libragephoto build, the following Optional CM -DCMAKE_CXX_STANDARD=17 -DRAGEPHOTO_BENCHMARK=ON -DRAGEPHOTO_C_API=OFF +-DRAGEPHOTO_C_LIBRARY=ON -DRAGEPHOTO_DOC=ON -DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON -DRAGEPHOTO_EXAMPLE_QTVIEWER=ON diff --git a/doc/index.doc b/doc/index.doc index 5b30a4c..3f39e8a 100644 --- a/doc/index.doc +++ b/doc/index.doc @@ -14,7 +14,7 @@ Reference RagePhoto (C++ API) RagePhotoA (C++ API based on C API) -RagePhotoC.h (C API) +RagePhoto.h (C API) RagePhotoData (Data Object Struct) RagePhotoFormatParser (Custom Format Parser Struct) diff --git a/doc/usage.doc b/doc/usage.doc index cfa78c2..a306beb 100644 --- a/doc/usage.doc +++ b/doc/usage.doc @@ -4,10 +4,10 @@

Including and using RagePhoto

-Include RagePhoto.h or RagePhotoA.h +Include RagePhoto (C++ native), RagePhotoA (C API wrapper) or \link RagePhotoB.hpp RagePhotoB \endlink (best implementation) \code{.cpp} -#include +#include \endcode Create a RagePhoto object @@ -128,7 +128,7 @@ const bool loaded = image.loadFromData(QByteArray::fromRawData(ragePhoto.jpegDat Using the JSON in Boost.JSON \code{.cpp} -std::error_code ec; +boost::json::error_code ec; const boost::json::value jv = boost::json::parse(ragePhoto.json(), ec); if (ec) return; @@ -137,8 +137,7 @@ if (ec) Using the JSON in Qt \code{.cpp} -const QByteArray json = ragePhoto.json(); -const QJsonDocument jd = QJsonDocument::fromJson(json); +const QJsonDocument jd = QJsonDocument::fromJson(ragePhoto.json()); if (jd.isNull()) return; \endcode diff --git a/examples/ragephoto-gtkviewer/src/main.cpp b/examples/ragephoto-gtkviewer/src/main.cpp index 05ba481..ed10beb 100644 --- a/examples/ragephoto-gtkviewer/src/main.cpp +++ b/examples/ragephoto-gtkviewer/src/main.cpp @@ -16,7 +16,7 @@ * responsible for anything with use of the software, you are self responsible. *****************************************************************************/ -#include +#include #include #include #include @@ -36,11 +36,11 @@ bool readPhotoFile(const std::string &filename, Gtk::Window *win, Gtk::Image *im if (ifs.is_open()) { std::string data(std::istreambuf_iterator{ifs}, {}); ifs.close(); - RagePhoto ragePhoto; + RagePhotoB ragePhoto; const bool loaded = ragePhoto.load(data); if (!loaded) { const int32_t error = ragePhoto.error(); - if (error <= RagePhoto::PhotoReadError) { + if (error <= RagePhotoB::PhotoReadError) { Gtk::MessageDialog msg(*win, "Failed to read photo: " + filename, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); msg.set_title("Open Photo"); msg.run(); diff --git a/examples/ragephoto-qtviewer/src/main.cpp b/examples/ragephoto-qtviewer/src/main.cpp index f7613b4..739df20 100644 --- a/examples/ragephoto-qtviewer/src/main.cpp +++ b/examples/ragephoto-qtviewer/src/main.cpp @@ -16,7 +16,7 @@ * responsible for anything with use of the software, you are self responsible. *****************************************************************************/ -#include +#include #include #include #include @@ -35,11 +35,11 @@ bool readPhotoFile(const QString &filename, QMainWindow *mainWindow, QLabel *pho if (file.open(QIODevice::ReadOnly)) { const QByteArray fileData = file.readAll(); file.close(); - RagePhoto ragePhoto; + RagePhotoB ragePhoto; const bool loaded = ragePhoto.load(fileData.data(), static_cast(fileData.size())); if (!loaded) { const int32_t error = ragePhoto.error(); - if (error <= RagePhoto::PhotoReadError) { + if (error <= RagePhotoB::PhotoReadError) { QMessageBox::warning(mainWindow, "Open Photo", "Failed to read photo: " + filename); return false; } diff --git a/src/RagePhoto-Extract.cpp b/src/RagePhoto-Extract.cpp index 6534d6c..3dacac6 100644 --- a/src/RagePhoto-Extract.cpp +++ b/src/RagePhoto-Extract.cpp @@ -16,7 +16,7 @@ * responsible for anything with use of the software, you are self responsible. *****************************************************************************/ -#include +#include #include int main(int argc, char *argv[]) @@ -27,18 +27,18 @@ int main(int argc, char *argv[]) } // Initialise RagePhoto - RagePhoto ragePhoto; + RagePhotoB ragePhoto; // Load Photo const bool loaded = ragePhoto.loadFile(argv[1]); if (!loaded) { const int32_t error = ragePhoto.error(); - if (error == RagePhoto::Uninitialised) { + if (error == RagePhotoB::Uninitialised) { std::cout << "Failed to open file: " << argv[1] << std::endl; return 1; } - else if (error <= RagePhoto::PhotoReadError) { + else if (error <= RagePhotoB::PhotoReadError) { std::cout << "Failed to load photo" << std::endl; return 1; } @@ -60,9 +60,9 @@ int main(int argc, char *argv[]) } const uint32_t photoFormat = ragePhoto.format(); - if (photoFormat == RagePhoto::GTA5) + if (photoFormat == RagePhotoB::GTA5) std::cout << "GTA V Photo successfully exported" << std::endl; - else if (photoFormat == RagePhoto::RDR2) + else if (photoFormat == RagePhotoB::RDR2) std::cout << "RDR 2 Photo successfully exported" << std::endl; else std::cout << "Photo successfully exported" << std::endl; diff --git a/src/RagePhoto.cpp b/src/RagePhoto.cpp index 76fa0fc..89f5f7a 100644 --- a/src/RagePhoto.cpp +++ b/src/RagePhoto.cpp @@ -17,7 +17,7 @@ *****************************************************************************/ #include "RagePhoto.hpp" -#ifdef LIBRAGEPHOTO_C_API +#ifdef LIBRAGEPHOTO_CXX_C #include "RagePhoto.h" #endif @@ -1223,7 +1223,7 @@ void RagePhoto::setTitle(const char *title, uint32_t bufferSize) m_data->error = Error::NoError; // 255 } -#ifdef LIBRAGEPHOTO_C_API +#ifdef LIBRAGEPHOTO_CXX_C ragephoto_t ragephoto_open() { return static_cast(new RagePhoto); diff --git a/src/RagePhotoA.hpp b/src/RagePhotoA.hpp index 72955aa..4c8c86c 100644 --- a/src/RagePhotoA.hpp +++ b/src/RagePhotoA.hpp @@ -25,10 +25,7 @@ #include /** -* \brief ABI Stable Wrapper for RagePhoto. -* -* Using RagePhotoA instead of RagePhoto allows your library or application to survive more changes in the RagePhoto class, -* disadvantages include that it doesn't always include the newest features, performance is about the same. +* \brief GTA V and RDR 2 Photo Parser (C API wrapper). */ class RagePhotoA { diff --git a/src/RagePhotoB b/src/RagePhotoB new file mode 100644 index 0000000..dc33bde --- /dev/null +++ b/src/RagePhotoB @@ -0,0 +1 @@ +#include "RagePhotoB.hpp" diff --git a/src/RagePhotoB.hpp b/src/RagePhotoB.hpp new file mode 100644 index 0000000..5be7c29 --- /dev/null +++ b/src/RagePhotoB.hpp @@ -0,0 +1,43 @@ +/***************************************************************************** +* libragephoto RAGE Photo Parser +* Copyright (C) 2023 Syping +* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* This software is provided as-is, no warranties are given to you, we are not +* responsible for anything with use of the software, you are self responsible. +*****************************************************************************/ + +#ifndef RAGEPHOTOB_HPP +#define RAGEPHOTOB_HPP + +#ifdef __cplusplus +#include "RagePhotoLibrary.h" +#ifdef LIBRAGEPHOTO_CXX_ONLY +#include "RagePhoto.hpp" +typedef RagePhoto RagePhotoB; +#elif defined LIBRAGEPHOTO_CXX_C +#ifdef LIBRAGEPHOTO_STATIC +#include "RagePhoto.hpp" +typedef RagePhoto RagePhotoB; +#else +#include "RagePhotoA.hpp" +typedef RagePhotoA RagePhotoB; +#endif // LIBRAGEPHOTO_STATIC +#elif defined LIBRAGEPHOTO_C_ONLY +#include "RagePhotoA.hpp" +typedef RagePhotoA RagePhotoB; +#else +#error "Could not determine best RagePhoto implementation, libragephoto installation might be corrupt!" +#endif // LIBRAGEPHOTO_CXX_ONLY +#endif // __cplusplus + +#endif // RAGEPHOTOB_HPP diff --git a/src/RagePhotoLibrary.h b/src/RagePhotoLibrary.h index e50f44f..04d1dd6 100644 --- a/src/RagePhotoLibrary.h +++ b/src/RagePhotoLibrary.h @@ -57,12 +57,13 @@ #endif // _WIN32 /* RAGEPHOTO LIBRARY BINDING END */ -/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY BEGIN */ +/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY BEGIN */ #ifdef LIBRAGEPHOTO_WASM -#ifndef RAGEPHOTO_C_API -#define RAGEPHOTO_C_API -#endif // RAGEPHOTO_C_API +#ifdef LIBRAGEPHOTO_CXX_ONLY +#undef LIBRAGEPHOTO_CXX_ONLY +#define LIBRAGEPHOTO_CXX_C +#endif // LIBRAGEPHOTO_CXX_ONLY #endif // LIBRAGEPHOTO_WASM -/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY END */ +/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY END */ #endif // RAGEPHOTOLIBRARY_H