implements PLN-0082
This commit is contained in:
+66
-2
@@ -5,8 +5,10 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.packer.models.PackerAssetCacheEntry;
|
||||
import p.packer.models.PackerFileCacheEntry;
|
||||
import p.packer.models.PackerTileIndexedV1;
|
||||
import p.packer.models.PackerDiagnostic;
|
||||
import p.packer.models.PackerGlyphBankRequirements;
|
||||
import p.packer.models.PackerPaletteV1;
|
||||
import p.packer.models.PackerTileIndexedV1;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -42,7 +44,7 @@ final class PackerGlyphBankWalkerTest {
|
||||
null,
|
||||
Map.of(
|
||||
"tile", Map.of("width", 16, "height", 16),
|
||||
"palette", Map.of("originalArgb8888", List.of(0xFFFFFFFF))),
|
||||
"palette", Map.of("rgba8888", List.of(0xFFFFFFFF))),
|
||||
List.of())));
|
||||
|
||||
final var result = walker.walk(assetRoot, new PackerGlyphBankRequirements(16), Optional.of(priorCache));
|
||||
@@ -52,6 +54,54 @@ final class PackerGlyphBankWalkerTest {
|
||||
assertTrue(tile.paletteIndices().length > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesRgba8888PaletteDataAndUsesIndexZeroAsOrdinaryColor() throws Exception {
|
||||
final Path assetRoot = Files.createDirectories(tempDir.resolve("rgba"));
|
||||
final Path filePath = assetRoot.resolve("tile.png");
|
||||
final BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
image.setRGB(0, 0, 0x80FF0000);
|
||||
image.setRGB(1, 0, 0x00000000);
|
||||
image.setRGB(2, 0, 0xFFFF00FF);
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int x = 3; x < 16; x++) {
|
||||
image.setRGB(x, y, 0xFF00FF00);
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", filePath.toFile());
|
||||
|
||||
final PackerGlyphBankWalker walker = new PackerGlyphBankWalker(MAPPER);
|
||||
final var result = walker.walk(assetRoot, new PackerGlyphBankRequirements(16));
|
||||
|
||||
assertTrue(result.diagnostics().stream().noneMatch(diagnostic -> diagnostic.message().contains("partial alpha")));
|
||||
final var metadata = result.probeResults().getFirst().metadata();
|
||||
final PackerTileIndexedV1 tile = (PackerTileIndexedV1) metadata.get("tile");
|
||||
final PackerPaletteV1 palette = (PackerPaletteV1) metadata.get("palette");
|
||||
|
||||
assertEquals(0, Byte.toUnsignedInt(tile.paletteIndices()[0]));
|
||||
assertEquals(1, Byte.toUnsignedInt(tile.paletteIndices()[1]));
|
||||
assertEquals(2, Byte.toUnsignedInt(tile.paletteIndices()[2]));
|
||||
assertArrayEquals(new int[]{0xFF000080, 0x00000000, 0xFF00FFFF, 0x00FF00FF}, palette.rgba8888());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsSixteenRgbaColorsAndRejectsSeventeenth() throws Exception {
|
||||
final Path validRoot = Files.createDirectories(tempDir.resolve("sixteen"));
|
||||
writeColorCountTile(validRoot.resolve("tile.png"), 16);
|
||||
|
||||
final PackerGlyphBankWalker walker = new PackerGlyphBankWalker(MAPPER);
|
||||
final var valid = walker.walk(validRoot, new PackerGlyphBankRequirements(16));
|
||||
|
||||
assertTrue(valid.diagnostics().stream().noneMatch(PackerDiagnostic::blocking));
|
||||
|
||||
final Path invalidRoot = Files.createDirectories(tempDir.resolve("seventeen"));
|
||||
writeColorCountTile(invalidRoot.resolve("tile.png"), 17);
|
||||
final var invalid = walker.walk(invalidRoot, new PackerGlyphBankRequirements(16));
|
||||
|
||||
assertTrue(invalid.probeResults().stream()
|
||||
.flatMap(probeResult -> probeResult.diagnostics().stream())
|
||||
.anyMatch(PackerDiagnostic::blocking));
|
||||
}
|
||||
|
||||
private void writeTile(Path path) throws Exception {
|
||||
final BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
for (int y = 0; y < 16; y++) {
|
||||
@@ -61,4 +111,18 @@ final class PackerGlyphBankWalkerTest {
|
||||
}
|
||||
ImageIO.write(image, "png", path.toFile());
|
||||
}
|
||||
|
||||
private void writeColorCountTile(Path path, int colorCount) throws Exception {
|
||||
final BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
final int index = Math.min(colorCount - 1, y * 16 + x);
|
||||
final int red = (index * 17) & 0xFF;
|
||||
final int green = (index * 31) & 0xFF;
|
||||
final int blue = (index * 47) & 0xFF;
|
||||
image.setRGB(x, y, 0xFF000000 | (red << 16) | (green << 8) | blue);
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", path.toFile());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user