Add PPI dirty-face payload save automation

This commit is contained in:
2026-06-02 10:18:35 +02:00
parent 4f4ac380ac
commit a8faa82b70
9 changed files with 280 additions and 35 deletions

View File

@@ -37,6 +37,7 @@ struct SaveProjectArgs {
std::uint32_t height = 0;
std::string layer_name = "Ink";
std::uint32_t frame_duration_ms = 100;
bool include_test_face_payload = false;
};
struct InspectImageArgs {
@@ -99,6 +100,30 @@ void print_error(std::string_view command, std::string_view message)
<< "\",\"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";
@@ -152,7 +177,7 @@ void print_help()
<< " load-project --path FILE\n"
<< " parse-layout --path FILE\n"
<< " record-render [--width N] [--height N]\n"
<< " save-project --path FILE --width N --height N [--layer-name NAME] [--frame-duration-ms N]\n"
<< " save-project --path FILE --width N --height N [--layer-name NAME] [--frame-duration-ms N] [--include-test-face-payload]\n"
<< " simulate-document-edits [--width N] [--height N]\n"
<< " simulate-document-history [--width N] [--height N] [--history N]\n"
<< " simulate-image-import [--width N] [--height N]\n"
@@ -289,6 +314,8 @@ pp::foundation::Status parse_save_project_args(int argc, char** argv, SaveProjec
} 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");
}
@@ -322,11 +349,25 @@ int save_project(int argc, char** argv)
return 2;
}
const auto test_payload = transparent_png_1x1_bytes();
const pp::assets::PpiDirtyFacePayloadConfig dirty_faces[] {
{
.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,
.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);
@@ -356,6 +397,7 @@ int save_project(int argc, char** argv)
<< ",\"frames\":1"
<< ",\"layerName\":\"" << json_escape(args.layer_name) << "\""
<< ",\"frameDurationMs\":" << args.frame_duration_ms
<< ",\"facePayloads\":" << (args.include_test_face_payload ? 1 : 0)
<< "}}\n";
return 0;
}
@@ -1111,26 +1153,6 @@ pp::foundation::Status parse_simulate_image_import_args(
int simulate_image_import(int argc, char** argv)
{
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 },
};
SimulateImageImportArgs args;
const auto status = parse_simulate_image_import_args(argc, argv, args);
if (!status.ok()) {
@@ -1138,7 +1160,7 @@ int simulate_image_import(int argc, char** argv)
return 2;
}
const auto image_result = pp::assets::decode_png_rgba8(transparent_png_1x1);
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;