implements PLN-0070
This commit is contained in:
@@ -64,7 +64,7 @@ impl GlyphAssetSlotIndex {
|
||||
const GLYPH_BANK_PALETTE_COUNT_V1: usize = 64;
|
||||
const GLYPH_BANK_COLORS_PER_PALETTE: usize = 16;
|
||||
const GLYPH_BANK_PALETTE_BYTES_V1: usize =
|
||||
GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * size_of::<u16>();
|
||||
GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * size_of::<u32>();
|
||||
|
||||
/// Resident metadata for a decoded/materialized asset inside a BankPolicy.
|
||||
#[derive(Debug)]
|
||||
@@ -655,10 +655,13 @@ impl AssetManager {
|
||||
[[Color::BLACK; GLYPH_BANK_COLORS_PER_PALETTE]; GLYPH_BANK_PALETTE_COUNT_V1];
|
||||
for (p, pal) in palettes.iter_mut().enumerate() {
|
||||
for (c, slot) in pal.iter_mut().enumerate() {
|
||||
let offset = (p * 16 + c) * 2;
|
||||
let color_raw =
|
||||
u16::from_le_bytes([palette_data[offset], palette_data[offset + 1]]);
|
||||
*slot = Color::from_rgb565_lossy(color_raw);
|
||||
let offset = (p * 16 + c) * 4;
|
||||
*slot = Color::rgba(
|
||||
palette_data[offset],
|
||||
palette_data[offset + 1],
|
||||
palette_data[offset + 2],
|
||||
palette_data[offset + 3],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,10 +690,13 @@ impl AssetManager {
|
||||
[[Color::BLACK; GLYPH_BANK_COLORS_PER_PALETTE]; GLYPH_BANK_PALETTE_COUNT_V1];
|
||||
for (p, pal) in palettes.iter_mut().enumerate() {
|
||||
for (c, slot) in pal.iter_mut().enumerate() {
|
||||
let offset = (p * 16 + c) * 2;
|
||||
let color_raw =
|
||||
u16::from_le_bytes([palette_data[offset], palette_data[offset + 1]]);
|
||||
*slot = Color::from_rgb565_lossy(color_raw);
|
||||
let offset = (p * 16 + c) * 4;
|
||||
*slot = Color::rgba(
|
||||
palette_data[offset],
|
||||
palette_data[offset + 1],
|
||||
palette_data[offset + 2],
|
||||
palette_data[offset + 3],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,14 +1312,13 @@ mod tests {
|
||||
let entry = test_glyph_asset_entry("glyphs", 2, 2);
|
||||
let mut data = vec![0x10, 0x23];
|
||||
data.extend_from_slice(&[0u8; GLYPH_BANK_PALETTE_BYTES_V1]);
|
||||
data[2] = 0x34;
|
||||
data[3] = 0x12;
|
||||
data[2..6].copy_from_slice(&[0x12, 0x34, 0x56, 0x78]);
|
||||
|
||||
let bank =
|
||||
AssetManager::decode_glyph_bank_from_buffer(&entry, &data).expect("glyph decode");
|
||||
|
||||
assert_eq!(bank.pixel_indices, vec![1, 0, 2, 3]);
|
||||
assert_eq!(bank.palettes[0][0], Color::from_rgb565_lossy(0x1234));
|
||||
assert_eq!(bank.palettes[0][0], Color::from_raw(0x12345678));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user