satdump/src-interface/viewer/viewer_projection.cpp

542 lines
24 KiB
C++
Raw Permalink Normal View History

2022-09-08 17:24:54 +02:00
#include "viewer.h"
#include "imgui/imgui_stdlib.h"
2022-09-08 17:24:54 +02:00
#include "common/map/map_drawer.h"
#include "common/projection/reprojector.h"
#include "logger.h"
#include "resources.h"
2022-09-08 18:21:29 +02:00
#include "core/style.h"
#include "main_ui.h"
2024-05-09 01:16:08 +02:00
#include "common/image/image_utils.h"
2022-09-12 23:53:45 +02:00
#include "common/widgets/switch.h"
#include "common/widgets/stepped_slider.h"
#include "imgui/pfd/pfd_utils.h"
2024-05-09 16:43:43 +02:00
#include "common/image/meta.h"
#include "common/projection/projs2/proj_json.h"
2024-02-27 19:10:22 +01:00
#include "common/widgets/spinner.h"
2022-09-08 17:24:54 +02:00
namespace satdump
{
int osm_url_regex_len = 0;
2023-10-22 01:35:37 +02:00
float general_progress = 0;
float general_sum = 1;
2023-10-23 16:10:03 +02:00
float *progress_pointer = nullptr;
2022-09-08 17:24:54 +02:00
void ViewerApplication::drawProjectionPanel()
{
bool disable_buttons = projections_are_generating;
bool disable_add_layer = is_opening_layer;
2022-09-14 17:33:58 +02:00
if (ImGui::CollapsingHeader("Projection", ImGuiTreeNodeFlags_DefaultOpen))
2022-09-08 17:24:54 +02:00
{
2022-09-14 17:23:50 +02:00
ImGui::Text("Output image : ");
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.40f);
ImGui::InputInt("##width", &projections_image_width, 0);
ImGui::SameLine();
ImGui::Text(u8"\uea76");
ImGui::SameLine();
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.40f);
ImGui::InputInt("##height", &projections_image_height, 0);
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.96f);
2023-04-13 21:05:19 +02:00
ImGui::Combo("##targetproj", &projections_current_selected_proj, "Equirectangular\0"
"UTM (Mercator)\0"
2022-09-08 17:24:54 +02:00
"Stereo\0"
"Satellite (TPERS)\0"
// "Azimuthal Equidistant\0"
);
2022-09-08 17:57:44 +02:00
2022-09-08 17:24:54 +02:00
if (projections_current_selected_proj == 0)
{
2024-02-28 17:26:48 +01:00
if (!projection_auto_mode)
{
ImGui::Text("Top Left Coordinates :");
ImGui::InputFloat("Lat##tl", &projections_equirectangular_tl_lat);
ImGui::InputFloat("Lon##tl", &projections_equirectangular_tl_lon);
ImGui::Spacing();
ImGui::Text("Bottom Right Coordinates :");
ImGui::InputFloat("Lat##br", &projections_equirectangular_br_lat);
ImGui::InputFloat("Lon##br", &projections_equirectangular_br_lon);
}
2022-09-08 17:24:54 +02:00
}
else if (projections_current_selected_proj == 1)
2022-09-12 16:43:04 +02:00
{
ImGui::InputInt("UTM Zone###projutmzone", &projections_utm_zone);
if (projections_utm_zone > 60)
projections_utm_zone = 60;
if (projections_utm_zone < 1)
projections_utm_zone = 1;
2024-02-27 14:06:25 +01:00
ImGui::Checkbox("South###projutmsouth", &projections_utm_south);
ImGui::InputFloat("Northing (m)##utm", &projections_utm_offset_y);
2024-02-27 14:06:25 +01:00
ImGui::Spacing();
ImGui::InputFloat("Scale (m/px)##utm", &projections_utm_scale);
2022-09-12 16:43:04 +02:00
}
else if (projections_current_selected_proj == 2)
2022-09-08 17:24:54 +02:00
{
2022-09-14 17:23:50 +02:00
ImGui::Text("Center Coordinates :");
2024-02-27 14:06:25 +01:00
ImGui::InputFloat("Lat##stereo", &projections_stereo_center_lat);
ImGui::InputFloat("Lon##stereo", &projections_stereo_center_lon);
2022-09-14 17:23:50 +02:00
ImGui::Spacing();
ImGui::InputFloat("Scale (m/px)##stereo", &projections_stereo_scale);
2022-09-08 17:24:54 +02:00
}
else if (projections_current_selected_proj == 3)
{
ImGui::Text("Center Coordinates :");
ImGui::InputFloat("Lat##tpers", &projections_tpers_lat);
ImGui::InputFloat("Lon##tpers", &projections_tpers_lon);
ImGui::Spacing();
ImGui::InputFloat("Altitude (m)##tpers", &projections_tpers_alt);
ImGui::InputFloat("Angle##tpers", &projections_tpers_ang);
ImGui::InputFloat("Azimuth##tpers", &projections_tpers_azi);
ImGui::Spacing();
ImGui::InputFloat("Scale##tpers", &projections_tpers_scale);
}
/*else if (projections_current_selected_proj == 4)
{
ImGui::Text("Center Coordinates :");
ImGui::InputFloat("Lat##eqaz", &projections_azeq_lat);
ImGui::InputFloat("Lon##eqaz", &projections_azeq_lon);
}*/
2024-03-05 10:48:11 +01:00
if (projections_current_selected_proj == 0 || projections_current_selected_proj == 2)
2023-01-29 17:30:31 +01:00
{
2024-02-28 17:26:48 +01:00
ImGui::Checkbox("Auto Mode###pojautomode", &projection_auto_mode);
ImGui::Checkbox("Auto Scale Mode##projautoscalemode", &projection_auto_scale_mode);
if (projection_auto_scale_mode)
{
ImGui::InputDouble("Scale X (m/px)##projscalexauto", &projection_autoscale_x);
ImGui::InputDouble("Scale Y (m/px)##projscalexauto", &projection_autoscale_y);
}
2022-09-08 17:57:44 +02:00
}
2022-09-09 16:59:27 +02:00
2022-09-14 17:23:50 +02:00
ImGui::Spacing();
2022-09-14 23:34:13 +02:00
ImGui::Separator();
ImGui::Spacing();
if (disable_buttons || projection_layers.size() == 0)
2022-09-14 17:23:50 +02:00
style::beginDisabled();
if (ImGui::Button("Generate Projection"))
{
ui_thread_pool.push([this](int)
{
logger->info("Update projection...");
generateProjectionImage();
logger->info("Done"); });
}
2024-02-27 19:10:22 +01:00
if (projections_are_generating)
{
ImGui::SameLine();
2024-03-09 23:26:14 -05:00
widgets::Spinner("###spinner1", ImGui::GetItemRectSize().y / 2 - ImGui::GetStyle().FramePadding.y, 3 * ui_scale, ImGui::GetColorU32(ImGuiCol_Text));
2024-02-27 19:10:22 +01:00
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
2023-10-22 01:35:37 +02:00
if (projections_are_generating)
ImGui::SetTooltip("Generating, please wait...");
2023-10-22 01:35:37 +02:00
if (projection_layers.size() == 0)
ImGui::SetTooltip("No layers loaded!");
}
2022-09-14 17:23:50 +02:00
ImGui::Spacing();
if (ImGui::Button("Save Projected Image"))
2022-09-09 16:59:27 +02:00
{
ui_thread_pool.push([this](int)
2023-10-22 01:35:37 +02:00
{ projections_are_generating = true;
logger->info("Saving Projection...");
2023-10-26 18:26:57 -04:00
std::string default_path = config::main_cfg["satdump_directories"]["default_projection_output_directory"]["value"].get<std::string>();
2024-05-08 21:38:32 +02:00
std::string saved_at = save_image_dialog("projection", default_path, "Save Projection", &projected_image_result, &viewer_app->save_type);
2022-09-09 16:59:27 +02:00
if (saved_at == "")
logger->info("Save cancelled");
else
logger->info("Saved current projection at %s", saved_at.c_str());
projections_are_generating = false; });
2022-09-09 16:59:27 +02:00
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
if (projections_are_generating)
ImGui::SetTooltip("Generating, please wait...");
if (projection_layers.size() == 0)
ImGui::SetTooltip("No layers loaded!");
}
if (disable_buttons || projection_layers.size() == 0)
style::endDisabled();
2022-09-08 17:24:54 +02:00
}
if (ImGui::CollapsingHeader("Layers"))
{
ImGui::BeginGroup();
2022-09-13 21:09:29 +02:00
ImGui::Text("Mode : ");
ImGui::SameLine();
ImGui::Text("Blend");
2022-09-12 23:53:45 +02:00
ImGui::SameLine();
ImGui::SetNextItemWidth(50);
ToggleButton("##projtog", &projections_mode_radio);
ImGui::SameLine();
ImGui::Text("Overlay");
ImGui::EndGroup();
2022-09-14 00:05:10 +02:00
ImGui::Separator(); //////////////////////////////////////////////////////
2022-09-14 23:34:13 +02:00
ImGui::Text("Layers :");
if (disable_add_layer)
style::beginDisabled();
2022-09-09 15:35:48 +02:00
ImGui::SameLine();
ImGuiStyle &imguistyle = ImGui::GetStyle();
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - ((projections_loading_new_layer ? 16.0 * ui_scale + imguistyle.ItemSpacing.x : 0) +
2024-04-01 14:51:47 +02:00
ImGui::CalcTextSize("Add Layer").x + imguistyle.FramePadding.x * 2.0));
2024-02-27 19:10:22 +01:00
if (projections_loading_new_layer)
{
2024-02-28 17:16:05 +01:00
widgets::Spinner("###spinner1", 8 * ui_scale, 3 * ui_scale, ImGui::GetColorU32(ImGuiCol_Text));
ImGui::SameLine();
}
if (ImGui::Button("Add Layer##button"))
ImGui::OpenPopup("Add Layer##popup", ImGuiPopupFlags_None);
if (disable_add_layer)
2022-09-14 23:34:13 +02:00
style::endDisabled();
{
if (ImGui::BeginPopupModal("Add Layer##popup", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
ImGui::RadioButton("Equirectangular", &selected_external_type, 0);
ImGui::RadioButton("Tile Map (OSM)", &selected_external_type, 1);
ImGui::RadioButton("GeoTIFF", &selected_external_type, 2);
ImGui::RadioButton("Other", &selected_external_type, 3);
if (selected_external_type == 0 ||
selected_external_type == 2 ||
selected_external_type == 3)
{
ImGui::InputText("Name", &projection_new_layer_name);
projection_new_layer_file.draw("Input Image");
if (selected_external_type == 3)
projection_new_layer_cfg.draw("Projection Config File");
2024-02-26 23:31:22 +01:00
ImGui::Checkbox("Normalize###normalizeinput", &projection_normalize_image);
}
2024-02-29 14:50:00 +01:00
else if (selected_external_type == 1)
{
2024-05-10 09:51:58 +02:00
ImGui::InputDouble("Lat1##osmlat1", &projection_osm_lat1);
ImGui::InputDouble("Lon1##osmlat1", &projection_osm_lon1);
ImGui::InputDouble("Lat2##osmlat1", &projection_osm_lat2);
ImGui::InputDouble("Lon2##osmlat1", &projection_osm_lon2);
2024-02-29 14:50:00 +01:00
ImGui::SliderInt("Zoom##osmsliderzoom", &projection_osm_zoom, 0, 6);
if (!urlgood)
ImGui::PushStyleColor(ImGuiCol_Text, style::theme.red.Value);
ImGui::InputText("Tile URL", &mapurl, ImGuiInputTextFlags_None);
if (!urlgood)
{
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Invalid URL! must be https://server/{z}/{x}/{y}.ext");
ImGui::PopStyleColor();
}
}
if (ImGui::Button("Add layer"))
{
2024-02-27 19:10:22 +01:00
auto func = [this](int)
{
2024-03-14 20:21:35 +01:00
LayerLoadingConfig cfg;
if (selected_external_type == 0)
cfg.type = "equirectangular";
else if (selected_external_type == 1)
cfg.type = "tilemap";
else if (selected_external_type == 2)
cfg.type = "geotiff";
else if (selected_external_type == 3)
cfg.type = "other";
cfg.file = projection_new_layer_file.getPath();
cfg.normalize = projection_normalize_image;
cfg.projfile = projection_new_layer_cfg.getPath();
if (selected_external_type == 1) // TODO: Move to reprojector backend
{
try
{
logger->info("Generating tile map");
2024-05-10 09:51:58 +02:00
image::Image timemap = downloadTileMap(mapurl, projection_osm_lat1, projection_osm_lon1, projection_osm_lat2, projection_osm_lon2, projection_osm_zoom);
projection_layers.push_front({"Tile Map", timemap});
}
catch (std::exception &e)
{
logger->error("Could not load tile map! %s", e.what());
projections_loading_new_layer = false;
}
}
else
{
try
{
ProjectionLayer newlayer = satdump::loadExternalLayer(cfg);
newlayer.name = projection_new_layer_name;
projection_layers.push_front(newlayer);
}
catch (std::exception &e)
{
logger->error(e.what());
}
}
2024-02-27 19:10:22 +01:00
projections_loading_new_layer = false;
};
ui_thread_pool.push(func);
projections_loading_new_layer = true;
2022-09-16 13:02:17 +02:00
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel"))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
2022-09-14 23:34:13 +02:00
}
2022-09-14 00:33:57 +02:00
2022-09-20 14:57:57 +02:00
if (ImGui::BeginListBox("##projectionslistbox", ImVec2(ImGui::GetWindowWidth(), 300 * ui_scale)))
2022-09-08 17:24:54 +02:00
{
2022-09-09 23:07:24 +02:00
for (int i = 0; i < (int)projection_layers.size(); i++)
2022-09-08 17:24:54 +02:00
{
2022-09-14 01:55:59 +02:00
ImGui::PushID(i);
2022-09-14 00:05:10 +02:00
ImGui::BeginGroup();
2022-09-09 23:07:24 +02:00
ProjectionLayer &layer = projection_layers[i];
2022-09-14 01:05:50 +02:00
std::string label;
label = layer.name;
2022-09-14 00:33:57 +02:00
ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPos().x, ImGui::GetCursorPos().y + 4 * ui_scale));
ImGui::PushTextWrapPos(ImGui::GetContentRegionMax().x - 70 * ui_scale);
2022-09-20 14:57:57 +02:00
ImGui::Text("%s", label.c_str());
ImGui::PopTextWrapPos();
2024-02-28 19:31:54 +01:00
int active_layers = 0;
for (auto &lay : projection_layers)
if (lay.enabled)
active_layers++;
2022-09-14 10:10:59 +02:00
ImGui::SameLine(ImGui::GetWindowWidth() - 70 * ui_scale);
2022-09-14 00:05:10 +02:00
ImGui::SetCursorPosY(ImGui::GetCursorPos().y - 2 * ui_scale);
2022-09-13 21:09:29 +02:00
ImGui::Checkbox(std::string("##enablelayer" + layer.name + std::to_string(i)).c_str(), &layer.enabled);
2024-02-28 19:31:54 +01:00
if (active_layers < 1)
2024-02-28 19:31:54 +01:00
layer.enabled = true;
2022-09-09 23:07:24 +02:00
{
if (disable_buttons)
2023-10-01 15:48:28 +02:00
ImGui::BeginDisabled();
2022-09-14 01:05:50 +02:00
// Closing button
ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPos().y - 2 * ui_scale);
2024-01-21 14:57:41 -05:00
ImGui::PushStyleColor(ImGuiCol_Text, style::theme.red.Value);
2024-01-25 12:31:42 -05:00
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4());
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0);
2022-09-14 10:10:59 +02:00
if (ImGui::Button(std::string(u8"\uf00d##layerdelete" + layer.name + std::to_string(i)).c_str()))
2022-09-09 23:07:24 +02:00
{
projection_layers.erase(projection_layers.begin() + i);
2024-01-25 12:31:42 -05:00
ImGui::PopStyleVar();
ImGui::PopStyleColor(2);
2022-09-14 01:05:50 +02:00
ImGui::EndGroup();
2022-09-14 02:01:51 +02:00
ImGui::PopID();
2022-09-09 23:07:24 +02:00
break;
}
2023-10-01 15:48:28 +02:00
if (projections_are_generating && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetTooltip("Wait for the processing to finish!");
2024-01-25 12:31:42 -05:00
ImGui::PopStyleVar();
ImGui::PopStyleColor(2);
if (disable_buttons)
2023-10-01 15:48:28 +02:00
ImGui::EndDisabled();
2022-09-14 01:05:50 +02:00
}
2024-02-28 19:31:54 +01:00
2022-09-14 01:05:50 +02:00
if (layer.enabled)
{
// ImGui::DragFloat(std::string("Opacity##opacitylayer" + layer.name + std::to_string(i)).c_str(), &layer.opacity, 1.0, 0, 100);
ImGui::Image((void *)(intptr_t)layer.getPreview(), {50 * ui_scale, 50 * ui_scale});
ImGui::SameLine();
ImGui::BeginGroup();
if (projections_mode_radio == 0)
style::beginDisabled();
2022-09-14 01:05:50 +02:00
FancySlider(std::string("##opacitylayer" + layer.name + std::to_string(i)).c_str(), "Opacity", &layer.opacity, ImGui::GetWindowWidth() - 76 * ui_scale);
if (projections_mode_radio == 0)
{
ImGui::SetItemTooltip("%s", "Opacity is for overlay mode only");
style::endDisabled();
}
ImGui::ProgressBar(layer.progress, ImVec2(ImGui::GetWindowWidth() - 76 * ui_scale, ImGui::GetFrameHeight()));
2022-09-14 01:05:50 +02:00
ImGui::EndGroup();
2022-09-09 23:07:24 +02:00
}
2022-09-14 00:05:10 +02:00
ImGui::EndGroup();
2022-09-14 01:55:59 +02:00
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID))
{
// Set payload to carry the index of our item (could be anything)
ImGui::SetDragDropPayload("LAYER_PROJECTION", &i, sizeof(int));
2022-09-20 14:57:57 +02:00
ImGui::Text("%s", label.c_str());
2022-09-14 01:55:59 +02:00
ImGui::EndDragDropSource();
}
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("LAYER_PROJECTION"))
{
IM_ASSERT(payload->DataSize == sizeof(int));
int payload_n = *(const int *)payload->Data;
ProjectionLayer pr = projection_layers[payload_n];
projection_layers.erase(projection_layers.begin() + payload_n);
auto it = projection_layers.begin();
projection_layers.insert(it + i, pr);
}
ImGui::EndDragDropTarget();
}
ImGui::PopID();
2022-09-14 00:33:57 +02:00
ImGui::Separator();
2022-09-08 17:24:54 +02:00
}
ImGui::EndListBox();
}
if (!(disable_buttons || disable_add_layer))
2023-10-22 01:35:37 +02:00
style::beginDisabled();
2023-10-23 16:10:03 +02:00
ImGui::ProgressBar((general_progress + (progress_pointer == nullptr ? 0 : *(progress_pointer))) / general_sum);
if (!(disable_buttons || disable_add_layer))
2023-10-22 01:35:37 +02:00
style::endDisabled();
2022-09-08 17:24:54 +02:00
}
if (ImGui::CollapsingHeader("Overlay##viewerpojoverlay"))
{
projection_overlay_handler.drawUI();
2022-09-08 17:24:54 +02:00
}
}
void ViewerApplication::generateProjectionImage()
{
2022-09-08 18:21:29 +02:00
projections_are_generating = true;
2023-10-22 01:35:37 +02:00
general_progress = 0;
general_sum = 0;
2022-09-08 18:21:29 +02:00
2024-02-27 23:57:15 +01:00
nlohmann::json cfg;
2022-09-08 17:57:44 +02:00
if (projections_current_selected_proj == 0)
{
2024-02-24 22:38:54 +01:00
cfg["type"] = "equirec";
cfg["offset_x"] = projections_equirectangular_tl_lon;
cfg["offset_y"] = projections_equirectangular_tl_lat;
2024-02-27 23:57:15 +01:00
cfg["scalar_x"] = (projections_equirectangular_br_lon - projections_equirectangular_tl_lon) / double(projections_image_width);
cfg["scalar_y"] = (projections_equirectangular_br_lat - projections_equirectangular_tl_lat) / double(projections_image_height);
2022-09-08 17:57:44 +02:00
}
else if (projections_current_selected_proj == 1)
2022-09-12 16:43:04 +02:00
{
2024-02-24 22:38:54 +01:00
cfg["type"] = "utm";
2024-03-13 20:18:59 +01:00
cfg["scale"] = projections_utm_scale;
2024-02-27 14:06:25 +01:00
cfg["zone"] = projections_utm_zone;
cfg["south"] = projections_utm_south;
2024-04-01 14:51:47 +02:00
cfg["offset_y"] = projections_utm_offset_y;
2022-09-12 16:43:04 +02:00
}
else if (projections_current_selected_proj == 2)
2022-09-08 17:57:44 +02:00
{
cfg["type"] = "stereo";
2024-03-13 20:18:59 +01:00
cfg["center_lon"] = projections_stereo_center_lon;
cfg["center_lat"] = projections_stereo_center_lat;
cfg["scale"] = projections_stereo_scale;
cfg["width"] = projections_image_width;
cfg["height"] = projections_image_height;
2022-09-08 17:57:44 +02:00
}
else if (projections_current_selected_proj == 3)
{
cfg["type"] = "tpers";
2024-03-13 20:18:59 +01:00
cfg["center_lon"] = projections_tpers_lon;
cfg["center_lat"] = projections_tpers_lat;
cfg["altitude"] = projections_tpers_alt;
cfg["tilt"] = projections_tpers_ang;
cfg["azimuth"] = projections_tpers_azi;
2024-03-13 20:18:59 +01:00
cfg["scale"] = projections_tpers_scale;
cfg["width"] = projections_image_width;
cfg["height"] = projections_image_height;
}
/*else if (projections_current_selected_proj == 4)
{
cfg["type"] = "azeq";
cfg["lon"] = projections_azeq_lon;
cfg["lat"] = projections_azeq_lat;
}*/
// Automatic projection settings!
2024-03-13 20:18:59 +01:00
if (projection_auto_scale_mode)
2023-01-29 17:30:31 +01:00
{
2024-03-13 20:18:59 +01:00
cfg["scale_x"] = projection_autoscale_x;
cfg["scale_y"] = projection_autoscale_y;
2023-01-29 17:30:31 +01:00
}
2024-03-13 20:18:59 +01:00
else
{
cfg["width"] = projections_image_width;
cfg["height"] = projections_image_height;
}
satdump::applyAutomaticProjectionSettings(projection_layers, projection_auto_mode, projection_auto_scale_mode, projections_image_width, projections_image_height, cfg);
2022-09-08 17:24:54 +02:00
2023-10-22 01:35:37 +02:00
for (int i = projection_layers.size() - 1; i >= 0; i--)
{
ProjectionLayer &layer = projection_layers[i];
if (!layer.enabled)
continue;
general_sum++;
}
general_sum += projection_overlay_handler.enabled();
2023-10-22 01:35:37 +02:00
2022-09-08 17:24:54 +02:00
// Generate all layers
2024-05-09 01:16:08 +02:00
std::vector<image::Image> layers_images =
2024-03-13 20:18:59 +01:00
generateAllProjectionLayers(projection_layers, projections_image_width, projections_image_height, cfg, &general_progress);
2022-09-08 17:24:54 +02:00
2022-09-08 19:48:06 +02:00
logger->info("Combining images...");
if (projections_mode_radio == 0) // Blend
{
2024-08-03 13:44:52 -04:00
projected_image_result = image::blend_images(layers_images);
2022-09-08 19:48:06 +02:00
}
else if (projections_mode_radio == 1) // Overlay
2022-09-08 19:48:06 +02:00
{
2024-05-09 01:16:08 +02:00
projected_image_result = image::Image(16, layers_images[0].width(), layers_images[0].height(), layers_images[0].channels());
for (int i = 0; i < (int)layers_images.size(); i++)
2022-09-23 20:46:41 +02:00
{
2024-05-09 01:16:08 +02:00
projected_image_result = image::merge_images_opacity(projected_image_result,
layers_images[i],
projection_layers[(projection_layers.size() - 1) - i].opacity / 100.0f);
2022-09-23 20:46:41 +02:00
}
2022-09-08 19:48:06 +02:00
}
2024-07-11 11:49:05 +02:00
// Copy projection metadata
if (image::has_metadata(layers_images[0]) && !image::has_metadata(projected_image_result))
image::set_metadata(projected_image_result, image::get_metadata(layers_images[0]));
2022-09-08 19:48:06 +02:00
// Free up memory
layers_images.clear();
2022-09-08 17:24:54 +02:00
2024-02-24 22:38:54 +01:00
logger->info("Applying overlays...");
2022-09-08 17:24:54 +02:00
// Setup projection to draw stuff on top
2022-12-15 21:43:39 +01:00
auto proj_func = satdump::reprojection::setupProjectionFunction(projections_image_width, projections_image_height, cfg, {});
2022-09-08 17:24:54 +02:00
// Draw map borders
2024-01-02 17:06:14 -05:00
projection_overlay_handler.clear_cache();
projection_overlay_handler.apply(projected_image_result, proj_func, &general_progress);
2023-10-14 22:25:43 +02:00
2022-09-08 17:24:54 +02:00
// Update ImageView
projection_image_widget.update(projected_image_result);
2023-10-23 20:33:19 +02:00
general_sum = 1;
general_progress = 1;
2023-10-23 16:10:03 +02:00
progress_pointer = nullptr;
2022-09-08 18:21:29 +02:00
projections_are_generating = false;
2022-09-08 17:24:54 +02:00
}
}