ragephoto-extract: use library save function to save jpeg
This commit is contained in:
parent
a404a29188
commit
2a66793f70
2 changed files with 8 additions and 36 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2023 Syping
|
||||
* Copyright (C) 2021-2025 Syping
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
|
|
@ -26,13 +26,10 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Initialise RagePhoto
|
||||
ragephoto_t ragephoto_in = ragephoto_open();
|
||||
|
||||
// Load Photo
|
||||
const int loaded = ragephoto_loadfile(ragephoto_in, argv[1]);
|
||||
|
||||
if (loaded != 1) {
|
||||
const bool loaded = ragephoto_loadfile(ragephoto_in, argv[1]);
|
||||
if (!loaded) {
|
||||
const int32_t error = ragephoto_error(ragephoto_in);
|
||||
if (error == RAGEPHOTO_ERROR_UNINITIALISED) {
|
||||
printf("Failed to open file: %s\n", argv[1]);
|
||||
|
|
@ -46,23 +43,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
// Write jpeg
|
||||
#ifdef _WIN32
|
||||
FILE *file = NULL;
|
||||
fopen_s(&file, argv[2], "wb");
|
||||
#else
|
||||
FILE *file = fopen(argv[2], "wb");
|
||||
#endif
|
||||
if (!file) {
|
||||
printf("Failed to write file: %s\n", argv[2]);
|
||||
ragephoto_close(ragephoto_in);
|
||||
return 1;
|
||||
}
|
||||
const size_t jpegSize = ragephoto_getphotosize(ragephoto_in);
|
||||
const size_t fileSize = fwrite(ragephoto_getphotojpeg(ragephoto_in), sizeof(char), jpegSize, file);
|
||||
fclose(file);
|
||||
|
||||
if (fileSize != jpegSize) {
|
||||
const bool saved = ragephoto_savefilef(ragephoto_in, argv[2], RAGEPHOTO_FORMAT_JPEG);
|
||||
if (!saved) {
|
||||
printf("Failed to write file: %s\n", argv[2]);
|
||||
ragephoto_close(ragephoto_in);
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021-2024 Syping
|
||||
* Copyright (C) 2021-2025 Syping
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
|
|
@ -26,10 +26,8 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Initialise RagePhoto
|
||||
RagePhoto ragePhoto;
|
||||
|
||||
// Load Photo
|
||||
const bool loaded = ragePhoto.loadFile(argv[1]);
|
||||
|
||||
if (!loaded) {
|
||||
|
|
@ -44,17 +42,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
// Write jpeg
|
||||
std::ofstream ofs(argv[2], std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
if (!ofs.is_open()) {
|
||||
std::cout << "Failed to write file: " << argv[2] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
ofs << ragePhoto.jpeg();
|
||||
const bool ok = ofs.good();
|
||||
ofs.close();
|
||||
const bool saved = ragePhoto.saveFile(argv[2], RagePhoto::JPEG);
|
||||
|
||||
if (!ok) {
|
||||
if (!saved) {
|
||||
std::cout << "Failed to write file: " << argv[2] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue