Extract image import route planning
This commit is contained in:
43
src/app_core/document_import.h
Normal file
43
src/app_core/document_import.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
namespace pp::app {
|
||||
|
||||
enum class DocumentImageImportAction {
|
||||
import_equirectangular,
|
||||
place_transform,
|
||||
};
|
||||
|
||||
struct DocumentImageImportPlan {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
DocumentImageImportAction action = DocumentImageImportAction::place_transform;
|
||||
bool imports_equirectangular = false;
|
||||
bool enters_transform_mode = false;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<DocumentImageImportPlan> plan_document_image_import(
|
||||
int width,
|
||||
int height) noexcept
|
||||
{
|
||||
if (width <= 0 || height <= 0) {
|
||||
return pp::foundation::Result<DocumentImageImportPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("image dimensions must be positive"));
|
||||
}
|
||||
|
||||
const auto wide_equirect = static_cast<long long>(width) == static_cast<long long>(height) * 2LL;
|
||||
const auto vertical_cube_strip = width == height / 6;
|
||||
|
||||
DocumentImageImportPlan plan;
|
||||
plan.width = width;
|
||||
plan.height = height;
|
||||
plan.imports_equirectangular = wide_equirect || vertical_cube_strip;
|
||||
plan.enters_transform_mode = !plan.imports_equirectangular;
|
||||
plan.action = plan.imports_equirectangular
|
||||
? DocumentImageImportAction::import_equirectangular
|
||||
: DocumentImageImportAction::place_transform;
|
||||
return pp::foundation::Result<DocumentImageImportPlan>::success(plan);
|
||||
}
|
||||
|
||||
} // namespace pp::app
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "app_core/canvas_tool_ui.h"
|
||||
#include "app_core/document_layer.h"
|
||||
#include "app_core/document_canvas.h"
|
||||
#include "app_core/document_import.h"
|
||||
#include "app_core/app_status.h"
|
||||
#include "app_core/history_ui.h"
|
||||
#include "settings.h"
|
||||
@@ -746,7 +747,11 @@ void App::init_menu_file()
|
||||
pick_image([this](std::string path){
|
||||
Image img;
|
||||
img.load_file(path);
|
||||
if (img.width == img.height / 6 || img.width == img.height * 2)
|
||||
const auto import_plan = pp::app::plan_document_image_import(img.width, img.height);
|
||||
if (!import_plan)
|
||||
return;
|
||||
|
||||
if (import_plan.value().imports_equirectangular)
|
||||
{
|
||||
Canvas::I->import_equirectangular(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user