Add document selection mask automation

This commit is contained in:
2026-06-02 10:55:12 +02:00
parent 1ab2a9b846
commit ddca24779e
9 changed files with 304 additions and 20 deletions

View File

@@ -1285,7 +1285,21 @@ int simulate_document_edits(int argc, char** argv)
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()
@@ -1295,6 +1309,7 @@ int simulate_document_edits(int argc, char** argv)
<< ",\"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")
@@ -1315,7 +1330,14 @@ int simulate_document_edits(int argc, char** argv)
}
std::cout << active_layer.frames[frame_index].duration_ms;
}
std::cout << "]}\n";
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;
}