implements PLN-0083
This commit is contained in:
+24
-20
@@ -38,7 +38,11 @@ import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class FileSystemPackerWorkspaceService implements PackerWorkspaceService {
|
||||
private static final int GLYPH_BANK_COLOR_KEY_RGB565 = 0xF81F;
|
||||
private static final int GLYPH_BANK_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;
|
||||
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";
|
||||
|
||||
@@ -1091,7 +1095,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
final byte[] sheetPixels = new byte[width * height];
|
||||
final Map<String, PackerRuntimeWalkFile> selectedByPath = new LinkedHashMap<>();
|
||||
runtimeAsset.walkProjection().buildCandidateFiles().forEach(file -> selectedByPath.put(file.relativePath(), file));
|
||||
final Map<Integer, Integer> declaredPaletteIndexByRgb = declaredPaletteIndexByRgb(declaration);
|
||||
final Map<Integer, Integer> declaredPaletteIndexByRgba = declaredPaletteIndexByRgba(declaration);
|
||||
|
||||
declaration.artifacts().stream()
|
||||
.sorted(Comparator.comparingInt(PackerAssetArtifactSelection::index))
|
||||
@@ -1108,7 +1112,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
tile,
|
||||
walkFile.metadata().get("palette"),
|
||||
artifact.file(),
|
||||
declaredPaletteIndexByRgb);
|
||||
declaredPaletteIndexByRgba);
|
||||
final int tileX = (artifact.index() % tilesPerRow) * tileSize;
|
||||
final int tileY = (artifact.index() / tilesPerRow) * tileSize;
|
||||
for (int localY = 0; localY < tile.height(); localY += 1) {
|
||||
@@ -1130,7 +1134,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
runtimeMetadata.put("tile_size", tileSize);
|
||||
runtimeMetadata.put("width", width);
|
||||
runtimeMetadata.put("height", height);
|
||||
runtimeMetadata.put("palette_count", 64);
|
||||
runtimeMetadata.put("palette_count", GLYPH_BANK_PALETTE_COUNT);
|
||||
runtimeMetadata.put("palette_authored", countAuthoredGlyphBankPalettes(declaration));
|
||||
runtimeMetadata.put("codec", Map.of());
|
||||
declaration.outputMetadata().forEach((key, value) -> {
|
||||
@@ -1150,7 +1154,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
"GLYPH",
|
||||
"NONE",
|
||||
payload,
|
||||
width * height + 2048,
|
||||
width * height + GLYPH_BANK_PALETTE_BYTES,
|
||||
runtimeMetadata,
|
||||
toolingMetadata,
|
||||
declaration.preloadEnabled());
|
||||
@@ -1160,7 +1164,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
PackerTileIndexedV1 tile,
|
||||
Object paletteMetadata,
|
||||
String artifactFile,
|
||||
Map<Integer, Integer> declaredPaletteIndexByRgb) {
|
||||
Map<Integer, Integer> declaredPaletteIndexByRgba) {
|
||||
final int[] rgba8888 = paletteColors(paletteMetadata);
|
||||
if (rgba8888.length == 0) {
|
||||
throw new IllegalStateException("Selected tile artifact is missing palette metadata required for palette remapping: " + artifactFile);
|
||||
@@ -1172,7 +1176,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
throw new IllegalStateException("Tile palette index exceeds discovered palette size for artifact: " + artifactFile);
|
||||
}
|
||||
final int rgba = rgba8888[paletteIndex];
|
||||
final Integer materialIndex = declaredPaletteIndexByRgb.get(rgba);
|
||||
final Integer materialIndex = declaredPaletteIndexByRgba.get(rgba);
|
||||
if (materialIndex == null || materialIndex < 0 || materialIndex > 15) {
|
||||
throw new IllegalStateException("Unable to resolve canonical palette index for artifact color in " + artifactFile);
|
||||
}
|
||||
@@ -1181,7 +1185,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
return remapped;
|
||||
}
|
||||
|
||||
private Map<Integer, Integer> declaredPaletteIndexByRgb(PackerAssetDeclaration declaration) {
|
||||
private Map<Integer, Integer> declaredPaletteIndexByRgba(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.");
|
||||
@@ -1272,7 +1276,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
|
||||
private byte[] emitGlyphBankPalettes(PackerAssetDeclaration declaration) {
|
||||
final byte[] bytes = new byte[64 * 16 * 2];
|
||||
final byte[] bytes = new byte[GLYPH_BANK_PALETTE_BYTES];
|
||||
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
|
||||
if (!(palettesNode instanceof com.fasterxml.jackson.databind.node.ArrayNode palettesArray)) {
|
||||
return bytes;
|
||||
@@ -1284,21 +1288,21 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
continue;
|
||||
}
|
||||
final int paletteIndex = indexNode.intValue();
|
||||
if (paletteIndex < 0 || paletteIndex >= 64) {
|
||||
if (paletteIndex < 0 || paletteIndex >= GLYPH_BANK_PALETTE_COUNT) {
|
||||
continue;
|
||||
}
|
||||
final int paletteBaseOffset = (paletteIndex * 16) * 2;
|
||||
bytes[paletteBaseOffset] = (byte) (GLYPH_BANK_COLOR_KEY_RGB565 & 0xFF);
|
||||
bytes[paletteBaseOffset + 1] = (byte) ((GLYPH_BANK_COLOR_KEY_RGB565 >>> 8) & 0xFF);
|
||||
final JsonNode convertedNode = paletteNode.path("convertedRgb565");
|
||||
if (!convertedNode.isArray()) {
|
||||
final JsonNode rgbaNode = paletteNode.path("rgba8888");
|
||||
if (!rgbaNode.isArray()) {
|
||||
continue;
|
||||
}
|
||||
for (int colorIndex = 0; colorIndex < Math.min(15, convertedNode.size()); colorIndex += 1) {
|
||||
final int rgb565 = convertedNode.get(colorIndex).asInt(0);
|
||||
final int baseOffset = ((paletteIndex * 16) + colorIndex + 1) * 2;
|
||||
bytes[baseOffset] = (byte) (rgb565 & 0xFF);
|
||||
bytes[baseOffset + 1] = (byte) ((rgb565 >>> 8) & 0xFF);
|
||||
for (int colorIndex = 0; colorIndex < Math.min(GLYPH_BANK_COLORS_PER_PALETTE, rgbaNode.size()); colorIndex += 1) {
|
||||
final int rgba = rgbaNode.get(colorIndex).asInt(0);
|
||||
final int baseOffset = ((paletteIndex * GLYPH_BANK_COLORS_PER_PALETTE) + colorIndex)
|
||||
* GLYPH_BANK_RGBA8888_BYTES_PER_COLOR;
|
||||
bytes[baseOffset] = (byte) ((rgba >>> 24) & 0xFF);
|
||||
bytes[baseOffset + 1] = (byte) ((rgba >>> 16) & 0xFF);
|
||||
bytes[baseOffset + 2] = (byte) ((rgba >>> 8) & 0xFF);
|
||||
bytes[baseOffset + 3] = (byte) (rgba & 0xFF);
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
|
||||
Reference in New Issue
Block a user