2021-11-03 11:21:37 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* libragephoto RAGE Photo Parser
|
2023-01-07 20:43:11 +01:00
|
|
|
* Copyright (C) 2021-2023 Syping
|
2021-11-03 11:21:37 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2023-06-07 06:57:23 +02:00
|
|
|
#include "RagePhoto.h"
|
2023-02-11 20:53:41 +01:00
|
|
|
#include <stdio.h>
|
2021-11-03 11:21:37 +01:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc != 3) {
|
|
|
|
printf("Usage: %s [photo] [jpegout]\n", argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-13 09:47:03 +01:00
|
|
|
// Initialise RagePhoto
|
2021-11-03 11:21:37 +01:00
|
|
|
ragephoto_t ragephoto_in = ragephoto_open();
|
|
|
|
|
|
|
|
// Load Photo
|
|
|
|
const int loaded = ragephoto_loadfile(ragephoto_in, argv[1]);
|
|
|
|
|
|
|
|
if (loaded != 1) {
|
2023-04-26 01:09:22 +02:00
|
|
|
const int32_t error = ragephoto_error(ragephoto_in);
|
|
|
|
if (error == RAGEPHOTO_ERROR_UNINITIALISED) {
|
2021-11-03 11:21:37 +01:00
|
|
|
printf("Failed to open file: %s\n", argv[1]);
|
2023-02-23 09:17:53 +01:00
|
|
|
ragephoto_close(ragephoto_in);
|
2021-11-03 11:21:37 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2023-04-26 01:09:22 +02:00
|
|
|
else if (error <= RAGEPHOTO_ERROR_PHOTOREADERROR) {
|
2021-11-03 11:21:37 +01:00
|
|
|
printf("Failed to load photo\n");
|
2023-02-23 09:17:53 +01:00
|
|
|
ragephoto_close(ragephoto_in);
|
2021-11-03 11:21:37 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write jpeg
|
2021-11-13 09:47:03 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
FILE *file = NULL;
|
|
|
|
fopen_s(&file, argv[2], "wb");
|
|
|
|
#else
|
2021-11-03 11:21:37 +01:00
|
|
|
FILE *file = fopen(argv[2], "wb");
|
2021-11-13 09:47:03 +01:00
|
|
|
#endif
|
2021-11-03 11:21:37 +01:00
|
|
|
if (!file) {
|
|
|
|
printf("Failed to write file: %s\n", argv[2]);
|
2023-02-23 09:17:53 +01:00
|
|
|
ragephoto_close(ragephoto_in);
|
2021-11-03 11:21:37 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2023-02-23 09:17:53 +01:00
|
|
|
const size_t jpegSize = ragephoto_getphotosize(ragephoto_in);
|
|
|
|
const size_t fileSize = fwrite(ragephoto_getphotojpeg(ragephoto_in), sizeof(char), jpegSize, file);
|
2021-11-03 11:21:37 +01:00
|
|
|
fclose(file);
|
|
|
|
|
2023-02-23 09:17:53 +01:00
|
|
|
if (fileSize != jpegSize) {
|
2021-11-03 11:21:37 +01:00
|
|
|
printf("Failed to write file: %s\n", argv[2]);
|
2023-02-23 09:17:53 +01:00
|
|
|
ragephoto_close(ragephoto_in);
|
2021-11-03 11:21:37 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-02-23 09:17:53 +01:00
|
|
|
const uint32_t photoFormat = ragephoto_getphotoformat(ragephoto_in);
|
2023-04-26 01:09:22 +02:00
|
|
|
if (photoFormat == RAGEPHOTO_FORMAT_GTA5)
|
2021-11-03 11:21:37 +01:00
|
|
|
printf("GTA V Photo successfully exported\n");
|
2023-04-26 01:09:22 +02:00
|
|
|
else if (photoFormat == RAGEPHOTO_FORMAT_RDR2)
|
2021-11-03 11:21:37 +01:00
|
|
|
printf("RDR 2 Photo successfully exported\n");
|
2023-02-23 09:17:53 +01:00
|
|
|
else
|
|
|
|
printf("Photo successfully exported\n");
|
2021-11-03 11:21:37 +01:00
|
|
|
|
|
|
|
ragephoto_close(ragephoto_in);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|