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
This commit is contained in:
Syping 2023-06-11 05:41:32 +02:00
parent d7943e552d
commit 12507be85d
13 changed files with 81 additions and 38 deletions

View File

@ -36,6 +36,10 @@ option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF)
if (RAGEPHOTO_C_LIBRARY) if (RAGEPHOTO_C_LIBRARY)
set(RAGEPHOTO_HEADERS set(RAGEPHOTO_HEADERS
src/RagePhoto.h src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h src/RagePhotoTypedefs.h
) )
@ -46,6 +50,8 @@ else()
set(RAGEPHOTO_HEADERS set(RAGEPHOTO_HEADERS
src/RagePhoto src/RagePhoto
src/RagePhoto.hpp src/RagePhoto.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h src/RagePhotoTypedefs.h
) )
@ -65,7 +71,7 @@ else()
endif() endif()
# RagePhoto Benchmark # RagePhoto Benchmark
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark" OFF) option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark (C++ only)" OFF)
if (RAGEPHOTO_BENCHMARK) if (RAGEPHOTO_BENCHMARK)
list(APPEND LIBRAGEPHOTO_DEFINES list(APPEND LIBRAGEPHOTO_DEFINES
RAGEPHOTO_BENCHMARK RAGEPHOTO_BENCHMARK
@ -74,18 +80,12 @@ endif()
# RagePhoto C API # RagePhoto C API
if (RAGEPHOTO_C_LIBRARY) if (RAGEPHOTO_C_LIBRARY)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API) set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_ONLY)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA
src/RagePhotoA.hpp
)
else() else()
if (RAGEPHOTO_C_API) if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API) set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_C)
list(APPEND RAGEPHOTO_HEADERS list(APPEND RAGEPHOTO_HEADERS
src/RagePhoto.h src/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
) )
else() else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_ONLY) set(LIBRAGEPHOTO_API LIBRAGEPHOTO_CXX_ONLY)

View File

@ -19,6 +19,7 @@ sudo cmake --install libragephoto-build
`-DCMAKE_CXX_STANDARD=17` `-DCMAKE_CXX_STANDARD=17`
`-DRAGEPHOTO_BENCHMARK=ON` `-DRAGEPHOTO_BENCHMARK=ON`
`-DRAGEPHOTO_C_API=OFF` `-DRAGEPHOTO_C_API=OFF`
`-DRAGEPHOTO_C_LIBRARY=ON`
`-DRAGEPHOTO_DOC=ON` `-DRAGEPHOTO_DOC=ON`
`-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON` `-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON`
`-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON` `-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON`

View File

@ -20,6 +20,7 @@ To customise your libragephoto build, the following <a href="#flags">Optional CM
-DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD=17
-DRAGEPHOTO_BENCHMARK=ON -DRAGEPHOTO_BENCHMARK=ON
-DRAGEPHOTO_C_API=OFF -DRAGEPHOTO_C_API=OFF
-DRAGEPHOTO_C_LIBRARY=ON
-DRAGEPHOTO_DOC=ON -DRAGEPHOTO_DOC=ON
-DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON -DRAGEPHOTO_EXAMPLE_GTKVIEWER=ON
-DRAGEPHOTO_EXAMPLE_QTVIEWER=ON -DRAGEPHOTO_EXAMPLE_QTVIEWER=ON

View File

@ -14,7 +14,7 @@
<b>Reference</b> <b>Reference</b>
RagePhoto (C++ API) RagePhoto (C++ API)
RagePhotoA (C++ API based on C API) RagePhotoA (C++ API based on C API)
RagePhotoC.h (C API) RagePhoto.h (C API)
RagePhotoData (Data Object Struct) RagePhotoData (Data Object Struct)
RagePhotoFormatParser (Custom Format Parser Struct) RagePhotoFormatParser (Custom Format Parser Struct)

View File

@ -4,10 +4,10 @@
<h4 id="cxx_include_usage">Including and using RagePhoto</h4> <h4 id="cxx_include_usage">Including and using RagePhoto</h4>
Include RagePhoto.h or RagePhotoA.h Include RagePhoto (C++ native), RagePhotoA (C API wrapper) or \link RagePhotoB.hpp RagePhotoB \endlink (best implementation)
\code{.cpp} \code{.cpp}
#include <RagePhoto.h> #include <RagePhoto>
\endcode \endcode
Create a RagePhoto object Create a RagePhoto object
@ -128,7 +128,7 @@ const bool loaded = image.loadFromData(QByteArray::fromRawData(ragePhoto.jpegDat
Using the JSON in Boost.JSON Using the JSON in Boost.JSON
\code{.cpp} \code{.cpp}
std::error_code ec; boost::json::error_code ec;
const boost::json::value jv = boost::json::parse(ragePhoto.json(), ec); const boost::json::value jv = boost::json::parse(ragePhoto.json(), ec);
if (ec) if (ec)
return; return;
@ -137,8 +137,7 @@ if (ec)
Using the JSON in Qt Using the JSON in Qt
\code{.cpp} \code{.cpp}
const QByteArray json = ragePhoto.json(); const QJsonDocument jd = QJsonDocument::fromJson(ragePhoto.json());
const QJsonDocument jd = QJsonDocument::fromJson(json);
if (jd.isNull()) if (jd.isNull())
return; return;
\endcode \endcode

View File

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible. * responsible for anything with use of the software, you are self responsible.
*****************************************************************************/ *****************************************************************************/
#include <RagePhoto> #include <RagePhotoB>
#include <gtkmm/application.h> #include <gtkmm/application.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/button.h> #include <gtkmm/button.h>
@ -36,11 +36,11 @@ bool readPhotoFile(const std::string &filename, Gtk::Window *win, Gtk::Image *im
if (ifs.is_open()) { if (ifs.is_open()) {
std::string data(std::istreambuf_iterator<char>{ifs}, {}); std::string data(std::istreambuf_iterator<char>{ifs}, {});
ifs.close(); ifs.close();
RagePhoto ragePhoto; RagePhotoB ragePhoto;
const bool loaded = ragePhoto.load(data); const bool loaded = ragePhoto.load(data);
if (!loaded) { if (!loaded) {
const int32_t error = ragePhoto.error(); 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); Gtk::MessageDialog msg(*win, "Failed to read photo: " + filename, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
msg.set_title("Open Photo"); msg.set_title("Open Photo");
msg.run(); msg.run();

View File

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible. * responsible for anything with use of the software, you are self responsible.
*****************************************************************************/ *****************************************************************************/
#include <RagePhoto> #include <RagePhotoB>
#include <QApplication> #include <QApplication>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -35,11 +35,11 @@ bool readPhotoFile(const QString &filename, QMainWindow *mainWindow, QLabel *pho
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
const QByteArray fileData = file.readAll(); const QByteArray fileData = file.readAll();
file.close(); file.close();
RagePhoto ragePhoto; RagePhotoB ragePhoto;
const bool loaded = ragePhoto.load(fileData.data(), static_cast<size_t>(fileData.size())); const bool loaded = ragePhoto.load(fileData.data(), static_cast<size_t>(fileData.size()));
if (!loaded) { if (!loaded) {
const int32_t error = ragePhoto.error(); const int32_t error = ragePhoto.error();
if (error <= RagePhoto::PhotoReadError) { if (error <= RagePhotoB::PhotoReadError) {
QMessageBox::warning(mainWindow, "Open Photo", "Failed to read photo: " + filename); QMessageBox::warning(mainWindow, "Open Photo", "Failed to read photo: " + filename);
return false; return false;
} }

View File

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible. * responsible for anything with use of the software, you are self responsible.
*****************************************************************************/ *****************************************************************************/
#include <RagePhoto> #include <RagePhotoB>
#include <fstream> #include <fstream>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -27,18 +27,18 @@ int main(int argc, char *argv[])
} }
// Initialise RagePhoto // Initialise RagePhoto
RagePhoto ragePhoto; RagePhotoB ragePhoto;
// Load Photo // Load Photo
const bool loaded = ragePhoto.loadFile(argv[1]); const bool loaded = ragePhoto.loadFile(argv[1]);
if (!loaded) { if (!loaded) {
const int32_t error = ragePhoto.error(); const int32_t error = ragePhoto.error();
if (error == RagePhoto::Uninitialised) { if (error == RagePhotoB::Uninitialised) {
std::cout << "Failed to open file: " << argv[1] << std::endl; std::cout << "Failed to open file: " << argv[1] << std::endl;
return 1; return 1;
} }
else if (error <= RagePhoto::PhotoReadError) { else if (error <= RagePhotoB::PhotoReadError) {
std::cout << "Failed to load photo" << std::endl; std::cout << "Failed to load photo" << std::endl;
return 1; return 1;
} }
@ -60,9 +60,9 @@ int main(int argc, char *argv[])
} }
const uint32_t photoFormat = ragePhoto.format(); const uint32_t photoFormat = ragePhoto.format();
if (photoFormat == RagePhoto::GTA5) if (photoFormat == RagePhotoB::GTA5)
std::cout << "GTA V Photo successfully exported" << std::endl; 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; std::cout << "RDR 2 Photo successfully exported" << std::endl;
else else
std::cout << "Photo successfully exported" << std::endl; std::cout << "Photo successfully exported" << std::endl;

View File

@ -17,7 +17,7 @@
*****************************************************************************/ *****************************************************************************/
#include "RagePhoto.hpp" #include "RagePhoto.hpp"
#ifdef LIBRAGEPHOTO_C_API #ifdef LIBRAGEPHOTO_CXX_C
#include "RagePhoto.h" #include "RagePhoto.h"
#endif #endif
@ -1223,7 +1223,7 @@ void RagePhoto::setTitle(const char *title, uint32_t bufferSize)
m_data->error = Error::NoError; // 255 m_data->error = Error::NoError; // 255
} }
#ifdef LIBRAGEPHOTO_C_API #ifdef LIBRAGEPHOTO_CXX_C
ragephoto_t ragephoto_open() ragephoto_t ragephoto_open()
{ {
return static_cast<ragephoto_t>(new RagePhoto); return static_cast<ragephoto_t>(new RagePhoto);

View File

@ -25,10 +25,7 @@
#include <iostream> #include <iostream>
/** /**
* \brief ABI Stable Wrapper for RagePhoto. * \brief GTA V and RDR 2 Photo Parser (C API wrapper).
*
* 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.
*/ */
class RagePhotoA class RagePhotoA
{ {

1
src/RagePhotoB Normal file
View File

@ -0,0 +1 @@
#include "RagePhotoB.hpp"

43
src/RagePhotoB.hpp Normal file
View File

@ -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

View File

@ -57,12 +57,13 @@
#endif // _WIN32 #endif // _WIN32
/* RAGEPHOTO LIBRARY BINDING END */ /* RAGEPHOTO LIBRARY BINDING END */
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY BEGIN */ /* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY BEGIN */
#ifdef LIBRAGEPHOTO_WASM #ifdef LIBRAGEPHOTO_WASM
#ifndef RAGEPHOTO_C_API #ifdef LIBRAGEPHOTO_CXX_ONLY
#define RAGEPHOTO_C_API #undef LIBRAGEPHOTO_CXX_ONLY
#endif // RAGEPHOTO_C_API #define LIBRAGEPHOTO_CXX_C
#endif // LIBRAGEPHOTO_CXX_ONLY
#endif // LIBRAGEPHOTO_WASM #endif // LIBRAGEPHOTO_WASM
/* ENABLE C API FOR RAGEPHOTO WASM LIBRARY END */ /* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY END */
#endif // RAGEPHOTOLIBRARY_H #endif // RAGEPHOTOLIBRARY_H