From 45311a3578fcdea90a937f72c122f57f791db842 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Tue, 8 Aug 2023 11:18:27 -0300 Subject: [PATCH] Fix border padding on the right and bottom sides not being placed (fix #3993) Prior to this fix, border padding was clipped to the edge of sprites on the right and bottom in all export sprite sheet types. This commit includes tests for 'Export Sprite Sheet' command using shape padding, border padding, inner padding with 'Packed' sheet type + 'Trim Cels' = true. This fix complements the aseprite/laf commit named: "Fix overlapped shape padding between frame images on Packed sheet tyoe" --- src/app/doc_exporter.cpp | 9 ++++- tests/scripts/app_command.lua | 49 +++++++++++++++++++++++++++- tests/sprites/4f-index-4x4.aseprite | Bin 0 -> 471 bytes tests/sprites/README.md | 2 ++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/sprites/4f-index-4x4.aseprite diff --git a/src/app/doc_exporter.cpp b/src/app/doc_exporter.cpp index 4a1b888da50..9b87017a467 100644 --- a/src/app/doc_exporter.cpp +++ b/src/app/doc_exporter.cpp @@ -1302,7 +1302,14 @@ void DocExporter::trimTexture(const Samples& samples, sample.isEmpty()) continue; - bounds |= sample.inTextureBounds(); + // We add the border padding in the sample size to do an union + // between full bounds and sample's inTextureBounds (it + // shouldn't make full bounds bigger). + gfx::Rect sampleBounds(sample.inTextureBounds()); + sampleBounds.w += m_borderPadding; + sampleBounds.h += m_borderPadding; + + bounds |= sampleBounds; } if (m_textureWidth == 0) { diff --git a/tests/scripts/app_command.lua b/tests/scripts/app_command.lua index 42d66c89cde..4f5b4688545 100644 --- a/tests/scripts/app_command.lua +++ b/tests/scripts/app_command.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2019-2020 Igara Studio S.A. +-- Copyright (C) 2019-2023 Igara Studio S.A. -- Copyright (C) 2018 David Capello -- -- This file is released under the terms of the MIT license. @@ -54,6 +54,53 @@ do -- ExportSpriteSheet 11,8,11,21,11,8,11, 11,8,11,21,11,11,8, }) + + local s = Sprite{ fromFile="sprites/4f-index-4x4.aseprite" } + app.command.ExportSpriteSheet { + type=SpriteSheetType.PACKED, + textureFilename="_test_export_spritesheet1.png", + shapePadding=1, + borderPadding=1, + trim=true, + } + local i = Image{ fromFile="_test_export_spritesheet1.png" } + expect_img(i, { + 0,0,0,0,0, + 0,1,0,2,0, + 0,1,0,2,0, + 0,1,0,0,0, + 0,0,0,3,0, + 0,0,0,3,0, + 0,0,0,0,0, + 0,4,4,0,0, + 0,0,0,0,0 + }) + + app.sprite = s + app.command.ExportSpriteSheet { + type=SpriteSheetType.PACKED, + textureFilename="_test_export_spritesheet1.png", + shapePadding=2, + borderPadding=1, + innerPadding=1, + trim=true, + } + local i = Image{ fromFile="_test_export_spritesheet1.png" } + expect_img(i, { + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + 0,0,1,0, 0,0,0,2, 0,0,0,0, 0,3,0,0, + 0,0,1,0, 0,0,0,2, 0,0,0,0, 0,3,0,0, + + 0,0,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + + 0,0,0,0, 0,0,0,4, 4,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, + }) end do -- NewLayer/RemoveLayer diff --git a/tests/sprites/4f-index-4x4.aseprite b/tests/sprites/4f-index-4x4.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..e98a603e0297feb7512f2933aeb10f72766844dc GIT binary patch literal 471 zcmcIfu?@m75Ij3JNrZ%`kW%3S20)@<2$l#02B0Fl&@u&s(6U0>H0Iv6M36|yJ0IWs z|9t1C0$z6mSp`_2VSd6w$sy)k|A+@K?K>M(E%AbxyC6A`+Ywhz`VuB?>F?n^5I=4N ztfVBah>g6;#;MTt>@20>GMP;wyd3+wJzd;p&B8j6so-^*AkJ{T9h-&*N|-Ir`%VSx nVtB>;Mbbh#@RkC0oTI;l0_QvdrpU)R*?^;Ik2*D-%uv1o;=D3p literal 0 HcmV?d00001 diff --git a/tests/sprites/README.md b/tests/sprites/README.md index 495f072b32d..c03b92f4933 100644 --- a/tests/sprites/README.md +++ b/tests/sprites/README.md @@ -25,6 +25,8 @@ merged in the same texture atlas. * `2f-index-3x3.aseprite`: Indexed, 2 frames, 1 layer, mask color set to index 21. +* `4f-index-4x4.aseprite`: Indexed, 4 frames, 1 layer, mask color set + to index 0. * `file-tests-props.aseprite`: Indexed, 64x64, 6 frames, 4 layers (one of them is a tilemap), 13 cels, 1 tag. * `slices.aseprite`: Indexed, 4x4, background layer, 2 slices.