44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#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
|