6125 lines
222 KiB
C++
6125 lines
222 KiB
C++
#include "app_core/app_preferences.h"
|
|
#include "app_core/app_status.h"
|
|
#include "app_core/brush_ui.h"
|
|
#include "app_core/canvas_tool_ui.h"
|
|
#include "app_core/document_animation.h"
|
|
#include "app_core/document_export.h"
|
|
#include "app_core/document_cloud.h"
|
|
#include "app_core/document_layer.h"
|
|
#include "app_core/document_platform_io.h"
|
|
#include "app_core/document_recording.h"
|
|
#include "app_core/document_resize.h"
|
|
#include "app_core/document_route.h"
|
|
#include "app_core/document_sharing.h"
|
|
#include "app_core/document_session.h"
|
|
#include "app_core/grid_ui.h"
|
|
#include "app_core/history_ui.h"
|
|
#include "app_core/quick_ui.h"
|
|
#include "assets/image_format.h"
|
|
#include "assets/image_metadata.h"
|
|
#include "assets/image_pixels.h"
|
|
#include "assets/ppi_header.h"
|
|
#include "document/document.h"
|
|
#include "document/ppi_export.h"
|
|
#include "document/ppi_import.h"
|
|
#include "foundation/parse.h"
|
|
#include "foundation/result.h"
|
|
#include "paint/blend.h"
|
|
#include "paint/stroke.h"
|
|
#include "paint/stroke_script.h"
|
|
#include "renderer_api/recording_renderer.h"
|
|
#ifdef PP_PANO_CLI_ENABLE_OPENGL_PLAN
|
|
#include "renderer_gl/command_plan.h"
|
|
#endif
|
|
#include "ui_core/layout_xml.h"
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <charconv>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <system_error>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
struct DocumentArgs {
|
|
std::uint32_t width = 0;
|
|
std::uint32_t height = 0;
|
|
std::uint32_t layers = 1;
|
|
std::uint32_t frames = 1;
|
|
std::uint32_t frame_duration_ms = 100;
|
|
};
|
|
|
|
struct SaveProjectArgs {
|
|
std::string path;
|
|
std::uint32_t width = 0;
|
|
std::uint32_t height = 0;
|
|
std::string layer_name = "Ink";
|
|
float layer_opacity = 1.0F;
|
|
std::uint32_t blend_mode = 0;
|
|
bool alpha_locked = false;
|
|
bool visible = true;
|
|
std::uint32_t layers = 1;
|
|
std::uint32_t frames = 1;
|
|
std::uint32_t frame_duration_ms = 100;
|
|
bool include_test_face_payload = false;
|
|
std::uint32_t payload_layer = 0;
|
|
std::uint32_t payload_frame = 0;
|
|
};
|
|
|
|
struct SaveDocumentProjectArgs {
|
|
std::string path;
|
|
std::uint32_t width = 64;
|
|
std::uint32_t height = 32;
|
|
};
|
|
|
|
struct InspectImageArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct ImportImageArgs {
|
|
std::string path;
|
|
std::uint32_t document_width = 0;
|
|
std::uint32_t document_height = 0;
|
|
std::uint32_t face = 0;
|
|
std::uint32_t x = 0;
|
|
std::uint32_t y = 0;
|
|
};
|
|
|
|
struct ExportImageArgs {
|
|
std::string path;
|
|
std::uint32_t width = 2;
|
|
std::uint32_t height = 2;
|
|
};
|
|
|
|
struct ParseLayoutArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct InspectProjectArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct ClassifyOpenArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct PlanOpenRouteArgs {
|
|
std::string path;
|
|
bool unsaved = false;
|
|
};
|
|
|
|
struct PlanDocumentFileArgs {
|
|
std::string work_directory;
|
|
std::string name;
|
|
bool target_exists = false;
|
|
};
|
|
|
|
struct PlanNewDocumentArgs {
|
|
std::string work_directory;
|
|
std::string name;
|
|
std::uint32_t resolution_index = 0;
|
|
bool target_exists = false;
|
|
};
|
|
|
|
struct PlanDocumentVersionArgs {
|
|
std::string directory;
|
|
std::string document_name;
|
|
std::vector<std::string> existing_paths;
|
|
};
|
|
|
|
struct PlanExportTargetArgs {
|
|
std::string kind;
|
|
std::string work_directory;
|
|
std::string directory;
|
|
std::string document_name;
|
|
std::string extension;
|
|
std::string suffix;
|
|
};
|
|
|
|
struct PlanExportStartArgs {
|
|
bool requires_license = false;
|
|
bool license_valid = true;
|
|
bool has_canvas = true;
|
|
};
|
|
|
|
struct PlanCloudUploadArgs {
|
|
bool has_canvas = true;
|
|
bool new_document = false;
|
|
bool unsaved = false;
|
|
};
|
|
|
|
struct PlanCloudBrowseArgs {
|
|
bool has_canvas = true;
|
|
std::string selected_file;
|
|
};
|
|
|
|
struct PlanCloudUploadAllArgs {
|
|
std::uint32_t file_count = 0;
|
|
bool progress_ui_available = true;
|
|
};
|
|
|
|
struct PlanRecordingSessionArgs {
|
|
bool running = false;
|
|
std::uint32_t frame_count = 0;
|
|
bool platform_deletes_recorded_files = false;
|
|
};
|
|
|
|
struct PlanShareFileArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct PlanPickedPathArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct PlanDisplayFileArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct PlanKeyboardVisibilityArgs {
|
|
bool visible = false;
|
|
};
|
|
|
|
struct PlanCursorVisibilityArgs {
|
|
bool visible = false;
|
|
};
|
|
|
|
struct PlanClipboardWriteArgs {
|
|
std::string text;
|
|
};
|
|
|
|
struct PlanAppPreferencesArgs {
|
|
float ui_scale = 1.0F;
|
|
float display_density = 1.0F;
|
|
float current_scale = 1.0F;
|
|
std::vector<float> scale_options;
|
|
float viewport_scale = 1.0F;
|
|
bool right_to_left = false;
|
|
bool timelapse_enabled = true;
|
|
bool recording_running = false;
|
|
bool vr_controllers_enabled = true;
|
|
int cursor_mode = 0;
|
|
};
|
|
|
|
struct PlanAppStatusArgs {
|
|
std::string document_name = "no-name";
|
|
bool unsaved = false;
|
|
int resolution = 512;
|
|
int resolution_index = 0;
|
|
float zoom = 1.0F;
|
|
std::uint32_t history_bytes = 0;
|
|
bool recording_running = false;
|
|
bool encoder_available = false;
|
|
std::uint32_t encoded_frames = 0;
|
|
};
|
|
|
|
struct PlanDocumentResizeArgs {
|
|
int current_resolution = 512;
|
|
int selected_resolution_index = 0;
|
|
};
|
|
|
|
struct PlanLayerRenameArgs {
|
|
std::string old_name = "Layer 1";
|
|
std::string new_name;
|
|
};
|
|
|
|
struct PlanLayerOperationArgs {
|
|
std::string kind = "select";
|
|
int layer_count = 1;
|
|
int index = 0;
|
|
int from_index = 0;
|
|
int to_index = 0;
|
|
int source_index = 0;
|
|
std::string name = "Layer";
|
|
float opacity = 1.0F;
|
|
bool flag = false;
|
|
int blend_mode = 0;
|
|
};
|
|
|
|
struct PlanAnimationOperationArgs {
|
|
std::string kind = "goto";
|
|
int frame_count = 1;
|
|
int total_duration = 1;
|
|
int current_frame = 0;
|
|
int selected_frame = 0;
|
|
int current_duration = 1;
|
|
int delta = 1;
|
|
int offset = 1;
|
|
int onion_size = 1;
|
|
};
|
|
|
|
struct PlanBrushOperationArgs {
|
|
std::string kind = "settings";
|
|
std::string path;
|
|
std::string thumbnail_path;
|
|
float r = 1.0F;
|
|
float g = 1.0F;
|
|
float b = 1.0F;
|
|
float a = 1.0F;
|
|
bool has_brush = true;
|
|
};
|
|
|
|
struct PlanGridOperationArgs {
|
|
std::string kind = "pick";
|
|
std::string path;
|
|
bool has_heightmap = true;
|
|
bool has_canvas = true;
|
|
bool supports_float32 = false;
|
|
bool supports_float16 = false;
|
|
int texture_resolution = 1024;
|
|
int sample_count = 32;
|
|
};
|
|
|
|
struct PlanHistoryOperationArgs {
|
|
std::string kind = "undo";
|
|
int undo_count = 0;
|
|
int redo_count = 0;
|
|
int memory_bytes = 0;
|
|
};
|
|
|
|
struct PlanCanvasToolArgs {
|
|
std::string kind = "draw";
|
|
bool current_mode_draw = false;
|
|
};
|
|
|
|
struct PlanCanvasToolStateArgs {
|
|
std::string mode = "draw";
|
|
bool picking = false;
|
|
bool touch_lock = false;
|
|
};
|
|
|
|
struct PlanQuickOperationArgs {
|
|
std::string kind = "brush";
|
|
int current_index = 0;
|
|
int slot_index = 0;
|
|
int brush_index = 0;
|
|
int color_index = 0;
|
|
int slot_count = 3;
|
|
bool fire_event = false;
|
|
};
|
|
|
|
struct SimulateAppSessionArgs {
|
|
bool has_canvas = true;
|
|
bool new_document = false;
|
|
bool unsaved = false;
|
|
bool close_prompt_open = false;
|
|
pp::app::DocumentSaveIntent save_intent = pp::app::DocumentSaveIntent::save;
|
|
};
|
|
|
|
struct SimulateStrokeArgs {
|
|
std::uint32_t x1 = 0;
|
|
std::uint32_t y1 = 0;
|
|
std::uint32_t x2 = 0;
|
|
std::uint32_t y2 = 0;
|
|
std::uint32_t spacing = 1;
|
|
};
|
|
|
|
struct SimulateStrokeScriptArgs {
|
|
std::string path;
|
|
};
|
|
|
|
struct ApplyStrokeScriptArgs {
|
|
std::string path;
|
|
std::string output_path;
|
|
std::uint32_t width = 64;
|
|
std::uint32_t height = 32;
|
|
};
|
|
|
|
struct SimulateDocumentEditsArgs {
|
|
std::uint32_t width = 128;
|
|
std::uint32_t height = 64;
|
|
};
|
|
|
|
struct SimulateImageImportArgs {
|
|
std::uint32_t width = 64;
|
|
std::uint32_t height = 32;
|
|
};
|
|
|
|
struct SimulateDocumentExportArgs {
|
|
std::uint32_t width = 64;
|
|
std::uint32_t height = 32;
|
|
};
|
|
|
|
struct SimulateDocumentHistoryArgs {
|
|
std::uint32_t width = 64;
|
|
std::uint32_t height = 32;
|
|
std::uint32_t history_entries = 4;
|
|
};
|
|
|
|
struct RecordRenderArgs {
|
|
std::uint32_t width = 64;
|
|
std::uint32_t height = 32;
|
|
bool exercise_clear = false;
|
|
};
|
|
|
|
void print_error(std::string_view command, std::string_view message)
|
|
{
|
|
std::cout << "{\"ok\":false,\"command\":\"" << command
|
|
<< "\",\"error\":\"" << message << "\"}\n";
|
|
}
|
|
|
|
std::span<const std::byte> transparent_png_1x1_bytes() noexcept
|
|
{
|
|
static constexpr std::array<std::byte, 68> transparent_png_1x1 {
|
|
std::byte { 0x89 }, std::byte { 0x50 }, std::byte { 0x4e }, std::byte { 0x47 },
|
|
std::byte { 0x0d }, std::byte { 0x0a }, std::byte { 0x1a }, std::byte { 0x0a },
|
|
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x0d },
|
|
std::byte { 0x49 }, std::byte { 0x48 }, std::byte { 0x44 }, std::byte { 0x52 },
|
|
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x01 },
|
|
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x01 },
|
|
std::byte { 0x08 }, std::byte { 0x06 }, std::byte { 0x00 }, std::byte { 0x00 },
|
|
std::byte { 0x00 }, std::byte { 0x1f }, std::byte { 0x15 }, std::byte { 0xc4 },
|
|
std::byte { 0x89 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 },
|
|
std::byte { 0x0b }, std::byte { 0x49 }, std::byte { 0x44 }, std::byte { 0x41 },
|
|
std::byte { 0x54 }, std::byte { 0x78 }, std::byte { 0x9c }, std::byte { 0x63 },
|
|
std::byte { 0x60 }, std::byte { 0x00 }, std::byte { 0x02 }, std::byte { 0x00 },
|
|
std::byte { 0x00 }, std::byte { 0x05 }, std::byte { 0x00 }, std::byte { 0x01 },
|
|
std::byte { 0x7a }, std::byte { 0x5e }, std::byte { 0xab }, std::byte { 0x3f },
|
|
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 },
|
|
std::byte { 0x49 }, std::byte { 0x45 }, std::byte { 0x4e }, std::byte { 0x44 },
|
|
std::byte { 0xae }, std::byte { 0x42 }, std::byte { 0x60 }, std::byte { 0x82 },
|
|
};
|
|
return transparent_png_1x1;
|
|
}
|
|
|
|
std::string json_escape(std::string_view value)
|
|
{
|
|
constexpr char hex[] = "0123456789abcdef";
|
|
std::string escaped;
|
|
escaped.reserve(value.size());
|
|
for (const unsigned char ch : value) {
|
|
switch (ch) {
|
|
case '"':
|
|
escaped += "\\\"";
|
|
break;
|
|
case '\\':
|
|
escaped += "\\\\";
|
|
break;
|
|
case '\b':
|
|
escaped += "\\b";
|
|
break;
|
|
case '\f':
|
|
escaped += "\\f";
|
|
break;
|
|
case '\n':
|
|
escaped += "\\n";
|
|
break;
|
|
case '\r':
|
|
escaped += "\\r";
|
|
break;
|
|
case '\t':
|
|
escaped += "\\t";
|
|
break;
|
|
default:
|
|
if (ch < 0x20U) {
|
|
escaped += "\\u00";
|
|
escaped.push_back(hex[(ch >> 4U) & 0x0fU]);
|
|
escaped.push_back(hex[ch & 0x0fU]);
|
|
} else {
|
|
escaped.push_back(static_cast<char>(ch));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return escaped;
|
|
}
|
|
|
|
const char* json_bool(bool value) noexcept
|
|
{
|
|
return value ? "true" : "false";
|
|
}
|
|
|
|
const char* document_open_kind_name(pp::app::DocumentOpenKind kind) noexcept
|
|
{
|
|
switch (kind) {
|
|
case pp::app::DocumentOpenKind::import_abr:
|
|
return "import-abr";
|
|
case pp::app::DocumentOpenKind::import_ppbr:
|
|
return "import-ppbr";
|
|
case pp::app::DocumentOpenKind::open_project:
|
|
return "open-project";
|
|
}
|
|
|
|
return "open-project";
|
|
}
|
|
|
|
const char* project_open_decision_name(pp::app::ProjectOpenDecision decision) noexcept
|
|
{
|
|
switch (decision) {
|
|
case pp::app::ProjectOpenDecision::open_now:
|
|
return "open-now";
|
|
case pp::app::ProjectOpenDecision::prompt_discard_unsaved:
|
|
return "prompt-discard-unsaved";
|
|
}
|
|
|
|
return "open-now";
|
|
}
|
|
|
|
const char* document_open_plan_action_name(pp::app::DocumentOpenPlanAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::DocumentOpenPlanAction::open_project_now:
|
|
return "open-project-now";
|
|
case pp::app::DocumentOpenPlanAction::prompt_discard_unsaved_project:
|
|
return "prompt-discard-unsaved-project";
|
|
case pp::app::DocumentOpenPlanAction::prompt_import_abr:
|
|
return "prompt-import-abr";
|
|
case pp::app::DocumentOpenPlanAction::prompt_import_ppbr:
|
|
return "prompt-import-ppbr";
|
|
}
|
|
|
|
return "open-project-now";
|
|
}
|
|
|
|
const char* close_request_decision_name(pp::app::CloseRequestDecision decision) noexcept
|
|
{
|
|
switch (decision) {
|
|
case pp::app::CloseRequestDecision::close_now:
|
|
return "close-now";
|
|
case pp::app::CloseRequestDecision::show_unsaved_prompt:
|
|
return "show-unsaved-prompt";
|
|
case pp::app::CloseRequestDecision::wait_for_existing_prompt:
|
|
return "wait-for-existing-prompt";
|
|
}
|
|
|
|
return "close-now";
|
|
}
|
|
|
|
const char* document_save_intent_name(pp::app::DocumentSaveIntent intent) noexcept
|
|
{
|
|
switch (intent) {
|
|
case pp::app::DocumentSaveIntent::save:
|
|
return "save";
|
|
case pp::app::DocumentSaveIntent::save_as:
|
|
return "save-as";
|
|
case pp::app::DocumentSaveIntent::save_version:
|
|
return "save-version";
|
|
case pp::app::DocumentSaveIntent::save_dirty_version:
|
|
return "save-dirty-version";
|
|
}
|
|
|
|
return "save";
|
|
}
|
|
|
|
const char* document_save_decision_name(pp::app::DocumentSaveDecision decision) noexcept
|
|
{
|
|
switch (decision) {
|
|
case pp::app::DocumentSaveDecision::no_op:
|
|
return "no-op";
|
|
case pp::app::DocumentSaveDecision::show_save_dialog:
|
|
return "show-save-dialog";
|
|
case pp::app::DocumentSaveDecision::save_existing:
|
|
return "save-existing";
|
|
case pp::app::DocumentSaveDecision::save_version:
|
|
return "save-version";
|
|
}
|
|
|
|
return "no-op";
|
|
}
|
|
|
|
const char* document_workflow_decision_name(pp::app::DocumentWorkflowDecision decision) noexcept
|
|
{
|
|
switch (decision) {
|
|
case pp::app::DocumentWorkflowDecision::unavailable:
|
|
return "unavailable";
|
|
case pp::app::DocumentWorkflowDecision::continue_now:
|
|
return "continue-now";
|
|
case pp::app::DocumentWorkflowDecision::prompt_save_before_continue:
|
|
return "prompt-save-before-continue";
|
|
}
|
|
|
|
return "unavailable";
|
|
}
|
|
|
|
const char* document_layer_rename_action_name(pp::app::DocumentLayerRenameAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::DocumentLayerRenameAction::no_op_same_name:
|
|
return "no-op-same-name";
|
|
case pp::app::DocumentLayerRenameAction::rename_and_record_undo:
|
|
return "rename-and-record-undo";
|
|
}
|
|
|
|
return "no-op-same-name";
|
|
}
|
|
|
|
const char* document_layer_operation_name(pp::app::DocumentLayerOperation operation) noexcept
|
|
{
|
|
switch (operation) {
|
|
case pp::app::DocumentLayerOperation::add:
|
|
return "add";
|
|
case pp::app::DocumentLayerOperation::duplicate:
|
|
return "duplicate";
|
|
case pp::app::DocumentLayerOperation::select:
|
|
return "select";
|
|
case pp::app::DocumentLayerOperation::reorder:
|
|
return "reorder";
|
|
case pp::app::DocumentLayerOperation::remove:
|
|
return "remove";
|
|
case pp::app::DocumentLayerOperation::set_opacity:
|
|
return "set-opacity";
|
|
case pp::app::DocumentLayerOperation::set_visibility:
|
|
return "set-visibility";
|
|
case pp::app::DocumentLayerOperation::set_alpha_lock:
|
|
return "set-alpha-lock";
|
|
case pp::app::DocumentLayerOperation::set_blend_mode:
|
|
return "set-blend-mode";
|
|
case pp::app::DocumentLayerOperation::set_highlight:
|
|
return "set-highlight";
|
|
}
|
|
|
|
return "select";
|
|
}
|
|
|
|
const char* document_animation_operation_name(pp::app::DocumentAnimationOperation operation) noexcept
|
|
{
|
|
switch (operation) {
|
|
case pp::app::DocumentAnimationOperation::add_frame:
|
|
return "add-frame";
|
|
case pp::app::DocumentAnimationOperation::duplicate_frame:
|
|
return "duplicate-frame";
|
|
case pp::app::DocumentAnimationOperation::remove_frame:
|
|
return "remove-frame";
|
|
case pp::app::DocumentAnimationOperation::adjust_duration:
|
|
return "adjust-duration";
|
|
case pp::app::DocumentAnimationOperation::move_frame:
|
|
return "move-frame";
|
|
case pp::app::DocumentAnimationOperation::goto_frame:
|
|
return "goto-frame";
|
|
case pp::app::DocumentAnimationOperation::goto_next:
|
|
return "goto-next";
|
|
case pp::app::DocumentAnimationOperation::goto_previous:
|
|
return "goto-previous";
|
|
case pp::app::DocumentAnimationOperation::set_onion_size:
|
|
return "set-onion-size";
|
|
}
|
|
|
|
return "goto-frame";
|
|
}
|
|
|
|
const char* brush_ui_texture_slot_name(pp::app::BrushUiTextureSlot slot) noexcept
|
|
{
|
|
switch (slot) {
|
|
case pp::app::BrushUiTextureSlot::tip:
|
|
return "tip";
|
|
case pp::app::BrushUiTextureSlot::pattern:
|
|
return "pattern";
|
|
case pp::app::BrushUiTextureSlot::dual:
|
|
return "dual";
|
|
}
|
|
|
|
return "tip";
|
|
}
|
|
|
|
const char* brush_ui_operation_name(pp::app::BrushUiOperation operation) noexcept
|
|
{
|
|
switch (operation) {
|
|
case pp::app::BrushUiOperation::set_tip_color:
|
|
return "set-tip-color";
|
|
case pp::app::BrushUiOperation::set_texture:
|
|
return "set-texture";
|
|
case pp::app::BrushUiOperation::replace_brush_from_preset:
|
|
return "replace-brush-from-preset";
|
|
case pp::app::BrushUiOperation::stroke_settings_changed:
|
|
return "stroke-settings-changed";
|
|
}
|
|
|
|
return "stroke-settings-changed";
|
|
}
|
|
|
|
const char* canvas_tool_operation_name(pp::app::CanvasToolOperation operation) noexcept
|
|
{
|
|
switch (operation) {
|
|
case pp::app::CanvasToolOperation::select_mode:
|
|
return "select-mode";
|
|
case pp::app::CanvasToolOperation::toggle_picking:
|
|
return "toggle-picking";
|
|
case pp::app::CanvasToolOperation::toggle_touch_lock:
|
|
return "toggle-touch-lock";
|
|
}
|
|
|
|
return "select-mode";
|
|
}
|
|
|
|
const char* canvas_tool_mode_name(pp::app::CanvasToolMode mode) noexcept
|
|
{
|
|
switch (mode) {
|
|
case pp::app::CanvasToolMode::draw:
|
|
return "draw";
|
|
case pp::app::CanvasToolMode::erase:
|
|
return "erase";
|
|
case pp::app::CanvasToolMode::line:
|
|
return "line";
|
|
case pp::app::CanvasToolMode::camera:
|
|
return "camera";
|
|
case pp::app::CanvasToolMode::grid:
|
|
return "grid";
|
|
case pp::app::CanvasToolMode::copy:
|
|
return "copy";
|
|
case pp::app::CanvasToolMode::cut:
|
|
return "cut";
|
|
case pp::app::CanvasToolMode::fill:
|
|
return "fill";
|
|
case pp::app::CanvasToolMode::mask_free:
|
|
return "mask-free";
|
|
case pp::app::CanvasToolMode::mask_line:
|
|
return "mask-line";
|
|
case pp::app::CanvasToolMode::flood_fill:
|
|
return "bucket";
|
|
}
|
|
|
|
return "draw";
|
|
}
|
|
|
|
const char* canvas_tool_transform_action_name(pp::app::CanvasToolTransformAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::CanvasToolTransformAction::none:
|
|
return "none";
|
|
case pp::app::CanvasToolTransformAction::copy:
|
|
return "copy";
|
|
case pp::app::CanvasToolTransformAction::cut:
|
|
return "cut";
|
|
}
|
|
|
|
return "none";
|
|
}
|
|
|
|
const char* grid_ui_operation_name(pp::app::GridUiOperation operation) noexcept
|
|
{
|
|
switch (operation) {
|
|
case pp::app::GridUiOperation::request_heightmap_pick:
|
|
return "request-heightmap-pick";
|
|
case pp::app::GridUiOperation::load_heightmap:
|
|
return "load-heightmap";
|
|
case pp::app::GridUiOperation::clear_heightmap:
|
|
return "clear-heightmap";
|
|
case pp::app::GridUiOperation::reload_heightmap:
|
|
return "reload-heightmap";
|
|
case pp::app::GridUiOperation::render_lightmap:
|
|
return "render-lightmap";
|
|
case pp::app::GridUiOperation::commit_heightmap:
|
|
return "commit-heightmap";
|
|
}
|
|
|
|
return "request-heightmap-pick";
|
|
}
|
|
|
|
const char* history_ui_operation_name(pp::app::HistoryUiOperation operation) noexcept
|
|
{
|
|
switch (operation) {
|
|
case pp::app::HistoryUiOperation::undo:
|
|
return "undo";
|
|
case pp::app::HistoryUiOperation::redo:
|
|
return "redo";
|
|
case pp::app::HistoryUiOperation::clear:
|
|
return "clear";
|
|
}
|
|
|
|
return "undo";
|
|
}
|
|
|
|
const char* quick_ui_slot_kind_name(pp::app::QuickUiSlotKind kind) noexcept
|
|
{
|
|
switch (kind) {
|
|
case pp::app::QuickUiSlotKind::brush:
|
|
return "brush";
|
|
case pp::app::QuickUiSlotKind::color:
|
|
return "color";
|
|
}
|
|
|
|
return "brush";
|
|
}
|
|
|
|
const char* quick_ui_operation_name(pp::app::QuickUiOperation operation) noexcept
|
|
{
|
|
switch (operation) {
|
|
case pp::app::QuickUiOperation::select_slot:
|
|
return "select-slot";
|
|
case pp::app::QuickUiOperation::open_slot_popup:
|
|
return "open-slot-popup";
|
|
case pp::app::QuickUiOperation::restore_state:
|
|
return "restore-state";
|
|
case pp::app::QuickUiOperation::reset_state:
|
|
return "reset-state";
|
|
}
|
|
|
|
return "select-slot";
|
|
}
|
|
|
|
const char* document_file_write_decision_name(pp::app::DocumentFileWriteDecision decision) noexcept
|
|
{
|
|
switch (decision) {
|
|
case pp::app::DocumentFileWriteDecision::save_now:
|
|
return "save-now";
|
|
case pp::app::DocumentFileWriteDecision::prompt_overwrite:
|
|
return "prompt-overwrite";
|
|
}
|
|
|
|
return "save-now";
|
|
}
|
|
|
|
const char* document_export_start_decision_name(pp::app::DocumentExportStartDecision decision) noexcept
|
|
{
|
|
switch (decision) {
|
|
case pp::app::DocumentExportStartDecision::start_now:
|
|
return "start-now";
|
|
case pp::app::DocumentExportStartDecision::show_license_disabled:
|
|
return "show-license-disabled";
|
|
case pp::app::DocumentExportStartDecision::unavailable_no_canvas:
|
|
return "unavailable-no-canvas";
|
|
}
|
|
|
|
return "unavailable-no-canvas";
|
|
}
|
|
|
|
const char* cloud_upload_action_name(pp::app::CloudUploadAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::CloudUploadAction::unavailable_no_canvas:
|
|
return "unavailable-no-canvas";
|
|
case pp::app::CloudUploadAction::show_save_required_warning:
|
|
return "show-save-required-warning";
|
|
case pp::app::CloudUploadAction::prompt_publish:
|
|
return "prompt-publish";
|
|
}
|
|
|
|
return "unavailable-no-canvas";
|
|
}
|
|
|
|
const char* cloud_browse_action_name(pp::app::CloudBrowseAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::CloudBrowseAction::unavailable_no_canvas:
|
|
return "unavailable-no-canvas";
|
|
case pp::app::CloudBrowseAction::show_browser:
|
|
return "show-browser";
|
|
}
|
|
|
|
return "unavailable-no-canvas";
|
|
}
|
|
|
|
const char* cloud_download_selection_action_name(pp::app::CloudDownloadSelectionAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::CloudDownloadSelectionAction::wait_for_selection:
|
|
return "wait-for-selection";
|
|
case pp::app::CloudDownloadSelectionAction::start_download:
|
|
return "start-download";
|
|
}
|
|
|
|
return "wait-for-selection";
|
|
}
|
|
|
|
const char* recording_start_action_name(pp::app::RecordingStartAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::RecordingStartAction::start_thread:
|
|
return "start-thread";
|
|
case pp::app::RecordingStartAction::no_op_already_running:
|
|
return "no-op-already-running";
|
|
}
|
|
|
|
return "no-op-already-running";
|
|
}
|
|
|
|
const char* recording_stop_action_name(pp::app::RecordingStopAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::RecordingStopAction::stop_thread:
|
|
return "stop-thread";
|
|
case pp::app::RecordingStopAction::no_op_not_running:
|
|
return "no-op-not-running";
|
|
}
|
|
|
|
return "no-op-not-running";
|
|
}
|
|
|
|
const char* document_share_action_name(pp::app::DocumentShareAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::DocumentShareAction::show_save_required_warning:
|
|
return "show-save-required-warning";
|
|
case pp::app::DocumentShareAction::share_now:
|
|
return "share-now";
|
|
}
|
|
|
|
return "show-save-required-warning";
|
|
}
|
|
|
|
const char* picked_path_action_name(pp::app::PickedPathAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::PickedPathAction::ignore_empty_path:
|
|
return "ignore-empty-path";
|
|
case pp::app::PickedPathAction::invoke_callback:
|
|
return "invoke-callback";
|
|
}
|
|
|
|
return "ignore-empty-path";
|
|
}
|
|
|
|
const char* display_file_action_name(pp::app::DisplayFileAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::DisplayFileAction::ignore_empty_path:
|
|
return "ignore-empty-path";
|
|
case pp::app::DisplayFileAction::open_external_file:
|
|
return "open-external-file";
|
|
}
|
|
|
|
return "ignore-empty-path";
|
|
}
|
|
|
|
const char* virtual_keyboard_action_name(pp::app::VirtualKeyboardAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::VirtualKeyboardAction::show_keyboard:
|
|
return "show-keyboard";
|
|
case pp::app::VirtualKeyboardAction::hide_keyboard:
|
|
return "hide-keyboard";
|
|
}
|
|
|
|
return "hide-keyboard";
|
|
}
|
|
|
|
const char* cursor_visibility_action_name(pp::app::CursorVisibilityAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::CursorVisibilityAction::show_cursor:
|
|
return "show-cursor";
|
|
case pp::app::CursorVisibilityAction::hide_cursor:
|
|
return "hide-cursor";
|
|
}
|
|
|
|
return "hide-cursor";
|
|
}
|
|
|
|
const char* clipboard_read_action_name(pp::app::ClipboardReadAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::ClipboardReadAction::read_text:
|
|
return "read-text";
|
|
}
|
|
|
|
return "read-text";
|
|
}
|
|
|
|
const char* clipboard_write_action_name(pp::app::ClipboardWriteAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::ClipboardWriteAction::write_text:
|
|
return "write-text";
|
|
}
|
|
|
|
return "write-text";
|
|
}
|
|
|
|
const char* interface_direction_name(pp::app::InterfaceDirection direction) noexcept
|
|
{
|
|
switch (direction) {
|
|
case pp::app::InterfaceDirection::left_to_right:
|
|
return "left-to-right";
|
|
case pp::app::InterfaceDirection::right_to_left:
|
|
return "right-to-left";
|
|
}
|
|
|
|
return "left-to-right";
|
|
}
|
|
|
|
const char* timelapse_recording_action_name(pp::app::TimelapseRecordingAction action) noexcept
|
|
{
|
|
switch (action) {
|
|
case pp::app::TimelapseRecordingAction::no_op:
|
|
return "no-op";
|
|
case pp::app::TimelapseRecordingAction::start_recording:
|
|
return "start-recording";
|
|
case pp::app::TimelapseRecordingAction::stop_recording:
|
|
return "stop-recording";
|
|
}
|
|
|
|
return "no-op";
|
|
}
|
|
|
|
pp::foundation::Result<float> parse_float_arg(std::string_view text)
|
|
{
|
|
float value = 0.0F;
|
|
const auto* begin = text.data();
|
|
const auto* end = begin + text.size();
|
|
const auto [ptr, ec] = std::from_chars(begin, end, value);
|
|
if (ec != std::errc {} || ptr != end) {
|
|
return pp::foundation::Result<float>::failure(
|
|
pp::foundation::Status::invalid_argument("invalid floating-point value"));
|
|
}
|
|
|
|
if (!std::isfinite(value)) {
|
|
return pp::foundation::Result<float>::failure(
|
|
pp::foundation::Status::invalid_argument("floating-point value must be finite"));
|
|
}
|
|
|
|
return pp::foundation::Result<float>::success(value);
|
|
}
|
|
|
|
pp::foundation::Result<int> parse_i32_arg(std::string_view text)
|
|
{
|
|
int value = 0;
|
|
const auto* begin = text.data();
|
|
const auto* end = begin + text.size();
|
|
const auto [ptr, ec] = std::from_chars(begin, end, value);
|
|
if (ec != std::errc {} || ptr != end) {
|
|
return pp::foundation::Result<int>::failure(
|
|
pp::foundation::Status::invalid_argument("invalid signed integer value"));
|
|
}
|
|
|
|
return pp::foundation::Result<int>::success(value);
|
|
}
|
|
|
|
void print_help()
|
|
{
|
|
std::cout
|
|
<< "pano_cli commands:\n"
|
|
<< " apply-stroke-script --path FILE --output FILE [--width N] [--height N]\n"
|
|
<< " create-document --width N --height N [--layers N] [--frames N] [--frame-duration-ms N]\n"
|
|
<< " export-image --path FILE [--width N] [--height N]\n"
|
|
<< " inspect-image --path FILE\n"
|
|
<< " import-image --path FILE [--document-width N] [--document-height N] [--face N] [--x N] [--y N]\n"
|
|
<< " inspect-project --path FILE\n"
|
|
<< " classify-open --path FILE\n"
|
|
<< " plan-open-route --path FILE [--unsaved]\n"
|
|
<< " plan-new-document --work-dir DIR --name NAME [--resolution-index N] [--target-exists]\n"
|
|
<< " plan-document-file --work-dir DIR --name NAME [--target-exists]\n"
|
|
<< " plan-document-version --directory DIR --doc-name NAME [--existing-path FILE]\n"
|
|
<< " plan-export-start [--requires-license] [--demo] [--no-canvas]\n"
|
|
<< " plan-export-target --kind file|collection|stem|name --doc-name NAME [--work-dir DIR] [--directory DIR] [--extension EXT] [--suffix SUFFIX]\n"
|
|
<< " plan-cloud-upload [--no-canvas] [--new-document] [--unsaved]\n"
|
|
<< " plan-cloud-browse [--no-canvas] [--selected-file FILE]\n"
|
|
<< " plan-cloud-upload-all [--file-count N] [--no-progress-ui]\n"
|
|
<< " plan-recording-session [--running] [--frame-count N] [--platform-deletes-recorded-files]\n"
|
|
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
|
<< " plan-app-status [--doc-name NAME] [--unsaved] [--resolution N] [--resolution-index N] [--zoom N] [--history-bytes N] [--recording-running] [--encoder-available] [--encoded-frames N]\n"
|
|
<< " plan-document-resize [--current-resolution N] [--selected-resolution-index N]\n"
|
|
<< " plan-layer-rename --old-name NAME --new-name NAME\n"
|
|
<< " plan-layer-operation --kind add|duplicate|select|reorder|remove|opacity|visibility|alpha-lock|blend-mode|highlight [--layer-count N] [--index N] [--from-index N] [--to-index N] [--source-index N] [--name NAME] [--opacity N] [--blend-mode N] [--enabled]\n"
|
|
<< " plan-animation-operation --kind add|duplicate|remove|duration|move|goto|next|prev|onion [--frame-count N] [--total-duration N] [--current-frame N] [--selected-frame N] [--current-duration N] [--delta N] [--offset N] [--onion-size N]\n"
|
|
<< " plan-brush-operation --kind color|tip|pattern|dual|preset|settings [--path FILE] [--thumb FILE] [--r N] [--g N] [--b N] [--a N] [--no-brush]\n"
|
|
<< " plan-canvas-tool --kind draw|erase|line|camera|grid|copy|cut|fill|mask-free|mask-line|bucket|pick|touch-lock [--current-mode-draw]\n"
|
|
<< " plan-canvas-tool-state [--mode draw|erase|line|camera|grid|copy|cut|fill|mask-free|mask-line|bucket] [--picking] [--touch-lock]\n"
|
|
<< " plan-grid-operation --kind pick|load|reload|clear|render|commit [--path FILE] [--no-heightmap] [--no-canvas] [--float32] [--float16] [--texture-resolution N] [--samples N]\n"
|
|
<< " plan-history-operation --kind undo|redo|clear [--undo-count N] [--redo-count N] [--memory-bytes N]\n"
|
|
<< " plan-quick-operation --kind brush|color|restore|reset [--current-index N] [--slot-index N] [--brush-index N] [--color-index N] [--slot-count N] [--fire-event]\n"
|
|
<< " plan-share-file [--path FILE]\n"
|
|
<< " plan-picked-path [--path FILE]\n"
|
|
<< " plan-display-file [--path FILE]\n"
|
|
<< " plan-keyboard-visibility [--visible]\n"
|
|
<< " plan-cursor-visibility [--visible]\n"
|
|
<< " plan-clipboard-read\n"
|
|
<< " plan-clipboard-write [--text TEXT]\n"
|
|
<< " load-project --path FILE\n"
|
|
<< " parse-layout --path FILE\n"
|
|
<< " record-render [--width N] [--height N] [--exercise-clear]\n"
|
|
<< " save-document-project --path FILE [--width N] [--height N]\n"
|
|
<< " save-project --path FILE --width N --height N [--layer-name NAME] [--layer-opacity N] [--blend-mode N] [--alpha-locked] [--hidden] [--layers N] [--frames N] [--frame-duration-ms N] [--include-test-face-payload] [--payload-layer N] [--payload-frame N]\n"
|
|
<< " simulate-document-edits [--width N] [--height N]\n"
|
|
<< " simulate-document-export [--width N] [--height N]\n"
|
|
<< " simulate-document-history [--width N] [--height N] [--history N]\n"
|
|
<< " simulate-app-session [--no-canvas] [--new-document] [--unsaved] [--close-prompt-open] [--save-intent save|save-as|save-version|save-dirty-version]\n"
|
|
<< " simulate-blend\n"
|
|
<< " simulate-image-import [--width N] [--height N]\n"
|
|
<< " simulate-stroke --x1 N --y1 N --x2 N --y2 N [--spacing N]\n"
|
|
<< " simulate-stroke-script --path FILE\n"
|
|
<< " --help\n";
|
|
}
|
|
|
|
pp::foundation::Status parse_document_args(int argc, char** argv, DocumentArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--width" || key == "--height" || key == "--layers" || key == "--frames"
|
|
|| key == "--frame-duration-ms") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else if (key == "--height") {
|
|
args.height = value.value();
|
|
} else if (key == "--layers") {
|
|
args.layers = value.value();
|
|
} else if (key == "--frames") {
|
|
args.frames = value.value();
|
|
} else {
|
|
args.frame_duration_ms = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
if (args.layers == 0) {
|
|
return pp::foundation::Status::invalid_argument("layer count must be greater than zero");
|
|
}
|
|
|
|
if (args.frames == 0) {
|
|
return pp::foundation::Status::invalid_argument("frame count must be greater than zero");
|
|
}
|
|
|
|
if (args.frame_duration_ms == 0) {
|
|
return pp::foundation::Status::invalid_argument("frame duration must be greater than zero");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int create_document(int argc, char** argv)
|
|
{
|
|
DocumentArgs args;
|
|
const auto status = parse_document_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("create-document", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto document_result = pp::document::CanvasDocument::create(
|
|
pp::document::DocumentConfig {
|
|
.width = args.width,
|
|
.height = args.height,
|
|
.layer_count = args.layers,
|
|
});
|
|
if (!document_result) {
|
|
print_error("create-document", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
auto document = document_result.value();
|
|
const auto duration_status = document.set_frame_duration(0, args.frame_duration_ms);
|
|
if (!duration_status.ok()) {
|
|
print_error("create-document", duration_status.message);
|
|
return 2;
|
|
}
|
|
|
|
for (std::uint32_t i = 1; i < args.frames; ++i) {
|
|
const auto added_frame = document.add_frame(args.frame_duration_ms);
|
|
if (!added_frame) {
|
|
print_error("create-document", added_frame.status().message);
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"create-document\",\"document\":{"
|
|
<< "\"width\":" << document.width()
|
|
<< ",\"height\":" << document.height()
|
|
<< ",\"layers\":" << document.layers().size()
|
|
<< ",\"activeLayer\":" << document.active_layer_index()
|
|
<< ",\"frames\":" << document.frames().size()
|
|
<< ",\"activeFrame\":" << document.active_frame_index()
|
|
<< ",\"animationDurationMs\":" << document.animation_duration_ms()
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Result<pp::document::CanvasDocument> create_export_sample_document(
|
|
std::uint32_t width,
|
|
std::uint32_t height)
|
|
{
|
|
const std::vector<std::uint8_t> red_pixel { 255, 0, 0, 255 };
|
|
const std::vector<std::uint8_t> blue_pixel { 0, 0, 255, 128 };
|
|
const pp::document::AnimationFrame root_frames[] {
|
|
{ .duration_ms = 100, .face_pixels = {} },
|
|
{ .duration_ms = 250, .face_pixels = {} },
|
|
};
|
|
const pp::document::AnimationFrame base_frames[] {
|
|
{
|
|
.duration_ms = 100,
|
|
.face_pixels = {
|
|
pp::document::LayerFacePixels {
|
|
.face_index = 0,
|
|
.x = 2,
|
|
.y = 3,
|
|
.width = 1,
|
|
.height = 1,
|
|
.rgba8 = red_pixel,
|
|
},
|
|
},
|
|
},
|
|
{ .duration_ms = 250, .face_pixels = {} },
|
|
};
|
|
const pp::document::AnimationFrame paint_frames[] {
|
|
{
|
|
.duration_ms = 333,
|
|
.face_pixels = {
|
|
pp::document::LayerFacePixels {
|
|
.face_index = 5,
|
|
.x = 4,
|
|
.y = 5,
|
|
.width = 1,
|
|
.height = 1,
|
|
.rgba8 = blue_pixel,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const pp::document::DocumentLayerConfig layers[] {
|
|
{
|
|
.name = "Base",
|
|
.visible = true,
|
|
.alpha_locked = false,
|
|
.opacity = 1.0F,
|
|
.blend_mode = pp::paint::BlendMode::normal,
|
|
.frames = std::span<const pp::document::AnimationFrame>(base_frames, 2),
|
|
},
|
|
{
|
|
.name = "Paint",
|
|
.visible = false,
|
|
.alpha_locked = true,
|
|
.opacity = 0.5F,
|
|
.blend_mode = pp::paint::BlendMode::overlay,
|
|
.frames = std::span<const pp::document::AnimationFrame>(paint_frames, 1),
|
|
},
|
|
};
|
|
|
|
return pp::document::CanvasDocument::create_from_snapshot(
|
|
pp::document::DocumentSnapshotConfig {
|
|
.width = width,
|
|
.height = height,
|
|
.layers = std::span<const pp::document::DocumentLayerConfig>(layers, 2),
|
|
.frames = std::span<const pp::document::AnimationFrame>(root_frames, 2),
|
|
.selection_masks = {},
|
|
});
|
|
}
|
|
|
|
pp::foundation::Status parse_save_document_project_args(
|
|
int argc,
|
|
char** argv,
|
|
SaveDocumentProjectArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.path = argv[++i];
|
|
} else if (key == "--width" || key == "--height") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else {
|
|
args.height = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
if (args.width < 8 || args.height < 8) {
|
|
return pp::foundation::Status::out_of_range("width and height must be at least 8 for document export");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int save_document_project(int argc, char** argv)
|
|
{
|
|
SaveDocumentProjectArgs args;
|
|
const auto status = parse_save_document_project_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("save-document-project", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto document = create_export_sample_document(args.width, args.height);
|
|
if (!document) {
|
|
print_error("save-document-project", document.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto exported = pp::document::export_ppi_project_document(document.value());
|
|
if (!exported) {
|
|
print_error("save-document-project", exported.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::ofstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("save-document-project", "project file could not be opened for writing");
|
|
return 2;
|
|
}
|
|
|
|
const auto& bytes = exported.value();
|
|
stream.write(reinterpret_cast<const char*>(bytes.data()), static_cast<std::streamsize>(bytes.size()));
|
|
if (!stream) {
|
|
print_error("save-document-project", "project file could not be written");
|
|
return 2;
|
|
}
|
|
|
|
const auto decoded = pp::assets::decode_ppi_project_images(bytes);
|
|
if (!decoded) {
|
|
print_error("save-document-project", decoded.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"save-document-project\""
|
|
<< ",\"path\":\"" << json_escape(args.path) << "\""
|
|
<< ",\"format\":\"ppi\""
|
|
<< ",\"bytes\":" << bytes.size()
|
|
<< ",\"document\":{\"width\":" << document.value().width()
|
|
<< ",\"height\":" << document.value().height()
|
|
<< ",\"layers\":" << document.value().layers().size()
|
|
<< ",\"frames\":" << document.value().frames().size()
|
|
<< ",\"facePayloads\":" << document.value().face_pixel_payload_count()
|
|
<< "},\"export\":{\"dirtyFaces\":" << decoded.value().project.body.summary.dirty_face_count
|
|
<< ",\"rgbaFacePayloads\":" << decoded.value().project.body.summary.rgba_face_payload_count
|
|
<< ",\"compressedBytes\":" << decoded.value().project.body.summary.compressed_face_bytes
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_save_project_args(int argc, char** argv, SaveProjectArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path" || key == "--layer-name") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
if (key == "--path") {
|
|
args.path = argv[++i];
|
|
} else {
|
|
args.layer_name = argv[++i];
|
|
}
|
|
} else if (key == "--layer-opacity") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = parse_float_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
args.layer_opacity = value.value();
|
|
} else if (key == "--alpha-locked") {
|
|
args.alpha_locked = true;
|
|
} else if (key == "--hidden") {
|
|
args.visible = false;
|
|
} else if (key == "--width" || key == "--height" || key == "--layers" || key == "--frames"
|
|
|| key == "--blend-mode" || key == "--frame-duration-ms" || key == "--payload-layer"
|
|
|| key == "--payload-frame") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else if (key == "--height") {
|
|
args.height = value.value();
|
|
} else if (key == "--layers") {
|
|
args.layers = value.value();
|
|
} else if (key == "--frames") {
|
|
args.frames = value.value();
|
|
} else if (key == "--blend-mode") {
|
|
args.blend_mode = value.value();
|
|
} else if (key == "--payload-layer") {
|
|
args.payload_layer = value.value();
|
|
} else if (key == "--payload-frame") {
|
|
args.payload_frame = value.value();
|
|
} else {
|
|
args.frame_duration_ms = value.value();
|
|
}
|
|
} else if (key == "--include-test-face-payload") {
|
|
args.include_test_face_payload = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
if (args.layer_name.empty()) {
|
|
return pp::foundation::Status::invalid_argument("layer name must not be empty");
|
|
}
|
|
|
|
if (args.layer_opacity < 0.0F || args.layer_opacity > 1.0F) {
|
|
return pp::foundation::Status::out_of_range("layer opacity must be in the range [0, 1]");
|
|
}
|
|
|
|
if (args.blend_mode > 4U) {
|
|
return pp::foundation::Status::out_of_range("blend mode must be in the range [0, 4]");
|
|
}
|
|
|
|
if (args.layers == 0) {
|
|
return pp::foundation::Status::invalid_argument("layer count must be greater than zero");
|
|
}
|
|
|
|
if (args.frames == 0) {
|
|
return pp::foundation::Status::invalid_argument("frame count must be greater than zero");
|
|
}
|
|
|
|
if (args.frame_duration_ms == 0) {
|
|
return pp::foundation::Status::invalid_argument("frame duration must be greater than zero");
|
|
}
|
|
|
|
if (args.include_test_face_payload && args.payload_layer >= args.layers) {
|
|
return pp::foundation::Status::out_of_range("payload layer must be inside the generated layer list");
|
|
}
|
|
|
|
if (args.include_test_face_payload && args.payload_frame >= args.frames) {
|
|
return pp::foundation::Status::out_of_range("payload frame must be inside the generated frame list");
|
|
}
|
|
|
|
if (!args.include_test_face_payload && (args.payload_layer != 0 || args.payload_frame != 0)) {
|
|
return pp::foundation::Status::invalid_argument(
|
|
"payload layer/frame options require --include-test-face-payload");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int save_project(int argc, char** argv)
|
|
{
|
|
SaveProjectArgs args;
|
|
const auto status = parse_save_project_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("save-project", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto test_payload = transparent_png_1x1_bytes();
|
|
const pp::assets::PpiDirtyFacePayloadConfig dirty_faces[] {
|
|
{
|
|
.layer_index = args.payload_layer,
|
|
.frame_index = args.payload_frame,
|
|
.face_index = 0,
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = 1,
|
|
.height = 1,
|
|
.png_rgba8 = test_payload,
|
|
},
|
|
};
|
|
const auto project = pp::assets::create_minimal_ppi_project(pp::assets::PpiMinimalProjectConfig {
|
|
.width = args.width,
|
|
.height = args.height,
|
|
.layer_name = args.layer_name,
|
|
.layer_metadata = pp::assets::PpiLayerMetadataConfig {
|
|
.opacity = args.layer_opacity,
|
|
.blend_mode = args.blend_mode,
|
|
.alpha_locked = args.alpha_locked,
|
|
.visible = args.visible,
|
|
},
|
|
.layer_count = args.layers,
|
|
.frame_count = args.frames,
|
|
.frame_duration_ms = args.frame_duration_ms,
|
|
.dirty_faces = args.include_test_face_payload
|
|
? std::span<const pp::assets::PpiDirtyFacePayloadConfig>(dirty_faces, 1)
|
|
: std::span<const pp::assets::PpiDirtyFacePayloadConfig>(),
|
|
});
|
|
if (!project) {
|
|
print_error("save-project", project.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::ofstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("save-project", "project file could not be opened for writing");
|
|
return 2;
|
|
}
|
|
|
|
const auto& bytes = project.value();
|
|
stream.write(reinterpret_cast<const char*>(bytes.data()), static_cast<std::streamsize>(bytes.size()));
|
|
if (!stream) {
|
|
print_error("save-project", "project file could not be written");
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"save-project\""
|
|
<< ",\"path\":\"" << json_escape(args.path) << "\""
|
|
<< ",\"format\":\"ppi\""
|
|
<< ",\"bytes\":" << bytes.size()
|
|
<< ",\"document\":{\"width\":" << args.width
|
|
<< ",\"height\":" << args.height
|
|
<< ",\"layers\":" << args.layers
|
|
<< ",\"frames\":" << args.frames
|
|
<< ",\"layerName\":\"" << json_escape(args.layer_name) << "\""
|
|
<< ",\"layerOpacity\":" << args.layer_opacity
|
|
<< ",\"blendMode\":" << args.blend_mode
|
|
<< ",\"alphaLocked\":" << (args.alpha_locked ? "true" : "false")
|
|
<< ",\"visible\":" << (args.visible ? "true" : "false")
|
|
<< ",\"frameDurationMs\":" << args.frame_duration_ms
|
|
<< ",\"facePayloads\":" << (args.include_test_face_payload ? 1 : 0)
|
|
<< ",\"payloadLayer\":" << args.payload_layer
|
|
<< ",\"payloadFrame\":" << args.payload_frame
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_inspect_image_args(int argc, char** argv, InspectImageArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int inspect_image(int argc, char** argv)
|
|
{
|
|
InspectImageArgs args;
|
|
const auto status = parse_inspect_image_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("inspect-image", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::ifstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("inspect-image", "image file could not be opened");
|
|
return 2;
|
|
}
|
|
|
|
const std::vector<char> chars {
|
|
std::istreambuf_iterator<char>(stream),
|
|
std::istreambuf_iterator<char>()
|
|
};
|
|
const auto* data = reinterpret_cast<const std::byte*>(chars.data());
|
|
const auto format = pp::assets::detect_image_format(std::span<const std::byte>(data, chars.size()));
|
|
if (!format) {
|
|
print_error("inspect-image", format.status().message);
|
|
return 2;
|
|
}
|
|
|
|
pp::foundation::Result<pp::assets::ImageMetadata> metadata =
|
|
pp::foundation::Result<pp::assets::ImageMetadata>::failure(
|
|
pp::foundation::Status::invalid_argument("image metadata is unavailable"));
|
|
if (format.value() == pp::assets::ImageFormat::png) {
|
|
metadata = pp::assets::parse_png_metadata(std::span<const std::byte>(data, chars.size()));
|
|
if (!metadata) {
|
|
print_error("inspect-image", metadata.status().message);
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"inspect-image\",\"format\":\""
|
|
<< pp::assets::image_format_name(format.value())
|
|
<< "\",\"bytes\":" << chars.size();
|
|
|
|
if (metadata) {
|
|
std::cout << ",\"metadata\":{\"width\":" << metadata.value().width
|
|
<< ",\"height\":" << metadata.value().height
|
|
<< ",\"bitDepth\":" << static_cast<int>(metadata.value().bit_depth)
|
|
<< ",\"components\":" << static_cast<int>(metadata.value().components)
|
|
<< ",\"colorType\":\"" << pp::assets::image_color_type_name(metadata.value().color_type)
|
|
<< "\"}";
|
|
} else {
|
|
std::cout << ",\"metadata\":null";
|
|
}
|
|
|
|
std::cout << "}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_import_image_args(int argc, char** argv, ImportImageArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
args.path = argv[++i];
|
|
} else if (key == "--document-width" || key == "--document-height"
|
|
|| key == "--face" || key == "--x" || key == "--y") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--document-width") {
|
|
args.document_width = value.value();
|
|
} else if (key == "--document-height") {
|
|
args.document_height = value.value();
|
|
} else if (key == "--face") {
|
|
args.face = value.value();
|
|
} else if (key == "--x") {
|
|
args.x = value.value();
|
|
} else {
|
|
args.y = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
if ((args.document_width == 0) != (args.document_height == 0)) {
|
|
return pp::foundation::Status::invalid_argument(
|
|
"document width and height must both be omitted or both be greater than zero");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int import_image(int argc, char** argv)
|
|
{
|
|
ImportImageArgs args;
|
|
const auto status = parse_import_image_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("import-image", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::ifstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("import-image", "image file could not be opened");
|
|
return 2;
|
|
}
|
|
|
|
const std::vector<char> chars {
|
|
std::istreambuf_iterator<char>(stream),
|
|
std::istreambuf_iterator<char>()
|
|
};
|
|
const auto* data = reinterpret_cast<const std::byte*>(chars.data());
|
|
const auto image_result = pp::assets::decode_png_rgba8(std::span<const std::byte>(data, chars.size()));
|
|
if (!image_result) {
|
|
print_error("import-image", image_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& image = image_result.value();
|
|
const std::uint32_t document_width = args.document_width == 0 ? image.width : args.document_width;
|
|
const std::uint32_t document_height = args.document_height == 0 ? image.height : args.document_height;
|
|
const auto document_result = pp::document::CanvasDocument::create(
|
|
pp::document::DocumentConfig {
|
|
.width = document_width,
|
|
.height = document_height,
|
|
.layer_count = 1,
|
|
});
|
|
if (!document_result) {
|
|
print_error("import-image", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
auto document = document_result.value();
|
|
const auto import_status = document.set_layer_frame_face_pixels(
|
|
0,
|
|
0,
|
|
pp::document::LayerFacePixels {
|
|
.face_index = args.face,
|
|
.x = args.x,
|
|
.y = args.y,
|
|
.width = image.width,
|
|
.height = image.height,
|
|
.rgba8 = image.pixels,
|
|
});
|
|
if (!import_status.ok()) {
|
|
print_error("import-image", import_status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"import-image\""
|
|
<< ",\"source\":\"" << json_escape(args.path) << "\""
|
|
<< ",\"image\":{\"format\":\"png\",\"width\":" << image.width
|
|
<< ",\"height\":" << image.height
|
|
<< ",\"bytes\":" << image.pixels.size()
|
|
<< "},\"document\":{\"width\":" << document.width()
|
|
<< ",\"height\":" << document.height()
|
|
<< ",\"layers\":" << document.layers().size()
|
|
<< ",\"frames\":" << document.frames().size()
|
|
<< ",\"facePayloads\":" << document.face_pixel_payload_count()
|
|
<< "},\"payload\":{\"face\":" << args.face
|
|
<< ",\"x\":" << args.x
|
|
<< ",\"y\":" << args.y
|
|
<< ",\"width\":" << image.width
|
|
<< ",\"height\":" << image.height
|
|
<< ",\"bytes\":" << image.pixels.size()
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_export_image_args(int argc, char** argv, ExportImageArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
args.path = argv[++i];
|
|
} else if (key == "--width" || key == "--height") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else {
|
|
args.height = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
constexpr std::uint64_t max_cli_export_bytes = 64ULL * 1024ULL * 1024ULL;
|
|
if (static_cast<std::uint64_t>(args.width) > max_cli_export_bytes / 4ULL / static_cast<std::uint64_t>(args.height)) {
|
|
return pp::foundation::Status::out_of_range("export image exceeds the CLI automation size limit");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int export_image(int argc, char** argv)
|
|
{
|
|
ExportImageArgs args;
|
|
const auto status = parse_export_image_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("export-image", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::vector<std::uint8_t> pixels(
|
|
static_cast<std::size_t>(args.width) * static_cast<std::size_t>(args.height) * 4U);
|
|
for (std::uint32_t y = 0; y < args.height; ++y) {
|
|
for (std::uint32_t x = 0; x < args.width; ++x) {
|
|
const auto offset = (static_cast<std::size_t>(y) * args.width + x) * 4U;
|
|
pixels[offset + 0U] = static_cast<std::uint8_t>((x * 37U) & 0xffU);
|
|
pixels[offset + 1U] = static_cast<std::uint8_t>((y * 53U) & 0xffU);
|
|
pixels[offset + 2U] = static_cast<std::uint8_t>(((x + y) * 29U) & 0xffU);
|
|
pixels[offset + 3U] = 255U;
|
|
}
|
|
}
|
|
|
|
const auto encoded = pp::assets::encode_png_rgba8(args.width, args.height, pixels);
|
|
if (!encoded) {
|
|
print_error("export-image", encoded.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::ofstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("export-image", "image file could not be opened for writing");
|
|
return 2;
|
|
}
|
|
|
|
const auto& bytes = encoded.value();
|
|
stream.write(reinterpret_cast<const char*>(bytes.data()), static_cast<std::streamsize>(bytes.size()));
|
|
if (!stream) {
|
|
print_error("export-image", "image file could not be written");
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"export-image\""
|
|
<< ",\"path\":\"" << json_escape(args.path) << "\""
|
|
<< ",\"image\":{\"format\":\"png\",\"width\":" << args.width
|
|
<< ",\"height\":" << args.height
|
|
<< ",\"bytes\":" << pixels.size()
|
|
<< "},\"file\":{\"bytes\":" << bytes.size()
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_inspect_project_args(int argc, char** argv, InspectProjectArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Status parse_classify_open_args(int argc, char** argv, ClassifyOpenArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int classify_open(int argc, char** argv)
|
|
{
|
|
ClassifyOpenArgs args;
|
|
const auto status = parse_classify_open_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("classify-open", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto route = pp::app::classify_document_open_path(args.path);
|
|
if (!route) {
|
|
print_error("classify-open", route.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"classify-open\""
|
|
<< ",\"route\":{\"kind\":\"" << document_open_kind_name(route.value().kind)
|
|
<< "\",\"path\":\"" << json_escape(route.value().path)
|
|
<< "\",\"directory\":\"" << json_escape(route.value().directory)
|
|
<< "\",\"name\":\"" << json_escape(route.value().name)
|
|
<< "\",\"extension\":\"" << json_escape(route.value().extension)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_open_route_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanOpenRouteArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.path = argv[++i];
|
|
} else if (key == "--unsaved") {
|
|
args.unsaved = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_open_route(int argc, char** argv)
|
|
{
|
|
PlanOpenRouteArgs args;
|
|
const auto status = parse_plan_open_route_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-open-route", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto route = pp::app::classify_document_open_path(args.path);
|
|
if (!route) {
|
|
print_error("plan-open-route", route.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto action = pp::app::plan_document_open(route.value().kind, args.unsaved);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-open-route\""
|
|
<< ",\"route\":{\"kind\":\"" << document_open_kind_name(route.value().kind)
|
|
<< "\",\"path\":\"" << json_escape(route.value().path)
|
|
<< "\",\"directory\":\"" << json_escape(route.value().directory)
|
|
<< "\",\"name\":\"" << json_escape(route.value().name)
|
|
<< "\",\"extension\":\"" << json_escape(route.value().extension)
|
|
<< "\"},\"state\":{\"unsaved\":" << json_bool(args.unsaved)
|
|
<< "},\"plan\":{\"action\":\"" << document_open_plan_action_name(action)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_document_file_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanDocumentFileArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--work-dir") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.work_directory = argv[++i];
|
|
} else if (key == "--name") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.name = argv[++i];
|
|
} else if (key == "--target-exists") {
|
|
args.target_exists = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.work_directory.empty()) {
|
|
return pp::foundation::Status::invalid_argument("work directory must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_document_file(int argc, char** argv)
|
|
{
|
|
PlanDocumentFileArgs args;
|
|
const auto status = parse_plan_document_file_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-document-file", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = pp::app::plan_document_file_save(
|
|
args.work_directory,
|
|
args.name,
|
|
[&args](const std::string&) {
|
|
return args.target_exists;
|
|
});
|
|
if (!plan) {
|
|
print_error("plan-document-file", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-document-file\""
|
|
<< ",\"target\":{\"name\":\"" << json_escape(plan.value().target.name)
|
|
<< "\",\"directory\":\"" << json_escape(plan.value().target.directory)
|
|
<< "\",\"path\":\"" << json_escape(plan.value().target.path)
|
|
<< "\",\"exists\":" << json_bool(args.target_exists)
|
|
<< "},\"decision\":\""
|
|
<< document_file_write_decision_name(plan.value().write_decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_new_document_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanNewDocumentArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--work-dir") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.work_directory = argv[++i];
|
|
} else if (key == "--name") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.name = argv[++i];
|
|
} else if (key == "--resolution-index") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto parsed = pp::foundation::parse_u32(argv[++i]);
|
|
if (!parsed) {
|
|
return parsed.status();
|
|
}
|
|
args.resolution_index = parsed.value();
|
|
} else if (key == "--target-exists") {
|
|
args.target_exists = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.work_directory.empty()) {
|
|
return pp::foundation::Status::invalid_argument("work directory must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_new_document(int argc, char** argv)
|
|
{
|
|
PlanNewDocumentArgs args;
|
|
const auto status = parse_plan_new_document_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-new-document", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = pp::app::plan_new_document(
|
|
args.work_directory,
|
|
args.name,
|
|
static_cast<int>(args.resolution_index),
|
|
[&args](const std::string&) {
|
|
return args.target_exists;
|
|
});
|
|
if (!plan) {
|
|
print_error("plan-new-document", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-new-document\""
|
|
<< ",\"target\":{\"name\":\"" << json_escape(plan.value().target.name)
|
|
<< "\",\"directory\":\"" << json_escape(plan.value().target.directory)
|
|
<< "\",\"path\":\"" << json_escape(plan.value().target.path)
|
|
<< "\",\"exists\":" << json_bool(args.target_exists)
|
|
<< "},\"document\":{\"resolution\":" << plan.value().resolution
|
|
<< ",\"resolutionIndex\":" << args.resolution_index
|
|
<< "},\"decision\":\""
|
|
<< document_file_write_decision_name(plan.value().write_decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_document_version_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanDocumentVersionArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--directory") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.directory = argv[++i];
|
|
} else if (key == "--doc-name") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.document_name = argv[++i];
|
|
} else if (key == "--existing-path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.existing_paths.push_back(argv[++i]);
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.directory.empty()) {
|
|
return pp::foundation::Status::invalid_argument("directory must not be empty");
|
|
}
|
|
|
|
if (args.document_name.empty()) {
|
|
return pp::foundation::Status::invalid_argument("document name must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_document_version(int argc, char** argv)
|
|
{
|
|
PlanDocumentVersionArgs args;
|
|
const auto status = parse_plan_document_version_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-document-version", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto target = pp::app::find_next_document_version_target(
|
|
args.directory,
|
|
args.document_name,
|
|
[&args](const std::string& path) {
|
|
return std::find(args.existing_paths.begin(), args.existing_paths.end(), path)
|
|
!= args.existing_paths.end();
|
|
});
|
|
if (!target) {
|
|
print_error("plan-document-version", target.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-document-version\""
|
|
<< ",\"input\":{\"directory\":\"" << json_escape(args.directory)
|
|
<< "\",\"documentName\":\"" << json_escape(args.document_name)
|
|
<< "\",\"existingPaths\":" << args.existing_paths.size()
|
|
<< "},\"target\":{\"name\":\"" << json_escape(target.value().name)
|
|
<< "\",\"path\":\"" << json_escape(target.value().path)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_export_start_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanExportStartArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--requires-license") {
|
|
args.requires_license = true;
|
|
} else if (key == "--demo") {
|
|
args.license_valid = false;
|
|
} else if (key == "--no-canvas") {
|
|
args.has_canvas = false;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_export_start(int argc, char** argv)
|
|
{
|
|
PlanExportStartArgs args;
|
|
const auto status = parse_plan_export_start_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-export-start", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decision = pp::app::plan_document_export_start(
|
|
args.requires_license,
|
|
args.license_valid,
|
|
args.has_canvas);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-export-start\""
|
|
<< ",\"state\":{\"requiresLicense\":" << json_bool(args.requires_license)
|
|
<< ",\"licenseValid\":" << json_bool(args.license_valid)
|
|
<< ",\"hasCanvas\":" << json_bool(args.has_canvas)
|
|
<< "},\"decision\":\"" << document_export_start_decision_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_cloud_upload_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanCloudUploadArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--no-canvas") {
|
|
args.has_canvas = false;
|
|
} else if (key == "--new-document") {
|
|
args.new_document = true;
|
|
} else if (key == "--unsaved") {
|
|
args.unsaved = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_cloud_upload(int argc, char** argv)
|
|
{
|
|
PlanCloudUploadArgs args;
|
|
const auto status = parse_plan_cloud_upload_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-cloud-upload", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = pp::app::plan_cloud_upload(
|
|
args.has_canvas,
|
|
args.new_document,
|
|
args.unsaved);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-cloud-upload\""
|
|
<< ",\"state\":{\"hasCanvas\":" << json_bool(args.has_canvas)
|
|
<< ",\"newDocument\":" << json_bool(args.new_document)
|
|
<< ",\"unsaved\":" << json_bool(args.unsaved)
|
|
<< "},\"decision\":\"" << cloud_upload_action_name(plan.action)
|
|
<< "\",\"saveBeforeUpload\":" << json_bool(plan.save_before_upload)
|
|
<< "}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_cloud_browse_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanCloudBrowseArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--no-canvas") {
|
|
args.has_canvas = false;
|
|
} else if (key == "--selected-file") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.selected_file = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_cloud_browse(int argc, char** argv)
|
|
{
|
|
PlanCloudBrowseArgs args;
|
|
const auto status = parse_plan_cloud_browse_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-cloud-browse", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto browse = pp::app::plan_cloud_browse(args.has_canvas);
|
|
const auto selection = pp::app::plan_cloud_download_selection(args.selected_file);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-cloud-browse\""
|
|
<< ",\"state\":{\"hasCanvas\":" << json_bool(args.has_canvas)
|
|
<< ",\"selectedFile\":\"" << json_escape(args.selected_file)
|
|
<< "\"},\"browseDecision\":\"" << cloud_browse_action_name(browse)
|
|
<< "\",\"selectionDecision\":\"" << cloud_download_selection_action_name(selection)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_cloud_upload_all_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanCloudUploadAllArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--file-count") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
args.file_count = value.value();
|
|
} else if (key == "--no-progress-ui") {
|
|
args.progress_ui_available = false;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_cloud_upload_all(int argc, char** argv)
|
|
{
|
|
PlanCloudUploadAllArgs args;
|
|
const auto status = parse_plan_cloud_upload_all_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-cloud-upload-all", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = pp::app::plan_cloud_bulk_upload(args.file_count, args.progress_ui_available);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-cloud-upload-all\""
|
|
<< ",\"state\":{\"fileCount\":" << args.file_count
|
|
<< ",\"progressUiAvailable\":" << json_bool(args.progress_ui_available)
|
|
<< "},\"plan\":{\"fileCount\":" << plan.file_count
|
|
<< ",\"progressTotal\":" << plan.progress_total
|
|
<< ",\"showProgress\":" << json_bool(plan.show_progress)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_recording_session_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanRecordingSessionArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--running") {
|
|
args.running = true;
|
|
} else if (key == "--frame-count") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
args.frame_count = value.value();
|
|
} else if (key == "--platform-deletes-recorded-files") {
|
|
args.platform_deletes_recorded_files = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_recording_session(int argc, char** argv)
|
|
{
|
|
PlanRecordingSessionArgs args;
|
|
const auto status = parse_plan_recording_session_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-recording-session", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto start = pp::app::plan_recording_start(args.running);
|
|
const auto stop = pp::app::plan_recording_stop(args.running);
|
|
const auto clear = pp::app::plan_recording_clear(
|
|
args.running,
|
|
args.platform_deletes_recorded_files);
|
|
const auto export_plan = pp::app::plan_recording_export(args.frame_count);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-recording-session\""
|
|
<< ",\"state\":{\"running\":" << json_bool(args.running)
|
|
<< ",\"frameCount\":" << args.frame_count
|
|
<< ",\"platformDeletesRecordedFiles\":" << json_bool(args.platform_deletes_recorded_files)
|
|
<< "},\"startDecision\":\"" << recording_start_action_name(start)
|
|
<< "\",\"stopDecision\":\"" << recording_stop_action_name(stop)
|
|
<< "\",\"clear\":{\"stopRunningRecording\":" << json_bool(clear.stop_running_recording)
|
|
<< ",\"deleteRecordedFiles\":" << json_bool(clear.delete_recorded_files)
|
|
<< ",\"frameCountAfterClear\":" << clear.frame_count_after_clear
|
|
<< "},\"export\":{\"frameCount\":" << export_plan.frame_count
|
|
<< ",\"progressTotal\":" << export_plan.progress_total
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_app_preferences_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanAppPreferencesArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--ui-scale" || key == "--display-density" || key == "--current-scale"
|
|
|| key == "--scale-option" || key == "--viewport-scale") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_float_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--ui-scale") {
|
|
args.ui_scale = value.value();
|
|
} else if (key == "--display-density") {
|
|
args.display_density = value.value();
|
|
} else if (key == "--current-scale") {
|
|
args.current_scale = value.value();
|
|
} else if (key == "--scale-option") {
|
|
args.scale_options.push_back(value.value());
|
|
} else {
|
|
args.viewport_scale = value.value();
|
|
}
|
|
} else if (key == "--rtl") {
|
|
args.right_to_left = true;
|
|
} else if (key == "--timelapse-disabled") {
|
|
args.timelapse_enabled = false;
|
|
} else if (key == "--recording-running") {
|
|
args.recording_running = true;
|
|
} else if (key == "--vr-controllers-disabled") {
|
|
args.vr_controllers_enabled = false;
|
|
} else if (key == "--cursor-mode") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
args.cursor_mode = static_cast<int>(value.value());
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_app_preferences(int argc, char** argv)
|
|
{
|
|
PlanAppPreferencesArgs args;
|
|
const auto status = parse_plan_app_preferences_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-app-preferences", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto ui_scale = pp::app::plan_ui_scale(args.ui_scale, args.display_density);
|
|
const auto scale_selection = pp::app::plan_scale_option_selection(
|
|
args.current_scale,
|
|
args.scale_options);
|
|
const auto viewport_scale = pp::app::plan_viewport_scale(args.viewport_scale);
|
|
const auto direction = pp::app::plan_interface_direction(args.right_to_left);
|
|
const auto timelapse = pp::app::plan_timelapse_preference(
|
|
args.timelapse_enabled,
|
|
args.recording_running);
|
|
const auto vr_controllers = pp::app::plan_vr_controllers_preference(args.vr_controllers_enabled);
|
|
const auto cursor_mode = pp::app::plan_canvas_cursor_mode(args.cursor_mode);
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-app-preferences\""
|
|
<< ",\"state\":{\"uiScale\":" << args.ui_scale
|
|
<< ",\"displayDensity\":" << args.display_density
|
|
<< ",\"currentScale\":" << args.current_scale
|
|
<< ",\"scaleOptions\":" << args.scale_options.size()
|
|
<< ",\"viewportScale\":" << args.viewport_scale
|
|
<< ",\"rtl\":" << json_bool(args.right_to_left)
|
|
<< ",\"timelapseEnabled\":" << json_bool(args.timelapse_enabled)
|
|
<< ",\"recordingRunning\":" << json_bool(args.recording_running)
|
|
<< ",\"vrControllersEnabled\":" << json_bool(args.vr_controllers_enabled)
|
|
<< ",\"cursorMode\":" << args.cursor_mode
|
|
<< "},\"uiScale\":{\"scale\":" << ui_scale.scale
|
|
<< ",\"displayDensity\":" << ui_scale.display_density
|
|
<< ",\"fontScale\":" << ui_scale.font_scale
|
|
<< "},\"scaleSelection\":{\"hasSelection\":" << json_bool(scale_selection.has_selection)
|
|
<< ",\"index\":" << scale_selection.index
|
|
<< "},\"viewportScale\":{\"scale\":" << viewport_scale.scale
|
|
<< "},\"direction\":\"" << interface_direction_name(direction.direction)
|
|
<< "\",\"timelapse\":{\"enabled\":" << json_bool(timelapse.enabled)
|
|
<< ",\"recordingAction\":\"" << timelapse_recording_action_name(timelapse.recording_action)
|
|
<< "\"},\"vrControllers\":{\"enabled\":" << json_bool(vr_controllers.value)
|
|
<< "},\"cursor\":{\"mode\":" << cursor_mode.value
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_app_status_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanAppStatusArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--doc-name") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.document_name = argv[++i];
|
|
} else if (key == "--unsaved") {
|
|
args.unsaved = true;
|
|
} else if (key == "--resolution" || key == "--resolution-index" || key == "--history-bytes"
|
|
|| key == "--encoded-frames") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--resolution") {
|
|
args.resolution = static_cast<int>(value.value());
|
|
} else if (key == "--resolution-index") {
|
|
args.resolution_index = static_cast<int>(value.value());
|
|
} else if (key == "--history-bytes") {
|
|
args.history_bytes = value.value();
|
|
} else {
|
|
args.encoded_frames = value.value();
|
|
}
|
|
} else if (key == "--zoom") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_float_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
args.zoom = value.value();
|
|
} else if (key == "--recording-running") {
|
|
args.recording_running = true;
|
|
} else if (key == "--encoder-available") {
|
|
args.encoder_available = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_app_status(int argc, char** argv)
|
|
{
|
|
PlanAppStatusArgs args;
|
|
const auto status = parse_plan_app_status_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-app-status", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto resolution_from_index = pp::app::display_resolution_from_index(args.resolution_index);
|
|
const auto resolution_index = pp::app::document_resolution_to_index(args.resolution);
|
|
const auto resolution_label = pp::app::document_resolution_label(args.resolution);
|
|
const auto recording_label = pp::app::make_recording_frame_label(
|
|
args.recording_running,
|
|
args.encoder_available,
|
|
static_cast<int>(args.encoded_frames));
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-app-status\""
|
|
<< ",\"state\":{\"documentName\":\"" << json_escape(args.document_name)
|
|
<< "\",\"unsaved\":" << json_bool(args.unsaved)
|
|
<< ",\"resolution\":" << args.resolution
|
|
<< ",\"resolutionIndex\":" << args.resolution_index
|
|
<< ",\"zoom\":" << args.zoom
|
|
<< ",\"historyBytes\":" << args.history_bytes
|
|
<< ",\"recordingRunning\":" << json_bool(args.recording_running)
|
|
<< ",\"encoderAvailable\":" << json_bool(args.encoder_available)
|
|
<< ",\"encodedFrames\":" << args.encoded_frames
|
|
<< "},\"title\":\"" << json_escape(pp::app::make_document_title(
|
|
args.document_name,
|
|
args.unsaved,
|
|
args.resolution))
|
|
<< "\",\"dpi\":\"" << json_escape(pp::app::make_dpi_label(args.zoom))
|
|
<< "\",\"memory\":\"" << json_escape(pp::app::make_history_memory_label(args.history_bytes))
|
|
<< "\",\"recording\":{\"visible\":" << json_bool(recording_label.visible)
|
|
<< ",\"text\":\"" << json_escape(recording_label.text)
|
|
<< "\"},\"resolutionMap\":{\"fromIndexValid\":" << json_bool(static_cast<bool>(resolution_from_index))
|
|
<< ",\"fromIndex\":" << (resolution_from_index ? resolution_from_index.value() : 0)
|
|
<< ",\"toIndexValid\":" << json_bool(static_cast<bool>(resolution_index))
|
|
<< ",\"toIndex\":" << (resolution_index ? resolution_index.value() : 0)
|
|
<< ",\"labelValid\":" << json_bool(static_cast<bool>(resolution_label))
|
|
<< ",\"label\":\"" << json_escape(resolution_label ? std::string(resolution_label.value()) : std::string())
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_document_resize_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanDocumentResizeArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--current-resolution" || key == "--selected-resolution-index") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--current-resolution") {
|
|
args.current_resolution = static_cast<int>(value.value());
|
|
} else {
|
|
args.selected_resolution_index = static_cast<int>(value.value());
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_document_resize(int argc, char** argv)
|
|
{
|
|
PlanDocumentResizeArgs args;
|
|
const auto status = parse_plan_document_resize_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-document-resize", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto state = pp::app::make_document_resize_dialog_state(args.current_resolution);
|
|
const auto plan = pp::app::plan_document_resize(args.selected_resolution_index);
|
|
if (!plan) {
|
|
print_error("plan-document-resize", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-document-resize\""
|
|
<< ",\"state\":{\"currentResolution\":" << state.current_resolution
|
|
<< ",\"currentResolutionText\":\"" << json_escape(state.current_resolution_text)
|
|
<< "\",\"currentResolutionIndex\":" << state.current_resolution_index
|
|
<< ",\"selectedResolutionIndex\":" << args.selected_resolution_index
|
|
<< "},\"plan\":{\"resolution\":" << plan.value().resolution
|
|
<< ",\"width\":" << plan.value().width
|
|
<< ",\"height\":" << plan.value().height
|
|
<< ",\"clearsHistory\":" << json_bool(plan.value().clears_history)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_layer_rename_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanLayerRenameArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--old-name" || key == "--new-name") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
if (key == "--old-name") {
|
|
args.old_name = argv[++i];
|
|
} else {
|
|
args.new_name = argv[++i];
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_layer_rename(int argc, char** argv)
|
|
{
|
|
PlanLayerRenameArgs args;
|
|
const auto status = parse_plan_layer_rename_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-layer-rename", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = pp::app::plan_document_layer_rename(args.old_name, args.new_name);
|
|
if (!plan) {
|
|
print_error("plan-layer-rename", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-layer-rename\""
|
|
<< ",\"state\":{\"oldName\":\"" << json_escape(args.old_name)
|
|
<< "\",\"newName\":\"" << json_escape(args.new_name)
|
|
<< "\"},\"plan\":{\"oldName\":\"" << json_escape(plan.value().old_name)
|
|
<< "\",\"newName\":\"" << json_escape(plan.value().new_name)
|
|
<< "\",\"action\":\"" << document_layer_rename_action_name(plan.value().action)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_layer_operation_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanLayerOperationArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--kind" || key == "--name") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
if (key == "--kind") {
|
|
args.kind = argv[++i];
|
|
} else {
|
|
args.name = argv[++i];
|
|
}
|
|
} else if (key == "--layer-count" || key == "--index" || key == "--from-index"
|
|
|| key == "--to-index" || key == "--source-index" || key == "--blend-mode") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--layer-count") {
|
|
args.layer_count = static_cast<int>(value.value());
|
|
} else if (key == "--index") {
|
|
args.index = static_cast<int>(value.value());
|
|
} else if (key == "--from-index") {
|
|
args.from_index = static_cast<int>(value.value());
|
|
} else if (key == "--to-index") {
|
|
args.to_index = static_cast<int>(value.value());
|
|
} else if (key == "--source-index") {
|
|
args.source_index = static_cast<int>(value.value());
|
|
} else {
|
|
args.blend_mode = static_cast<int>(value.value());
|
|
}
|
|
} else if (key == "--opacity") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_float_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
args.opacity = value.value();
|
|
} else if (key == "--enabled") {
|
|
args.flag = true;
|
|
} else if (key == "--disabled") {
|
|
args.flag = false;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::DocumentLayerOperationPlan> make_layer_operation_plan(
|
|
const PlanLayerOperationArgs& args)
|
|
{
|
|
if (args.kind == "add") {
|
|
return pp::app::plan_document_layer_add(args.layer_count, args.index, args.name);
|
|
}
|
|
if (args.kind == "duplicate") {
|
|
return pp::app::plan_document_layer_duplicate(args.layer_count, args.source_index);
|
|
}
|
|
if (args.kind == "select") {
|
|
return pp::app::plan_document_layer_select(args.layer_count, args.index);
|
|
}
|
|
if (args.kind == "reorder") {
|
|
return pp::app::plan_document_layer_reorder(args.layer_count, args.from_index, args.to_index);
|
|
}
|
|
if (args.kind == "remove") {
|
|
return pp::app::plan_document_layer_remove(args.layer_count, args.index);
|
|
}
|
|
if (args.kind == "opacity") {
|
|
return pp::app::plan_document_layer_opacity(args.layer_count, args.index, args.opacity);
|
|
}
|
|
if (args.kind == "visibility") {
|
|
return pp::app::plan_document_layer_visibility(args.layer_count, args.index, args.flag);
|
|
}
|
|
if (args.kind == "alpha-lock") {
|
|
return pp::app::plan_document_layer_alpha_lock(args.layer_count, args.index, args.flag);
|
|
}
|
|
if (args.kind == "blend-mode") {
|
|
return pp::app::plan_document_layer_blend_mode(args.layer_count, args.index, args.blend_mode);
|
|
}
|
|
if (args.kind == "highlight") {
|
|
return pp::app::plan_document_layer_highlight(args.layer_count, args.index, args.flag);
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::DocumentLayerOperationPlan>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown layer operation kind"));
|
|
}
|
|
|
|
int plan_layer_operation(int argc, char** argv)
|
|
{
|
|
PlanLayerOperationArgs args;
|
|
const auto status = parse_plan_layer_operation_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-layer-operation", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = make_layer_operation_plan(args);
|
|
if (!plan) {
|
|
print_error("plan-layer-operation", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& value = plan.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-layer-operation\""
|
|
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
|
<< "\",\"layerCount\":" << args.layer_count
|
|
<< ",\"index\":" << args.index
|
|
<< ",\"fromIndex\":" << args.from_index
|
|
<< ",\"toIndex\":" << args.to_index
|
|
<< ",\"sourceIndex\":" << args.source_index
|
|
<< ",\"name\":\"" << json_escape(args.name)
|
|
<< "\",\"opacity\":" << args.opacity
|
|
<< ",\"flag\":" << json_bool(args.flag)
|
|
<< ",\"blendMode\":" << args.blend_mode
|
|
<< "},\"plan\":{\"operation\":\"" << document_layer_operation_name(value.operation)
|
|
<< "\",\"index\":" << value.index
|
|
<< ",\"fromIndex\":" << value.from_index
|
|
<< ",\"toIndex\":" << value.to_index
|
|
<< ",\"insertIndex\":" << value.insert_index
|
|
<< ",\"sourceIndex\":" << value.source_index
|
|
<< ",\"name\":\"" << json_escape(value.name)
|
|
<< "\",\"opacity\":" << value.opacity
|
|
<< ",\"flag\":" << json_bool(value.flag)
|
|
<< ",\"blendMode\":" << value.blend_mode
|
|
<< ",\"mutatesDocument\":" << json_bool(value.mutates_document)
|
|
<< ",\"marksUnsaved\":" << json_bool(value.marks_unsaved)
|
|
<< ",\"reloadsAnimationLayers\":" << json_bool(value.reloads_animation_layers)
|
|
<< ",\"updatesTitle\":" << json_bool(value.updates_title)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_animation_operation_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanAnimationOperationArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--kind") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.kind = argv[++i];
|
|
} else if (key == "--frame-count" || key == "--total-duration" || key == "--current-frame"
|
|
|| key == "--selected-frame" || key == "--current-duration" || key == "--delta"
|
|
|| key == "--offset" || key == "--onion-size") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_i32_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--frame-count") {
|
|
args.frame_count = value.value();
|
|
} else if (key == "--total-duration") {
|
|
args.total_duration = value.value();
|
|
} else if (key == "--current-frame") {
|
|
args.current_frame = value.value();
|
|
} else if (key == "--selected-frame") {
|
|
args.selected_frame = value.value();
|
|
} else if (key == "--current-duration") {
|
|
args.current_duration = value.value();
|
|
} else if (key == "--delta") {
|
|
args.delta = value.value();
|
|
} else if (key == "--offset") {
|
|
args.offset = value.value();
|
|
} else {
|
|
args.onion_size = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::DocumentAnimationOperationPlan> make_animation_operation_plan(
|
|
const PlanAnimationOperationArgs& args)
|
|
{
|
|
if (args.kind == "add") {
|
|
return pp::app::plan_animation_add_frame(args.frame_count, args.current_frame);
|
|
}
|
|
if (args.kind == "duplicate") {
|
|
return pp::app::plan_animation_duplicate_frame(args.frame_count, args.selected_frame);
|
|
}
|
|
if (args.kind == "remove") {
|
|
return pp::app::plan_animation_remove_frame(args.frame_count, args.selected_frame);
|
|
}
|
|
if (args.kind == "duration") {
|
|
return pp::app::plan_animation_adjust_duration(
|
|
args.frame_count,
|
|
args.selected_frame,
|
|
args.current_duration,
|
|
args.delta);
|
|
}
|
|
if (args.kind == "move") {
|
|
return pp::app::plan_animation_move_frame(args.frame_count, args.selected_frame, args.offset);
|
|
}
|
|
if (args.kind == "goto") {
|
|
return pp::app::plan_animation_goto_frame(args.total_duration, args.current_frame);
|
|
}
|
|
if (args.kind == "next") {
|
|
return pp::app::plan_animation_step_frame(args.total_duration, args.current_frame, 1);
|
|
}
|
|
if (args.kind == "prev") {
|
|
return pp::app::plan_animation_step_frame(args.total_duration, args.current_frame, -1);
|
|
}
|
|
if (args.kind == "onion") {
|
|
return pp::app::plan_animation_onion_size(args.onion_size);
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::DocumentAnimationOperationPlan>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown animation operation kind"));
|
|
}
|
|
|
|
int plan_animation_operation(int argc, char** argv)
|
|
{
|
|
PlanAnimationOperationArgs args;
|
|
const auto status = parse_plan_animation_operation_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-animation-operation", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = make_animation_operation_plan(args);
|
|
if (!plan) {
|
|
print_error("plan-animation-operation", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& value = plan.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-animation-operation\""
|
|
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
|
<< "\",\"frameCount\":" << args.frame_count
|
|
<< ",\"totalDuration\":" << args.total_duration
|
|
<< ",\"currentFrame\":" << args.current_frame
|
|
<< ",\"selectedFrame\":" << args.selected_frame
|
|
<< ",\"currentDuration\":" << args.current_duration
|
|
<< ",\"delta\":" << args.delta
|
|
<< ",\"offset\":" << args.offset
|
|
<< ",\"onionSize\":" << args.onion_size
|
|
<< "},\"plan\":{\"operation\":\"" << document_animation_operation_name(value.operation)
|
|
<< "\",\"frameCount\":" << value.frame_count
|
|
<< ",\"currentFrame\":" << value.current_frame
|
|
<< ",\"selectedFrame\":" << value.selected_frame
|
|
<< ",\"targetFrame\":" << value.target_frame
|
|
<< ",\"frameDuration\":" << value.frame_duration
|
|
<< ",\"durationDelta\":" << value.duration_delta
|
|
<< ",\"moveOffset\":" << value.move_offset
|
|
<< ",\"onionSize\":" << value.onion_size
|
|
<< ",\"requiresSelectedFrame\":" << json_bool(value.requires_selected_frame)
|
|
<< ",\"mutatesDocument\":" << json_bool(value.mutates_document)
|
|
<< ",\"reloadsAnimationLayers\":" << json_bool(value.reloads_animation_layers)
|
|
<< ",\"updatesCanvasAnimation\":" << json_bool(value.updates_canvas_animation)
|
|
<< ",\"marksUnsaved\":" << json_bool(value.marks_unsaved)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_brush_operation_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanBrushOperationArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--kind" || key == "--path" || key == "--thumb") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
if (key == "--kind") {
|
|
args.kind = argv[++i];
|
|
} else if (key == "--path") {
|
|
args.path = argv[++i];
|
|
} else {
|
|
args.thumbnail_path = argv[++i];
|
|
}
|
|
} else if (key == "--r" || key == "--g" || key == "--b" || key == "--a") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_float_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--r") {
|
|
args.r = value.value();
|
|
} else if (key == "--g") {
|
|
args.g = value.value();
|
|
} else if (key == "--b") {
|
|
args.b = value.value();
|
|
} else {
|
|
args.a = value.value();
|
|
}
|
|
} else if (key == "--no-brush") {
|
|
args.has_brush = false;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::BrushUiPlan> make_brush_operation_plan(
|
|
const PlanBrushOperationArgs& args)
|
|
{
|
|
if (args.kind == "color") {
|
|
return pp::app::plan_brush_ui_color(args.r, args.g, args.b, args.a);
|
|
}
|
|
if (args.kind == "tip") {
|
|
return pp::app::plan_brush_ui_texture(
|
|
pp::app::BrushUiTextureSlot::tip,
|
|
args.path,
|
|
args.thumbnail_path);
|
|
}
|
|
if (args.kind == "pattern") {
|
|
return pp::app::plan_brush_ui_texture(
|
|
pp::app::BrushUiTextureSlot::pattern,
|
|
args.path,
|
|
args.thumbnail_path);
|
|
}
|
|
if (args.kind == "dual") {
|
|
return pp::app::plan_brush_ui_texture(
|
|
pp::app::BrushUiTextureSlot::dual,
|
|
args.path,
|
|
args.thumbnail_path);
|
|
}
|
|
if (args.kind == "preset") {
|
|
return pp::app::plan_brush_ui_preset_replace(args.has_brush);
|
|
}
|
|
if (args.kind == "settings") {
|
|
return pp::foundation::Result<pp::app::BrushUiPlan>::success(
|
|
pp::app::plan_brush_ui_stroke_settings_changed());
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::BrushUiPlan>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown brush operation kind"));
|
|
}
|
|
|
|
int plan_brush_operation(int argc, char** argv)
|
|
{
|
|
PlanBrushOperationArgs args;
|
|
const auto status = parse_plan_brush_operation_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-brush-operation", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = make_brush_operation_plan(args);
|
|
if (!plan) {
|
|
print_error("plan-brush-operation", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& value = plan.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-brush-operation\""
|
|
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
|
<< "\",\"path\":\"" << json_escape(args.path)
|
|
<< "\",\"thumb\":\"" << json_escape(args.thumbnail_path)
|
|
<< "\",\"r\":" << args.r
|
|
<< ",\"g\":" << args.g
|
|
<< ",\"b\":" << args.b
|
|
<< ",\"a\":" << args.a
|
|
<< ",\"hasBrush\":" << json_bool(args.has_brush)
|
|
<< "},\"plan\":{\"operation\":\"" << brush_ui_operation_name(value.operation)
|
|
<< "\",\"textureSlot\":\"" << brush_ui_texture_slot_name(value.texture_slot)
|
|
<< "\",\"path\":\"" << json_escape(value.path)
|
|
<< "\",\"thumb\":\"" << json_escape(value.thumbnail_path)
|
|
<< "\",\"r\":" << value.r
|
|
<< ",\"g\":" << value.g
|
|
<< ",\"b\":" << value.b
|
|
<< ",\"a\":" << value.a
|
|
<< ",\"mutatesBrush\":" << json_bool(value.mutates_brush)
|
|
<< ",\"preservesExistingColor\":" << json_bool(value.preserves_existing_color)
|
|
<< ",\"loadsBrushResources\":" << json_bool(value.loads_brush_resources)
|
|
<< ",\"updateColorUi\":" << json_bool(value.update_color_ui)
|
|
<< ",\"updateBrushUi\":" << json_bool(value.update_brush_ui)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_canvas_tool_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanCanvasToolArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--kind") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.kind = argv[++i];
|
|
} else if (key == "--current-mode-draw") {
|
|
args.current_mode_draw = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::CanvasToolPlan> make_canvas_tool_plan(const PlanCanvasToolArgs& args)
|
|
{
|
|
if (args.kind == "pick") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_pick_toggle(args.current_mode_draw));
|
|
}
|
|
if (args.kind == "touch-lock") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_touch_lock_toggle());
|
|
}
|
|
if (args.kind == "draw") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::draw));
|
|
}
|
|
if (args.kind == "erase") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::erase));
|
|
}
|
|
if (args.kind == "line") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::line));
|
|
}
|
|
if (args.kind == "camera") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::camera));
|
|
}
|
|
if (args.kind == "grid") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::grid));
|
|
}
|
|
if (args.kind == "copy") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::copy));
|
|
}
|
|
if (args.kind == "cut") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::cut));
|
|
}
|
|
if (args.kind == "fill") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::fill));
|
|
}
|
|
if (args.kind == "mask-free") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::mask_free));
|
|
}
|
|
if (args.kind == "mask-line") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::mask_line));
|
|
}
|
|
if (args.kind == "bucket") {
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::success(
|
|
pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::flood_fill));
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::CanvasToolPlan>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown canvas tool kind"));
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::CanvasToolMode> parse_canvas_tool_mode(std::string_view mode)
|
|
{
|
|
if (mode == "draw") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::draw);
|
|
}
|
|
if (mode == "erase") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::erase);
|
|
}
|
|
if (mode == "line") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::line);
|
|
}
|
|
if (mode == "camera") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::camera);
|
|
}
|
|
if (mode == "grid") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::grid);
|
|
}
|
|
if (mode == "copy") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::copy);
|
|
}
|
|
if (mode == "cut") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::cut);
|
|
}
|
|
if (mode == "fill") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::fill);
|
|
}
|
|
if (mode == "mask-free") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::mask_free);
|
|
}
|
|
if (mode == "mask-line") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::mask_line);
|
|
}
|
|
if (mode == "bucket") {
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::success(pp::app::CanvasToolMode::flood_fill);
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::CanvasToolMode>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown canvas tool mode"));
|
|
}
|
|
|
|
int plan_canvas_tool(int argc, char** argv)
|
|
{
|
|
PlanCanvasToolArgs args;
|
|
const auto status = parse_plan_canvas_tool_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-canvas-tool", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = make_canvas_tool_plan(args);
|
|
if (!plan) {
|
|
print_error("plan-canvas-tool", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& value = plan.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-canvas-tool\""
|
|
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
|
<< "\",\"currentModeDraw\":" << json_bool(args.current_mode_draw)
|
|
<< "},\"plan\":{\"operation\":\"" << canvas_tool_operation_name(value.operation)
|
|
<< "\",\"mode\":\"" << canvas_tool_mode_name(value.mode)
|
|
<< "\",\"transformAction\":\"" << canvas_tool_transform_action_name(value.transform_action)
|
|
<< "\",\"selectsToolbarButton\":" << json_bool(value.selects_toolbar_button)
|
|
<< ",\"updatesCanvasMode\":" << json_bool(value.updates_canvas_mode)
|
|
<< ",\"togglesPicking\":" << json_bool(value.toggles_picking)
|
|
<< ",\"togglesTouchLock\":" << json_bool(value.toggles_touch_lock)
|
|
<< ",\"requiresDrawMode\":" << json_bool(value.requires_draw_mode)
|
|
<< ",\"noOp\":" << json_bool(value.no_op)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_canvas_tool_state_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanCanvasToolStateArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--mode") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.mode = argv[++i];
|
|
} else if (key == "--picking") {
|
|
args.picking = true;
|
|
} else if (key == "--touch-lock") {
|
|
args.touch_lock = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_canvas_tool_state(int argc, char** argv)
|
|
{
|
|
PlanCanvasToolStateArgs args;
|
|
const auto status = parse_plan_canvas_tool_state_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-canvas-tool-state", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto mode = parse_canvas_tool_mode(args.mode);
|
|
if (!mode) {
|
|
print_error("plan-canvas-tool-state", mode.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto state = pp::app::plan_canvas_tool_button_state(
|
|
mode.value(),
|
|
args.picking,
|
|
args.touch_lock);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-canvas-tool-state\""
|
|
<< ",\"state\":{\"mode\":\"" << json_escape(args.mode)
|
|
<< "\",\"picking\":" << json_bool(args.picking)
|
|
<< ",\"touchLock\":" << json_bool(args.touch_lock)
|
|
<< "},\"toolbar\":{\"mode\":\"" << canvas_tool_mode_name(state.mode)
|
|
<< "\",\"pickActive\":" << json_bool(state.pick_active)
|
|
<< ",\"touchLockActive\":" << json_bool(state.touch_lock_active)
|
|
<< ",\"penActive\":" << json_bool(state.pen_active)
|
|
<< ",\"eraseActive\":" << json_bool(state.erase_active)
|
|
<< ",\"lineActive\":" << json_bool(state.line_active)
|
|
<< ",\"cameraActive\":" << json_bool(state.camera_active)
|
|
<< ",\"gridActive\":" << json_bool(state.grid_active)
|
|
<< ",\"copyActive\":" << json_bool(state.copy_active)
|
|
<< ",\"cutActive\":" << json_bool(state.cut_active)
|
|
<< ",\"fillActive\":" << json_bool(state.fill_active)
|
|
<< ",\"maskFreeActive\":" << json_bool(state.mask_free_active)
|
|
<< ",\"maskLineActive\":" << json_bool(state.mask_line_active)
|
|
<< ",\"bucketActive\":" << json_bool(state.flood_fill_active)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_grid_operation_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanGridOperationArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--kind" || key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
if (key == "--kind") {
|
|
args.kind = argv[++i];
|
|
} else {
|
|
args.path = argv[++i];
|
|
}
|
|
} else if (key == "--texture-resolution" || key == "--samples") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_i32_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--texture-resolution") {
|
|
args.texture_resolution = value.value();
|
|
} else {
|
|
args.sample_count = value.value();
|
|
}
|
|
} else if (key == "--no-heightmap") {
|
|
args.has_heightmap = false;
|
|
} else if (key == "--no-canvas") {
|
|
args.has_canvas = false;
|
|
} else if (key == "--float32") {
|
|
args.supports_float32 = true;
|
|
} else if (key == "--float16") {
|
|
args.supports_float16 = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::GridUiPlan> make_grid_operation_plan(const PlanGridOperationArgs& args)
|
|
{
|
|
if (args.kind == "pick") {
|
|
return pp::foundation::Result<pp::app::GridUiPlan>::success(pp::app::plan_grid_heightmap_pick());
|
|
}
|
|
if (args.kind == "load") {
|
|
return pp::app::plan_grid_heightmap_load(args.path);
|
|
}
|
|
if (args.kind == "reload") {
|
|
return pp::app::plan_grid_heightmap_reload(args.path);
|
|
}
|
|
if (args.kind == "clear") {
|
|
return pp::foundation::Result<pp::app::GridUiPlan>::success(
|
|
pp::app::plan_grid_heightmap_clear(args.has_heightmap));
|
|
}
|
|
if (args.kind == "render") {
|
|
return pp::app::plan_grid_lightmap_render(
|
|
args.has_heightmap,
|
|
args.supports_float32,
|
|
args.supports_float16,
|
|
args.texture_resolution,
|
|
args.sample_count);
|
|
}
|
|
if (args.kind == "commit") {
|
|
return pp::foundation::Result<pp::app::GridUiPlan>::success(
|
|
pp::app::plan_grid_heightmap_commit(args.has_canvas));
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::GridUiPlan>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown grid operation kind"));
|
|
}
|
|
|
|
int plan_grid_operation(int argc, char** argv)
|
|
{
|
|
PlanGridOperationArgs args;
|
|
const auto status = parse_plan_grid_operation_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-grid-operation", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = make_grid_operation_plan(args);
|
|
if (!plan) {
|
|
print_error("plan-grid-operation", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& value = plan.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-grid-operation\""
|
|
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
|
<< "\",\"path\":\"" << json_escape(args.path)
|
|
<< "\",\"hasHeightmap\":" << json_bool(args.has_heightmap)
|
|
<< ",\"hasCanvas\":" << json_bool(args.has_canvas)
|
|
<< ",\"float32\":" << json_bool(args.supports_float32)
|
|
<< ",\"float16\":" << json_bool(args.supports_float16)
|
|
<< ",\"textureResolution\":" << args.texture_resolution
|
|
<< ",\"samples\":" << args.sample_count
|
|
<< "},\"plan\":{\"operation\":\"" << grid_ui_operation_name(value.operation)
|
|
<< "\",\"path\":\"" << json_escape(value.path)
|
|
<< "\",\"textureResolution\":" << value.texture_resolution
|
|
<< ",\"sampleCount\":" << value.sample_count
|
|
<< ",\"opensPicker\":" << json_bool(value.opens_picker)
|
|
<< ",\"loadsHeightmap\":" << json_bool(value.loads_heightmap)
|
|
<< ",\"clearsHeightmap\":" << json_bool(value.clears_heightmap)
|
|
<< ",\"rendersLightmap\":" << json_bool(value.renders_lightmap)
|
|
<< ",\"commitsHeightmap\":" << json_bool(value.commits_heightmap)
|
|
<< ",\"updatesPreview\":" << json_bool(value.updates_preview)
|
|
<< ",\"updatesGroundOpacity\":" << json_bool(value.updates_ground_opacity)
|
|
<< ",\"updatesShadingMode\":" << json_bool(value.updates_shading_mode)
|
|
<< ",\"showsUnsupportedMessage\":" << json_bool(value.shows_unsupported_message)
|
|
<< ",\"showsProgress\":" << json_bool(value.shows_progress)
|
|
<< ",\"mutatesGridState\":" << json_bool(value.mutates_grid_state)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_history_operation_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanHistoryOperationArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--kind") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.kind = argv[++i];
|
|
} else if (key == "--undo-count" || key == "--redo-count" || key == "--memory-bytes") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_i32_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--undo-count") {
|
|
args.undo_count = value.value();
|
|
} else if (key == "--redo-count") {
|
|
args.redo_count = value.value();
|
|
} else {
|
|
args.memory_bytes = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::HistoryUiPlan> make_history_operation_plan(
|
|
const PlanHistoryOperationArgs& args)
|
|
{
|
|
if (args.kind == "undo") {
|
|
return pp::app::plan_history_undo(args.undo_count);
|
|
}
|
|
if (args.kind == "redo") {
|
|
return pp::app::plan_history_redo(args.redo_count);
|
|
}
|
|
if (args.kind == "clear") {
|
|
return pp::app::plan_history_clear(args.undo_count, args.redo_count, args.memory_bytes);
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::HistoryUiPlan>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown history operation kind"));
|
|
}
|
|
|
|
int plan_history_operation(int argc, char** argv)
|
|
{
|
|
PlanHistoryOperationArgs args;
|
|
const auto status = parse_plan_history_operation_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-history-operation", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = make_history_operation_plan(args);
|
|
if (!plan) {
|
|
print_error("plan-history-operation", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& value = plan.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-history-operation\""
|
|
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
|
<< "\",\"undoCount\":" << args.undo_count
|
|
<< ",\"redoCount\":" << args.redo_count
|
|
<< ",\"memoryBytes\":" << args.memory_bytes
|
|
<< "},\"plan\":{\"operation\":\"" << history_ui_operation_name(value.operation)
|
|
<< "\",\"undoCount\":" << value.undo_count
|
|
<< ",\"redoCount\":" << value.redo_count
|
|
<< ",\"memoryBytes\":" << value.memory_bytes
|
|
<< ",\"invokesUndo\":" << json_bool(value.invokes_undo)
|
|
<< ",\"invokesRedo\":" << json_bool(value.invokes_redo)
|
|
<< ",\"clearsHistory\":" << json_bool(value.clears_history)
|
|
<< ",\"updatesMemoryLabel\":" << json_bool(value.updates_memory_label)
|
|
<< ",\"updatesTitle\":" << json_bool(value.updates_title)
|
|
<< ",\"noOp\":" << json_bool(value.no_op)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_quick_operation_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanQuickOperationArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--kind") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.kind = argv[++i];
|
|
} else if (key == "--current-index" || key == "--slot-index" || key == "--brush-index"
|
|
|| key == "--color-index" || key == "--slot-count") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const auto value = parse_i32_arg(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
if (key == "--current-index") {
|
|
args.current_index = value.value();
|
|
} else if (key == "--slot-index") {
|
|
args.slot_index = value.value();
|
|
} else if (key == "--brush-index") {
|
|
args.brush_index = value.value();
|
|
} else if (key == "--color-index") {
|
|
args.color_index = value.value();
|
|
} else {
|
|
args.slot_count = value.value();
|
|
}
|
|
} else if (key == "--fire-event") {
|
|
args.fire_event = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
pp::foundation::Result<pp::app::QuickUiPlan> make_quick_operation_plan(
|
|
const PlanQuickOperationArgs& args)
|
|
{
|
|
if (args.kind == "brush") {
|
|
return pp::app::plan_quick_slot_click(
|
|
pp::app::QuickUiSlotKind::brush,
|
|
args.current_index,
|
|
args.slot_index,
|
|
args.slot_count);
|
|
}
|
|
if (args.kind == "color") {
|
|
return pp::app::plan_quick_slot_click(
|
|
pp::app::QuickUiSlotKind::color,
|
|
args.current_index,
|
|
args.slot_index,
|
|
args.slot_count);
|
|
}
|
|
if (args.kind == "restore") {
|
|
return pp::app::plan_quick_state_restore(
|
|
args.brush_index,
|
|
args.color_index,
|
|
args.slot_count,
|
|
args.fire_event);
|
|
}
|
|
if (args.kind == "reset") {
|
|
return pp::app::plan_quick_state_reset(args.slot_count, args.fire_event);
|
|
}
|
|
|
|
return pp::foundation::Result<pp::app::QuickUiPlan>::failure(
|
|
pp::foundation::Status::invalid_argument("unknown quick operation kind"));
|
|
}
|
|
|
|
int plan_quick_operation(int argc, char** argv)
|
|
{
|
|
PlanQuickOperationArgs args;
|
|
const auto status = parse_plan_quick_operation_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-quick-operation", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto plan = make_quick_operation_plan(args);
|
|
if (!plan) {
|
|
print_error("plan-quick-operation", plan.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& value = plan.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-quick-operation\""
|
|
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
|
<< "\",\"currentIndex\":" << args.current_index
|
|
<< ",\"slotIndex\":" << args.slot_index
|
|
<< ",\"brushIndex\":" << args.brush_index
|
|
<< ",\"colorIndex\":" << args.color_index
|
|
<< ",\"slotCount\":" << args.slot_count
|
|
<< ",\"fireEvent\":" << json_bool(args.fire_event)
|
|
<< "},\"plan\":{\"operation\":\"" << quick_ui_operation_name(value.operation)
|
|
<< "\",\"slotKind\":\"" << quick_ui_slot_kind_name(value.slot_kind)
|
|
<< "\",\"slotIndex\":" << value.slot_index
|
|
<< ",\"previousIndex\":" << value.previous_index
|
|
<< ",\"slotCount\":" << value.slot_count
|
|
<< ",\"fireEvent\":" << json_bool(value.fire_event)
|
|
<< ",\"updatesSelection\":" << json_bool(value.updates_selection)
|
|
<< ",\"opensBrushPopup\":" << json_bool(value.opens_brush_popup)
|
|
<< ",\"opensColorPicker\":" << json_bool(value.opens_color_picker)
|
|
<< ",\"invokesChangeCallback\":" << json_bool(value.invokes_change_callback)
|
|
<< ",\"restoresSlots\":" << json_bool(value.restores_slots)
|
|
<< ",\"resetsSlots\":" << json_bool(value.resets_slots)
|
|
<< ",\"redrawsBrushPreviews\":" << json_bool(value.redraws_brush_previews)
|
|
<< ",\"mutatesQuickState\":" << json_bool(value.mutates_quick_state)
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_share_file_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanShareFileArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_share_file(int argc, char** argv)
|
|
{
|
|
PlanShareFileArgs args;
|
|
const auto status = parse_plan_share_file_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-share-file", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decision = pp::app::plan_document_share(args.path);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-share-file\""
|
|
<< ",\"state\":{\"path\":\"" << json_escape(args.path)
|
|
<< "\"},\"decision\":\"" << document_share_action_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_picked_path_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanPickedPathArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_picked_path(int argc, char** argv)
|
|
{
|
|
PlanPickedPathArgs args;
|
|
const auto status = parse_plan_picked_path_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-picked-path", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decision = pp::app::plan_picked_path(args.path);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-picked-path\""
|
|
<< ",\"state\":{\"path\":\"" << json_escape(args.path)
|
|
<< "\"},\"decision\":\"" << picked_path_action_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_display_file_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanDisplayFileArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_display_file(int argc, char** argv)
|
|
{
|
|
PlanDisplayFileArgs args;
|
|
const auto status = parse_plan_display_file_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-display-file", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decision = pp::app::plan_display_file(args.path);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-display-file\""
|
|
<< ",\"state\":{\"path\":\"" << json_escape(args.path)
|
|
<< "\"},\"decision\":\"" << display_file_action_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_keyboard_visibility_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanKeyboardVisibilityArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--visible") {
|
|
args.visible = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_keyboard_visibility(int argc, char** argv)
|
|
{
|
|
PlanKeyboardVisibilityArgs args;
|
|
const auto status = parse_plan_keyboard_visibility_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-keyboard-visibility", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decision = pp::app::plan_virtual_keyboard(args.visible);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-keyboard-visibility\""
|
|
<< ",\"state\":{\"visible\":" << json_bool(args.visible)
|
|
<< "},\"decision\":\"" << virtual_keyboard_action_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_cursor_visibility_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanCursorVisibilityArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--visible") {
|
|
args.visible = true;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_cursor_visibility(int argc, char** argv)
|
|
{
|
|
PlanCursorVisibilityArgs args;
|
|
const auto status = parse_plan_cursor_visibility_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-cursor-visibility", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decision = pp::app::plan_cursor_visibility(args.visible);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-cursor-visibility\""
|
|
<< ",\"state\":{\"visible\":" << json_bool(args.visible)
|
|
<< "},\"decision\":\"" << cursor_visibility_action_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
int plan_clipboard_read(int, char**)
|
|
{
|
|
const auto decision = pp::app::plan_clipboard_read();
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-clipboard-read\""
|
|
<< ",\"decision\":\"" << clipboard_read_action_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_clipboard_write_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanClipboardWriteArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--text") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
args.text = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_clipboard_write(int argc, char** argv)
|
|
{
|
|
PlanClipboardWriteArgs args;
|
|
const auto status = parse_plan_clipboard_write_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-clipboard-write", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decision = pp::app::plan_clipboard_write(args.text);
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-clipboard-write\""
|
|
<< ",\"state\":{\"text\":\"" << json_escape(args.text)
|
|
<< "\"},\"decision\":\"" << clipboard_write_action_name(decision)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_plan_export_target_args(
|
|
int argc,
|
|
char** argv,
|
|
PlanExportTargetArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
auto read_value = [&](std::string& output) -> pp::foundation::Status {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
output = argv[++i];
|
|
return pp::foundation::Status::success();
|
|
};
|
|
|
|
if (key == "--kind") {
|
|
const auto status = read_value(args.kind);
|
|
if (!status.ok()) {
|
|
return status;
|
|
}
|
|
} else if (key == "--work-dir") {
|
|
const auto status = read_value(args.work_directory);
|
|
if (!status.ok()) {
|
|
return status;
|
|
}
|
|
} else if (key == "--directory") {
|
|
const auto status = read_value(args.directory);
|
|
if (!status.ok()) {
|
|
return status;
|
|
}
|
|
} else if (key == "--doc-name") {
|
|
const auto status = read_value(args.document_name);
|
|
if (!status.ok()) {
|
|
return status;
|
|
}
|
|
} else if (key == "--extension") {
|
|
const auto status = read_value(args.extension);
|
|
if (!status.ok()) {
|
|
return status;
|
|
}
|
|
} else if (key == "--suffix") {
|
|
const auto status = read_value(args.suffix);
|
|
if (!status.ok()) {
|
|
return status;
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.kind.empty()) {
|
|
return pp::foundation::Status::invalid_argument("kind must not be empty");
|
|
}
|
|
|
|
if (args.document_name.empty()) {
|
|
return pp::foundation::Status::invalid_argument("document name must not be empty");
|
|
}
|
|
|
|
if ((args.kind == "file" || args.kind == "collection") && args.work_directory.empty()) {
|
|
return pp::foundation::Status::invalid_argument("work directory must not be empty");
|
|
}
|
|
|
|
if (args.kind == "stem" && args.directory.empty()) {
|
|
return pp::foundation::Status::invalid_argument("directory must not be empty");
|
|
}
|
|
|
|
if (args.kind == "file" && args.extension.empty()) {
|
|
return pp::foundation::Status::invalid_argument("extension must not be empty");
|
|
}
|
|
|
|
if ((args.kind == "collection" || args.kind == "name") && args.suffix.empty()) {
|
|
return pp::foundation::Status::invalid_argument("suffix must not be empty");
|
|
}
|
|
|
|
if (args.kind != "file" && args.kind != "collection" && args.kind != "stem" && args.kind != "name") {
|
|
return pp::foundation::Status::invalid_argument("unknown export target kind");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int plan_export_target(int argc, char** argv)
|
|
{
|
|
PlanExportTargetArgs args;
|
|
const auto status = parse_plan_export_target_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("plan-export-target", status.message);
|
|
return 2;
|
|
}
|
|
|
|
if (args.kind == "file") {
|
|
const auto target = pp::app::make_document_export_file_target(
|
|
args.work_directory,
|
|
args.document_name,
|
|
args.extension);
|
|
if (!target) {
|
|
print_error("plan-export-target", target.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-export-target\""
|
|
<< ",\"kind\":\"file\",\"target\":{\"path\":\"" << json_escape(target.value().path)
|
|
<< "\",\"suggestedName\":\"" << json_escape(target.value().suggested_name)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
if (args.kind == "collection") {
|
|
const auto target = pp::app::make_document_export_collection_target(
|
|
args.work_directory,
|
|
args.document_name,
|
|
args.suffix);
|
|
if (!target) {
|
|
print_error("plan-export-target", target.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-export-target\""
|
|
<< ",\"kind\":\"collection\",\"target\":{\"directory\":\"" << json_escape(target.value().directory)
|
|
<< "\",\"stemPath\":\"" << json_escape(target.value().stem_path)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
if (args.kind == "stem") {
|
|
const auto target = pp::app::make_document_export_stem_target(args.directory, args.document_name);
|
|
if (!target) {
|
|
print_error("plan-export-target", target.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-export-target\""
|
|
<< ",\"kind\":\"stem\",\"target\":{\"stemPath\":\"" << json_escape(target.value().stem_path)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
const auto target = pp::app::make_document_export_suggested_name(args.document_name, args.suffix);
|
|
if (!target) {
|
|
print_error("plan-export-target", target.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"plan-export-target\""
|
|
<< ",\"kind\":\"name\",\"target\":{\"suggestedName\":\"" << json_escape(target.value().name)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_simulate_app_session_args(
|
|
int argc,
|
|
char** argv,
|
|
SimulateAppSessionArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--new-document") {
|
|
args.new_document = true;
|
|
} else if (key == "--no-canvas") {
|
|
args.has_canvas = false;
|
|
} else if (key == "--unsaved") {
|
|
args.unsaved = true;
|
|
} else if (key == "--close-prompt-open") {
|
|
args.close_prompt_open = true;
|
|
} else if (key == "--save-intent") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
const std::string_view value(argv[++i]);
|
|
if (value == "save") {
|
|
args.save_intent = pp::app::DocumentSaveIntent::save;
|
|
} else if (value == "save-as") {
|
|
args.save_intent = pp::app::DocumentSaveIntent::save_as;
|
|
} else if (value == "save-version") {
|
|
args.save_intent = pp::app::DocumentSaveIntent::save_version;
|
|
} else if (value == "save-dirty-version") {
|
|
args.save_intent = pp::app::DocumentSaveIntent::save_dirty_version;
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown save intent");
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int simulate_app_session(int argc, char** argv)
|
|
{
|
|
SimulateAppSessionArgs args;
|
|
const auto status = parse_simulate_app_session_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("simulate-app-session", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto open_decision = pp::app::plan_project_open(args.unsaved);
|
|
const auto close_decision = pp::app::plan_close_request(args.unsaved, args.close_prompt_open);
|
|
const auto save_decision = pp::app::plan_document_save(
|
|
args.new_document,
|
|
args.unsaved,
|
|
args.save_intent);
|
|
const auto workflow_decision = pp::app::plan_document_workflow(args.has_canvas, args.unsaved);
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-app-session\""
|
|
<< ",\"state\":{\"hasCanvas\":" << json_bool(args.has_canvas)
|
|
<< ",\"newDocument\":" << json_bool(args.new_document)
|
|
<< ",\"unsaved\":" << json_bool(args.unsaved)
|
|
<< ",\"closePromptOpen\":" << json_bool(args.close_prompt_open)
|
|
<< "},\"decisions\":{\"projectOpen\":\""
|
|
<< project_open_decision_name(open_decision)
|
|
<< "\",\"closeRequest\":\""
|
|
<< close_request_decision_name(close_decision)
|
|
<< "\",\"saveIntent\":\""
|
|
<< document_save_intent_name(args.save_intent)
|
|
<< "\",\"saveRequest\":\""
|
|
<< document_save_decision_name(save_decision)
|
|
<< "\",\"workflowStart\":\""
|
|
<< document_workflow_decision_name(workflow_decision)
|
|
<< "\"}}\n";
|
|
return 0;
|
|
}
|
|
|
|
int inspect_project(int argc, char** argv)
|
|
{
|
|
InspectProjectArgs args;
|
|
const auto status = parse_inspect_project_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("inspect-project", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::ifstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("inspect-project", "project file could not be opened");
|
|
return 2;
|
|
}
|
|
|
|
const std::vector<char> chars {
|
|
std::istreambuf_iterator<char>(stream),
|
|
std::istreambuf_iterator<char>()
|
|
};
|
|
const auto* data = reinterpret_cast<const std::byte*>(chars.data());
|
|
const auto project = pp::assets::parse_ppi_project_index(std::span<const std::byte>(data, chars.size()));
|
|
if (!project) {
|
|
print_error("inspect-project", project.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"inspect-project\""
|
|
<< ",\"documentVersion\":\"" << project.value().layout.header.document_version.major
|
|
<< "." << project.value().layout.header.document_version.minor << "\""
|
|
<< ",\"softwareVersion\":\"" << project.value().layout.header.software_version.major
|
|
<< "." << project.value().layout.header.software_version.minor
|
|
<< "." << project.value().layout.header.software_version.fix
|
|
<< "." << project.value().layout.header.software_version.build << "\""
|
|
<< ",\"thumbnail\":{\"width\":" << project.value().layout.header.thumbnail.width
|
|
<< ",\"height\":" << project.value().layout.header.thumbnail.height
|
|
<< ",\"components\":" << project.value().layout.header.thumbnail.components
|
|
<< ",\"bytes\":" << project.value().layout.thumbnail_bytes
|
|
<< "},\"body\":{\"offset\":" << project.value().layout.body_offset
|
|
<< ",\"bytes\":" << project.value().layout.body_bytes
|
|
<< ",\"width\":" << project.value().body.summary.width
|
|
<< ",\"height\":" << project.value().body.summary.height
|
|
<< ",\"layers\":" << project.value().body.summary.layer_count
|
|
<< ",\"frames\":" << project.value().body.summary.declared_frame_count
|
|
<< ",\"dirtyFaces\":" << project.value().body.summary.dirty_face_count
|
|
<< ",\"rgbaFacePayloads\":" << project.value().body.summary.rgba_face_payload_count
|
|
<< ",\"compressedBytes\":" << project.value().body.summary.compressed_face_bytes
|
|
<< ",\"infoBytes\":" << project.value().body.summary.info_bytes
|
|
<< "},\"layers\":[";
|
|
for (std::size_t layer_index = 0; layer_index < project.value().body.layers.size(); ++layer_index) {
|
|
const auto& layer = project.value().body.layers[layer_index];
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << "{\"index\":" << layer_index
|
|
<< ",\"storedOrder\":" << layer.stored_order
|
|
<< ",\"name\":\"" << json_escape(layer.name) << "\""
|
|
<< ",\"opacity\":" << layer.opacity
|
|
<< ",\"blendMode\":" << layer.blend_mode
|
|
<< ",\"alphaLocked\":" << (layer.alpha_locked ? "true" : "false")
|
|
<< ",\"visible\":" << (layer.visible ? "true" : "false")
|
|
<< ",\"frames\":[";
|
|
for (std::size_t frame_index = 0; frame_index < layer.frames.size(); ++frame_index) {
|
|
const auto& frame = layer.frames[frame_index];
|
|
if (frame_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << "{\"index\":" << frame_index
|
|
<< ",\"durationMs\":" << frame.duration_ms
|
|
<< ",\"dirtyFaces\":[";
|
|
bool first_face = true;
|
|
for (std::size_t face_index = 0; face_index < frame.faces.size(); ++face_index) {
|
|
const auto& face = frame.faces[face_index];
|
|
if (!face.has_data) {
|
|
continue;
|
|
}
|
|
if (!first_face) {
|
|
std::cout << ",";
|
|
}
|
|
first_face = false;
|
|
std::cout << "{\"face\":" << face_index
|
|
<< ",\"box\":[" << face.x0 << "," << face.y0 << "," << face.x1 << "," << face.y1 << "]"
|
|
<< ",\"bodyPayloadOffset\":" << face.body_payload_offset
|
|
<< ",\"bytes\":" << face.payload_bytes
|
|
<< ",\"png\":{\"width\":" << face.png_width
|
|
<< ",\"height\":" << face.png_height
|
|
<< "}}";
|
|
}
|
|
std::cout << "]}";
|
|
}
|
|
std::cout << "]}";
|
|
}
|
|
std::cout << "]}\n";
|
|
return 0;
|
|
}
|
|
|
|
int load_project(int argc, char** argv)
|
|
{
|
|
InspectProjectArgs args;
|
|
const auto status = parse_inspect_project_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("load-project", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::ifstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("load-project", "project file could not be opened");
|
|
return 2;
|
|
}
|
|
|
|
const std::string chars {
|
|
std::istreambuf_iterator<char>(stream),
|
|
std::istreambuf_iterator<char>()
|
|
};
|
|
const auto* data = reinterpret_cast<const std::byte*>(chars.data());
|
|
const auto project = pp::assets::decode_ppi_project_images(std::span<const std::byte>(data, chars.size()));
|
|
if (!project) {
|
|
print_error("load-project", project.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto document_result = pp::document::import_ppi_project_document(project.value());
|
|
if (!document_result) {
|
|
print_error("load-project", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& document = document_result.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"load-project\""
|
|
<< ",\"source\":\"ppi\""
|
|
<< ",\"pixelDataLoaded\":" << (document.face_pixel_payload_count() > 0U ? "true" : "false")
|
|
<< ",\"facePayloads\":" << document.face_pixel_payload_count()
|
|
<< ",\"document\":{\"width\":" << document.width()
|
|
<< ",\"height\":" << document.height()
|
|
<< ",\"layers\":" << document.layers().size()
|
|
<< ",\"frames\":" << document.frames().size()
|
|
<< ",\"animationDurationMs\":" << document.animation_duration_ms()
|
|
<< ",\"layerNames\":[";
|
|
for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << "\"" << json_escape(document.layers()[layer_index].name) << "\"";
|
|
}
|
|
std::cout << "],\"layerFrameCounts\":[";
|
|
for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << document.layers()[layer_index].frames.size();
|
|
}
|
|
std::cout << "],\"layerDurationsMs\":[";
|
|
for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
const auto duration = document.layer_animation_duration_ms(layer_index);
|
|
std::cout << (duration ? duration.value() : 0U);
|
|
}
|
|
std::cout << "],\"layerOpacities\":[";
|
|
for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << document.layers()[layer_index].opacity;
|
|
}
|
|
std::cout << "],\"layerBlendModes\":[";
|
|
for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << "\"" << pp::paint::blend_mode_name(document.layers()[layer_index].blend_mode) << "\"";
|
|
}
|
|
std::cout << "],\"layerAlphaLocked\":[";
|
|
for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << (document.layers()[layer_index].alpha_locked ? "true" : "false");
|
|
}
|
|
std::cout << "],\"layerVisible\":[";
|
|
for (std::size_t layer_index = 0; layer_index < document.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << (document.layers()[layer_index].visible ? "true" : "false");
|
|
}
|
|
std::cout << "]}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_simulate_stroke_args(int argc, char** argv, SimulateStrokeArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--x1" || key == "--y1" || key == "--x2" || key == "--y2" || key == "--spacing") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--x1") {
|
|
args.x1 = value.value();
|
|
} else if (key == "--y1") {
|
|
args.y1 = value.value();
|
|
} else if (key == "--x2") {
|
|
args.x2 = value.value();
|
|
} else if (key == "--y2") {
|
|
args.y2 = value.value();
|
|
} else {
|
|
args.spacing = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.spacing == 0) {
|
|
return pp::foundation::Status::invalid_argument("stroke spacing must be greater than zero");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int simulate_stroke(int argc, char** argv)
|
|
{
|
|
SimulateStrokeArgs args;
|
|
const auto status = parse_simulate_stroke_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("simulate-stroke", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const pp::paint::StrokePoint points[] {
|
|
pp::paint::StrokePoint {
|
|
.x = static_cast<float>(args.x1),
|
|
.y = static_cast<float>(args.y1),
|
|
.pressure = 1.0F,
|
|
},
|
|
pp::paint::StrokePoint {
|
|
.x = static_cast<float>(args.x2),
|
|
.y = static_cast<float>(args.y2),
|
|
.pressure = 1.0F,
|
|
},
|
|
};
|
|
const auto samples = pp::paint::sample_stroke(
|
|
points,
|
|
pp::paint::StrokeSamplingConfig {
|
|
.spacing = static_cast<float>(args.spacing),
|
|
});
|
|
if (!samples) {
|
|
print_error("simulate-stroke", samples.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& first = samples.value().front();
|
|
const auto& last = samples.value().back();
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-stroke\""
|
|
<< ",\"samples\":" << samples.value().size()
|
|
<< ",\"first\":{\"x\":" << first.x << ",\"y\":" << first.y << "}"
|
|
<< ",\"last\":{\"x\":" << last.x << ",\"y\":" << last.y
|
|
<< ",\"distance\":" << last.distance << "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_simulate_stroke_script_args(int argc, char** argv, SimulateStrokeScriptArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int simulate_stroke_script(int argc, char** argv)
|
|
{
|
|
SimulateStrokeScriptArgs args;
|
|
const auto status = parse_simulate_stroke_script_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("simulate-stroke-script", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::ifstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("simulate-stroke-script", "stroke script file could not be opened");
|
|
return 2;
|
|
}
|
|
|
|
const std::string text {
|
|
std::istreambuf_iterator<char>(stream),
|
|
std::istreambuf_iterator<char>()
|
|
};
|
|
const auto script = pp::paint::parse_stroke_script(text);
|
|
if (!script) {
|
|
print_error("simulate-stroke-script", script.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::size_t total_samples = 0;
|
|
float total_distance = 0.0F;
|
|
for (const auto& stroke : script.value().strokes) {
|
|
const pp::paint::StrokePoint points[] { stroke.start, stroke.end };
|
|
const auto samples = pp::paint::sample_stroke(
|
|
points,
|
|
pp::paint::StrokeSamplingConfig {
|
|
.spacing = stroke.spacing,
|
|
});
|
|
if (!samples) {
|
|
print_error("simulate-stroke-script", samples.status().message);
|
|
return 2;
|
|
}
|
|
|
|
total_samples += samples.value().size();
|
|
total_distance += samples.value().back().distance;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-stroke-script\""
|
|
<< ",\"strokes\":" << script.value().strokes.size()
|
|
<< ",\"samples\":" << total_samples
|
|
<< ",\"distance\":" << total_distance << "}\n";
|
|
return 0;
|
|
}
|
|
|
|
int simulate_blend(int argc, char**)
|
|
{
|
|
if (argc > 2) {
|
|
print_error("simulate-blend", "unknown option");
|
|
return 2;
|
|
}
|
|
|
|
const auto normal = pp::paint::blend_pixels(
|
|
pp::paint::Rgba { .r = 0.2F, .g = 0.4F, .b = 0.6F, .a = 0.5F },
|
|
pp::paint::Rgba { .r = 0.8F, .g = 0.2F, .b = 0.1F, .a = 0.25F },
|
|
pp::paint::BlendMode::normal);
|
|
const auto multiply = pp::paint::blend_pixels(
|
|
pp::paint::Rgba { .r = 0.25F, .g = 0.5F, .b = 0.75F, .a = 1.0F },
|
|
pp::paint::Rgba { .r = 0.5F, .g = 0.5F, .b = 0.5F, .a = 1.0F },
|
|
pp::paint::BlendMode::multiply);
|
|
const auto stroke_normal = pp::paint::blend_stroke_alpha(
|
|
0.2F,
|
|
0.8F,
|
|
0.25F,
|
|
pp::paint::StrokeBlendMode::normal);
|
|
const auto stroke_linear_height = pp::paint::blend_stroke_alpha(
|
|
0.5F,
|
|
0.25F,
|
|
0.16F,
|
|
pp::paint::StrokeBlendMode::linear_height);
|
|
const auto stroke_height = pp::paint::blend_stroke_alpha(
|
|
0.5F,
|
|
0.25F,
|
|
0.16F,
|
|
pp::paint::StrokeBlendMode::height);
|
|
const auto stroke_unknown = pp::paint::blend_stroke_alpha(
|
|
0.2F,
|
|
0.2F,
|
|
0.5F,
|
|
static_cast<pp::paint::StrokeBlendMode>(255));
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-blend\""
|
|
<< ",\"finalBlendModes\":5"
|
|
<< ",\"strokeBlendModes\":11"
|
|
<< ",\"normal\":{\"r\":" << normal.r
|
|
<< ",\"g\":" << normal.g
|
|
<< ",\"b\":" << normal.b
|
|
<< ",\"a\":" << normal.a
|
|
<< "}"
|
|
<< ",\"multiply\":{\"r\":" << multiply.r
|
|
<< ",\"g\":" << multiply.g
|
|
<< ",\"b\":" << multiply.b
|
|
<< ",\"a\":" << multiply.a
|
|
<< "}"
|
|
<< ",\"stroke\":{\"normal\":" << stroke_normal
|
|
<< ",\"linearHeight\":" << stroke_linear_height
|
|
<< ",\"height\":" << stroke_height
|
|
<< ",\"unknown\":" << stroke_unknown
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_apply_stroke_script_args(int argc, char** argv, ApplyStrokeScriptArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path" || key == "--output") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
if (key == "--path") {
|
|
args.path = argv[++i];
|
|
} else {
|
|
args.output_path = argv[++i];
|
|
}
|
|
} else if (key == "--width" || key == "--height") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else {
|
|
args.height = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty() || args.output_path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path and output must not be empty");
|
|
}
|
|
|
|
if (args.width < 8 || args.height < 8 || args.width > 4096 || args.height > 4096) {
|
|
return pp::foundation::Status::out_of_range("width and height must be between 8 and 4096");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
std::uint8_t pressure_to_alpha(float pressure) noexcept
|
|
{
|
|
const auto normalized = std::clamp(pressure, 0.0F, 1.0F);
|
|
const auto alpha = static_cast<int>(std::lround(normalized * 255.0F));
|
|
return static_cast<std::uint8_t>(std::clamp(alpha, 1, 255));
|
|
}
|
|
|
|
std::uint32_t clamp_sample_coordinate(float value, std::uint32_t limit) noexcept
|
|
{
|
|
if (limit == 0U) {
|
|
return 0;
|
|
}
|
|
|
|
const auto rounded = static_cast<int>(std::lround(value));
|
|
const auto clamped = std::clamp(rounded, 0, static_cast<int>(limit - 1U));
|
|
return static_cast<std::uint32_t>(clamped);
|
|
}
|
|
|
|
int apply_stroke_script(int argc, char** argv)
|
|
{
|
|
ApplyStrokeScriptArgs args;
|
|
const auto status = parse_apply_stroke_script_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("apply-stroke-script", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::ifstream script_stream(args.path, std::ios::binary);
|
|
if (!script_stream) {
|
|
print_error("apply-stroke-script", "stroke script file could not be opened");
|
|
return 2;
|
|
}
|
|
|
|
const std::string text {
|
|
std::istreambuf_iterator<char>(script_stream),
|
|
std::istreambuf_iterator<char>()
|
|
};
|
|
const auto script = pp::paint::parse_stroke_script(text);
|
|
if (!script) {
|
|
print_error("apply-stroke-script", script.status().message);
|
|
return 2;
|
|
}
|
|
|
|
struct AppliedPoint {
|
|
std::uint32_t x = 0;
|
|
std::uint32_t y = 0;
|
|
std::uint32_t stroke_index = 0;
|
|
float pressure = 1.0F;
|
|
};
|
|
|
|
std::vector<AppliedPoint> applied_points;
|
|
std::vector<std::size_t> samples_per_stroke;
|
|
std::size_t total_samples = 0;
|
|
float total_distance = 0.0F;
|
|
std::uint32_t x0 = args.width;
|
|
std::uint32_t y0 = args.height;
|
|
std::uint32_t x1 = 0;
|
|
std::uint32_t y1 = 0;
|
|
|
|
for (std::size_t stroke_index = 0; stroke_index < script.value().strokes.size(); ++stroke_index) {
|
|
const auto& stroke = script.value().strokes[stroke_index];
|
|
const pp::paint::StrokePoint points[] { stroke.start, stroke.end };
|
|
const auto samples = pp::paint::sample_stroke(
|
|
points,
|
|
pp::paint::StrokeSamplingConfig {
|
|
.spacing = stroke.spacing,
|
|
});
|
|
if (!samples) {
|
|
print_error("apply-stroke-script", samples.status().message);
|
|
return 2;
|
|
}
|
|
|
|
samples_per_stroke.push_back(samples.value().size());
|
|
total_samples += samples.value().size();
|
|
total_distance += samples.value().back().distance;
|
|
for (const auto& sample : samples.value()) {
|
|
const auto x = clamp_sample_coordinate(sample.x, args.width);
|
|
const auto y = clamp_sample_coordinate(sample.y, args.height);
|
|
x0 = std::min(x0, x);
|
|
y0 = std::min(y0, y);
|
|
x1 = std::max(x1, x);
|
|
y1 = std::max(y1, y);
|
|
applied_points.push_back(AppliedPoint {
|
|
.x = x,
|
|
.y = y,
|
|
.stroke_index = static_cast<std::uint32_t>(stroke_index),
|
|
.pressure = sample.pressure,
|
|
});
|
|
}
|
|
}
|
|
|
|
if (applied_points.empty()) {
|
|
print_error("apply-stroke-script", "stroke script produced no samples");
|
|
return 2;
|
|
}
|
|
|
|
const auto payload_width = x1 - x0 + 1U;
|
|
const auto payload_height = y1 - y0 + 1U;
|
|
std::vector<std::uint8_t> rgba8(
|
|
static_cast<std::size_t>(payload_width) * payload_height * pp::document::rgba8_components,
|
|
0);
|
|
for (std::size_t point_index = 0; point_index < applied_points.size(); ++point_index) {
|
|
const auto& point = applied_points[point_index];
|
|
const auto local_x = point.x - x0;
|
|
const auto local_y = point.y - y0;
|
|
const auto pixel_index = (static_cast<std::size_t>(local_y) * payload_width + local_x)
|
|
* pp::document::rgba8_components;
|
|
rgba8[pixel_index + 0U] = static_cast<std::uint8_t>(64U + ((point.stroke_index * 53U) % 192U));
|
|
rgba8[pixel_index + 1U] = static_cast<std::uint8_t>((point_index * 31U) % 256U);
|
|
rgba8[pixel_index + 2U] = static_cast<std::uint8_t>(255U - ((point.stroke_index * 29U) % 192U));
|
|
rgba8[pixel_index + 3U] = pressure_to_alpha(point.pressure);
|
|
}
|
|
|
|
const auto document_result = pp::document::CanvasDocument::create(
|
|
pp::document::DocumentConfig {
|
|
.width = args.width,
|
|
.height = args.height,
|
|
.layer_count = 1,
|
|
});
|
|
if (!document_result) {
|
|
print_error("apply-stroke-script", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
auto document = document_result.value();
|
|
auto edit_status = document.rename_layer(0, "Stroke Script");
|
|
if (!edit_status.ok()) {
|
|
print_error("apply-stroke-script", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
edit_status = document.set_layer_frame_face_pixels(
|
|
0,
|
|
0,
|
|
pp::document::LayerFacePixels {
|
|
.face_index = 0,
|
|
.x = x0,
|
|
.y = y0,
|
|
.width = payload_width,
|
|
.height = payload_height,
|
|
.rgba8 = std::move(rgba8),
|
|
});
|
|
if (!edit_status.ok()) {
|
|
print_error("apply-stroke-script", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto exported = pp::document::export_ppi_project_document(document);
|
|
if (!exported) {
|
|
print_error("apply-stroke-script", exported.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::ofstream output_stream(args.output_path, std::ios::binary);
|
|
if (!output_stream) {
|
|
print_error("apply-stroke-script", "project file could not be opened for writing");
|
|
return 2;
|
|
}
|
|
|
|
const auto& bytes = exported.value();
|
|
output_stream.write(reinterpret_cast<const char*>(bytes.data()), static_cast<std::streamsize>(bytes.size()));
|
|
if (!output_stream) {
|
|
print_error("apply-stroke-script", "project file could not be written");
|
|
return 2;
|
|
}
|
|
|
|
const auto decoded = pp::assets::decode_ppi_project_images(bytes);
|
|
if (!decoded) {
|
|
print_error("apply-stroke-script", decoded.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"apply-stroke-script\""
|
|
<< ",\"path\":\"" << json_escape(args.path) << "\""
|
|
<< ",\"output\":\"" << json_escape(args.output_path) << "\""
|
|
<< ",\"strokes\":" << script.value().strokes.size()
|
|
<< ",\"samples\":" << total_samples
|
|
<< ",\"distance\":" << total_distance
|
|
<< ",\"samplesPerStroke\":[";
|
|
for (std::size_t stroke_index = 0; stroke_index < samples_per_stroke.size(); ++stroke_index) {
|
|
if (stroke_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << samples_per_stroke[stroke_index];
|
|
}
|
|
std::cout << "],\"document\":{\"width\":" << document.width()
|
|
<< ",\"height\":" << document.height()
|
|
<< ",\"layers\":" << document.layers().size()
|
|
<< ",\"frames\":" << document.frames().size()
|
|
<< ",\"facePayloads\":" << document.face_pixel_payload_count()
|
|
<< "},\"payload\":{\"face\":0"
|
|
<< ",\"box\":[" << x0 << "," << y0 << "," << (x1 + 1U) << "," << (y1 + 1U) << "]"
|
|
<< ",\"width\":" << payload_width
|
|
<< ",\"height\":" << payload_height
|
|
<< ",\"bytes\":" << document.layers()[0].frames[0].face_pixels[0].rgba8.size()
|
|
<< "},\"export\":{\"bytes\":" << bytes.size()
|
|
<< ",\"dirtyFaces\":" << decoded.value().project.body.summary.dirty_face_count
|
|
<< ",\"rgbaFacePayloads\":" << decoded.value().project.body.summary.rgba_face_payload_count
|
|
<< ",\"compressedBytes\":" << decoded.value().project.body.summary.compressed_face_bytes
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_simulate_document_edits_args(
|
|
int argc,
|
|
char** argv,
|
|
SimulateDocumentEditsArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--width" || key == "--height") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else {
|
|
args.height = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
const auto render_target_size = pp::renderer::texture_byte_size(pp::renderer::TextureDesc {
|
|
.extent = pp::renderer::Extent2D { .width = args.width, .height = args.height },
|
|
.format = pp::renderer::TextureFormat::rgba8,
|
|
.usage = pp::renderer::TextureUsage::render_target | pp::renderer::TextureUsage::sampled | pp::renderer::TextureUsage::upload_destination | pp::renderer::TextureUsage::readback_source | pp::renderer::TextureUsage::copy_source | pp::renderer::TextureUsage::copy_destination,
|
|
.debug_name = "record-render-texture",
|
|
});
|
|
if (!render_target_size) {
|
|
return render_target_size.status();
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int simulate_document_edits(int argc, char** argv)
|
|
{
|
|
SimulateDocumentEditsArgs args;
|
|
const auto status = parse_simulate_document_edits_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("simulate-document-edits", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto document_result = pp::document::CanvasDocument::create(
|
|
pp::document::DocumentConfig {
|
|
.width = args.width,
|
|
.height = args.height,
|
|
.layer_count = 1,
|
|
});
|
|
if (!document_result) {
|
|
print_error("simulate-document-edits", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
auto document = document_result.value();
|
|
auto edit_status = document.set_frame_duration(0, 100);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto layer_result = document.add_layer("Paint");
|
|
if (!layer_result) {
|
|
print_error("simulate-document-edits", layer_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const std::size_t paint_layer = layer_result.value();
|
|
edit_status = document.rename_layer(paint_layer, "Ink");
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
edit_status = document.set_layer_visible(paint_layer, false);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
edit_status = document.set_layer_alpha_locked(paint_layer, true);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
edit_status = document.set_layer_opacity(paint_layer, 0.625F);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
edit_status = document.set_layer_blend_mode(paint_layer, pp::paint::BlendMode::overlay);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
edit_status = document.set_active_layer(paint_layer);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto duplicated_frame = document.duplicate_frame(0);
|
|
if (!duplicated_frame) {
|
|
print_error("simulate-document-edits", duplicated_frame.status().message);
|
|
return 2;
|
|
}
|
|
edit_status = document.set_frame_duration(duplicated_frame.value(), 333);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto added_frame = document.add_frame(250);
|
|
if (!added_frame) {
|
|
print_error("simulate-document-edits", added_frame.status().message);
|
|
return 2;
|
|
}
|
|
edit_status = document.move_frame(added_frame.value(), 0);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
edit_status = document.move_layer(paint_layer, 0);
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
edit_status = document.set_layer_frame_face_pixels(
|
|
0,
|
|
0,
|
|
pp::document::LayerFacePixels {
|
|
.face_index = 2,
|
|
.x = 1,
|
|
.y = 2,
|
|
.width = 1,
|
|
.height = 1,
|
|
.rgba8 = { 255, 0, 0, 255 },
|
|
});
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
edit_status = document.set_selection_mask(pp::document::SelectionMask {
|
|
.face_index = 4,
|
|
.x = 3,
|
|
.y = 5,
|
|
.width = 2,
|
|
.height = 2,
|
|
.alpha8 = { 0, 64, 128, 255 },
|
|
});
|
|
if (!edit_status.ok()) {
|
|
print_error("simulate-document-edits", edit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& active_layer = document.layers()[document.active_layer_index()];
|
|
const auto& selection_mask = document.selection_masks()[0];
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-document-edits\""
|
|
<< ",\"document\":{\"width\":" << document.width()
|
|
<< ",\"height\":" << document.height()
|
|
<< ",\"layers\":" << document.layers().size()
|
|
<< ",\"frames\":" << document.frames().size()
|
|
<< ",\"activeLayer\":" << document.active_layer_index()
|
|
<< ",\"activeFrame\":" << document.active_frame_index()
|
|
<< ",\"animationDurationMs\":" << document.animation_duration_ms()
|
|
<< ",\"facePayloads\":" << document.face_pixel_payload_count()
|
|
<< ",\"selectionMasks\":" << document.selection_mask_payload_count()
|
|
<< "},\"activeLayer\":{\"name\":\"" << json_escape(active_layer.name)
|
|
<< "\",\"visible\":" << (active_layer.visible ? "true" : "false")
|
|
<< ",\"alphaLocked\":" << (active_layer.alpha_locked ? "true" : "false")
|
|
<< ",\"opacity\":" << active_layer.opacity
|
|
<< ",\"blendMode\":\"" << pp::paint::blend_mode_name(active_layer.blend_mode)
|
|
<< "\",\"frames\":" << active_layer.frames.size()
|
|
<< "},\"frames\":[";
|
|
for (std::size_t frame_index = 0; frame_index < document.frames().size(); ++frame_index) {
|
|
if (frame_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << document.frames()[frame_index].duration_ms;
|
|
}
|
|
std::cout << "],\"activeLayerFrameDurations\":[";
|
|
for (std::size_t frame_index = 0; frame_index < active_layer.frames.size(); ++frame_index) {
|
|
if (frame_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << active_layer.frames[frame_index].duration_ms;
|
|
}
|
|
std::cout << "],\"selectionMask\":{\"face\":" << selection_mask.face_index
|
|
<< ",\"x\":" << selection_mask.x
|
|
<< ",\"y\":" << selection_mask.y
|
|
<< ",\"width\":" << selection_mask.width
|
|
<< ",\"height\":" << selection_mask.height
|
|
<< ",\"bytes\":" << selection_mask.alpha8.size()
|
|
<< ",\"maxAlpha\":" << static_cast<int>(selection_mask.alpha8.back())
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_simulate_image_import_args(
|
|
int argc,
|
|
char** argv,
|
|
SimulateImageImportArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--width" || key == "--height") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else {
|
|
args.height = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int simulate_image_import(int argc, char** argv)
|
|
{
|
|
SimulateImageImportArgs args;
|
|
const auto status = parse_simulate_image_import_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("simulate-image-import", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto image_result = pp::assets::decode_png_rgba8(transparent_png_1x1_bytes());
|
|
if (!image_result) {
|
|
print_error("simulate-image-import", image_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto document_result = pp::document::CanvasDocument::create(
|
|
pp::document::DocumentConfig {
|
|
.width = args.width,
|
|
.height = args.height,
|
|
.layer_count = 1,
|
|
});
|
|
if (!document_result) {
|
|
print_error("simulate-image-import", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& image = image_result.value();
|
|
auto document = document_result.value();
|
|
const auto import_status = document.set_layer_frame_face_pixels(
|
|
0,
|
|
0,
|
|
pp::document::LayerFacePixels {
|
|
.face_index = 0,
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = image.width,
|
|
.height = image.height,
|
|
.rgba8 = image.pixels,
|
|
});
|
|
if (!import_status.ok()) {
|
|
print_error("simulate-image-import", import_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& payload = document.layers()[0].frames[0].face_pixels[0];
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-image-import\""
|
|
<< ",\"image\":{\"format\":\"png\",\"width\":" << image.width
|
|
<< ",\"height\":" << image.height
|
|
<< ",\"bytes\":" << image.pixels.size()
|
|
<< ",\"alpha\":" << static_cast<int>(image.pixels[3])
|
|
<< "},\"document\":{\"width\":" << document.width()
|
|
<< ",\"height\":" << document.height()
|
|
<< ",\"layers\":" << document.layers().size()
|
|
<< ",\"frames\":" << document.frames().size()
|
|
<< ",\"facePayloads\":" << document.face_pixel_payload_count()
|
|
<< "},\"payload\":{\"face\":" << payload.face_index
|
|
<< ",\"x\":" << payload.x
|
|
<< ",\"y\":" << payload.y
|
|
<< ",\"width\":" << payload.width
|
|
<< ",\"height\":" << payload.height
|
|
<< ",\"bytes\":" << payload.rgba8.size()
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_simulate_document_export_args(
|
|
int argc,
|
|
char** argv,
|
|
SimulateDocumentExportArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--width" || key == "--height") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else {
|
|
args.height = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
if (args.width < 8 || args.height < 8) {
|
|
return pp::foundation::Status::out_of_range("width and height must be at least 8 for export simulation");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int simulate_document_export(int argc, char** argv)
|
|
{
|
|
SimulateDocumentExportArgs args;
|
|
const auto status = parse_simulate_document_export_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("simulate-document-export", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto document_result = create_export_sample_document(args.width, args.height);
|
|
if (!document_result) {
|
|
print_error("simulate-document-export", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto exported = pp::document::export_ppi_project_document(document_result.value());
|
|
if (!exported) {
|
|
print_error("simulate-document-export", exported.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto decoded = pp::assets::decode_ppi_project_images(exported.value());
|
|
if (!decoded) {
|
|
print_error("simulate-document-export", decoded.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto imported = pp::document::import_ppi_project_document(decoded.value());
|
|
if (!imported) {
|
|
print_error("simulate-document-export", imported.status().message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& source = document_result.value();
|
|
const auto& roundtrip = imported.value();
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-document-export\""
|
|
<< ",\"source\":{\"width\":" << source.width()
|
|
<< ",\"height\":" << source.height()
|
|
<< ",\"layers\":" << source.layers().size()
|
|
<< ",\"frames\":" << source.frames().size()
|
|
<< ",\"facePayloads\":" << source.face_pixel_payload_count()
|
|
<< "},\"export\":{\"bytes\":" << exported.value().size()
|
|
<< ",\"dirtyFaces\":" << decoded.value().project.body.summary.dirty_face_count
|
|
<< ",\"rgbaFacePayloads\":" << decoded.value().project.body.summary.rgba_face_payload_count
|
|
<< ",\"compressedBytes\":" << decoded.value().project.body.summary.compressed_face_bytes
|
|
<< "},\"roundtrip\":{\"layers\":" << roundtrip.layers().size()
|
|
<< ",\"frames\":" << roundtrip.frames().size()
|
|
<< ",\"facePayloads\":" << roundtrip.face_pixel_payload_count()
|
|
<< ",\"layerNames\":[";
|
|
for (std::size_t layer_index = 0; layer_index < roundtrip.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << "\"" << json_escape(roundtrip.layers()[layer_index].name) << "\"";
|
|
}
|
|
std::cout << "],\"layerFrameCounts\":[";
|
|
for (std::size_t layer_index = 0; layer_index < roundtrip.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << roundtrip.layers()[layer_index].frames.size();
|
|
}
|
|
std::cout << "],\"layerDurationsMs\":[";
|
|
for (std::size_t layer_index = 0; layer_index < roundtrip.layers().size(); ++layer_index) {
|
|
if (layer_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
const auto duration = roundtrip.layer_animation_duration_ms(layer_index);
|
|
std::cout << (duration ? duration.value() : 0U);
|
|
}
|
|
std::cout << "]},\"payloads\":[";
|
|
for (std::size_t payload_index = 0; payload_index < decoded.value().faces.size(); ++payload_index) {
|
|
const auto& payload = decoded.value().faces[payload_index];
|
|
if (payload_index != 0U) {
|
|
std::cout << ",";
|
|
}
|
|
std::cout << "{\"layer\":" << payload.layer_index
|
|
<< ",\"frame\":" << payload.frame_index
|
|
<< ",\"face\":" << payload.face_index
|
|
<< ",\"x\":" << payload.descriptor.x0
|
|
<< ",\"y\":" << payload.descriptor.y0
|
|
<< ",\"bytes\":" << payload.image.pixels.size()
|
|
<< ",\"alpha\":" << static_cast<int>(payload.image.pixels[3])
|
|
<< "}";
|
|
}
|
|
std::cout << "]}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_simulate_document_history_args(
|
|
int argc,
|
|
char** argv,
|
|
SimulateDocumentHistoryArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--width" || key == "--height" || key == "--history") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else if (key == "--height") {
|
|
args.height = value.value();
|
|
} else {
|
|
args.history_entries = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int simulate_document_history(int argc, char** argv)
|
|
{
|
|
SimulateDocumentHistoryArgs args;
|
|
const auto status = parse_simulate_document_history_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("simulate-document-history", status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto document_result = pp::document::CanvasDocument::create(
|
|
pp::document::DocumentConfig {
|
|
.width = args.width,
|
|
.height = args.height,
|
|
.layer_count = 1,
|
|
});
|
|
if (!document_result) {
|
|
print_error("simulate-document-history", document_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
auto history_result = pp::document::DocumentHistory::create(
|
|
document_result.value(),
|
|
static_cast<std::size_t>(args.history_entries));
|
|
if (!history_result) {
|
|
print_error("simulate-document-history", history_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
auto history = history_result.value();
|
|
auto with_layer = history.current();
|
|
const auto layer_result = with_layer.add_layer("Paint");
|
|
if (!layer_result) {
|
|
print_error("simulate-document-history", layer_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
auto apply_status = history.apply(with_layer);
|
|
if (!apply_status.ok()) {
|
|
print_error("simulate-document-history", apply_status.message);
|
|
return 2;
|
|
}
|
|
|
|
auto with_frame = history.current();
|
|
const auto frame_result = with_frame.add_frame(250);
|
|
if (!frame_result) {
|
|
print_error("simulate-document-history", frame_result.status().message);
|
|
return 2;
|
|
}
|
|
|
|
apply_status = history.apply(with_frame);
|
|
if (!apply_status.ok()) {
|
|
print_error("simulate-document-history", apply_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto undo_status = history.undo();
|
|
if (!undo_status.ok()) {
|
|
print_error("simulate-document-history", undo_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto undo_layers = history.current().layers().size();
|
|
const auto undo_frames = history.current().frames().size();
|
|
const auto undo_can_redo = history.can_redo();
|
|
const auto undo_index = history.current_index();
|
|
|
|
const auto redo_status = history.redo();
|
|
if (!redo_status.ok()) {
|
|
print_error("simulate-document-history", redo_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto& current = history.current();
|
|
std::cout << "{\"ok\":true,\"command\":\"simulate-document-history\""
|
|
<< ",\"history\":{\"size\":" << history.size()
|
|
<< ",\"currentIndex\":" << history.current_index()
|
|
<< ",\"canUndo\":" << (history.can_undo() ? "true" : "false")
|
|
<< ",\"canRedo\":" << (history.can_redo() ? "true" : "false")
|
|
<< "},\"undo\":{\"layers\":" << undo_layers
|
|
<< ",\"frames\":" << undo_frames
|
|
<< ",\"currentIndex\":" << undo_index
|
|
<< ",\"canRedo\":" << (undo_can_redo ? "true" : "false")
|
|
<< "},\"current\":{\"width\":" << current.width()
|
|
<< ",\"height\":" << current.height()
|
|
<< ",\"layers\":" << current.layers().size()
|
|
<< ",\"frames\":" << current.frames().size()
|
|
<< ",\"activeLayer\":" << current.active_layer_index()
|
|
<< ",\"activeFrame\":" << current.active_frame_index()
|
|
<< ",\"animationDurationMs\":" << current.animation_duration_ms()
|
|
<< "}}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_record_render_args(int argc, char** argv, RecordRenderArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--exercise-clear") {
|
|
args.exercise_clear = true;
|
|
} else if (key == "--width" || key == "--height") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
const auto value = pp::foundation::parse_u32(argv[++i]);
|
|
if (!value) {
|
|
return value.status();
|
|
}
|
|
|
|
if (key == "--width") {
|
|
args.width = value.value();
|
|
} else {
|
|
args.height = value.value();
|
|
}
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.width == 0 || args.height == 0) {
|
|
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int record_render(int argc, char** argv)
|
|
{
|
|
RecordRenderArgs args;
|
|
const auto status = parse_record_render_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("record-render", status.message);
|
|
return 2;
|
|
}
|
|
|
|
pp::renderer::RecordingRenderDevice device;
|
|
const auto texture = device.create_texture(pp::renderer::TextureDesc {
|
|
.extent = pp::renderer::Extent2D { .width = args.width, .height = args.height },
|
|
.format = pp::renderer::TextureFormat::rgba8,
|
|
.usage = pp::renderer::TextureUsage::render_target | pp::renderer::TextureUsage::sampled | pp::renderer::TextureUsage::upload_destination | pp::renderer::TextureUsage::readback_source | pp::renderer::TextureUsage::copy_source | pp::renderer::TextureUsage::copy_destination,
|
|
.debug_name = "record-render-texture",
|
|
});
|
|
const auto target = device.create_render_target(pp::renderer::TextureDesc {
|
|
.extent = pp::renderer::Extent2D { .width = args.width, .height = args.height },
|
|
.format = pp::renderer::TextureFormat::rgba8,
|
|
.usage = pp::renderer::TextureUsage::render_target | pp::renderer::TextureUsage::sampled | pp::renderer::TextureUsage::upload_destination | pp::renderer::TextureUsage::readback_source | pp::renderer::TextureUsage::copy_source | pp::renderer::TextureUsage::copy_destination,
|
|
.debug_name = "record-render-target",
|
|
});
|
|
const auto blit_target = device.create_render_target(pp::renderer::TextureDesc {
|
|
.extent = pp::renderer::Extent2D { .width = args.width, .height = args.height },
|
|
.format = pp::renderer::TextureFormat::rgba8,
|
|
.usage = pp::renderer::TextureUsage::render_target | pp::renderer::TextureUsage::sampled | pp::renderer::TextureUsage::upload_destination | pp::renderer::TextureUsage::readback_source | pp::renderer::TextureUsage::copy_source | pp::renderer::TextureUsage::copy_destination,
|
|
.debug_name = "record-render-blit-target",
|
|
});
|
|
const auto mip_texture = device.create_texture(pp::renderer::TextureDesc {
|
|
.extent = pp::renderer::Extent2D { .width = 4, .height = 4 },
|
|
.format = pp::renderer::TextureFormat::rgba8,
|
|
.mip_levels = 3,
|
|
.usage = pp::renderer::TextureUsage::sampled | pp::renderer::TextureUsage::copy_source | pp::renderer::TextureUsage::copy_destination,
|
|
.debug_name = "record-render-mip-texture",
|
|
});
|
|
const auto readback_buffer = device.create_readback_buffer(
|
|
static_cast<std::uint64_t>(args.width) * args.height * 4U);
|
|
const std::array<std::byte, 4> upload_pixel {
|
|
std::byte { 0xff },
|
|
std::byte { 0x00 },
|
|
std::byte { 0xff },
|
|
std::byte { 0xff },
|
|
};
|
|
const std::array<std::byte, 64> uniform_mvp {};
|
|
static constexpr char shader_source[] = "void main() {}";
|
|
const auto shader = device.create_shader_program(pp::renderer::ShaderProgramDesc {
|
|
.debug_name = "pano-cli-record-render",
|
|
.vertex = pp::renderer::ShaderStageSource {
|
|
.source = shader_source,
|
|
.source_size = sizeof(shader_source) - 1U,
|
|
},
|
|
.fragment = pp::renderer::ShaderStageSource {
|
|
.source = shader_source,
|
|
.source_size = sizeof(shader_source) - 1U,
|
|
},
|
|
});
|
|
const auto mesh = device.create_mesh(pp::renderer::MeshDesc {
|
|
.vertex_count = 3,
|
|
.index_count = 3,
|
|
.topology = pp::renderer::PrimitiveTopology::triangles,
|
|
.debug_name = "record-render-mesh",
|
|
});
|
|
|
|
if (!texture.ok()) {
|
|
print_error("record-render", texture.status().message);
|
|
return 2;
|
|
}
|
|
if (!target.ok()) {
|
|
print_error("record-render", target.status().message);
|
|
return 2;
|
|
}
|
|
if (!blit_target.ok()) {
|
|
print_error("record-render", blit_target.status().message);
|
|
return 2;
|
|
}
|
|
if (!mip_texture.ok()) {
|
|
print_error("record-render", mip_texture.status().message);
|
|
return 2;
|
|
}
|
|
if (!readback_buffer.ok()) {
|
|
print_error("record-render", readback_buffer.status().message);
|
|
return 2;
|
|
}
|
|
if (!shader.ok()) {
|
|
print_error("record-render", shader.status().message);
|
|
return 2;
|
|
}
|
|
if (!mesh.ok()) {
|
|
print_error("record-render", mesh.status().message);
|
|
return 2;
|
|
}
|
|
constexpr std::size_t created_resources = 7;
|
|
|
|
auto* trace = device.trace();
|
|
auto& context = device.immediate_context();
|
|
bool clear_rejected_orphaned_trace_end = false;
|
|
bool clear_reused_render_pass = false;
|
|
if (args.exercise_clear) {
|
|
const auto interrupted_trace_status = trace->begin_scope("renderer", "interrupted-frame");
|
|
if (!interrupted_trace_status.ok()) {
|
|
print_error("record-render", interrupted_trace_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto interrupted_begin_status = context.begin_render_pass(*target.value(), pp::renderer::RenderPassDesc {});
|
|
if (!interrupted_begin_status.ok()) {
|
|
print_error("record-render", interrupted_begin_status.message);
|
|
return 2;
|
|
}
|
|
|
|
device.clear();
|
|
const auto stale_trace_end_status = trace->end_scope();
|
|
if (stale_trace_end_status.ok()) {
|
|
print_error("record-render", "recording clear did not reset trace scope state");
|
|
return 2;
|
|
}
|
|
clear_rejected_orphaned_trace_end = true;
|
|
|
|
const auto reuse_begin_status = context.begin_render_pass(*target.value(), pp::renderer::RenderPassDesc {});
|
|
if (!reuse_begin_status.ok()) {
|
|
print_error("record-render", reuse_begin_status.message);
|
|
return 2;
|
|
}
|
|
context.end_render_pass();
|
|
clear_reused_render_pass = true;
|
|
device.clear();
|
|
}
|
|
|
|
const auto trace_begin_status = trace->begin_scope("renderer", "pano_cli_record_render");
|
|
if (!trace_begin_status.ok()) {
|
|
print_error("record-render", trace_begin_status.message);
|
|
return 2;
|
|
}
|
|
const auto trace_marker_status = trace->marker("renderer", "frame");
|
|
if (!trace_marker_status.ok()) {
|
|
print_error("record-render", trace_marker_status.message);
|
|
return 2;
|
|
}
|
|
const auto trace_end_status = trace->end_scope();
|
|
if (!trace_end_status.ok()) {
|
|
print_error("record-render", trace_end_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto transition_upload_status = context.transition_texture(
|
|
*texture.value(),
|
|
pp::renderer::TextureState::undefined,
|
|
pp::renderer::TextureState::upload_destination);
|
|
if (!transition_upload_status.ok()) {
|
|
print_error("record-render", transition_upload_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto upload_status = context.upload_texture(
|
|
*texture.value(),
|
|
pp::renderer::ReadbackRegion {
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = 1,
|
|
.height = 1,
|
|
},
|
|
upload_pixel);
|
|
if (!upload_status.ok()) {
|
|
print_error("record-render", upload_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto transition_shader_read_status = context.transition_texture(
|
|
*texture.value(),
|
|
pp::renderer::TextureState::upload_destination,
|
|
pp::renderer::TextureState::shader_read);
|
|
if (!transition_shader_read_status.ok()) {
|
|
print_error("record-render", transition_shader_read_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto transition_mip_destination_status = context.transition_texture(
|
|
*mip_texture.value(),
|
|
pp::renderer::TextureState::undefined,
|
|
pp::renderer::TextureState::copy_destination);
|
|
if (!transition_mip_destination_status.ok()) {
|
|
print_error("record-render", transition_mip_destination_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto mipmap_status = context.generate_mipmaps(*mip_texture.value());
|
|
if (!mipmap_status.ok()) {
|
|
print_error("record-render", mipmap_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto transition_mip_shader_read_status = context.transition_texture(
|
|
*mip_texture.value(),
|
|
pp::renderer::TextureState::copy_destination,
|
|
pp::renderer::TextureState::shader_read);
|
|
if (!transition_mip_shader_read_status.ok()) {
|
|
print_error("record-render", transition_mip_shader_read_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto begin_status = context.begin_render_pass(
|
|
*target.value(),
|
|
pp::renderer::RenderPassDesc {
|
|
.clear_color = pp::renderer::ClearColor { .r = 0.0F, .g = 0.0F, .b = 0.0F, .a = 1.0F },
|
|
.clear_depth_enabled = true,
|
|
.clear_depth = 1.0F,
|
|
});
|
|
if (!begin_status.ok()) {
|
|
print_error("record-render", begin_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto viewport_status = context.set_viewport(
|
|
pp::renderer::Viewport { .x = 0, .y = 0, .width = args.width, .height = args.height });
|
|
if (!viewport_status.ok()) {
|
|
print_error("record-render", viewport_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto scissor_status = context.set_scissor(pp::renderer::ScissorRect {
|
|
.enabled = true,
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = args.width,
|
|
.height = args.height,
|
|
});
|
|
if (!scissor_status.ok()) {
|
|
print_error("record-render", scissor_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto shader_status = context.bind_shader(*shader.value());
|
|
const auto uniform_status = context.set_shader_uniform("mvp", uniform_mvp);
|
|
const auto blend_status = context.set_blend_state(pp::renderer::BlendState {
|
|
.enabled = true,
|
|
.source_color = pp::renderer::BlendFactor::source_alpha,
|
|
.destination_color = pp::renderer::BlendFactor::one_minus_source_alpha,
|
|
.source_alpha = pp::renderer::BlendFactor::one,
|
|
.destination_alpha = pp::renderer::BlendFactor::one_minus_source_alpha,
|
|
});
|
|
const auto depth_status = context.set_depth_state(pp::renderer::DepthState {
|
|
.test_enabled = true,
|
|
.write_enabled = true,
|
|
.compare = pp::renderer::CompareOp::less_or_equal,
|
|
});
|
|
const auto bind_texture_status = context.bind_texture(0, *texture.value());
|
|
const auto bind_sampler_status = context.bind_sampler(0, pp::renderer::SamplerDesc {
|
|
.min_filter = pp::renderer::SamplerFilter::linear,
|
|
.mag_filter = pp::renderer::SamplerFilter::linear,
|
|
.mip_filter = pp::renderer::SamplerFilter::linear,
|
|
.address_u = pp::renderer::SamplerAddressMode::clamp_to_edge,
|
|
.address_v = pp::renderer::SamplerAddressMode::clamp_to_edge,
|
|
.address_w = pp::renderer::SamplerAddressMode::clamp_to_edge,
|
|
});
|
|
const auto mesh_status = context.bind_mesh(*mesh.value());
|
|
const auto draw_status = context.draw(pp::renderer::DrawDesc {
|
|
.vertex_count = 3,
|
|
.index_count = 3,
|
|
});
|
|
context.end_render_pass();
|
|
|
|
if (!shader_status.ok()) {
|
|
print_error("record-render", shader_status.message);
|
|
return 2;
|
|
}
|
|
if (!uniform_status.ok()) {
|
|
print_error("record-render", uniform_status.message);
|
|
return 2;
|
|
}
|
|
if (!blend_status.ok()) {
|
|
print_error("record-render", blend_status.message);
|
|
return 2;
|
|
}
|
|
if (!depth_status.ok()) {
|
|
print_error("record-render", depth_status.message);
|
|
return 2;
|
|
}
|
|
if (!bind_texture_status.ok()) {
|
|
print_error("record-render", bind_texture_status.message);
|
|
return 2;
|
|
}
|
|
if (!bind_sampler_status.ok()) {
|
|
print_error("record-render", bind_sampler_status.message);
|
|
return 2;
|
|
}
|
|
if (!mesh_status.ok()) {
|
|
print_error("record-render", mesh_status.message);
|
|
return 2;
|
|
}
|
|
if (!draw_status.ok()) {
|
|
print_error("record-render", draw_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto readback_status = context.read_texture(
|
|
*texture.value(),
|
|
pp::renderer::ReadbackRegion {
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = args.width,
|
|
.height = args.height,
|
|
},
|
|
*readback_buffer.value());
|
|
if (!readback_status.ok()) {
|
|
print_error("record-render", readback_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto copy_status = context.copy_texture(
|
|
*texture.value(),
|
|
pp::renderer::ReadbackRegion {
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = args.width,
|
|
.height = args.height,
|
|
},
|
|
*texture.value(),
|
|
pp::renderer::ReadbackRegion {
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = args.width,
|
|
.height = args.height,
|
|
});
|
|
if (!copy_status.ok()) {
|
|
print_error("record-render", copy_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto capture_status = context.capture_frame(*target.value(), *readback_buffer.value());
|
|
if (!capture_status.ok()) {
|
|
print_error("record-render", capture_status.message);
|
|
return 2;
|
|
}
|
|
|
|
const auto blit_status = context.blit_render_target(
|
|
*target.value(),
|
|
pp::renderer::ReadbackRegion {
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = args.width,
|
|
.height = args.height,
|
|
},
|
|
*blit_target.value(),
|
|
pp::renderer::ReadbackRegion {
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = args.width,
|
|
.height = args.height,
|
|
},
|
|
pp::renderer::BlitFilter::nearest);
|
|
if (!blit_status.ok()) {
|
|
print_error("record-render", blit_status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::size_t draw_commands = 0;
|
|
std::size_t scissor_commands = 0;
|
|
std::size_t blend_commands = 0;
|
|
std::size_t depth_commands = 0;
|
|
std::size_t uniform_commands = 0;
|
|
std::size_t bind_texture_commands = 0;
|
|
std::size_t bind_sampler_commands = 0;
|
|
std::size_t upload_commands = 0;
|
|
std::size_t mipmap_commands = 0;
|
|
std::size_t transition_commands = 0;
|
|
std::size_t transition_to_upload = 0;
|
|
std::size_t transition_to_shader_read = 0;
|
|
std::size_t copy_commands = 0;
|
|
std::size_t readback_commands = 0;
|
|
std::size_t capture_commands = 0;
|
|
std::size_t blit_commands = 0;
|
|
std::size_t trace_markers = 0;
|
|
std::size_t trace_begin_scopes = 0;
|
|
std::size_t trace_end_scopes = 0;
|
|
std::size_t render_passes = 0;
|
|
std::size_t depth_clears = 0;
|
|
std::size_t stencil_clears = 0;
|
|
std::uint64_t draw_vertices = 0;
|
|
std::uint64_t draw_indices = 0;
|
|
std::uint64_t uniform_bytes = 0;
|
|
std::uint64_t upload_bytes = 0;
|
|
std::uint64_t mipmap_levels = 0;
|
|
std::uint64_t mipmap_bytes = 0;
|
|
std::uint64_t copy_source_bytes = 0;
|
|
std::uint64_t copy_destination_bytes = 0;
|
|
std::uint64_t bound_texture_bytes = 0;
|
|
std::uint64_t readback_bytes = 0;
|
|
std::uint64_t capture_bytes = 0;
|
|
std::uint64_t blit_source_bytes = 0;
|
|
std::uint64_t blit_destination_bytes = 0;
|
|
std::size_t labeled_command_descriptors = 0;
|
|
const auto count_label = [&labeled_command_descriptors](const char* label) {
|
|
if (label != nullptr && label[0] != '\0') {
|
|
++labeled_command_descriptors;
|
|
}
|
|
};
|
|
const auto commands = device.commands();
|
|
const auto features = device.features();
|
|
#ifdef PP_PANO_CLI_ENABLE_OPENGL_PLAN
|
|
const auto open_gl_plan = pp::renderer::gl::plan_recorded_render_commands(commands);
|
|
#endif
|
|
for (const auto& command : commands) {
|
|
if (command.kind == pp::renderer::RecordedRenderCommandKind::begin_render_pass) {
|
|
++render_passes;
|
|
count_label(command.target_desc.debug_name);
|
|
if (command.clear_depth_enabled) {
|
|
++depth_clears;
|
|
}
|
|
if (command.clear_stencil_enabled) {
|
|
++stencil_clears;
|
|
}
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::draw) {
|
|
++draw_commands;
|
|
count_label(command.mesh_desc.debug_name);
|
|
draw_vertices += command.draw_desc.vertex_count;
|
|
draw_indices += command.draw_desc.index_count;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::set_scissor) {
|
|
++scissor_commands;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::set_blend_state) {
|
|
++blend_commands;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::set_depth_state) {
|
|
++depth_commands;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::set_shader_uniform) {
|
|
++uniform_commands;
|
|
uniform_bytes += command.uniform_bytes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::bind_texture) {
|
|
++bind_texture_commands;
|
|
count_label(command.texture_desc.debug_name);
|
|
const auto bound_bytes = pp::renderer::texture_byte_size(command.texture_desc);
|
|
if (bound_bytes.ok()) {
|
|
bound_texture_bytes += bound_bytes.value();
|
|
}
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::bind_sampler) {
|
|
++bind_sampler_commands;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::bind_mesh) {
|
|
count_label(command.mesh_desc.debug_name);
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::generate_mipmaps) {
|
|
++mipmap_commands;
|
|
count_label(command.texture_desc.debug_name);
|
|
mipmap_levels += command.generated_mip_levels;
|
|
mipmap_bytes += command.generated_mip_bytes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::transition_texture) {
|
|
++transition_commands;
|
|
count_label(command.texture_desc.debug_name);
|
|
if (command.after_state == pp::renderer::TextureState::upload_destination) {
|
|
++transition_to_upload;
|
|
}
|
|
if (command.after_state == pp::renderer::TextureState::shader_read) {
|
|
++transition_to_shader_read;
|
|
}
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::upload_texture) {
|
|
++upload_commands;
|
|
count_label(command.texture_desc.debug_name);
|
|
upload_bytes += command.upload_bytes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::copy_texture) {
|
|
++copy_commands;
|
|
count_label(command.source_desc.debug_name);
|
|
count_label(command.destination_desc.debug_name);
|
|
copy_source_bytes += command.copy_source_bytes;
|
|
copy_destination_bytes += command.copy_destination_bytes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::read_texture) {
|
|
++readback_commands;
|
|
count_label(command.texture_desc.debug_name);
|
|
readback_bytes += command.readback_bytes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::capture_frame) {
|
|
++capture_commands;
|
|
count_label(command.target_desc.debug_name);
|
|
capture_bytes += command.capture_bytes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::blit_render_target) {
|
|
++blit_commands;
|
|
count_label(command.source_desc.debug_name);
|
|
count_label(command.destination_desc.debug_name);
|
|
blit_source_bytes += command.blit_source_bytes;
|
|
blit_destination_bytes += command.blit_destination_bytes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::trace_marker) {
|
|
++trace_markers;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::trace_begin_scope) {
|
|
++trace_begin_scopes;
|
|
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::trace_end_scope) {
|
|
++trace_end_scopes;
|
|
}
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"record-render\""
|
|
<< ",\"backend\":\"" << device.backend_name() << "\""
|
|
<< ",\"features\":{\"framebufferFetch\":" << json_bool(features.framebuffer_fetch)
|
|
<< ",\"explicitTextureTransitions\":" << json_bool(features.explicit_texture_transitions)
|
|
<< ",\"textureCopy\":" << json_bool(features.texture_copy)
|
|
<< ",\"renderTargetBlit\":" << json_bool(features.render_target_blit)
|
|
<< ",\"frameCapture\":" << json_bool(features.frame_capture)
|
|
<< ",\"float16RenderTargets\":" << json_bool(features.float16_render_targets)
|
|
<< ",\"float32RenderTargets\":" << json_bool(features.float32_render_targets)
|
|
<< "}"
|
|
<< ",\"target\":{\"width\":" << args.width
|
|
<< ",\"height\":" << args.height
|
|
<< ",\"format\":\"rgba8\"}"
|
|
<< ",\"createdResources\":" << created_resources
|
|
<< ",\"exercisedClearReset\":" << json_bool(args.exercise_clear)
|
|
<< ",\"clearRejectedOrphanedTraceEnd\":" << json_bool(clear_rejected_orphaned_trace_end)
|
|
<< ",\"clearReusedRenderPass\":" << json_bool(clear_reused_render_pass)
|
|
<< ",\"labeledCommandDescriptors\":" << labeled_command_descriptors
|
|
<< ",\"commands\":" << commands.size()
|
|
#ifdef PP_PANO_CLI_ENABLE_OPENGL_PLAN
|
|
<< ",\"openGlPlan\":{\"available\":true"
|
|
<< ",\"supported\":" << json_bool(open_gl_plan.supported)
|
|
<< ",\"commands\":" << open_gl_plan.commands.size()
|
|
<< ",\"renderPasses\":" << open_gl_plan.render_pass_count
|
|
<< ",\"drawCommands\":" << open_gl_plan.draw_command_count
|
|
<< ",\"shaderBindCommands\":" << open_gl_plan.shader_bind_command_count
|
|
<< ",\"uniformCommands\":" << open_gl_plan.uniform_command_count
|
|
<< ",\"textureBindCommands\":" << open_gl_plan.texture_bind_command_count
|
|
<< ",\"samplerBindCommands\":" << open_gl_plan.sampler_bind_command_count
|
|
<< ",\"uploadCommands\":" << open_gl_plan.upload_command_count
|
|
<< ",\"mipmapCommands\":" << open_gl_plan.mipmap_command_count
|
|
<< ",\"transitionCommands\":" << open_gl_plan.transition_command_count
|
|
<< ",\"copyCommands\":" << open_gl_plan.copy_command_count
|
|
<< ",\"readbackCommands\":" << open_gl_plan.readback_command_count
|
|
<< ",\"captureCommands\":" << open_gl_plan.capture_command_count
|
|
<< ",\"passthroughCommands\":" << open_gl_plan.passthrough_command_count
|
|
<< ",\"traceCommands\":" << open_gl_plan.trace_command_count
|
|
<< ",\"unsupportedCommands\":" << open_gl_plan.unsupported_command_count
|
|
<< ",\"renderPassOrderErrors\":" << open_gl_plan.render_pass_order_error_count
|
|
<< ",\"dependencyErrors\":" << open_gl_plan.dependency_error_count
|
|
<< ",\"endedInRenderPass\":" << json_bool(open_gl_plan.ended_in_render_pass)
|
|
<< "}"
|
|
#endif
|
|
<< ",\"renderPasses\":" << render_passes
|
|
<< ",\"depthClears\":" << depth_clears
|
|
<< ",\"stencilClears\":" << stencil_clears
|
|
<< ",\"drawCommands\":" << draw_commands
|
|
<< ",\"drawVertices\":" << draw_vertices
|
|
<< ",\"drawIndices\":" << draw_indices
|
|
<< ",\"scissorCommands\":" << scissor_commands
|
|
<< ",\"blendCommands\":" << blend_commands
|
|
<< ",\"depthCommands\":" << depth_commands
|
|
<< ",\"uniformCommands\":" << uniform_commands
|
|
<< ",\"uniformBytes\":" << uniform_bytes
|
|
<< ",\"bindTextureCommands\":" << bind_texture_commands
|
|
<< ",\"bindSamplerCommands\":" << bind_sampler_commands
|
|
<< ",\"boundTextureBytes\":" << bound_texture_bytes
|
|
<< ",\"uploadCommands\":" << upload_commands
|
|
<< ",\"uploadBytes\":" << upload_bytes
|
|
<< ",\"mipmapCommands\":" << mipmap_commands
|
|
<< ",\"mipmapLevels\":" << mipmap_levels
|
|
<< ",\"mipmapBytes\":" << mipmap_bytes
|
|
<< ",\"transitionCommands\":" << transition_commands
|
|
<< ",\"transitionToUpload\":" << transition_to_upload
|
|
<< ",\"transitionToShaderRead\":" << transition_to_shader_read
|
|
<< ",\"copyCommands\":" << copy_commands
|
|
<< ",\"copySourceBytes\":" << copy_source_bytes
|
|
<< ",\"copyDestinationBytes\":" << copy_destination_bytes
|
|
<< ",\"readbackCommands\":" << readback_commands
|
|
<< ",\"readbackBytes\":" << readback_bytes
|
|
<< ",\"captureCommands\":" << capture_commands
|
|
<< ",\"captureBytes\":" << capture_bytes
|
|
<< ",\"blitCommands\":" << blit_commands
|
|
<< ",\"blitSourceBytes\":" << blit_source_bytes
|
|
<< ",\"blitDestinationBytes\":" << blit_destination_bytes
|
|
<< ",\"traceMarkers\":" << trace_markers
|
|
<< ",\"traceBeginScopes\":" << trace_begin_scopes
|
|
<< ",\"traceEndScopes\":" << trace_end_scopes
|
|
<< ",\"first\":\""
|
|
<< pp::renderer::recorded_render_command_kind_name(commands.front().kind)
|
|
<< "\",\"last\":\""
|
|
<< pp::renderer::recorded_render_command_kind_name(commands.back().kind)
|
|
<< "\"}\n";
|
|
return 0;
|
|
}
|
|
|
|
pp::foundation::Status parse_layout_args(int argc, char** argv, ParseLayoutArgs& args)
|
|
{
|
|
for (int i = 2; i < argc; ++i) {
|
|
const std::string_view key(argv[i]);
|
|
if (key == "--path") {
|
|
if (i + 1 >= argc) {
|
|
return pp::foundation::Status::invalid_argument("missing value for option");
|
|
}
|
|
|
|
args.path = argv[++i];
|
|
} else {
|
|
return pp::foundation::Status::invalid_argument("unknown option");
|
|
}
|
|
}
|
|
|
|
if (args.path.empty()) {
|
|
return pp::foundation::Status::invalid_argument("path must not be empty");
|
|
}
|
|
|
|
return pp::foundation::Status::success();
|
|
}
|
|
|
|
int parse_layout(int argc, char** argv)
|
|
{
|
|
ParseLayoutArgs args;
|
|
const auto status = parse_layout_args(argc, argv, args);
|
|
if (!status.ok()) {
|
|
print_error("parse-layout", status.message);
|
|
return 2;
|
|
}
|
|
|
|
std::ifstream stream(args.path, std::ios::binary);
|
|
if (!stream) {
|
|
print_error("parse-layout", "layout file could not be opened");
|
|
return 2;
|
|
}
|
|
|
|
const std::string xml {
|
|
std::istreambuf_iterator<char>(stream),
|
|
std::istreambuf_iterator<char>()
|
|
};
|
|
const auto summary = pp::ui::parse_layout_xml(xml);
|
|
if (!summary) {
|
|
print_error("parse-layout", summary.status().message);
|
|
return 2;
|
|
}
|
|
|
|
std::cout << "{\"ok\":true,\"command\":\"parse-layout\""
|
|
<< ",\"nodes\":" << summary.value().node_count
|
|
<< ",\"lengthAttributes\":" << summary.value().length_attribute_count
|
|
<< "}\n";
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if (argc < 2) {
|
|
print_help();
|
|
return 1;
|
|
}
|
|
|
|
const std::string_view command(argv[1]);
|
|
if (command == "--help" || command == "-h") {
|
|
print_help();
|
|
return 0;
|
|
}
|
|
|
|
if (command == "create-document") {
|
|
return create_document(argc, argv);
|
|
}
|
|
|
|
if (command == "inspect-image") {
|
|
return inspect_image(argc, argv);
|
|
}
|
|
|
|
if (command == "export-image") {
|
|
return export_image(argc, argv);
|
|
}
|
|
|
|
if (command == "import-image") {
|
|
return import_image(argc, argv);
|
|
}
|
|
|
|
if (command == "inspect-project") {
|
|
return inspect_project(argc, argv);
|
|
}
|
|
|
|
if (command == "classify-open") {
|
|
return classify_open(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-open-route") {
|
|
return plan_open_route(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-document-file") {
|
|
return plan_document_file(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-new-document") {
|
|
return plan_new_document(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-document-version") {
|
|
return plan_document_version(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-export-start") {
|
|
return plan_export_start(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-export-target") {
|
|
return plan_export_target(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-cloud-upload") {
|
|
return plan_cloud_upload(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-cloud-browse") {
|
|
return plan_cloud_browse(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-cloud-upload-all") {
|
|
return plan_cloud_upload_all(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-recording-session") {
|
|
return plan_recording_session(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-app-preferences") {
|
|
return plan_app_preferences(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-app-status") {
|
|
return plan_app_status(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-document-resize") {
|
|
return plan_document_resize(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-layer-rename") {
|
|
return plan_layer_rename(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-layer-operation") {
|
|
return plan_layer_operation(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-animation-operation") {
|
|
return plan_animation_operation(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-brush-operation") {
|
|
return plan_brush_operation(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-canvas-tool") {
|
|
return plan_canvas_tool(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-canvas-tool-state") {
|
|
return plan_canvas_tool_state(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-grid-operation") {
|
|
return plan_grid_operation(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-history-operation") {
|
|
return plan_history_operation(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-quick-operation") {
|
|
return plan_quick_operation(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-share-file") {
|
|
return plan_share_file(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-picked-path") {
|
|
return plan_picked_path(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-display-file") {
|
|
return plan_display_file(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-keyboard-visibility") {
|
|
return plan_keyboard_visibility(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-cursor-visibility") {
|
|
return plan_cursor_visibility(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-clipboard-read") {
|
|
return plan_clipboard_read(argc, argv);
|
|
}
|
|
|
|
if (command == "plan-clipboard-write") {
|
|
return plan_clipboard_write(argc, argv);
|
|
}
|
|
|
|
if (command == "load-project") {
|
|
return load_project(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-stroke") {
|
|
return simulate_stroke(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-stroke-script") {
|
|
return simulate_stroke_script(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-blend") {
|
|
return simulate_blend(argc, argv);
|
|
}
|
|
|
|
if (command == "apply-stroke-script") {
|
|
return apply_stroke_script(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-document-edits") {
|
|
return simulate_document_edits(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-document-export") {
|
|
return simulate_document_export(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-document-history") {
|
|
return simulate_document_history(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-app-session") {
|
|
return simulate_app_session(argc, argv);
|
|
}
|
|
|
|
if (command == "simulate-image-import") {
|
|
return simulate_image_import(argc, argv);
|
|
}
|
|
|
|
if (command == "parse-layout") {
|
|
return parse_layout(argc, argv);
|
|
}
|
|
|
|
if (command == "record-render") {
|
|
return record_render(argc, argv);
|
|
}
|
|
|
|
if (command == "save-document-project") {
|
|
return save_document_project(argc, argv);
|
|
}
|
|
|
|
if (command == "save-project") {
|
|
return save_project(argc, argv);
|
|
}
|
|
|
|
print_error(command, "unknown command");
|
|
return 2;
|
|
}
|