2025-05-02 10:31:47 +02:00
|
|
|
#include "pfd_utils.h"
|
2025-05-03 12:12:36 +02:00
|
|
|
#include "core/backend.h"
|
2023-10-19 15:42:54 -04:00
|
|
|
#include "core/config.h"
|
|
|
|
|
#include "logger.h"
|
2025-05-02 10:31:47 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <sstream>
|
2023-09-25 23:37:58 -04:00
|
|
|
|
2023-10-19 15:42:54 -04:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
#include <direct.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-05-25 14:30:24 +02:00
|
|
|
#include "image/io.h"
|
2024-05-08 21:38:32 +02:00
|
|
|
|
2025-06-08 18:06:12 +02:00
|
|
|
// TODOREWORK move/rename this file
|
2023-09-25 23:37:58 -04:00
|
|
|
namespace satdump
|
|
|
|
|
{
|
2024-05-09 01:16:08 +02:00
|
|
|
std::string save_image_dialog(std::string default_name, std::string default_path, std::string window_title, image::Image *image, std::string *default_ext)
|
2023-09-25 23:37:58 -04:00
|
|
|
{
|
2025-05-02 10:31:47 +02:00
|
|
|
std::vector<std::string> saveopts = {"PNG Files", "*.png", "JPEG 2000 Files", "*.j2k", "JPEG Files", "*.jpg *.jpeg", "PBM Files",
|
|
|
|
|
"*.pbm *.pgm *.ppm", "TIFF Files", "*.tif *.tiff *.gtif", "QOI Files", "*.qoi"};
|
2023-09-25 23:37:58 -04:00
|
|
|
|
2024-03-09 23:26:14 -05:00
|
|
|
size_t i = 1;
|
2024-05-08 21:38:32 +02:00
|
|
|
for (auto it = saveopts.begin() + 1;; it += 2)
|
2024-02-27 23:44:16 +01:00
|
|
|
{
|
2024-02-28 19:52:09 -05:00
|
|
|
std::stringstream ss(*it);
|
|
|
|
|
std::string token;
|
|
|
|
|
|
|
|
|
|
while (std::getline(ss, token, ' '))
|
2024-02-27 23:44:16 +01:00
|
|
|
{
|
2024-02-28 19:52:09 -05:00
|
|
|
if (token.substr(2) == *default_ext)
|
|
|
|
|
{
|
|
|
|
|
std::rotate(saveopts.begin(), it - 1, it);
|
|
|
|
|
std::rotate(saveopts.begin() + 1, it, it + 1);
|
|
|
|
|
goto done_ext;
|
|
|
|
|
}
|
2024-02-27 23:44:16 +01:00
|
|
|
}
|
2024-02-28 19:52:09 -05:00
|
|
|
|
|
|
|
|
i += 2;
|
|
|
|
|
if (i >= saveopts.size())
|
|
|
|
|
break;
|
2024-02-27 23:44:16 +01:00
|
|
|
}
|
2023-09-25 23:37:58 -04:00
|
|
|
|
2024-05-08 21:38:32 +02:00
|
|
|
done_ext:
|
2023-10-19 16:16:35 -04:00
|
|
|
#ifdef __ANDROID__
|
2025-07-10 20:59:36 +02:00
|
|
|
*default_ext = satdump_cfg.getValueFromSatDumpGeneral<std::string>("image_format");
|
2023-10-19 16:16:35 -04:00
|
|
|
#endif
|
|
|
|
|
|
2024-01-08 15:04:24 -05:00
|
|
|
#if defined(_MSC_VER)
|
2023-10-19 15:42:54 -04:00
|
|
|
if (default_path == ".")
|
|
|
|
|
{
|
2024-02-24 22:38:54 +01:00
|
|
|
char *cwd;
|
2023-10-19 15:42:54 -04:00
|
|
|
cwd = _getcwd(NULL, 0);
|
|
|
|
|
if (cwd != 0)
|
|
|
|
|
default_path = cwd;
|
|
|
|
|
}
|
|
|
|
|
default_path += "\\";
|
2024-01-08 15:04:24 -05:00
|
|
|
#elif defined(__ANDROID__)
|
|
|
|
|
if (default_path == ".")
|
|
|
|
|
default_path = "/storage/emulated/0";
|
|
|
|
|
default_path += "/";
|
2023-10-19 15:42:54 -04:00
|
|
|
#else
|
|
|
|
|
default_path += "/";
|
|
|
|
|
#endif
|
2025-05-03 12:12:36 +02:00
|
|
|
std::string save_name = default_name + "." + *default_ext;
|
2023-10-19 15:42:54 -04:00
|
|
|
|
2025-05-03 12:12:36 +02:00
|
|
|
std::vector<std::pair<std::string, std::string>> final_saveopt;
|
|
|
|
|
for (int i = 0; i < saveopts.size() / 2; i++)
|
|
|
|
|
final_saveopt.push_back({saveopts[i * 2 + 0], saveopts[i * 2 + 1]});
|
2023-10-19 15:42:54 -04:00
|
|
|
|
2025-05-03 12:12:36 +02:00
|
|
|
std::string path = backend::saveFileDialog(final_saveopt, default_path, save_name);
|
|
|
|
|
|
|
|
|
|
if (path.size() > 0)
|
2023-10-19 15:42:54 -04:00
|
|
|
{
|
2024-05-09 01:16:08 +02:00
|
|
|
image::save_img(*image, path);
|
2023-10-19 15:42:54 -04:00
|
|
|
std::string extension = std::filesystem::path(path).extension().string();
|
|
|
|
|
if (extension.size() > 1)
|
|
|
|
|
*default_ext = extension.substr(1);
|
|
|
|
|
}
|
2026-01-14 08:13:26 +01:00
|
|
|
|
2023-10-19 15:42:54 -04:00
|
|
|
return path;
|
2023-09-25 23:37:58 -04:00
|
|
|
}
|
2025-05-02 10:31:47 +02:00
|
|
|
} // namespace satdump
|