implements PLN-0088
This commit is contained in:
+39
-4
@@ -38,11 +38,11 @@ import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class FileSystemPackerWorkspaceService implements PackerWorkspaceService {
|
||||
private static final int GLYPH_BANK_PALETTE_COUNT = 64;
|
||||
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_PALETTE_COUNT * GLYPH_BANK_COLORS_PER_PALETTE * GLYPH_BANK_RGBA8888_BYTES_PER_COLOR;
|
||||
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";
|
||||
|
||||
@@ -1125,6 +1125,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
});
|
||||
|
||||
final byte[] packedPixels = packNibbles(sheetPixels);
|
||||
final int paletteCount = runtimeGlyphPaletteCount(declaration);
|
||||
final byte[] paletteBytes = emitGlyphBankPalettes(declaration);
|
||||
final byte[] payload = new byte[packedPixels.length + paletteBytes.length];
|
||||
System.arraycopy(packedPixels, 0, payload, 0, packedPixels.length);
|
||||
@@ -1134,7 +1135,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
runtimeMetadata.put("tile_size", tileSize);
|
||||
runtimeMetadata.put("width", width);
|
||||
runtimeMetadata.put("height", height);
|
||||
runtimeMetadata.put("palette_count", GLYPH_BANK_PALETTE_COUNT);
|
||||
runtimeMetadata.put("palette_count", paletteCount);
|
||||
runtimeMetadata.put("palette_authored", countAuthoredGlyphBankPalettes(declaration));
|
||||
runtimeMetadata.put("codec", Map.of());
|
||||
declaration.outputMetadata().forEach((key, value) -> {
|
||||
@@ -1288,7 +1289,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
continue;
|
||||
}
|
||||
final int paletteIndex = indexNode.intValue();
|
||||
if (paletteIndex < 0 || paletteIndex >= GLYPH_BANK_PALETTE_COUNT) {
|
||||
if (paletteIndex < 0 || paletteIndex >= GLYPH_BANK_MAX_PALETTE_COUNT) {
|
||||
continue;
|
||||
}
|
||||
final JsonNode rgbaNode = paletteNode.path("rgba8888");
|
||||
@@ -1313,6 +1314,40 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
return palettesNode instanceof ArrayNode palettesArray ? palettesArray.size() : 0;
|
||||
}
|
||||
|
||||
private int runtimeGlyphPaletteCount(PackerAssetDeclaration declaration) {
|
||||
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
|
||||
if (!(palettesNode instanceof ArrayNode palettesArray) || palettesArray.isEmpty()) {
|
||||
throw new IllegalStateException("Glyph packing requires at least one declared pipeline palette.");
|
||||
}
|
||||
int maxPaletteIndex = -1;
|
||||
final Set<Integer> seen = new HashSet<>();
|
||||
for (JsonNode declarationNode : palettesArray) {
|
||||
final JsonNode indexNode = declarationNode.path("index");
|
||||
final JsonNode paletteNode = declarationNode.path("palette");
|
||||
if (!indexNode.isInt() || indexNode.intValue() < 0) {
|
||||
throw new IllegalStateException("Glyph packing requires non-negative integer palette indices.");
|
||||
}
|
||||
final int paletteIndex = indexNode.intValue();
|
||||
if (!seen.add(paletteIndex)) {
|
||||
throw new IllegalStateException("Glyph packing requires unique palette indices.");
|
||||
}
|
||||
if (paletteIndex >= GLYPH_BANK_MAX_PALETTE_COUNT) {
|
||||
throw new IllegalStateException("Glyph packing supports palette indices in 0.."
|
||||
+ (GLYPH_BANK_MAX_PALETTE_COUNT - 1) + ".");
|
||||
}
|
||||
if (!paletteNode.path("rgba8888").isArray()) {
|
||||
throw new IllegalStateException("Glyph packing requires rgba8888 entries in each declared palette.");
|
||||
}
|
||||
maxPaletteIndex = Math.max(maxPaletteIndex, paletteIndex);
|
||||
}
|
||||
final int paletteCount = maxPaletteIndex + 1;
|
||||
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;
|
||||
}
|
||||
|
||||
private byte[] encodeScenePackRequest(ScenePackRequest request) {
|
||||
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
writeBytes(output, new byte[]{'S', 'C', 'N', 'E'});
|
||||
|
||||
+8
@@ -324,6 +324,14 @@ public final class PackerAssetDeclarationParser {
|
||||
"Field 'output.pipeline.palettes' contains duplicate palette index " + indexNode.intValue() + ".",
|
||||
manifestPath,
|
||||
true));
|
||||
} else if (indexNode.intValue() >= MAX_PIPELINE_PALETTES) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'output.pipeline.palettes' cannot declare palette index " + indexNode.intValue()
|
||||
+ "; maximum supported index is " + (MAX_PIPELINE_PALETTES - 1) + ".",
|
||||
manifestPath,
|
||||
true));
|
||||
}
|
||||
|
||||
if (!paletteNode.isObject()) {
|
||||
|
||||
Reference in New Issue
Block a user