implements PLN-0082

This commit is contained in:
2026-05-23 22:20:24 +01:00
parent ad2bfeb66f
commit 0be02622c4
8 changed files with 120 additions and 106 deletions
@@ -1161,22 +1161,19 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
Object paletteMetadata,
String artifactFile,
Map<Integer, Integer> declaredPaletteIndexByRgb) {
final int[] originalArgb8888 = originalPaletteColors(paletteMetadata);
if (originalArgb8888.length == 0) {
final int[] rgba8888 = paletteColors(paletteMetadata);
if (rgba8888.length == 0) {
throw new IllegalStateException("Selected tile artifact is missing palette metadata required for palette remapping: " + artifactFile);
}
final byte[] remapped = Arrays.copyOf(tile.paletteIndices(), tile.paletteIndices().length);
for (int index = 0; index < remapped.length; index += 1) {
final int paletteIndex = Byte.toUnsignedInt(remapped[index]);
if (paletteIndex == 0) {
continue;
}
if (paletteIndex > originalArgb8888.length) {
if (paletteIndex >= rgba8888.length) {
throw new IllegalStateException("Tile palette index exceeds discovered palette size for artifact: " + artifactFile);
}
final int originalArgb = originalArgb8888[paletteIndex - 1];
final Integer materialIndex = declaredPaletteIndexByRgb.get(rgb24(originalArgb));
if (materialIndex == null || materialIndex < 1 || materialIndex > 15) {
final int rgba = rgba8888[paletteIndex];
final Integer materialIndex = declaredPaletteIndexByRgb.get(rgba);
if (materialIndex == null || materialIndex < 0 || materialIndex > 15) {
throw new IllegalStateException("Unable to resolve canonical palette index for artifact color in " + artifactFile);
}
remapped[index] = (byte) (materialIndex & 0x0F);
@@ -1189,29 +1186,29 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
if (!(palettesNode instanceof ArrayNode palettesArray) || palettesArray.isEmpty()) {
throw new IllegalStateException("Glyph packing requires at least one declared pipeline palette.");
}
final JsonNode paletteNode = palettesArray.get(0).path("palette").path("originalArgb8888");
final JsonNode paletteNode = palettesArray.get(0).path("palette").path("rgba8888");
if (!paletteNode.isArray() || paletteNode.isEmpty()) {
throw new IllegalStateException("Glyph packing requires originalArgb8888 entries in the declared pipeline palette.");
throw new IllegalStateException("Glyph packing requires rgba8888 entries in the declared pipeline palette.");
}
final LinkedHashMap<Integer, Integer> mapping = new LinkedHashMap<>();
for (int index = 0; index < paletteNode.size(); index += 1) {
final JsonNode colorNode = paletteNode.get(index);
if (!colorNode.canConvertToInt()) {
throw new IllegalStateException("Declared pipeline palette contains a non-integer originalArgb8888 entry.");
throw new IllegalStateException("Declared pipeline palette contains a non-integer rgba8888 entry.");
}
mapping.put(rgb24(colorNode.intValue()), index + 1);
mapping.put(colorNode.intValue(), index);
}
return Map.copyOf(mapping);
}
private int[] originalPaletteColors(Object paletteMetadata) {
private int[] paletteColors(Object paletteMetadata) {
if (paletteMetadata instanceof PackerPaletteV1 palette) {
return palette.originalArgb8888();
return palette.rgba8888();
}
if (!(paletteMetadata instanceof Map<?, ?> map)) {
return new int[0];
}
final Object colors = map.get("originalArgb8888");
final Object colors = map.get("rgba8888");
if (!(colors instanceof List<?> list)) {
return new int[0];
}
@@ -1226,10 +1223,6 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
return values;
}
private int rgb24(int argb) {
return argb & 0x00FFFFFF;
}
private PackedAsset packSceneBank(PackerRuntimeAsset runtimeAsset, PackerAssetDeclaration declaration) {
final ScenePackRequest request = runtimeAsset.walkProjection().buildCandidateFiles().stream()
.map(file -> file.metadata().get("scenePackRequest"))
@@ -109,17 +109,12 @@ public final class PackerReadMessageMapper {
"paletteIndices", List.copyOf(paletteIndices));
}
if (value instanceof PackerPaletteV1 palette) {
final List<Integer> originalArgb8888 = new java.util.ArrayList<>(palette.originalArgb8888().length);
for (int argb : palette.originalArgb8888()) {
originalArgb8888.add(argb);
}
final List<Integer> convertedRgb565 = new java.util.ArrayList<>(palette.convertedRgb565().length);
for (short rgb565 : palette.convertedRgb565()) {
convertedRgb565.add(Short.toUnsignedInt(rgb565));
final List<Integer> rgba8888 = new java.util.ArrayList<>(palette.rgba8888().length);
for (int rgba : palette.rgba8888()) {
rgba8888.add(rgba);
}
return Map.of(
"originalArgb8888", List.copyOf(originalArgb8888),
"convertedRgb565", List.copyOf(convertedRgb565));
"rgba8888", List.copyOf(rgba8888));
}
if (value instanceof Map<?, ?> nestedMap) {
final java.util.LinkedHashMap<String, Object> normalized = new java.util.LinkedHashMap<>();