implements PLN-0089

This commit is contained in:
2026-07-14 16:29:18 +01:00
parent fae4e9a9fd
commit 13425cee03
3 changed files with 21 additions and 15 deletions
@@ -41,8 +41,6 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
private static final int GLYPH_BANK_MAX_PALETTE_COUNT = 64;
private static final int GLYPH_BANK_COLORS_PER_PALETTE = 16;
private static final int GLYPH_BANK_RGBA8888_BYTES_PER_COLOR = 4;
private static final int GLYPH_BANK_PALETTE_BYTES =
GLYPH_BANK_MAX_PALETTE_COUNT * GLYPH_BANK_COLORS_PER_PALETTE * GLYPH_BANK_RGBA8888_BYTES_PER_COLOR;
private static final String SCENE_BANK_SUPPORT_FILE = "scene-bank.studio.json";
private static final String SCENE_PACK_REQUEST_FILE = "scene-bank.pack-request.json";
@@ -1126,7 +1124,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
final byte[] packedPixels = packNibbles(sheetPixels);
final int paletteCount = runtimeGlyphPaletteCount(declaration);
final byte[] paletteBytes = emitGlyphBankPalettes(declaration);
final byte[] paletteBytes = emitGlyphBankPalettes(declaration, paletteCount);
final byte[] payload = new byte[packedPixels.length + paletteBytes.length];
System.arraycopy(packedPixels, 0, payload, 0, packedPixels.length);
System.arraycopy(paletteBytes, 0, payload, packedPixels.length, paletteBytes.length);
@@ -1155,7 +1153,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
"GLYPH",
"NONE",
payload,
width * height + GLYPH_BANK_PALETTE_BYTES,
width * height + paletteBytes.length,
runtimeMetadata,
toolingMetadata,
declaration.preloadEnabled());
@@ -1276,8 +1274,8 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
return packed;
}
private byte[] emitGlyphBankPalettes(PackerAssetDeclaration declaration) {
final byte[] bytes = new byte[GLYPH_BANK_PALETTE_BYTES];
private byte[] emitGlyphBankPalettes(PackerAssetDeclaration declaration, int paletteCount) {
final byte[] bytes = new byte[glyphBankPaletteBytes(paletteCount)];
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
if (!(palettesNode instanceof com.fasterxml.jackson.databind.node.ArrayNode palettesArray)) {
return bytes;
@@ -1289,7 +1287,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
continue;
}
final int paletteIndex = indexNode.intValue();
if (paletteIndex < 0 || paletteIndex >= GLYPH_BANK_MAX_PALETTE_COUNT) {
if (paletteIndex < 0 || paletteIndex >= paletteCount) {
continue;
}
final JsonNode rgbaNode = paletteNode.path("rgba8888");
@@ -1309,6 +1307,14 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
return bytes;
}
private int glyphBankPaletteBytes(int paletteCount) {
if (paletteCount < 1 || paletteCount > GLYPH_BANK_MAX_PALETTE_COUNT) {
throw new IllegalStateException("Glyph packing requires palette_count in 1..="
+ GLYPH_BANK_MAX_PALETTE_COUNT + ".");
}
return paletteCount * GLYPH_BANK_COLORS_PER_PALETTE * GLYPH_BANK_RGBA8888_BYTES_PER_COLOR;
}
private int countAuthoredGlyphBankPalettes(PackerAssetDeclaration declaration) {
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
return palettesNode instanceof ArrayNode palettesArray ? palettesArray.size() : 0;