SVG spritesheets: pack, merge, rasterize
Packing an SVG sheet makes a new SVG holding its drawing once (as a symbol), each region a clipped view of it at its new place; merging makes an SVG whenever any sheet is one, with PNG sheets embedded as images (the merged sheet's file name takes the matching extension). Both go through Image::compose, which also does the pixel versions, so merge_append is gone. Vector sheets save as their SVG (autosaves too, and images load as PNG or SVG by content), and their asset key includes the SVG. Rasterize in the Spritesheets menu turns selected SVG sheets into PNGs beside them, with a toast for each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bec89bf48f
commit
5f01e8065d
14 files changed
+316
-82
No files matched your search
+25
-1
@@ -27,7 +27,8 @@ TEST_CASE("Image png round trip and uid tracking")
|
||||
CHECK(copy.uid != image.uid);
|
||||
CHECK(copy.pixel_read({1, 1}) == glm::vec4(1.0f));
|
||||
|
||||
auto merged = Image::merge_append(image, loaded, true);
|
||||
auto merged = Image::compose({{&image, {}, image.size, {}}, {&loaded, {}, loaded.size, {image.size.x, 0}}},
|
||||
{image.size.x * 2, image.size.y}, false);
|
||||
CHECK(merged.size == glm::ivec2(4, 2));
|
||||
CHECK(merged.pixel_read({2, 0}) == image.pixel_read({0, 0}));
|
||||
}
|
||||
@@ -74,3 +75,26 @@ TEST_CASE("an SVG spritesheet loads in SVG units and draws again at any scale")
|
||||
CHECK(large.unit_size_get() == image.unit_size_get());
|
||||
CHECK(large.uid != image.uid);
|
||||
}
|
||||
|
||||
TEST_CASE("SVG spritesheets compose into SVGs that draw the same")
|
||||
{
|
||||
Image vector(test::TEST_DIR / "render" / "vector.svg");
|
||||
REQUIRE(vector.is_vector());
|
||||
|
||||
// The circle (left half) and the square (right half) swapped: each part is a clipped view of the drawing.
|
||||
auto swapped =
|
||||
Image::compose({{&vector, {16, 0}, {16, 16}, {0, 0}}, {&vector, {0, 0}, {16, 16}, {16, 0}}}, vector.size, true);
|
||||
REQUIRE(swapped.is_vector());
|
||||
CHECK(swapped.size == vector.size);
|
||||
CHECK(swapped.pixel_read({24.0f, 8.0f}) == vector.pixel_read({8.0f, 8.0f}));
|
||||
CHECK(swapped.pixel_read({1.0f, 1.0f}) == glm::vec4());
|
||||
|
||||
// A PNG part is embedded as an image, pixel for pixel; composing the result again still works.
|
||||
const std::vector<uint8_t> pixels{255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255};
|
||||
Image raster(pixels.data(), {2, 2});
|
||||
auto mixed = Image::compose({{&swapped, {}, swapped.size, {}}, {&raster, {}, raster.size, {32, 0}}}, {34, 16}, true);
|
||||
REQUIRE(mixed.is_vector());
|
||||
CHECK(mixed.pixel_read({33.0f, 1.0f}) == raster.pixel_read({1.0f, 1.0f}));
|
||||
CHECK(Image::compose({{&mixed, {}, mixed.size, {}}}, mixed.size, true).pixel_read({24.0f, 8.0f}) ==
|
||||
vector.pixel_read({8.0f, 8.0f}));
|
||||
}
|
||||
Reference in new issue
Block a user