libragephoto: introduce C library port

CMakeLists.txt: fixes for MSVC and C library support
RagePhoto: non C++11 support
RagePhotoC: clarify C instance support in comment
RagePhotoTypedefs: add typedefs for C library
This commit is contained in:
Syping 2023-06-06 19:39:22 +02:00
parent af3580dff4
commit 3046cbd077
5 changed files with 1261 additions and 16 deletions

View file

@ -17,7 +17,7 @@
****************************************************************************]]
cmake_minimum_required(VERSION 3.8)
project(ragephoto VERSION 0.4.1 LANGUAGES CXX)
project(ragephoto VERSION 0.5.0 LANGUAGES C CXX)
include(GNUInstallDirs)
# RagePhoto CMake includes
@ -32,14 +32,26 @@ else()
endif()
# RagePhoto Source files
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF)
if (RAGEPHOTO_C_LIBRARY)
set(RAGEPHOTO_HEADERS
src/RagePhotoC.h
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.c
)
else()
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
endif()
# RagePhoto Library Type
option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF)
@ -60,14 +72,21 @@ if (RAGEPHOTO_BENCHMARK)
endif()
# RagePhoto C API
if (RAGEPHOTO_C_API)
if (RAGEPHOTO_C_LIBRARY)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h
src/RagePhotoC.h
)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI)
if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h
src/RagePhotoC.h
)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI)
endif()
endif()
# RagePhoto Win32 Shared Resources
@ -99,7 +118,7 @@ target_compile_definitions(ragephoto PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
if (MSVC)
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_LIBRARY)
target_compile_options(ragephoto PRIVATE "/Zc:__cplusplus")
endif()
target_include_directories(ragephoto PUBLIC
@ -143,7 +162,6 @@ option(RAGEPHOTO_EXTRACT "Build libragephoto with ragephoto-extract" ${RPTL_ON})
if (RAGEPHOTO_EXTRACT)
# RagePhoto-Extract Source files
if (RAGEPHOTO_C_API)
enable_language(C)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
@ -161,7 +179,7 @@ if (RAGEPHOTO_EXTRACT)
set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
if (MSVC AND NOT RAGEPHOTO_C_API)
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_API)
target_compile_options(ragephoto-extract PRIVATE "/Zc:__cplusplus")
endif()
target_link_libraries(ragephoto-extract PRIVATE ragephoto)

1213
src/RagePhoto.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -970,7 +970,11 @@ bool RagePhoto::saveFile(const std::string &filename, uint32_t photoFormat)
m_data->error = Error::Uninitialised; // 0
return false;
}
#if (RAGEPHOTO_CXX_STD >= 11) && (__cplusplus >= 201103L)
ofs << sdata;
#else
ofs.write(sdata.data(), sdata.size());
#endif
ok = ofs.good();
ofs.close();
return ok;

View file

@ -36,7 +36,7 @@ extern "C" {
* \file RagePhotoC.h
*/
/** RagePhoto C++ class typedef for C API. */
/** RagePhoto C instance/C++ class typedef. */
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */

View file

@ -70,6 +70,12 @@ typedef struct RagePhotoFormatParser {
ragephoto_saveszfunc_t funcSaveSz; /**< Pointer to saveSize function */
} RagePhotoFormatParser;
/** RagePhoto instance struct for storing data and format parser pointer. */
typedef struct RagePhotoInstance {
RagePhotoData *data; /**< Pointer for data */
RagePhotoFormatParser *parser; /**< Pointer for format parser */
} RagePhotoInstance;
/* RagePhoto default sizes */
#define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER 524288UL /**< GTA V default Photo Buffer Size */
#define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER 1048576UL /**< RDR 2 default Photo Buffer Size */
@ -126,6 +132,10 @@ typedef struct RagePhotoFormatParser {
#define RAGEPHOTO_FORMAT_GTA5 0x01000000UL /**< GTA V Photo Format */
#define RAGEPHOTO_FORMAT_RDR2 0x04000000UL /**< RDR 2 Photo Format */
/* RagePhoto sign initials */
#define RAGEPHOTO_SIGNINITIAL_GTA5 0xE47AB81CUL /**< GTA V Sign Initial */
#define RAGEPHOTO_SIGNINITIAL_RDR2 0x00FEEB1EUL /**< RDR 2 Sign Initial */
#ifdef __cplusplus
}
#endif // __cplusplus