Compare commits

...

60 Commits
test ... master

Author SHA1 Message Date
Syping c74b4a415f libragephoto 0.5.1 release
- ragephoto_open: fix memory leak when instance can't be allocated
- ragephoto_loadfile: fix file handle leak when data heap can't be
allocated
- ragephotodata_load: fix printf print types
- RagePhoto.cpp: remove std namespace from C functions
2023-10-25 16:33:01 +02:00
Syping 6fdc075741 libragephoto 0.5.0 release
- CMakeLists.txt: add missing RagePhotoA for C API builds
- updated README.md
2023-06-11 23:07:41 +02:00
Syping 12507be85d 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
2023-06-11 05:41:32 +02:00
Syping d7943e552d GitHub Actions: fix WebAssembly C build 2023-06-09 05:05:42 +02:00
Syping b838c505a4 libragephoto: C++ headers have now .hpp extension
RagePhoto.h -> RagePhoto.hpp
RagePhotoA.h -> RagePhotoA.hpp
RagePhotoC.h -> RagePhoto.h

unicode.cmake: exclude codecvt for C builds
GitHub Actions: separate C and CXX builds
2023-06-07 06:57:23 +02:00
Syping 6acf7b7338 RagePhoto.c: fix potential memory issue 2023-06-07 06:12:24 +02:00
Syping 24e0d9c03e RagePhoto.c: fix potential memory issue 2023-06-07 06:09:37 +02:00
Syping 6066d92ee9 RagePhoto.c: fix potential memory issue, fix debug code 2023-06-06 21:05:55 +02:00
Syping c3e838cecf RagePhoto.c: fix iconv code 2023-06-06 20:27:51 +02:00
Syping 8a29d8aebe GitHub Actions: use C library for WebAssembly build
RagePhoto.c: fix header includes
2023-06-06 20:22:20 +02:00
Syping 3046cbd077 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
2023-06-06 19:39:22 +02:00
Syping af3580dff4 libragephoto 0.4.1 release
RagePhotoA: fix setData() pointer passthrough
2023-05-25 23:30:26 +02:00
Syping 4aedd8b869 libragephoto 0.4.0 release
- CMakeLists.txt: bump version to 0.4.0
- RagePhoto(A): add headerSum2 for RDR 2
- RagePhotoC: add ragephoto_setphotoheader2() for RDR 2
- RagePhotoTypedefs: remove unnamedSum1, rename unnamedSum2 ->
headerSum2
- RagePhotoTypedefs: remove ragephoto_bool_t for bool
2023-05-14 11:44:59 +02:00
Syping 3d9d632d7b libragephoto: add RDR 2 SignInitial 2023-05-09 23:28:38 +02:00
Syping f1485be7a7 libragephoto: add defines for C API
RagePhotoTypedefs.h: add defines for C API
RagePhoto-Extract.c: take advantage of C API defines
2023-04-26 01:09:22 +02:00
Syping d8c0d7d470 libragephoto: rename BINDING to PUBLIC, some other changes
- doc/Doxyfile.in: rename BINDING to PUBLIC
- doc/usage.doc: fix a usage example
- CMakeLists.txt: include CPack only when libragephoto is Top Level
- RagePhoto.h: rename BINDING TO PUBLIC
- RagePhotoC.h: rename BINDING TO PUBLIC
- RagePhotoLibrary.h: rename BINDING to PUBLIC, add new checks
2023-04-09 21:22:13 +02:00
Syping 933918454f libragephoto 0.3.0 release
- update README.md
- update documentation
- ragephoto-gtkviewer: fix error uint8_t -> int32_t, NULL -> nullptr
- ragephoto-qtviewer: fix error uint8_t -> int32_t
- RagePhotoA: fix documentation, fix error()
- RagePhotoC: add brief
2023-04-02 21:33:48 +02:00
Syping 302be665e2 RagePhoto: use C++17 u8path when available 2023-03-27 17:49:35 +02:00
Syping cac7fd221f RagePhoto(A): add jpegSign() function
- RagePhotoC: add ragephoto_getphotosign() ragephoto_getphotosignf()
ragephotodata_getphotosign() and ragephotodata_getphotosignf() functions
2023-03-15 08:22:38 +01:00
Syping 564a8c92b5 CMakeLists.txt: add C++17 build flags for MSVC 2023-03-09 05:30:01 +01:00
Syping 6d943e7b20 libragephoto: use C++17 for the CI/CD build 2023-03-06 20:31:54 +01:00
Syping 3c433ca072 libragephoto: add opt-in C++17 support
- RagePhoto(A): add jpeg_view() function
- CMakeLists.txt: move C++17 and WebAssembly stuff inside include files
2023-03-03 03:26:59 +01:00
Syping 4ca8ac9297 RagePhoto: replace strncmp with memcmp
RagePhoto(A): fix header spelling mistake
RagePhotoA: update header description
2023-02-24 23:51:32 +01:00
Syping d75eba2a46 libragephoto: add new ragephotodata functions and improvements
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
2023-02-23 09:17:53 +01:00
Syping 9807f0d696 libragephoto: update C API
RagePhotoA: add new C API functions
RagePhotoC: add ragephotodata_clear(), ragephotodata_load(),
ragephotodata_getsavesize(), ragephotodata_getsavesizef(),
ragephotodata_setbufferdefault(), ragephotodata_setbufferoffsets()
2023-02-20 14:58:41 +01:00
Syping e51d50f77e RagePhoto: fix inline related issues 2023-02-20 13:37:40 +01:00
Syping d13c22dc05 RagePhoto: add clear() and load() as static functions 2023-02-20 11:56:23 +01:00
Syping 2a8070b75e libragephoto: add custom parser feature
- RagePhoto: add addParser()
- RagePhotoC: add ragephoto_addparser()
- RagePhoto(C): rename all ragePhotoData to rp_data
2023-02-20 11:27:14 +01:00
Syping 659feb0cbf RagePhoto: update ragephoto_setphotodata function
- RagePhotoTypedefs: add saveSize function
2023-02-11 22:40:13 +01:00
Syping b2e765c2af libragephoto: fix build errors and some includes
- RagePhoto-Extract: include stdio.h
- RagePhotoC: include stddef.h instead of stdio.h
- RagePhotoTypedefs: include stddef.h
2023-02-11 20:53:41 +01:00
Syping df388acaec RagePhoto: improve C compatibility further 2023-02-11 20:47:05 +01:00
Syping 0900feda84 libragephoto: add typedefs for format parser 2023-02-11 20:06:00 +01:00
Syping 429f011cff CMakeLists.txt: add CPack package generation 2023-02-11 18:53:15 +01:00
Syping 255c1a28b9 C API: ragephoto_setphotodata(c) returns now bool 2023-02-08 19:59:56 +01:00
Syping 45a45701f6 libragephoto: various changes
- libragephoto_global.h seperated to RagePhotoConfig.h and
RagePhotoLibrary.h
- RagePhotoData.h renamed to RagePhotoTypedefs.h
- RagePhotoData: updated struct and documentated it
- RagePhotoC: changed ragephoto_setphotodata ABI, added
ragephoto_setphotodatac for copying
- RagePhotoA: adapted for the ABI changes
- RagePhoto: adapted for the ABI changes and updated struct
2023-02-07 03:06:22 +01:00
Syping 8e73219549 RagePhotoData: make it clear that RagePhotoData is a C type struct 2023-01-11 18:45:35 +01:00
Syping 1173db1aa8 RagePhoto: avoid setData() replacing it's own RagePhotoData 2023-01-08 18:34:47 +01:00
Syping 96eae4f957 change setData() attitude with the internal data object
- when takeOwnership is false, instead of deleting the old object and
generating a new object from scratch, it clears now the old object
2023-01-08 18:18:28 +01:00
Syping a704ee046a add setData() and ragephoto_setphotodata() functions
RagePhoto: add setData() and ragephoto_setphotodata() functions
RagePhotoA: wrap setData() function to ragephoto_setphotodata()
RagePhotoC: update header for ragephoto_setphotodata()
2023-01-08 17:45:54 +01:00
Syping 24d6f58b74 RagePhoto: fix build error for older C++ standards 2023-01-08 15:44:28 +01:00
Syping 2b878cf416 RagePhoto: make RagePhotoData m_data a pointer 2023-01-08 15:21:16 +01:00
Syping db9a0eaf9a RagePhoto: uncomment setHeader HeaderMallocError code 2023-01-08 14:09:36 +01:00
Syping 13650527be add function ragephoto_getphotodata() to the C API
RagePhoto: add function ragephoto_getphotodata() to the C API
RagePhotoA: wrap data() function to ragephoto_getphotodata()
RagePhotoC: update header for ragephoto_getphotodata()
RagePhotoData: improve header include statement
2023-01-08 13:57:37 +01:00
Syping d7e31ecada struct, enum and few other changes
RagePhoto: updated comments to the new error codes, update code for the
new RagePhotoData names
RagePhotoData: change names of photoData to jpeg, photoSize to jpegSize
RagePhotoA: copied documentation from RagePhoto
RagePhoto::Error: add error type HeaderMallocError
2023-01-08 13:35:32 +01:00
Syping f99456cb63 RagePhotoData: change struct to a C typedef struct 2023-01-07 22:09:35 +01:00
Syping f0a0580682 RagePhoto: fix iconv regression 2023-01-07 21:17:49 +01:00
Syping e08b45d980 low level improvements and data type changes
- RagePhoto: removed setFormatLoadFunction (will be replaced with a
better solution later)
- RagePhoto: code updates for the RagePhotoData changes
- RagePhotoA: have now RagePhoto enum's available
- RagePhotoData: changed description, json, header and title types to
char*
- RagePhotoData: removed photoLoaded in favour of nullptr check
- examples: prepared for the API update
2023-01-07 20:43:11 +01:00
Syping 4b9637e0fd Emscripten: add _malloc to EXPORTED_FUNCTIONS 2023-01-05 16:03:47 +01:00
Syping 54912a63ab Emscripten: set ALLOW_MEMORY_GROWTH to 1 2023-01-05 15:46:57 +01:00
Syping 95943203e0 libragephoto: 2022 update 2022-12-28 07:39:06 +01:00
Syping 087534bf6e CMake: improved Unicode tests
CodecvtTest.cpp: fix error codes
IconvTest.cpp: add Japanese, Korean, Russian and Taiwanese tests
WincvtTest.cpp: fix error codes
2022-12-28 07:18:15 +01:00
Syping 91404a5f77 CMake: improved Unicode tests
unicode.cmake: avoid errors when spaces exists
CodecvtTest.cpp: add Japanese, Korean, Russian and Taiwanese tests
WincvtTest.cpp: add Japanese, Korean, Russian and Taiwanese tests
2022-12-28 05:56:01 +01:00
Syping 1d522d0667 CMakeLists.txt 2022 update 2022-08-04 06:26:54 +02:00
Syping 6a50ca75a1 CMakeLists.txt update, RagePhoto add data() function
RagePhoto::data() returns internal RagePhotoData object
2021-12-14 03:15:52 +01:00
Syping 930897cf97 windows.yml: add Windows MSVC cross compile 2021-12-04 08:37:58 +01:00
Syping 7326cc26c7 unicode.cmake improvements, RagePhoto API changes
RagePhoto: remove class from Error enum
RagePhotoA: error() uint32_t -> uint8_t
RagePhoto-Extract: remove Error:: from Error enums
ragephoto-gtkviewer: RagePhoto::Error -> uint8_t, remove Error:: from
Error enum
ragephoto-qtviewer: RagePhoto::Error -> uint8_t, remove Error:: from
Error enum
2021-12-02 05:55:50 +01:00
Syping eed3290633 CMake and GitHub Actions update installations 2021-12-02 03:14:19 +01:00
Syping 9132f92410 GitHub Actions: Artifact uploads added 2021-12-01 09:04:10 +01:00
Syping 6d71d480b7 GitHub Actions: add webassembly.yml and update ubuntu.yml 2021-12-01 07:52:57 +01:00
Syping aa9ac44f3e CMake, Doc and README updates
CMake: add EM_ON EM_OFF and rename BUILD_* and WITH_* options to
RAGEPHOTO_*
Doc: change C++ API to C/C++ API
README: change build libragephoto section and add the reworked CMake
options
2021-12-01 07:41:47 +01:00
40 changed files with 4331 additions and 1252 deletions

29
.github/workflows/ubuntu-c.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Ubuntu C
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake gcc g++ ninja-build -qq
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install/usr/local
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Ubuntu
path: |
${{github.workspace}}/install/

29
.github/workflows/ubuntu-cxx.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Ubuntu CXX
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake gcc g++ ninja-build -qq
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install/usr/local
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Ubuntu
path: |
${{github.workspace}}/install/

View File

@ -1,28 +0,0 @@
name: Ubuntu
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
BUILD_TYPE: Release
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake git gcc g++ make ninja-build -qq
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: sudo cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

30
.github/workflows/webassembly-c.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: WebAssembly C
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake ninja-build -qq
- name: Configure CMake
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload
uses: actions/upload-artifact@v2
with:
name: WebAssembly
path: |
${{github.workspace}}/build/libragephoto.js
${{github.workspace}}/build/libragephoto.wasm

30
.github/workflows/webassembly-cxx.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: WebAssembly CXX
on: push
jobs:
Release:
runs-on: ubuntu-latest
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install cmake ninja-build -qq
- name: Configure CMake
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload
uses: actions/upload-artifact@v2
with:
name: WebAssembly
path: |
${{github.workspace}}/build/libragephoto.js
${{github.workspace}}/build/libragephoto.wasm

34
.github/workflows/windows-c.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Windows C
on: push
jobs:
Release:
runs-on: windows-latest
env:
BUILD_TYPE: Release
strategy:
matrix:
arch:
- amd64
- amd64_x86
- amd64_arm64
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_C_LIBRARY=ON -DRAGEPHOTO_UNICODE=wincvt -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Windows MSVC ${{matrix.arch}}
path: |
${{github.workspace}}/install/

34
.github/workflows/windows-cxx.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Windows CXX
on: push
jobs:
Release:
runs-on: windows-latest
env:
BUILD_TYPE: Release
strategy:
matrix:
arch:
- amd64
- amd64_x86
- amd64_arm64
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAGEPHOTO_UNICODE=wincvt -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --prefix ${{github.workspace}}/install
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Windows MSVC ${{matrix.arch}}
path: |
${{github.workspace}}/install/

View File

@ -1,23 +0,0 @@
name: Windows
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
BUILD_TYPE: Release
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: ilammy/msvc-dev-cmd@v1
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

View File

@ -1,6 +1,6 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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:
@ -16,153 +16,157 @@
* responsible for anything with use of the software, you are self responsible.
****************************************************************************]]
cmake_minimum_required(VERSION 3.7)
project(ragephoto VERSION 0.1.0 LANGUAGES CXX)
cmake_minimum_required(VERSION 3.8)
project(ragephoto VERSION 0.5.1 LANGUAGES C CXX)
include(GNUInstallDirs)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# RagePhoto CMake includes
include(cmake/cxxstd.cmake)
include(cmake/unicode.cmake)
# RagePhoto Top Level ON
if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto")
set(RPTL_ON ON)
else()
set(RPTL_ON OFF)
endif()
# RagePhoto Source files
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoData.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/RagePhoto.h
src/RagePhotoA
src/RagePhotoA.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.c
)
else()
set(RAGEPHOTO_HEADERS
src/RagePhoto
src/RagePhoto.hpp
src/RagePhotoB
src/RagePhotoB.hpp
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
endif()
# RagePhoto Library Type
if (EMSCRIPTEN)
option(BUILD_SHARED "Build libragephoto as shared library" OFF)
else()
option(BUILD_SHARED "Build libragephoto as shared library" ON)
endif()
if (BUILD_SHARED)
option(WITH_C_API "Build libragephoto with C API support" ON)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_SHARED)
else()
if (EMSCRIPTEN)
option(WITH_C_API "Build libragephoto with C API support" ON)
else()
option(WITH_C_API "Build libragephoto with C API support" OFF)
endif()
option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF)
if (RAGEPHOTO_STATIC)
option(RAGEPHOTO_C_API "Build libragephoto with C API support" OFF)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_STATIC)
else()
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_SHARED)
endif()
# RagePhoto Benchmark
option(WITH_BENCHMARK "Build with libragephoto benchmark" OFF)
if (WITH_BENCHMARK)
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark (C++ only)" OFF)
if (RAGEPHOTO_BENCHMARK)
list(APPEND LIBRAGEPHOTO_DEFINES
RAGEPHOTO_BENCHMARK
)
endif()
# RagePhoto C API
if (WITH_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h
src/RagePhotoC.h
)
if (RAGEPHOTO_C_LIBRARY)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_ONLY)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI)
if (RAGEPHOTO_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)
endif()
endif()
# RagePhoto Win32 Shared Resources
if (WIN32)
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
configure_file(src/ragephoto.rc.in resources/ragephoto.rc @ONLY)
configure_file(src/ragephoto.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto.rc" @ONLY)
list(APPEND RAGEPHOTO_SHARED_RESOURCES
${PROJECT_BINARY_DIR}/resources/ragephoto.rc
"${ragephoto_BINARY_DIR}/resources/ragephoto.rc"
)
endif()
# RagePhoto Configures + Target + Installs
configure_file(src/ragephoto.pc.in pkgconfig/ragephoto.pc @ONLY)
configure_file(src/libragephoto_global.h.in include/libragephoto_global.h @ONLY)
configure_file(src/ragephoto.pc.in "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" @ONLY)
configure_file(src/RagePhotoConfig.h.in "${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h" @ONLY)
list(APPEND RAGEPHOTO_HEADERS
${PROJECT_BINARY_DIR}/include/libragephoto_global.h
"${ragephoto_BINARY_DIR}/include/RagePhotoConfig.h"
)
if (BUILD_SHARED)
if (RAGEPHOTO_STATIC)
add_library(ragephoto STATIC ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_STATIC_RESOURCES})
else()
add_library(ragephoto SHARED ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_SHARED_RESOURCES})
set_target_properties(ragephoto PROPERTIES
PREFIX "lib"
VERSION "${ragephoto_VERSION}"
SOVERSION "${ragephoto_VERSION}"
)
else()
add_library(ragephoto STATIC ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_STATIC_RESOURCES})
endif()
target_compile_definitions(ragephoto PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
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
${ragephoto_BINARY_DIR}/include
${ragephoto_SOURCE_DIR}/src
"${ragephoto_BINARY_DIR}/include"
"${ragephoto_SOURCE_DIR}/src"
)
install(TARGETS ragephoto DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${RAGEPHOTO_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/RagePhoto)
install(FILES ${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(TARGETS ragephoto
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
install(FILES ${RAGEPHOTO_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/RagePhoto")
if (UNIX)
install(FILES "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
# RagePhoto WebAssembly Target
if (EMSCRIPTEN)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
add_executable(ragephoto-wasm ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES})
set_target_properties(ragephoto-wasm PROPERTIES
PREFIX "lib"
OUTPUT_NAME "ragephoto"
)
target_compile_definitions(ragephoto-wasm PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
target_link_options(ragephoto-wasm PRIVATE
"SHELL:-O2"
"SHELL:--no-entry"
"SHELL:-s WASM=1"
"SHELL:-s EXPORTED_FUNCTIONS=_free"
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
)
target_include_directories(ragephoto-wasm PUBLIC
${ragephoto_BINARY_DIR}/include
${ragephoto_SOURCE_DIR}/src
)
else()
message(WARNING "A useable WebAssembly build needs at least CMake 3.13.0 or newer")
endif()
include(cmake/wasm.cmake)
endif()
# RagePhoto Documentation
option(WITH_DOCUMENTATION "Build libragephoto with documentation" OFF)
if (WITH_DOCUMENTATION)
option(RAGEPHOTO_DOC "Build libragephoto with documentation" OFF)
if (RAGEPHOTO_DOC)
add_subdirectory(doc)
endif()
# RagePhoto Examples
option(WITH_GTK_EXAMPLE "Build libragephoto with GTK Photo Viewer" OFF)
if (WITH_GTK_EXAMPLE)
option(RAGEPHOTO_EXAMPLE_GTKVIEWER "Build libragephoto with GTK Photo Viewer" OFF)
if (RAGEPHOTO_EXAMPLE_GTKVIEWER)
add_subdirectory(examples/ragephoto-gtkviewer)
endif()
option(WITH_QT_EXAMPLE "Build libragephoto with Qt Photo Viewer" OFF)
if (WITH_QT_EXAMPLE)
option(RAGEPHOTO_EXAMPLE_QTVIEWER "Build libragephoto with Qt Photo Viewer" OFF)
if (RAGEPHOTO_EXAMPLE_QTVIEWER)
add_subdirectory(examples/ragephoto-qtviewer)
endif()
# RagePhoto Extract Tool
if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto")
option(WITH_EXTRACT "Build libragephoto with ragephoto-extract" ON)
else()
option(WITH_EXTRACT "Build libragephoto with ragephoto-extract" OFF)
endif()
if (WITH_EXTRACT)
option(RAGEPHOTO_EXTRACT "Build libragephoto with ragephoto-extract" ${RPTL_ON})
if (RAGEPHOTO_EXTRACT)
# RagePhoto-Extract Source files
if (WITH_C_API)
enable_language(C)
if (RAGEPHOTO_C_API)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
@ -170,9 +174,9 @@ if (WITH_EXTRACT)
# RagePhoto-Extract Win32 Shared Resources
if (WIN32)
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
configure_file(src/ragephoto-extract.rc.in resources/ragephoto-extract.rc @ONLY)
configure_file(src/ragephoto-extract.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc" @ONLY)
list(APPEND EXTRACT_RESOURCES
${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc
"${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc"
)
endif()
# RagePhoto-Extract Target + Installs
@ -180,6 +184,22 @@ if (WITH_EXTRACT)
set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
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)
install(TARGETS ragephoto-extract DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS ragephoto-extract DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
# CPack Package Generation
if (RPTL_ON)
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_DESCRIPTION "Open Source RAGE Photo Parser for GTA V and RDR 2")
set(CPACK_PACKAGE_NAME "libragephoto")
set(CPACK_PACKAGE_VENDOR "Syping")
set(CPACK_PACKAGE_VERSION_MAJOR "${ragephoto_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${ragephoto_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${ragephoto_VERSION_PATCH}")
set(CPACK_STRIP_FILES ON)
include(CPack)
endif()

View File

@ -9,37 +9,34 @@ Open Source RAGE Photo Parser for GTA V and RDR 2
#### Build libragephoto
```bash
git clone https://github.com/Syping/libragephoto && cd libragephoto
mkdir -p build && cd build
cmake ../
make -j $(nproc --all)
sudo make install
git clone https://github.com/Syping/libragephoto
cmake -B libragephoto-build libragephoto
cmake --build libragephoto-build
sudo cmake --install libragephoto-build
```
##### Optional CMake flags
`-DWITH_DOCUMENTATION=ON`
`-DWITH_EXTRACT=OFF`
`-DWITH_GTK_EXAMPLE=ON`
`-DWITH_QT_EXAMPLE=ON`
`-DBUILD_SHARED=OFF`
`-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`
`-DRAGEPHOTO_EXTRACT=OFF`
`-DRAGEPHOTO_STATIC=ON`
#### How to Use libragephoto
#### RagePhoto API
```cpp
RagePhoto ragePhoto;
bool loaded = ragePhoto.load(data, size);
std::string photo = ragePhoto.photo();
const char* photoData = ragePhoto.photoData();
uint32_t photoSize = ragePhoto.photoSize();
std::string json = ragePhoto.json();
std::string title = ragePhoto.title();
RagePhoto::Error error = ragePhoto.error();
uint32_t format = ragePhoto.format(); // RagePhoto::GTA5 or RagePhoto::RDR2
```
[RagePhoto C API](https://libragephoto.syping.de/doc/RagePhotoC_8h.html)
[RagePhoto C API](https://libragephoto.syping.de/doc/RagePhoto_8h.html)
[RagePhoto C++ API](https://libragephoto.syping.de/doc/classRagePhoto.html)
#### libragephoto Documentation
[Main Page](https://libragephoto.syping.de/doc/)
[Build libragephoto](https://libragephoto.syping.de/doc/Build.html)
[Using libragephoto](https://libragephoto.syping.de/doc/Usage.html)
#### How to Use ragephoto-extract
```bash

21
cmake/cxxstd.cmake Normal file
View File

@ -0,0 +1,21 @@
#[[**************************************************************************
* 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.
****************************************************************************]]
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11 CACHE STRING "libragephoto C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON)

View File

@ -1,6 +1,6 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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:
@ -16,47 +16,61 @@
* responsible for anything with use of the software, you are self responsible.
****************************************************************************]]
# RagePhoto Unicode functionality tests
message("-- Testing codecvt")
try_run(CODECVT_RUN CODECVT_COMPILE ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests/CodecvtTest.cpp)
if (CODECVT_COMPILE AND CODECVT_RUN EQUAL 0)
set(CODECVT_COMPAT TRUE)
message("-- Testing codecvt - yes")
set(RAGEPHOTO_UNICODE "" CACHE STRING "libragephoto Unicode implementation")
if (RAGEPHOTO_UNICODE)
string(TOUPPER "UNICODE_${RAGEPHOTO_UNICODE}" UNICODE_DEF)
list(APPEND LIBRAGEPHOTO_DEFINES
"${UNICODE_DEF}"
)
message("-- UnicodeCvt - ${RAGEPHOTO_UNICODE}")
else()
message("-- Testing codecvt - no")
endif()
message("-- Testing iconv")
try_run(ICONV_RUN ICONV_COMPILE ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests/IconvTest.cpp)
if (ICONV_COMPILE AND ICONV_RUN EQUAL 0)
set(ICONV_COMPAT TRUE)
message("-- Testing iconv - yes")
else()
message("-- Testing iconv - no")
endif()
if (WIN32)
message("-- Testing wincvt")
try_run(WINCVT_RUN WINCVT_COMPILE ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests/WincvtTest.cpp)
if (WINCVT_COMPILE AND WINCVT_RUN EQUAL 0)
set(WINCVT_COMPAT TRUE)
message("-- Testing wincvt - yes")
# RagePhoto Unicode functionality tests
message("-- Testing codecvt")
try_run(CODECVT_RUN CODECVT_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/CodecvtTest.cpp")
if (CODECVT_COMPILE AND CODECVT_RUN EQUAL 0)
set(CODECVT_COMPAT TRUE)
message("-- Testing codecvt - yes")
else()
message("-- Testing wincvt - no")
message("-- Testing codecvt - no")
endif()
message("-- Testing iconv")
try_run(ICONV_RUN ICONV_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/IconvTest.cpp")
if (ICONV_COMPILE AND ICONV_RUN EQUAL 0)
set(ICONV_COMPAT TRUE)
message("-- Testing iconv - yes")
else()
message("-- Testing iconv - no")
endif()
if (WIN32)
message("-- Testing wincvt")
try_run(WINCVT_RUN WINCVT_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/WincvtTest.cpp")
if (WINCVT_COMPILE AND WINCVT_RUN EQUAL 0)
set(WINCVT_COMPAT TRUE)
message("-- Testing wincvt - yes")
else()
message("-- Testing wincvt - no")
endif()
endif()
# Unicode implementation for RagePhoto
if (WINCVT_COMPAT)
list(APPEND LIBRAGEPHOTO_DEFINES
"UNICODE_WINCVT"
)
message("-- UnicodeCvt - wincvt")
elseif (CODECVT_COMPAT AND NOT RAGEPHOTO_C_LIBRARY)
list(APPEND LIBRAGEPHOTO_DEFINES
"UNICODE_CODECVT"
)
message("-- UnicodeCvt - codecvt")
elseif (ICONV_COMPAT)
list(APPEND LIBRAGEPHOTO_DEFINES
"UNICODE_ICONV"
)
message("-- UnicodeCvt - iconv")
else()
message("-- UnicodeCvt - none")
endif()
endif()
# Unicode implementation for RagePhoto
if (WINCVT_COMPAT)
list(APPEND LIBRAGEPHOTO_DEFINES
UNICODE_WINCVT
)
elseif (CODECVT_COMPAT)
list(APPEND LIBRAGEPHOTO_DEFINES
UNICODE_CODECVT
)
elseif (ICONV_COMPAT)
list(APPEND LIBRAGEPHOTO_DEFINES
UNICODE_ICONV
)
endif()

47
cmake/wasm.cmake Normal file
View File

@ -0,0 +1,47 @@
#[[**************************************************************************
* 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.
****************************************************************************]]
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
add_executable(ragephoto-wasm ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES})
set_target_properties(ragephoto-wasm PROPERTIES
PREFIX "lib"
OUTPUT_NAME "ragephoto"
)
target_compile_definitions(ragephoto-wasm PRIVATE
LIBRAGEPHOTO_LIBRARY
LIBRAGEPHOTO_WASM
${LIBRAGEPHOTO_DEFINES}
)
target_link_options(ragephoto-wasm PRIVATE
"SHELL:-O3"
"SHELL:--no-entry"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s MODULARIZE=1"
"SHELL:-s WASM=1"
"SHELL:-s WASM_BIGINT=1"
"SHELL:-s EXPORT_NAME=libragephotoModule"
"SHELL:-s EXPORTED_FUNCTIONS=_free,_malloc"
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
)
target_include_directories(ragephoto-wasm PUBLIC
"${ragephoto_BINARY_DIR}/include"
"${ragephoto_SOURCE_DIR}/src"
)
else()
message(WARNING "A useable WebAssembly build needs at least CMake 3.13.0 or newer")
endif()

View File

@ -1,12 +1,16 @@
PROJECT_NAME = "libragephoto"
PROJECT_NUMBER = "Version: @ragephoto_VERSION@"
INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/index.doc" \
"@CMAKE_CURRENT_SOURCE_DIR@/build.doc" \
"@CMAKE_CURRENT_SOURCE_DIR@/usage.doc" \
"src"
OUTPUT_DIRECTORY = "@CMAKE_CURRENT_BINARY_DIR@"
EXTRACT_PRIVATE = NO
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
PREDEFINED = "protected=private" \
"__cplusplus" \
"@LIBRAGEPHOTO_API@"
PREDEFINED = "__cplusplus=201703L" \
"RAGEPHOTO_CXX_STD=17" \
"@LIBRAGEPHOTO_API@" \
"LIBRAGEPHOTO_C_PUBLIC=" \
"LIBRAGEPHOTO_CXX_PUBLIC="

30
doc/build.doc Normal file
View File

@ -0,0 +1,30 @@
/*! \page Build Build libragephoto
Keep sure you have CMake and a C++ compiler installed, then do the following or the equivalent necessary.
<h4 id="build">Build libragephoto</h4>
\code{.sh}
cmake -B libragephoto-build libragephoto
cmake --build libragephoto-build
\endcode
<h4 id="install">Install libragephoto</h4>
\code{.sh}
sudo cmake --install libragephoto-build
\endcode
To customise your libragephoto build, the following <a href="#flags">Optional CMake flags</a> can be used
<h4 id="flags">Optional CMake flags</h4>
\code{.sh}
-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
-DRAGEPHOTO_EXTRACT=OFF
-DRAGEPHOTO_STATIC=ON
\endcode
*/

View File

@ -5,14 +5,22 @@
- Read/Write RAGE Photos error free and correct
- Support for metadata stored in RAGE Photos
- Export RAGE Photos to jpeg with ragephoto-extract
- High Efficient and Simple C++ API
- High Efficient and Simple C/C++ API
<b>Main Class:</b>
- RagePhoto
<b>Getting started</b>
\subpage Build "Build libragephoto"
\subpage Usage "Using libragephoto"
<b>Project Pages:</b>
- https://git.syping.de/Syping/libragephoto
- https://gitlab.com/Syping/libragephoto
- https://github.com/Syping/libragephoto
<b>Reference</b>
RagePhoto (C++ API)
RagePhotoA (C++ API based on C API)
RagePhoto.h (C API)
RagePhotoData (Data Object Struct)
RagePhotoFormatParser (Custom Format Parser Struct)
<b>Project Pages</b>
https://git.syping.de/Syping/libragephoto
https://gitlab.com/Syping/libragephoto
https://github.com/Syping/libragephoto
*/

188
doc/usage.doc Normal file
View File

@ -0,0 +1,188 @@
/*! \page Usage Using libragephoto
<h3 id="api_cxx">C++ API</h3>
<h4 id="cxx_include_usage">Including and using RagePhoto</h4>
Include RagePhoto (C++ native), RagePhotoA (C API wrapper) or \link RagePhotoB.hpp RagePhotoB \endlink (best implementation)
\code{.cpp}
#include <RagePhoto>
\endcode
Create a RagePhoto object
\code{.cpp}
RagePhoto ragePhoto;
\endcode
<h4 id="cxx_loading">Loading a Photo</h4>
From a file using RagePhoto::loadFile
\code{.cpp}
const char* filename = "PGTA5123456789";
const bool loaded = ragePhoto.loadFile(filename);
\endcode
From a file using RagePhoto::load(const std::string&)
\code{.cpp}
// Reading file
const char* filename = "PGTA5123456789";
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
if (!ifs.is_open())
return;
std::string sdata(std::istreambuf_iterator<char>{ifs}, {});
ifs.close();
// Loading file
const bool loaded = ragePhoto.load(sdata);
\endcode
From a char* using RagePhoto::load(const char*, size_t)
\code{.cpp}
const bool loaded = ragePhoto.load(data, size);
\endcode
<h4 id="cxx_using">Using a Photo</h4>
\code{.cpp}
// Returns the Photo Format
const uint32_t format = ragePhoto.format();
// Returns the JPEG as std::string
const std::string jpeg = ragePhoto.jpeg();
// Returns the JPEG as const char*
const char* jpeg = ragePhoto.jpegData();
const uint32_t size = ragePhoto.jpegSize();
// Returns the JSON
const char* json = ragePhoto.json();
// Returns the Title
const char* title = ragePhoto.title();
\endcode
Detecting if Photo is from GTA V or RDR 2
\code{.cpp}
switch (ragePhoto.format()) {
case RagePhoto::PhotoFormat::GTA5:
std::cout << "GTA V format detected" << std::endl;
break;
case RagePhoto::PhotoFormat::RDR2:
std::cout << "RDR 2 format detected" << std::endl;
break;
default:
std::cout << "Unknown format detected" << std::endl;
}
\endcode
Saving the JPEG from a Photo
\code{.cpp}
// Example saveJpeg function
bool saveJpeg(RagePhoto* ragePhoto, const std::string& filename) {
std::ofstream ofs(filename, std::ios::out | std::ios::binary | std::ios::trunc);
if (!ofs.is_open())
return false;
ofs << ragePhoto->jpeg();
const bool saved = ofs.good();
ofs.close();
return saved;
}
// Using the saveJpeg function
const char* filename = "PGTA5123456789.jpg";
const bool saved = saveJpeg(&ragePhoto, filename);
\endcode
Using the JPEG in GTK+ (gtkmm)
\code{.cpp}
// Writing pixbuf loader
GdkPixbufLoader* pixbuf_loader = gdk_pixbuf_loader_new();
gdk_pixbuf_loader_write(pixbuf_loader, reinterpret_cast<const guchar*>(ragePhoto.jpegData()), ragePhoto.jpegSize(), nullptr);
GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader);
gdk_pixbuf_loader_close(pixbuf_loader, nullptr);
// Set image
Gtk::Image image;
image.set(Glib::wrap(pixbuf));
\endcode
Using the JPEG in Qt
\code{.cpp}
// Returns the JPEG as QImage
const QImage image = QImage::fromData(QByteArray::fromRawData(ragePhoto.jpegData(), ragePhoto.jpegSize()), "JPEG");
// Loading the JPEG in QImage
QImage image;
const bool loaded = image.loadFromData(QByteArray::fromRawData(ragePhoto.jpegData(), ragePhoto.jpegSize()), "JPEG");
\endcode
Using the JSON in Boost.JSON
\code{.cpp}
boost::json::error_code ec;
const boost::json::value jv = boost::json::parse(ragePhoto.json(), ec);
if (ec)
return;
\endcode
Using the JSON in Qt
\code{.cpp}
const QJsonDocument jd = QJsonDocument::fromJson(ragePhoto.json());
if (jd.isNull())
return;
\endcode
<h4 id="cxx_error">Detect Photo errors</h4>
\code{.cpp}
const int32_t error = ragePhoto.error();
switch (error) {
case RagePhoto::Error::NoFormatIdentifier:
std::cout << "No format identifier" << std::endl;
break;
case RagePhoto::Error::IncompatibleFormat:
std::cout << "Incompatible format" << std::endl;
break;
// Detect for more errors here...
case RagePhoto::Error::NoError:
std::cout << "No error detected" << std::endl;
break;
default:
std::cout << "Unknown error detected" << std::endl;
}
\endcode
Available error codes: RagePhoto::Error
<h3 id="cmake">Including libragephoto in a CMake project</h3>
<h4 id="cmake_pkgconfig">Using PkgConfig</h4>
\code{.cmake}
find_package(PkgConfig REQUIRED)
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
target_compile_options(your_project PRIVATE ${RAGEPHOTO_CFLAGS})
target_link_libraries(your_project PRIVATE ${RAGEPHOTO_LIBRARIES})
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
target_link_directories(your_project PRIVATE ${RAGEPHOTO_LIBRARY_DIRS})
endif()
target_include_directories(your_project PRIVATE ${RAGEPHOTO_INCLUDE_DIRS})
\endcode
<h4 id="cmake_add_subdirectory">Using add_subdirectory</h4>
\code{.cmake}
add_subdirectory(src/libragephoto)
target_link_libraries(your_project PRIVATE ragephoto)
\endcode
*/

View File

@ -1,6 +1,6 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* Copyright (C) 2021-2022 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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:
@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto.h>
#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 RagePhoto::Error error = ragePhoto.error();
if (error <= RagePhoto::Error::PhotoReadError) {
const int32_t error = ragePhoto.error();
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();
@ -48,11 +48,11 @@ 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(), nullptr);
GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader);
gdk_pixbuf_loader_close(pixbuf_loader, NULL);
gdk_pixbuf_loader_close(pixbuf_loader, nullptr);
image->set(Glib::wrap(pixbuf));
win->set_title("RagePhoto GTK Photo Viewer - " + ragePhoto.title());
win->set_title("RagePhoto GTK Photo Viewer - " + std::string(ragePhoto.title()));
return true;
}
else {

View File

@ -1,6 +1,6 @@
#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* Copyright (C) 2021-2022 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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:
@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <RagePhoto.h>
#include <RagePhotoB>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
@ -35,19 +35,19 @@ 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 RagePhoto::Error error = ragePhoto.error();
if (error <= RagePhoto::Error::PhotoReadError) {
const int32_t error = ragePhoto.error();
if (error <= RagePhotoB::PhotoReadError) {
QMessageBox::warning(mainWindow, "Open Photo", "Failed to read photo: " + filename);
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("RagePhoto Qt Photo Viewer - " + QString::fromStdString(ragePhoto.title()));
mainWindow->setWindowTitle(QStringLiteral("RagePhoto Qt Photo Viewer - ") + QString::fromUtf8(ragePhoto.title()));
return true;
}
else {

1
src/RagePhoto Normal file
View File

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

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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:
@ -16,7 +16,8 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhotoC.h"
#include "RagePhoto.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
@ -32,12 +33,15 @@ int main(int argc, char *argv[])
const int loaded = ragephoto_loadfile(ragephoto_in, argv[1]);
if (loaded != 1) {
if (ragephoto_error(ragephoto_in) == 0) {
const int32_t error = ragephoto_error(ragephoto_in);
if (error == RAGEPHOTO_ERROR_UNINITIALISED) {
printf("Failed to open file: %s\n", argv[1]);
ragephoto_close(ragephoto_in);
return 1;
}
else if (ragephoto_getphotosize(ragephoto_in) <= 0) {
else if (error <= RAGEPHOTO_ERROR_PHOTOREADERROR) {
printf("Failed to load photo\n");
ragephoto_close(ragephoto_in);
return 1;
}
}
@ -51,20 +55,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);

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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:
@ -16,7 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhoto.h"
#include <RagePhotoB>
#include <fstream>
int main(int argc, char *argv[])
@ -27,17 +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) {
if (ragePhoto.error() == RagePhoto::Error::Uninitialised) {
const int32_t error = ragePhoto.error();
if (error == RagePhotoB::Uninitialised) {
std::cout << "Failed to open file: " << argv[1] << std::endl;
return 1;
}
else if (ragePhoto.error() <= RagePhoto::Error::PhotoReadError) {
else if (error <= RagePhotoB::PhotoReadError) {
std::cout << "Failed to load photo" << std::endl;
return 1;
}
@ -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();
@ -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 == RagePhotoB::GTA5)
std::cout << "GTA V Photo successfully exported" << std::endl;
else
else if (photoFormat == RagePhotoB::RDR2)
std::cout << "RDR 2 Photo successfully exported" << std::endl;
else
std::cout << "Photo successfully exported" << std::endl;
return 0;
}

1230
src/RagePhoto.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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:
@ -19,160 +19,297 @@
#ifndef RAGEPHOTO_H
#define RAGEPHOTO_H
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
#include "libragephoto_global.h"
#include "RagePhotoData.h"
#include <unordered_map>
#include <functional>
#include <iostream>
#include <cstdlib>
#include <cstdint>
#include <cstdio>
extern "C" {
#endif // __cplusplus
typedef std::function<bool(const char*, size_t, RagePhotoData*)> RagePhotoLoadFunc;
/**
* \brief GTA V and RDR 2 Photo Parser.
/** C API for RagePhoto.
* \file RagePhoto.h
*/
class LIBRAGEPHOTO_CXX_EXPORT RagePhoto
{
public:
/** Default sizes */
enum DefaultSize : uint32_t {
DEFAULT_GTA5_PHOTOBUFFER = 524288UL, /**< GTA V default Photo Buffer Size */
DEFAULT_RDR2_PHOTOBUFFER = 1048576UL, /**< RDR 2 default Photo Buffer Size */
DEFAULT_DESCBUFFER = 256UL, /**< Default Description Buffer Size */
DEFAULT_JSONBUFFER = 3072UL, /**< Default JSON Buffer Size */
DEFAULT_TITLBUFFER = 256UL, /**< Default Title Buffer Size */
GTA5_HEADERSIZE = 264UL, /**< GTA V Header Size */
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
};
/** Parsing and set errors */
enum class Error : uint8_t {
DescBufferTight = 38, /**< Description Buffer is too tight */
DescMallocError = 30, /**< Description Buffer can't be allocated */
DescReadError = 31, /**< Description can't be read successfully */
HeaderBufferTight = 34, /**< Header Buffer is too tight */
IncompatibleFormat = 2, /**< Format is incompatible */
IncompleteChecksum = 6, /**< Header checksum is incomplete */
IncompleteDescBuffer = 29, /**< Description Buffer Size is incomplete */
IncompleteDescMarker = 27, /**< Description Marker is incomplete */
IncompleteDescOffset = 10, /**< Description Offset is incomplete */
IncompleteEOF = 7, /**< End Of File Offset is incomplete */
IncompleteHeader = 3, /**< Header is incomplete */
IncompleteJendMarker = 32, /**< JEND Marker is incomplete */
IncompleteJpegMarker = 11, /**< JPEG Marker is incomplete */
IncompleteJsonBuffer = 19, /**< JSON Buffer Size is incomplete */
IncompleteJsonMarker = 17, /**< JSON Marker incomplete */
IncompleteJsonOffset = 8, /**< JSON Offset incomplete */
IncompletePhotoBuffer = 13, /**< Photo Buffer Size is incomplete */
IncompletePhotoSize = 14, /**< Photo Size is incomplete */
IncompleteTitleBuffer = 24, /**< Title Buffer Size is incomplete */
IncompleteTitleMarker = 22, /**< Title Marker is incomplete */
IncompleteTitleOffset = 9, /**< Title Offset is incomplete */
IncorrectDescMarker = 28, /**< Description Marker is incorrect */
IncorrectJendMarker = 33, /**< JEND Marker is incorrect */
IncorrectJpegMarker = 12, /**< JPEG Marker is incorrect */
IncorrectJsonMarker = 18, /**< JSON Marker is incorrect */
IncorrectTitleMarker = 23, /**< Title Marker is incorrect */
JsonBufferTight = 36, /**< JSON Buffer is too tight */
JsonMallocError = 20, /**< JSON Buffer can't be allocated */
JsonReadError = 21, /**< JSON can't be read successfully */
NoError = 255, /**< Finished without errors */
NoFormatIdentifier = 1, /**< No format detected, empty file */
PhotoBufferTight = 35, /**< Photo Buffer is too tight */
PhotoMallocError = 15, /**< Photo Buffer can't be allocated */
PhotoReadError = 16, /**< Photo can't be read */
TitleBufferTight = 37, /**< Title Buffer is too tight */
TitleMallocError = 25, /**< Title Buffer can't be allocated */
TitleReadError = 26, /**< Title can't be read */
UnicodeHeaderError = 5, /**< Header can't be decoded */
UnicodeInitError = 4, /**< Failed to initialise Unicode decoder */
Uninitialised = 0, /**< Uninitialised, file access failed */
};
/** Photo Formats */
enum PhotoFormat : uint32_t {
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
};
RagePhoto();
~RagePhoto();
void clear(); /**< Resets the RagePhoto instance to default values. */
/** Loads a Photo from a const char*.
* \param data Photo data
* \param size Photo data size
*/
bool load(const char *data, size_t size);
/** Loads a Photo from a std::string.
* \param data Photo data
*/
bool load(const std::string &data);
/** Loads a Photo from a file.
* \param filename File to load
*/
bool loadFile(const std::string &filename);
Error error() const; /**< Returns the last error occurred. */
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string photo() const; /**< Returns the Photo JPEG data. */
const char *photoData() const; /**< Returns the Photo JPEG data. */
uint32_t photoSize() const; /**< Returns the Photo JPEG data size. */
const std::string& description() const; /**< Returns the Photo description. */
const std::string& json() const; /**< Returns the Photo JSON data. */
const std::string& header() const; /**< Returns the Photo header. */
const std::string& title() const; /**< Returns the Photo title. */
static const char* version(); /**< Returns the library version. */
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
bool save(char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param data Photo data
*/
bool save(char *data);
/** Saves a Photo to a std::string.
* \param photoFormat Photo Format (GTA V or RDR 2)
* \param ok \p true when saved successfully
*/
const std::string save(uint32_t photoFormat, bool *ok = nullptr);
/** Saves a Photo to a std::string.
* \param ok \p true when saved successfully
*/
const std::string save(bool *ok = nullptr);
bool saveFile(const std::string &filename, uint32_t photoFormat); /**< Saves a Photo to a file. */
bool saveFile(const std::string &filename); /**< Saves a Photo to a file. */
static size_t saveSize(RagePhotoData *ragePhotoData, uint32_t photoFormat); /**< Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *ragePhotoData); /**< Returns the Photo save file size. */
size_t saveSize(uint32_t photoFormat); /**< Returns the Photo save file size. */
size_t saveSize(); /**< Returns the Photo save file size. */
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
static void setBufferDefault(RagePhotoData *ragePhotoData); /**< Sets all cross-format Buffer to default size. */
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
static void setBufferOffsets(RagePhotoData *ragePhotoData); /**< Moves all Buffer offsets to correct position. */
void setDescription(const std::string &description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */
void setFormatLoadFunction(uint32_t photoFormat, RagePhotoLoadFunc func); /**< Sets a custom Photo Format load function. */
void setJson(const std::string &json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
void setHeader(const std::string &header, uint32_t headerSum); /**< Sets the Photo header. (EXPERT ONLY) */
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*/
bool setPhoto(const char *data, uint32_t size, uint32_t bufferSize = 0);
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param bufferSize JPEG buffer size
*/
bool setPhoto(const std::string &data, uint32_t bufferSize = 0);
void setTitle(const std::string &title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
private:
std::unordered_map<uint8_t, RagePhotoLoadFunc> m_loadFuncs;
RagePhotoData m_data;
};
#else
#include "RagePhotoC.h"
/** RagePhoto C instance/C++ class typedef. */
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_C_PUBLIC ragephoto_t ragephoto_open();
/** Add a custom defined RagePhotoFormatParser.
* \param instance \p ragephoto_t instance
* \param rp_parser RagePhotoFormatParser parser to add
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_addparser(ragephoto_t instance, RagePhotoFormatParser *rp_parser);
/** Resets the RagePhotoData object to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_clear(ragephoto_t instance);
/** Resets the RagePhotoData object to default values.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_clear(RagePhotoData *rp_data);
/** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a const char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t size);
/** Loads a Photo from a file.
* \param instance \p ragephoto_t instance
* \param filename File to load
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_loadfile(ragephoto_t instance, const char *filename);
/** Returns the last error occurred.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC int32_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_format_rdr2();
/** Returns the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC RagePhotoData* ragephoto_getphotodata(ragephoto_t instance);
/** Returns the Photo description.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotodesc(ragephoto_t instance);
/** Returns the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosign(ragephoto_t instance);
/** Returns the Photo JPEG sign.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephoto_getphotosignf(ragephoto_t instance, uint32_t photoFormat);
/** Returns the Photo JPEG sign.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data);
/** Returns the Photo JPEG sign.
* \param rp_data RagePhotoData object
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat);
/** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephotodata_getsavesize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
/** Returns the Photo save file size.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC size_t ragephotodata_getsavesizef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_save(ragephoto_t instance, char *data);
/** Saves a Photo to a char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_save(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param rp_data RagePhotoData object
* \param rp_parser RagePhotoFormatParser parser array
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephotodata_savef(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, char *data, uint32_t photoFormat);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefile(ragephoto_t instance, const char *filename);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferdefault(ragephoto_t instance);
/** Sets all cross-format Buffer to default size.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferdefault(RagePhotoData *rp_data);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param rp_data RagePhotoData object
*/
LIBRAGEPHOTO_C_PUBLIC void ragephotodata_setbufferoffsets(RagePhotoData *rp_data);
/** Sets the internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being set
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodata(ragephoto_t instance, RagePhotoData *rp_data);
/** Copies RagePhotoData object to internal RagePhotoData object.
* \param instance \p ragephoto_t instance
* \param rp_data RagePhotoData object being copied
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotodatac(ragephoto_t instance, RagePhotoData *rp_data);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
* \param description Description
* \param bufferSize Description buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
/** Sets the Photo JPEG data.
* \param instance \p ragephoto_t instance
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/
LIBRAGEPHOTO_C_PUBLIC bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance
* \param json JSON data
* \param bufferSize JSON data buffer size
*
* Default bufferSize: 3072UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo header. (RDR 2) */
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphotoheader2(ragephoto_t instance, const char *header, uint32_t headerSum, uint32_t headerSum2);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
* \param title Title
* \param bufferSize Title buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_PUBLIC void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_C_PUBLIC const char* ragephoto_version();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTO_H

191
src/RagePhoto.hpp Normal file
View File

@ -0,0 +1,191 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* 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:
*
* 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 RAGEPHOTO_HPP
#define RAGEPHOTO_HPP
#ifdef __cplusplus
#include "RagePhotoLibrary.h"
#include "RagePhotoTypedefs.h"
#include <iostream>
#include <cstdlib>
#include <cstdint>
#include <cstdio>
/**
* \brief GTA V and RDR 2 Photo Parser.
*/
class LIBRAGEPHOTO_CXX_PUBLIC RagePhoto
{
public:
/** Default sizes */
enum DefaultSize : uint32_t {
DEFAULT_GTA5_PHOTOBUFFER = 524288UL, /**< GTA V default Photo Buffer Size */
DEFAULT_RDR2_PHOTOBUFFER = 1048576UL, /**< RDR 2 default Photo Buffer Size */
DEFAULT_DESCBUFFER = 256UL, /**< Default Description Buffer Size */
DEFAULT_JSONBUFFER = 3072UL, /**< Default JSON Buffer Size */
DEFAULT_TITLBUFFER = 256UL, /**< Default Title Buffer Size */
GTA5_HEADERSIZE = 264UL, /**< GTA V Header Size */
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
};
/** Parsing and set errors */
enum Error : int32_t {
DescBufferTight = 39L, /**< Description Buffer is too tight */
DescMallocError = 31L, /**< Description Buffer can't be allocated */
DescReadError = 32L, /**< Description can't be read successfully */
HeaderBufferTight = 35L, /**< Header Buffer is too tight */
HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
IncompatibleFormat = 2L, /**< Format is incompatible */
IncompleteChecksum = 7L, /**< Header checksum is incomplete */
IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
IncompleteHeader = 3L, /**< Header is incomplete */
IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
JsonBufferTight = 37L, /**< JSON Buffer is too tight */
JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
JsonReadError = 22L, /**< JSON can't be read successfully */
NoError = 255L, /**< Finished without errors */
NoFormatIdentifier = 1L, /**< No format detected, empty file */
PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
PhotoReadError = 17L, /**< Photo can't be read */
TitleBufferTight = 38L, /**< Title Buffer is too tight */
TitleMallocError = 26L, /**< Title Buffer can't be allocated */
TitleReadError = 27L, /**< Title can't be read */
UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
Uninitialised = 0L, /**< Uninitialised, file access failed */
};
/** Photo Formats */
enum PhotoFormat : uint32_t {
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
};
/** Sign Initials */
enum SignInitials : uint32_t {
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
};
RagePhoto();
~RagePhoto();
void addParser(RagePhotoFormatParser *rp_parser); /**< Add a custom defined RagePhotoFormatParser. */
static void clear(RagePhotoData *rp_data); /**< Resets the RagePhotoData object to default values. */
void clear(); /**< Resets the RagePhotoData object to default values. */
RagePhotoData* data(); /**< Returns the internal RagePhotoData object. */
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Loads a Photo from a const char*. */
/** Loads a Photo from a const char*.
* \param data Photo data
* \param size Photo data size
*/
bool load(const char *data, size_t size);
/** Loads a Photo from a std::string.
* \param data Photo data
*/
bool load(const std::string &data);
/** Loads a Photo from a file.
* \param filename File to load
*/
bool loadFile(const std::string &filename);
int32_t error() const; /**< Returns the last error occurred. */
uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string jpeg() const; /**< Returns the Photo JPEG data. */
#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
const std::string_view jpeg_view() const; /**< Returns the Photo JPEG data. */
#endif
const char* jpegData() const; /**< Returns the Photo JPEG data. */
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
static uint64_t jpegSign(RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */
uint64_t jpegSign(uint32_t photoFormat) const; /**< Returns the Photo JPEG sign. */
uint64_t jpegSign() const; /**< Returns the Photo JPEG sign. */
uint32_t jpegSize() const; /**< Returns the Photo JPEG data size. */
const char* description() const; /**< Returns the Photo description. */
const char* json() const; /**< Returns the Photo JSON data. */
const char* header() const; /**< Returns the Photo header. */
const char* title() const; /**< Returns the Photo title. */
static const char* version(); /**< Returns the library version. */
static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Saves a Photo to a char*. */
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
bool save(char *data, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param data Photo data
*/
bool save(char *data);
/** Saves a Photo to a std::string.
* \param photoFormat Photo Format (GTA V or RDR 2)
* \param ok \p true when saved successfully
*/
const std::string save(uint32_t photoFormat, bool *ok = nullptr);
/** Saves a Photo to a std::string.
* \param ok \p true when saved successfully
*/
const std::string save(bool *ok = nullptr);
bool saveFile(const std::string &filename, uint32_t photoFormat); /**< Saves a Photo to a file. */
bool saveFile(const std::string &filename); /**< Saves a Photo to a file. */
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser); /**< Returns the Photo save file size. */
size_t saveSize(uint32_t photoFormat); /**< Returns the Photo save file size. */
size_t saveSize(); /**< Returns the Photo save file size. */
static void setBufferDefault(RagePhotoData *rp_data); /**< Sets all cross-format Buffer to default size. */
void setBufferDefault(); /**< Sets all cross-format Buffer to default size. */
static void setBufferOffsets(RagePhotoData *rp_data); /**< Moves all Buffer offsets to correct position. */
void setBufferOffsets(); /**< Moves all Buffer offsets to correct position. */
bool setData(RagePhotoData *rp_data, bool takeCopy = true); /**< Sets the internal RagePhotoData object. */
void setDescription(const char *description, uint32_t bufferSize = 0); /**< Sets the Photo description. */
void setFormat(uint32_t photoFormat); /**< Sets the Photo Format (GTA V or RDR 2). */
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0);
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const std::string &data, uint32_t bufferSize = 0);
void setJson(const char *json, uint32_t bufferSize = 0); /**< Sets the Photo JSON data. */
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0); /**< Sets the Photo header. */
void setTitle(const char *title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
private:
RagePhotoData *m_data;
RagePhotoFormatParser *m_parser;
};
#endif // __cplusplus
#endif // RAGEPHOTO_HPP

1
src/RagePhotoA Normal file
View File

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

View File

@ -1,152 +0,0 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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 RAGEPHOTOA_H
#define RAGEPHOTOA_H
#ifdef __cplusplus
#include "RagePhotoC.h"
#include <cstdlib>
#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 worse performance, which should be pretty minimal, and not always include the newest features.
*/
class RagePhotoA
{
public:
RagePhotoA() {
instance = ragephoto_open();
}
~RagePhotoA() {
ragephoto_close(instance);
}
void clear() {
ragephoto_clear(instance);
}
bool load(const char *data, size_t size) {
return ragephoto_load(instance, data, size);
}
bool load(const std::string &data) {
return ragephoto_load(instance, data.data(), data.size());
}
bool loadFile(const char *filename) {
return ragephoto_loadfile(instance, filename);
}
uint32_t error() const {
return ragephoto_error(instance);
}
uint32_t format() const {
return ragephoto_getphotoformat(instance);
}
const std::string photo() const {
return std::string(ragephoto_getphotojpeg(instance), ragephoto_getphotosize(instance));
}
const char *photoData() const {
return ragephoto_getphotojpeg(instance);
}
uint32_t photoSize() const {
return ragephoto_getphotosize(instance);
}
const char* description() const {
return ragephoto_getphotodesc(instance);
}
const char* json() const {
return ragephoto_getphotojson(instance);
}
const char* header() const {
return ragephoto_getphotoheader(instance);
}
const char* title() const {
return ragephoto_getphototitle(instance);
}
static const char* version() {
return ragephoto_version();
}
bool save(char *data, uint32_t photoFormat) {
return ragephoto_savef(instance, data, photoFormat);
}
bool save(char *data) {
return ragephoto_save(instance, data);
}
const std::string save(uint32_t photoFormat, bool *ok = nullptr) {
std::string data;
const size_t size = ragephoto_getsavesizef(instance, photoFormat);
if (size == 0) {
if (ok)
*ok = false;
return data;
}
data.resize(size);
const bool saved = ragephoto_savef(instance, &data[0], photoFormat);
if (ok)
*ok = saved;
return data;
}
const std::string save(bool *ok = nullptr) {
return save(ragephoto_getphotoformat(instance), ok);
}
bool saveFile(const char *filename, uint32_t photoFormat) {
return ragephoto_savefilef(instance, filename, photoFormat);
}
bool saveFile(const char *filename) {
return ragephoto_savefile(instance, filename);
}
size_t saveSize(uint32_t photoFormat) {
return ragephoto_getsavesizef(instance, photoFormat);
}
size_t saveSize() {
return ragephoto_getsavesize(instance);
}
void setBufferDefault() {
ragephoto_setbufferdefault(instance);
}
void setBufferOffsets() {
ragephoto_setbufferoffsets(instance);
}
void setDescription(const char *description, uint32_t bufferSize = 0) {
ragephoto_setphotodesc(instance, description, bufferSize);
}
void setFormat(uint32_t photoFormat) {
ragephoto_setphotoformat(instance, photoFormat);
}
void setJson(const char *json, uint32_t bufferSize = 0) {
ragephoto_setphotojson(instance, json, bufferSize);
}
void setHeader(const char *header, uint32_t headerSum) {
ragephoto_setphotoheader(instance, header, headerSum);
}
bool setPhoto(const char *data, uint32_t size, uint32_t bufferSize = 0) {
return ragephoto_setphotojpeg(instance, data, size, bufferSize);
}
bool setPhoto(const std::string &data, uint32_t bufferSize = 0) {
return ragephoto_setphotojpeg(instance, data.data(), static_cast<uint32_t>(data.size()), bufferSize);
}
void setTitle(const char *title, uint32_t bufferSize = 0) {
ragephoto_setphototitle(instance, title, bufferSize);
}
private:
ragephoto_t instance;
};
#endif // __cplusplus
#endif // RAGEPHOTOA_H

345
src/RagePhotoA.hpp Normal file
View File

@ -0,0 +1,345 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* 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:
*
* 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 RAGEPHOTOA_HPP
#define RAGEPHOTOA_HPP
#ifdef __cplusplus
#include "RagePhoto.h"
#include <cstdlib>
#include <iostream>
/**
* \brief GTA V and RDR 2 Photo Parser (C API wrapper).
*/
class RagePhotoA
{
public:
/** Default sizes */
enum DefaultSize : uint32_t {
DEFAULT_GTA5_PHOTOBUFFER = 524288UL, /**< GTA V default Photo Buffer Size */
DEFAULT_RDR2_PHOTOBUFFER = 1048576UL, /**< RDR 2 default Photo Buffer Size */
DEFAULT_DESCBUFFER = 256UL, /**< Default Description Buffer Size */
DEFAULT_JSONBUFFER = 3072UL, /**< Default JSON Buffer Size */
DEFAULT_TITLBUFFER = 256UL, /**< Default Title Buffer Size */
GTA5_HEADERSIZE = 264UL, /**< GTA V Header Size */
RDR2_HEADERSIZE = 272UL, /**< RDR 2 Header Size */
};
/** Parsing and set errors */
enum Error : int32_t {
DescBufferTight = 39L, /**< Description Buffer is too tight */
DescMallocError = 31L, /**< Description Buffer can't be allocated */
DescReadError = 32L, /**< Description can't be read successfully */
HeaderBufferTight = 35L, /**< Header Buffer is too tight */
HeaderMallocError = 4L, /**< Header Buffer can't be allocated */
IncompatibleFormat = 2L, /**< Format is incompatible */
IncompleteChecksum = 7L, /**< Header checksum is incomplete */
IncompleteDescBuffer = 30L, /**< Description Buffer Size is incomplete */
IncompleteDescMarker = 28L, /**< Description Marker is incomplete */
IncompleteDescOffset = 11L, /**< Description Offset is incomplete */
IncompleteEOF = 8L, /**< End Of File Offset is incomplete */
IncompleteHeader = 3L, /**< Header is incomplete */
IncompleteJendMarker = 33L, /**< JEND Marker is incomplete */
IncompleteJpegMarker = 12L, /**< JPEG Marker is incomplete */
IncompleteJsonBuffer = 20L, /**< JSON Buffer Size is incomplete */
IncompleteJsonMarker = 18L, /**< JSON Marker incomplete */
IncompleteJsonOffset = 9L, /**< JSON Offset incomplete */
IncompletePhotoBuffer = 14L, /**< Photo Buffer Size is incomplete */
IncompletePhotoSize = 15L, /**< Photo Size is incomplete */
IncompleteTitleBuffer = 25L, /**< Title Buffer Size is incomplete */
IncompleteTitleMarker = 23L, /**< Title Marker is incomplete */
IncompleteTitleOffset = 10L, /**< Title Offset is incomplete */
IncorrectDescMarker = 29L, /**< Description Marker is incorrect */
IncorrectJendMarker = 34L, /**< JEND Marker is incorrect */
IncorrectJpegMarker = 13L, /**< JPEG Marker is incorrect */
IncorrectJsonMarker = 19L, /**< JSON Marker is incorrect */
IncorrectTitleMarker = 24L, /**< Title Marker is incorrect */
JsonBufferTight = 37L, /**< JSON Buffer is too tight */
JsonMallocError = 21L, /**< JSON Buffer can't be allocated */
JsonReadError = 22L, /**< JSON can't be read successfully */
NoError = 255L, /**< Finished without errors */
NoFormatIdentifier = 1L, /**< No format detected, empty file */
PhotoBufferTight = 36L, /**< Photo Buffer is too tight */
PhotoMallocError = 16L, /**< Photo Buffer can't be allocated */
PhotoReadError = 17L, /**< Photo can't be read */
TitleBufferTight = 38L, /**< Title Buffer is too tight */
TitleMallocError = 26L, /**< Title Buffer can't be allocated */
TitleReadError = 27L, /**< Title can't be read */
UnicodeInitError = 5L, /**< Failed to initialise Unicode decoder */
UnicodeHeaderError = 6L, /**< Header can't be encoded/decoded successfully */
Uninitialised = 0L, /**< Uninitialised, file access failed */
};
/** Photo Formats */
enum PhotoFormat : uint32_t {
GTA5 = 0x01000000UL, /**< GTA V Photo Format */
RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */
};
/** Sign Initials */
enum SignInitials : uint32_t {
SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */
SIRDR2 = 0x00FEEB1EUL, /**< RDR 2 Sign Initial */
};
RagePhotoA() {
instance = ragephoto_open();
}
~RagePhotoA() {
ragephoto_close(instance);
}
/** Add a custom defined RagePhotoFormatParser. */
void addParser(RagePhotoFormatParser *rp_parser) {
ragephoto_addparser(instance, rp_parser);
}
/** Resets the RagePhotoData object to default values. */
static void clear(RagePhotoData *rp_data) {
ragephotodata_clear(rp_data);
}
/** Resets the RagePhotoData object to default values. */
void clear() {
ragephoto_clear(instance);
}
/** Returns the internal RagePhotoData object. */
RagePhotoData* data() {
return ragephoto_getphotodata(instance);
}
/** Loads a Photo from a const char*. */
static bool load(const char *data, size_t size, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
return ragephotodata_load(rp_data, rp_parser, data, size);
}
/** Loads a Photo from a const char*.
* \param data Photo data
* \param size Photo data size
*/
bool load(const char *data, size_t size) {
return ragephoto_load(instance, data, size);
}
/** Loads a Photo from a std::string.
* \param data Photo data
*/
bool load(const std::string &data) {
return ragephoto_load(instance, data.data(), data.size());
}
/** Loads a Photo from a file.
* \param filename File to load
*/
bool loadFile(const char *filename) {
return ragephoto_loadfile(instance, filename);
}
/** Returns the last error occurred. */
int32_t error() const {
return ragephoto_error(instance);
}
/** Returns the Photo Format (GTA V or RDR 2). */
uint32_t format() const {
return ragephoto_getphotoformat(instance);
}
/** Returns the Photo JPEG data. */
const std::string jpeg() const {
const char *jpegData = ragephoto_getphotojpeg(instance);
if (jpegData)
return std::string(jpegData, ragephoto_getphotosize(instance));
else
return std::string();
}
#if (__cplusplus >= 201703L)
/** Returns the Photo JPEG data. */
const std::string_view jpeg_view() const {
const char *jpegData = ragephoto_getphotojpeg(instance);
if (jpegData)
return std::string_view(jpegData, ragephoto_getphotosize(instance));
else
return std::string_view();
}
#endif
/** Returns the Photo JPEG data. */
const char* jpegData() const {
return ragephoto_getphotojpeg(instance);
}
/** Returns the Photo JPEG sign. */
static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data) {
return ragephotodata_getphotosignf(rp_data, photoFormat);
}
/** Returns the Photo JPEG sign. */
static uint64_t jpegSign(RagePhotoData *rp_data) {
return ragephotodata_getphotosign(rp_data);
}
/** Returns the Photo JPEG sign. */
uint64_t jpegSign(uint32_t photoFormat) const {
return ragephoto_getphotosignf(instance, photoFormat);
}
/** Returns the Photo JPEG sign. */
uint64_t jpegSign() const {
return ragephoto_getphotosign(instance);
}
/** Returns the Photo JPEG data size. */
uint32_t jpegSize() const {
return ragephoto_getphotosize(instance);
}
/** Returns the Photo description. */
const char* description() const {
return ragephoto_getphotodesc(instance);
}
/** Returns the Photo JSON data. */
const char* json() const {
return ragephoto_getphotojson(instance);
}
/** Returns the Photo header. */
const char* header() const {
return ragephoto_getphotoheader(instance);
}
/** Returns the Photo title. */
const char* title() const {
return ragephoto_getphototitle(instance);
}
/** Returns the library version. */
static const char* version() {
return ragephoto_version();
}
/** Saves a Photo to a char*. */
static bool save(char *data, uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
return ragephotodata_savef(rp_data, rp_parser, data, photoFormat);
}
/** Saves a Photo to a char*. */
static bool save(char *data, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
return ragephotodata_save(rp_data, rp_parser, data);
}
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
bool save(char *data, uint32_t photoFormat) {
return ragephoto_savef(instance, data, photoFormat);
}
/** Saves a Photo to a char*.
* \param data Photo data
*/
bool save(char *data) {
return ragephoto_save(instance, data);
}
/** Saves a Photo to a std::string.
* \param photoFormat Photo Format (GTA V or RDR 2)
* \param ok \p true when saved successfully
*/
const std::string save(uint32_t photoFormat, bool *ok = nullptr) {
std::string sdata;
const size_t size = ragephoto_getsavesizef(instance, photoFormat);
if (size == 0) {
if (ok)
*ok = false;
return sdata;
}
sdata.resize(size);
const bool saved = ragephoto_savef(instance, &sdata[0], photoFormat);
if (ok)
*ok = saved;
return sdata;
}
/** Saves a Photo to a std::string.
* \param ok \p true when saved successfully
*/
const std::string save(bool *ok = nullptr) {
return save(ragephoto_getphotoformat(instance), ok);
}
/** Saves a Photo to a file. */
bool saveFile(const char *filename, uint32_t photoFormat) {
return ragephoto_savefilef(instance, filename, photoFormat);
}
/** Saves a Photo to a file. */
bool saveFile(const char *filename) {
return ragephoto_savefile(instance, filename);
}
/** Returns the Photo save file size. */
static size_t saveSize(uint32_t photoFormat, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
return ragephotodata_getsavesizef(rp_data, rp_parser, photoFormat);
}
/** Returns the Photo save file size. */
static size_t saveSize(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser) {
return ragephotodata_getsavesize(rp_data, rp_parser);
}
/** Returns the Photo save file size. */
size_t saveSize(uint32_t photoFormat) {
return ragephoto_getsavesizef(instance, photoFormat);
}
/** Returns the Photo save file size. */
size_t saveSize() {
return ragephoto_getsavesize(instance);
}
/** Sets all cross-format Buffer to default size. */
static void setBufferDefault(RagePhotoData *rp_data) {
ragephotodata_setbufferdefault(rp_data);
}
/** Sets all cross-format Buffer to default size. */
void setBufferDefault() {
ragephoto_setbufferdefault(instance);
}
/** Moves all Buffer offsets to correct position. */
static void setBufferOffsets(RagePhotoData *rp_data) {
ragephotodata_setbufferoffsets(rp_data);
}
/** Moves all Buffer offsets to correct position. */
void setBufferOffsets() {
ragephoto_setbufferoffsets(instance);
}
/** Sets the internal RagePhotoData object. */
bool setData(RagePhotoData *ragePhotoData, bool takeCopy = true) {
if (takeCopy)
return ragephoto_setphotodatac(instance, ragePhotoData);
else
return ragephoto_setphotodata(instance, ragePhotoData);
}
/** Sets the Photo description. */
void setDescription(const char *description, uint32_t bufferSize = 0) {
ragephoto_setphotodesc(instance, description, bufferSize);
}
/** Sets the Photo Format (GTA V or RDR 2). */
void setFormat(uint32_t photoFormat) {
ragephoto_setphotoformat(instance, photoFormat);
}
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const char *data, uint32_t size, uint32_t bufferSize = 0) {
return ragephoto_setphotojpeg(instance, data, size, bufferSize);
}
/** Sets the Photo JPEG data.
* \param data JPEG data
* \param bufferSize JPEG buffer size
*/
bool setJpeg(const std::string &data, uint32_t bufferSize = 0) {
return ragephoto_setphotojpeg(instance, data.data(), static_cast<uint32_t>(data.size()), bufferSize);
}
/** Sets the Photo JSON data. */
void setJson(const char *json, uint32_t bufferSize = 0) {
ragephoto_setphotojson(instance, json, bufferSize);
}
/** Sets the Photo header. */
void setHeader(const char *header, uint32_t headerSum, uint32_t headerSum2 = 0) {
ragephoto_setphotoheader2(instance, header, headerSum, headerSum2);
}
/** Sets the Photo title. */
void setTitle(const char *title, uint32_t bufferSize = 0) {
ragephoto_setphototitle(instance, title, bufferSize);
}
private:
ragephoto_t instance;
};
#endif // __cplusplus
#endif // RAGEPHOTOA_HPP

1
src/RagePhotoB Normal file
View File

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

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* 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:
@ -16,37 +16,28 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef RAGEPHOTODATA_H
#define RAGEPHOTODATA_H
#ifndef RAGEPHOTOB_HPP
#define RAGEPHOTOB_HPP
#ifdef __cplusplus
#include "libragephoto_global.h"
#include <iostream>
#include <cstdint>
struct LIBRAGEPHOTO_CXX_EXPORT RagePhotoData
{
bool photoLoaded;
char* photoData;
std::string description;
std::string json;
std::string header;
std::string title;
uint8_t error;
uint32_t descBuffer;
uint32_t descOffset;
uint32_t endOfFile;
uint32_t headerSum;
uint32_t jsonBuffer;
uint32_t jsonOffset;
uint32_t photoBuffer;
uint32_t photoFormat;
uint32_t photoSize;
uint32_t titlBuffer;
uint32_t titlOffset;
uint32_t unnamedSum1;
uint32_t unnamedSum2;
};
#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 // RAGEPHOTODATA_H
#endif // RAGEPHOTOB_HPP

View File

@ -1,215 +0,0 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 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 RAGEPHOTOC_H
#define RAGEPHOTOC_H
#include "libragephoto_global.h"
#include <stdint.h>
#include <stdio.h>
#ifdef LIBRAGEPHOTO_C_NOAPI
#error "libragephoto was built without C API"
#endif // LIBRAGEPHOTO_C_NOAPI
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/** \file RagePhotoC.h */
/** RagePhoto C++ class typedef for C API. */
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_C_EXPORT ragephoto_t ragephoto_open();
/** Resets the \p ragephoto_t instance to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_clear(ragephoto_t instance);
/** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_C_EXPORT int ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a file.
* \param instance \p ragephoto_t instance
* \param filename File to load
*/
LIBRAGEPHOTO_C_EXPORT int ragephoto_loadfile(ragephoto_t instance, const char *filename);
/** Returns the last error occurred.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT uint8_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_format_rdr2();
/** Returns the Photo description.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotodesc(ragephoto_t instance);
/** Returns the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_EXPORT size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
*/
LIBRAGEPHOTO_C_EXPORT int ragephoto_save(ragephoto_t instance, char *data);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_EXPORT int ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
*/
LIBRAGEPHOTO_C_EXPORT int ragephoto_savefile(ragephoto_t instance, const char *filename);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_EXPORT int ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_setbufferdefault(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
* \param description Description
* \param bufferSize Description buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
/** Sets the Photo JPEG data.
* \param instance \p ragephoto_t instance
* \param data JPEG data
* \param size JPEG data size
* \param bufferSize JPEG buffer size
*
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/
LIBRAGEPHOTO_C_EXPORT int ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance
* \param json JSON data
* \param bufferSize JSON data buffer size
*
* Default bufferSize: 3072UL
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. (EXPERT ONLY) */
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
* \param title Title
* \param bufferSize Title buffer size
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_C_EXPORT void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_version();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RAGEPHOTOC_H

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* 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:
@ -16,42 +16,17 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef LIBRAGEPHOTO_GLOBAL_H
#define LIBRAGEPHOTO_GLOBAL_H
#ifndef RAGEPHOTOCONFIG_H
#define RAGEPHOTOCONFIG_H
/* CMAKE CONFIG BEGIN */
#define @LIBRAGEPHOTO_API@
#define @LIBRAGEPHOTO_LIBTYPE@
#define RAGEPHOTO_CXX_STD @CMAKE_CXX_STANDARD@
#define RAGEPHOTO_VERSION "@ragephoto_VERSION@"
#define RAGEPHOTO_VERSION_MAJOR @ragephoto_VERSION_MAJOR@
#define RAGEPHOTO_VERSION_MINOR @ragephoto_VERSION_MINOR@
#define RAGEPHOTO_VERSION_PATCH @ragephoto_VERSION_PATCH@
/* CMAKE CONFIG END */
/* RAGEPHOTO LIBRARY EXPORT BEGIN */
#ifdef _WIN32
#ifndef LIBRAGEPHOTO_STATIC
#ifdef LIBRAGEPHOTO_LIBRARY
#define LIBRAGEPHOTO_C_EXPORT __declspec(dllexport)
#define LIBRAGEPHOTO_CXX_EXPORT __declspec(dllexport)
#else
#define LIBRAGEPHOTO_C_EXPORT __declspec(dllimport)
#define LIBRAGEPHOTO_CXX_EXPORT __declspec(dllimport)
#endif // LIBRAGEPHOTO_LIBRARY
#else
#define LIBRAGEPHOTO_C_EXPORT
#define LIBRAGEPHOTO_CXX_EXPORT
#endif // LIBRAGEPHOTO_STATIC
#else
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#define LIBRAGEPHOTO_C_EXPORT EMSCRIPTEN_KEEPALIVE
#define LIBRAGEPHOTO_CXX_EXPORT
#else
#define LIBRAGEPHOTO_C_EXPORT
#define LIBRAGEPHOTO_CXX_EXPORT
#endif // __EMSCRIPTEN__
#endif // _WIN32
/* RAGEPHOTO LIBRARY EXPORT END */
#endif // LIBRAGEPHOTO_GLOBAL_H
#endif // RAGEPHOTOCONFIG_H

69
src/RagePhotoLibrary.h Normal file
View File

@ -0,0 +1,69 @@
/*****************************************************************************
* 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 RAGEPHOTOLIBRARY_H
#define RAGEPHOTOLIBRARY_H
#include "RagePhotoConfig.h"
/* RAGEPHOTO LIBRARY BINDING BEGIN */
#ifdef _WIN32
#ifndef LIBRAGEPHOTO_STATIC
#ifdef LIBRAGEPHOTO_LIBRARY
#define LIBRAGEPHOTO_C_PUBLIC __declspec(dllexport)
#define LIBRAGEPHOTO_CXX_PUBLIC __declspec(dllexport)
#else
#define LIBRAGEPHOTO_C_PUBLIC __declspec(dllimport)
#define LIBRAGEPHOTO_CXX_PUBLIC __declspec(dllimport)
#endif // LIBRAGEPHOTO_LIBRARY
#else
#define LIBRAGEPHOTO_C_PUBLIC
#define LIBRAGEPHOTO_CXX_PUBLIC
#endif // LIBRAGEPHOTO_STATIC
#else
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#define LIBRAGEPHOTO_C_PUBLIC EMSCRIPTEN_KEEPALIVE
#define LIBRAGEPHOTO_CXX_PUBLIC
#else
#ifdef __GNUC__
#ifndef LIBRAGEPHOTO_STATIC
#define LIBRAGEPHOTO_C_PUBLIC __attribute__((visibility("default")))
#define LIBRAGEPHOTO_CXX_PUBLIC __attribute__((visibility("default")))
#else
#define LIBRAGEPHOTO_C_PUBLIC
#define LIBRAGEPHOTO_CXX_PUBLIC
#endif // LIBRAGEPHOTO_STATIC
#else
#define LIBRAGEPHOTO_C_PUBLIC
#define LIBRAGEPHOTO_CXX_PUBLIC
#endif // __GNUC__
#endif // __EMSCRIPTEN__
#endif // _WIN32
/* RAGEPHOTO LIBRARY BINDING END */
/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY BEGIN */
#ifdef LIBRAGEPHOTO_WASM
#ifdef LIBRAGEPHOTO_CXX_ONLY
#undef LIBRAGEPHOTO_CXX_ONLY
#define LIBRAGEPHOTO_CXX_C
#endif // LIBRAGEPHOTO_CXX_ONLY
#endif // LIBRAGEPHOTO_WASM
/* ENABLE C API FOR LIBRAGEPHOTO WASM LIBRARY END */
#endif // RAGEPHOTOLIBRARY_H

143
src/RagePhotoTypedefs.h Normal file
View File

@ -0,0 +1,143 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* 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:
*
* 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 RAGEPHOTOTYPEDEFS_H
#define RAGEPHOTOTYPEDEFS_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/** RagePhoto data struct for storing internal data. */
typedef struct RagePhotoData {
char* jpeg; /**< Pointer for internal JPEG buffer */
char* description; /**< Pointer for internal Description buffer */
char* json; /**< Pointer for internal JSON buffer */
char* header; /**< Pointer for internal Header buffer */
char* title; /**< Pointer for internal Title buffer */
int32_t error; /**< RagePhoto error code */
uint32_t descBuffer; /**< Description buffer length */
uint32_t descOffset; /**< Description buffer offset */
uint32_t endOfFile; /**< End Of File offset */
uint32_t headerSum; /**< Checksum of the header 1 */
uint32_t headerSum2; /**< Checksum of the header 2 (RDR 2 only) */
uint32_t jpegBuffer; /**< JPEG buffer length */
uint32_t jpegSize; /**< Internal JPEG buffer length and size of JPEG */
uint32_t jsonBuffer; /**< JSON buffer length */
uint32_t jsonOffset; /**< JSON buffer offset */
uint32_t photoFormat; /**< Photo file format magic */
uint32_t titlBuffer; /**< Title buffer length */
uint32_t titlOffset; /**< Title buffer offset */
} RagePhotoData;
/** RagePhoto load function typedef. */
typedef bool (*ragephoto_loadfunc_t)(RagePhotoData*, const char*, size_t);
/** RagePhoto save function typedef (char* allocated by caller). */
typedef bool (*ragephoto_savefunc_t)(RagePhotoData*, char*, uint32_t);
/** RagePhoto save function typedef (char* allocated by function). */
typedef bool (*ragephoto_savepfunc_t)(RagePhotoData*, char**, uint32_t);
/** RagePhoto saveSize function typedef. */
typedef size_t (*ragephoto_saveszfunc_t)(RagePhotoData*, uint32_t);
/** RagePhoto format parser struct for registering custom formats. */
typedef struct RagePhotoFormatParser {
uint32_t photoFormat; /**< Photo file format magic */
ragephoto_loadfunc_t funcLoad; /**< Pointer to load function */
ragephoto_savefunc_t funcSave; /**< Pointer to save function */
ragephoto_savepfunc_t funcSavep; /**< Pointer to savep function */
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 */
#define RAGEPHOTO_DEFAULT_DESCBUFFER 256UL /**< Default Description Buffer Size */
#define RAGEPHOTO_DEFAULT_JSONBUFFER 3072UL /**< Default JSON Buffer Size */
#define RAGEPHOTO_DEFAULT_TITLBUFFER 256UL /**< Default Title Buffer Size */
#define RAGEPHOTO_GTA5_HEADERSIZE 264UL /**< GTA V Header Size */
#define RAGEPHOTO_RDR2_HEADERSIZE 272UL /**< RDR 2 Header Size */
/* RagePhoto error codes */
#define RAGEPHOTO_ERROR_DESCBUFFERTIGHT 39L /**< Description Buffer is too tight */
#define RAGEPHOTO_ERROR_DESCMALLOCERROR 31L /**< Description Buffer can't be allocated */
#define RAGEPHOTO_ERROR_DESCREADERROR 32L /**< Description can't be read successfully */
#define RAGEPHOTO_ERROR_HEADERBUFFERTIGHT 35L /**< Header Buffer is too tight */
#define RAGEPHOTO_ERROR_HEADERMALLOCERROR 4L /**< Header Buffer can't be allocated */
#define RAGEPHOTO_ERROR_INCOMPATIBLEFORMAT 2L /**< Format is incompatible */
#define RAGEPHOTO_ERROR_INCOMPLETECHECKSUM 7L /**< Header checksum is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCBUFFER 30L /**< Description Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCMARKER 28L /**< Description Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEDESCOFFSET 11L /**< Description Offset is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEEOF 8L /**< End Of File Offset is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEHEADER 3L /**< Header is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJENDMARKER 33L /**< JEND Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJPEGMARKER 12L /**< JPEG Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONBUFFER 20L /**< JSON Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONMARKER 18L /**< JSON Marker incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEJSONOFFSET 9L /**< JSON Offset incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOBUFFER 14L /**< Photo Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETEPHOTOSIZE 15L /**< Photo Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEBUFFER 25L /**< Title Buffer Size is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEMARKER 23L /**< Title Marker is incomplete */
#define RAGEPHOTO_ERROR_INCOMPLETETITLEOFFSET 10L /**< Title Offset is incomplete */
#define RAGEPHOTO_ERROR_INCORRECTDESCMARKER 29L /**< Description Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJENDMARKER 34L /**< JEND Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJPEGMARKER 13L /**< JPEG Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTJSONMARKER 19L /**< JSON Marker is incorrect */
#define RAGEPHOTO_ERROR_INCORRECTTITLEMARKER 24L /**< Title Marker is incorrect */
#define RAGEPHOTO_ERROR_JSONBUFFERTIGHT 37L /**< JSON Buffer is too tight */
#define RAGEPHOTO_ERROR_JSONMALLOCERROR 21L /**< JSON Buffer can't be allocated */
#define RAGEPHOTO_ERROR_JSONREADERROR 22L /**< JSON can't be read successfully */
#define RAGEPHOTO_ERROR_NOERROR 255L /**< Finished without errors */
#define RAGEPHOTO_ERROR_NOFORMATIDENTIFIER 1L /**< No format detected, empty file */
#define RAGEPHOTO_ERROR_PHOTOBUFFERTIGHT 36L /**< Photo Buffer is too tight */
#define RAGEPHOTO_ERROR_PHOTOMALLOCERROR 16L /**< Photo Buffer can't be allocated */
#define RAGEPHOTO_ERROR_PHOTOREADERROR 17L /**< Photo can't be read */
#define RAGEPHOTO_ERROR_TITLEBUFFERTIGHT 38L /**< Title Buffer is too tight */
#define RAGEPHOTO_ERROR_TITLEMALLOCERROR 26L /**< Title Buffer can't be allocated */
#define RAGEPHOTO_ERROR_TITLEREADERROR 27L /**< Title can't be read */
#define RAGEPHOTO_ERROR_UNICODEINITERROR 5L /**< Failed to initialise Unicode decoder */
#define RAGEPHOTO_ERROR_UNICODEHEADERERROR 6L /**< Header can't be encoded/decoded successfully */
#define RAGEPHOTO_ERROR_UNINITIALISED 0L /**< Uninitialised, file access failed */
/* RagePhoto formats */
#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
#endif // RAGEPHOTOTYPEDEFS_H

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* Copyright (C) 2021-2022 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -23,7 +23,7 @@
int main(int argc, char *argv[])
{
char photoHeader[256] = {
const unsigned char photoHeader_english[256] = {
0x50, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x54, 0x00,
0x4f, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00,
0x30, 0x00, 0x32, 0x00, 0x2f, 0x00, 0x30, 0x00,
@ -57,10 +57,184 @@ int main(int argc, char *argv[])
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char photoHeader_japanese[256] = {
0x99, 0x51, 0x1f, 0x77, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x32, 0x00, 0x3a, 0x00,
0x35, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char photoHeader_korean[256] = {
0xac, 0xc0, 0xc4, 0xc9, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x31, 0x00, 0x38, 0x00, 0x3a, 0x00,
0x32, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char photoHeader_russian[256] = {
0x24, 0x04, 0x1e, 0x04, 0x22, 0x04, 0x1e, 0x04,
0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x31, 0x00,
0x32, 0x00, 0x2f, 0x00, 0x32, 0x00, 0x38, 0x00,
0x2f, 0x00, 0x32, 0x00, 0x32, 0x00, 0x20, 0x00,
0x30, 0x00, 0x34, 0x00, 0x3a, 0x00, 0x32, 0x00,
0x35, 0x00, 0x3a, 0x00, 0x31, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char photoHeader_taiwanese[256] = {
0xf8, 0x76, 0x47, 0x72, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x31, 0x00, 0x3a, 0x00,
0x30, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
std::string photoString = convert.to_bytes(reinterpret_cast<char16_t*>(photoHeader));
if (convert.converted() == 0) {
return -1;
}
return strcmp(photoString.c_str(), "PHOTO - 02/01/17 08:42:44");
std::string photoString;
// English
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_english));
if (convert.converted() == 0)
return 1;
if (strcmp(photoString.c_str(), "PHOTO - 02/01/17 08:42:44") != 0)
return 2;
// Japanese
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_japanese));
if (convert.converted() == 0)
return 3;
if (strcmp(photoString.c_str(), "写真 - 12/28/22 04:22:57") != 0)
return 4;
// Korean
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_korean));
if (convert.converted() == 0)
return 5;
if (strcmp(photoString.c_str(), "사진 - 12/28/22 04:18:28") != 0)
return 6;
// Russian
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_russian));
if (convert.converted() == 0)
return 7;
if (strcmp(photoString.c_str(), "ФОТО - 12/28/22 04:25:10") != 0)
return 8;
// Taiwanese
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_taiwanese));
if (convert.converted() == 0)
return 9;
if (strcmp(photoString.c_str(), "相片 - 12/28/22 04:21:01") != 0)
return 10;
return 0;
}

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* Copyright (C) 2021-2022 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -22,7 +22,7 @@
int main(int argc, char *argv[])
{
char photoHeader[256] = {
unsigned char photoHeader_english[256] = {
0x50, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x54, 0x00,
0x4f, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00,
0x30, 0x00, 0x32, 0x00, 0x2f, 0x00, 0x30, 0x00,
@ -56,18 +56,207 @@ int main(int argc, char *argv[])
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
char photoHeader_string[256];
unsigned char photoHeader_japanese[256] = {
0x99, 0x51, 0x1f, 0x77, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x32, 0x00, 0x3a, 0x00,
0x35, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char photoHeader_korean[256] = {
0xac, 0xc0, 0xc4, 0xc9, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x31, 0x00, 0x38, 0x00, 0x3a, 0x00,
0x32, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char photoHeader_russian[256] = {
0x24, 0x04, 0x1e, 0x04, 0x22, 0x04, 0x1e, 0x04,
0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x31, 0x00,
0x32, 0x00, 0x2f, 0x00, 0x32, 0x00, 0x38, 0x00,
0x2f, 0x00, 0x32, 0x00, 0x32, 0x00, 0x20, 0x00,
0x30, 0x00, 0x34, 0x00, 0x3a, 0x00, 0x32, 0x00,
0x35, 0x00, 0x3a, 0x00, 0x31, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char photoHeader_taiwanese[256] = {
0xf8, 0x76, 0x47, 0x72, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x31, 0x00, 0x3a, 0x00,
0x30, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
size_t src_s, dst_s, ret;
char photoString[256];
iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE");
if (iconv_in == (iconv_t)-1)
return -1;
size_t src_s = sizeof(photoHeader);
size_t dst_s = sizeof(photoHeader_string);
char *src = photoHeader;
char *dst = photoHeader_string;
const size_t ret = iconv(iconv_in, &src, &src_s, &dst, &dst_s);
iconv_close(iconv_in);
if (ret == static_cast<size_t>(-1)) {
return -1;
}
return strcmp(photoHeader_string, "PHOTO - 02/01/17 08:42:44");
// English
src_s = sizeof(photoHeader_english);
dst_s = sizeof(photoString);
char *src_english = (char*)photoHeader_english;
char *dst_english = photoString;
ret = iconv(iconv_in, &src_english, &src_s, &dst_english, &dst_s);
if (ret == static_cast<size_t>(-1))
return 1;
if (strcmp(photoString, "PHOTO - 02/01/17 08:42:44") != 0)
return 2;
// Japanese
src_s = sizeof(photoHeader_japanese);
dst_s = sizeof(photoString);
char *src_japanese = (char*)photoHeader_japanese;
char *dst_japanese = photoString;
ret = iconv(iconv_in, &src_japanese, &src_s, &dst_japanese, &dst_s);
if (ret == static_cast<size_t>(-1))
return 3;
if (strcmp(photoString, "写真 - 12/28/22 04:22:57") != 0)
return 4;
// Korean
src_s = sizeof(photoHeader_korean);
dst_s = sizeof(photoString);
char *src_korean = (char*)photoHeader_korean;
char *dst_korean = photoString;
ret = iconv(iconv_in, &src_korean, &src_s, &dst_korean, &dst_s);
if (ret == static_cast<size_t>(-1))
return 5;
if (strcmp(photoString, "사진 - 12/28/22 04:18:28") != 0)
return 6;
// Russian
src_s = sizeof(photoHeader_russian);
dst_s = sizeof(photoString);
char *src_russian = (char*)photoHeader_russian;
char *dst_russian = photoString;
ret = iconv(iconv_in, &src_russian, &src_s, &dst_russian, &dst_s);
if (ret == static_cast<size_t>(-1))
return 7;
if (strcmp(photoString, "ФОТО - 12/28/22 04:25:10") != 0)
return 8;
// Taiwanese
src_s = sizeof(photoHeader_taiwanese);
dst_s = sizeof(photoString);
char *src_taiwanese = (char*)photoHeader_taiwanese;
char *dst_taiwanese = photoString;
ret = iconv(iconv_in, &src_taiwanese, &src_s, &dst_taiwanese, &dst_s);
if (ret == static_cast<size_t>(-1))
return 9;
if (strcmp(photoString, "相片 - 12/28/22 04:21:01") != 0)
return 10;
return 0;
}

View File

@ -1,6 +1,6 @@
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
* Copyright (C) 2021-2022 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -22,7 +22,7 @@
int main(int argc, char *argv[])
{
char photoHeader[256] = {
const unsigned char photoHeader_english[256] = {
0x50, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x54, 0x00,
0x4f, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00,
0x30, 0x00, 0x32, 0x00, 0x2f, 0x00, 0x30, 0x00,
@ -56,10 +56,184 @@ int main(int argc, char *argv[])
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
char photoHeader_string[256];
const int converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<wchar_t*>(photoHeader), -1, photoHeader_string, 256, NULL, NULL);
if (converted == 0) {
return -1;
}
return strcmp(photoHeader_string, "PHOTO - 02/01/17 08:42:44");
const unsigned char photoHeader_japanese[256] = {
0x99, 0x51, 0x1f, 0x77, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x32, 0x00, 0x3a, 0x00,
0x35, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char photoHeader_korean[256] = {
0xac, 0xc0, 0xc4, 0xc9, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x31, 0x00, 0x38, 0x00, 0x3a, 0x00,
0x32, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char photoHeader_russian[256] = {
0x24, 0x04, 0x1e, 0x04, 0x22, 0x04, 0x1e, 0x04,
0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x31, 0x00,
0x32, 0x00, 0x2f, 0x00, 0x32, 0x00, 0x38, 0x00,
0x2f, 0x00, 0x32, 0x00, 0x32, 0x00, 0x20, 0x00,
0x30, 0x00, 0x34, 0x00, 0x3a, 0x00, 0x32, 0x00,
0x35, 0x00, 0x3a, 0x00, 0x31, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char photoHeader_taiwanese[256] = {
0xf8, 0x76, 0x47, 0x72, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x31, 0x00, 0x3a, 0x00,
0x30, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int converted;
char photoString[256];
// English
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_english), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 1;
if (strcmp(photoString, "PHOTO - 02/01/17 08:42:44") != 0)
return 2;
// Japanese
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_japanese), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 3;
if (strcmp(photoString, "写真 - 12/28/22 04:22:57") != 0)
return 4;
// Korean
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_korean), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 5;
if (strcmp(photoString, "사진 - 12/28/22 04:18:28") != 0)
return 6;
// Russian
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_russian), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 7;
if (strcmp(photoString, "ФОТО - 12/28/22 04:25:10") != 0)
return 8;
// Taiwanese
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_taiwanese), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 9;
if (strcmp(photoString, "相片 - 12/28/22 04:21:01") != 0)
return 10;
return 0;
}