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

View file

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

View file

@ -20,6 +20,7 @@ To customise your libragephoto build, the following <a href="#flags">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

View file

@ -14,7 +14,7 @@
<b>Reference</b>
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)

View file

@ -4,10 +4,10 @@
<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}
#include <RagePhoto.h>
#include <RagePhoto>
\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

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto>
#include <RagePhotoB>
#include <gtkmm/application.h>
#include <gtkmm/box.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()) {
std::string data(std::istreambuf_iterator<char>{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();

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto>
#include <RagePhotoB>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
@ -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<size_t>(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;
}

View file

@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto>
#include <RagePhotoB>
#include <fstream>
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;

View file

@ -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<ragephoto_t>(new RagePhoto);

View file

@ -25,10 +25,7 @@
#include <iostream>
/**
* \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
{

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
/* 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