RagePhoto-Extract: use C API when enabled

This commit is contained in:
Syping 2021-11-03 11:21:37 +01:00
parent 2fcc5b0ba7
commit d8c99b9067
3 changed files with 74 additions and 4 deletions

View file

@ -116,9 +116,12 @@ else()
option(WITH_EXTRACT "Build libragephoto with ragephoto-extract" OFF)
endif()
if (WITH_EXTRACT)
set(EXTRACT_SOURCES
src/RagePhoto-Extract.cpp
)
if (WITH_C_API)
enable_language(C)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
endif()
add_executable(ragephoto-extract ${RAGEPHOTO_HEADERS} ${EXTRACT_SOURCES})
target_link_libraries(ragephoto-extract PRIVATE ragephoto)
install(TARGETS ragephoto-extract DESTINATION ${CMAKE_INSTALL_BINDIR})

68
src/RagePhoto-Extract.c Normal file
View file

@ -0,0 +1,68 @@
/*****************************************************************************
* 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.
*****************************************************************************/
#include "RagePhoto.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 3) {
printf("Usage: %s [photo] [jpegout]\n", argv[0]);
return 0;
}
ragephoto_t ragephoto_in = ragephoto_open();
// Load Photo
const int loaded = ragephoto_loadfile(ragephoto_in, argv[1]);
if (loaded != 1) {
if (ragephoto_error(ragephoto_in) == 0) {
printf("Failed to open file: %s\n", argv[1]);
return 1;
}
else if (ragephoto_getphotosize(ragephoto_in) <= 0) {
printf("Failed to load photo\n");
return 1;
}
}
// Write jpeg
FILE *file = fopen(argv[2], "wb");
if (!file) {
printf("Failed to write file: %s\n", argv[2]);
return 1;
}
const size_t size = fwrite(ragephoto_getphotojpeg(ragephoto_in), sizeof(char), ragephoto_getphotosize(ragephoto_in), file);
fclose(file);
if (size != ragephoto_getphotosize(ragephoto_in)) {
printf("Failed to write file: %s\n", argv[2]);
return 1;
}
if (ragephoto_getphotoformat(ragephoto_in) == ragephoto_format_gta5())
printf("GTA V Photo successfully exported\n");
else
printf("RDR 2 Photo successfully exported\n");
ragephoto_close(ragephoto_in);
return 0;
}

View file

@ -19,7 +19,6 @@
#include "RagePhoto.h"
#include <fstream>
#include <iostream>
#include <iterator>
int main(int argc, char *argv[])
{