From 2a66793f709345b465482ee62977eb19735f3eff Mon Sep 17 00:00:00 2001 From: Syping Date: Wed, 29 Oct 2025 05:50:02 +0100 Subject: [PATCH] ragephoto-extract: use library save function to save jpeg --- src/extract/RagePhoto-Extract.c | 28 +++++----------------------- src/extract/RagePhoto-Extract.cpp | 16 +++------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/src/extract/RagePhoto-Extract.c b/src/extract/RagePhoto-Extract.c index 85f57a0..36b8895 100644 --- a/src/extract/RagePhoto-Extract.c +++ b/src/extract/RagePhoto-Extract.c @@ -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; diff --git a/src/extract/RagePhoto-Extract.cpp b/src/extract/RagePhoto-Extract.cpp index 8dabf5b..bfe50ea 100644 --- a/src/extract/RagePhoto-Extract.cpp +++ b/src/extract/RagePhoto-Extract.cpp @@ -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; }