/* Layout template — описание сетки в микроячейках (Phase 11b). * * Template — declarative описание layout'а: имя, набор CellTemplate * (col/row/cs/rs/role/order/widget). Layout::apply_template() из template'а * + SourcePool создаёт конкретные Cell-объекты (CameraCell/WidgetCell). * * Грид: 8×8 микроячейки на output W×H. Для 1920×1080 микроячейка = 240×135 (16:9). * * Загружается из JSON через template_loader. * * Лицензия: LGPL-2.1+ */ #ifndef CUFRAMES_COMPOSER_CPP_TEMPLATE_HPP #define CUFRAMES_COMPOSER_CPP_TEMPLATE_HPP #include "types.hpp" #include #include namespace cfc { constexpr int kGridCols = 8; constexpr int kGridRows = 8; enum class CellRole { Camera = 0, Widget = 1, }; struct CellTemplate { int col = 0, row = 0; int cs = 1, rs = 1; CellRole role = CellRole::Camera; int order = 0; std::string widget; /* имя widget'а для role=Widget */ }; struct LayoutTemplate { std::string name; int priority = 0; std::vector cells; int nb_camera_cells() const { int n = 0; for (auto& c : cells) if (c.role == CellRole::Camera) ++n; return n; } }; /* Перевести {col,row,cs,rs} в pixel-rect для output W×H. */ inline Rect to_pixels(const CellTemplate& c, int W, int H) { Rect r; r.x = (c.col * W) / kGridCols; r.y = (c.row * H) / kGridRows; r.w = (c.cs * W) / kGridCols; r.h = (c.rs * H) / kGridRows; /* NV12 4:2:0 — чётные. */ r.x &= ~1; r.y &= ~1; r.w &= ~1; r.h &= ~1; if (r.x + r.w > W) r.w = W - r.x; if (r.y + r.h > H) r.h = H - r.y; return r; } } // namespace cfc #endif /* CUFRAMES_COMPOSER_CPP_TEMPLATE_HPP */