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]
|
||||
|
||||
@@ -366,7 +366,7 @@ mod tests {
|
||||
bank_type: BankType::GLYPH,
|
||||
offset,
|
||||
size,
|
||||
decoded_size: 16 * 16 + (GLYPH_BANK_PALETTE_COUNT_V1 as u64 * 16 * 2),
|
||||
decoded_size: 16 * 16 + (GLYPH_BANK_PALETTE_COUNT_V1 as u64 * 16 * 4),
|
||||
codec: AssetCodec::None,
|
||||
metadata: json!({
|
||||
"tile_size": 16,
|
||||
@@ -449,7 +449,7 @@ mod tests {
|
||||
bank_type: BankType::GLYPH,
|
||||
offset: 4,
|
||||
size: 4,
|
||||
decoded_size: 16 * 16 + (GLYPH_BANK_PALETTE_COUNT_V1 as u64 * 16 * 2),
|
||||
decoded_size: 16 * 16 + (GLYPH_BANK_PALETTE_COUNT_V1 as u64 * 16 * 4),
|
||||
codec: AssetCodec::None,
|
||||
metadata: json!({
|
||||
"tile_size": 16,
|
||||
|
||||
@@ -65,23 +65,4 @@ impl Color {
|
||||
(self.0 & 0xFF) as u8
|
||||
}
|
||||
|
||||
#[deprecated(note = "Temporary bridge until the renderer buffer migrates to RGBA8888.")]
|
||||
pub const fn to_rgb565_lossy(self) -> u16 {
|
||||
let (r, g, b, _) = Self::unpack_to_native(self.0);
|
||||
let r5 = (r as u16 >> 3) & 0x1F;
|
||||
let g6 = (g as u16 >> 2) & 0x3F;
|
||||
let b5 = (b as u16 >> 3) & 0x1F;
|
||||
(r5 << 11) | (g6 << 5) | b5
|
||||
}
|
||||
|
||||
#[deprecated(note = "Temporary bridge until asset palettes migrate to RGBA8888.")]
|
||||
pub const fn from_rgb565_lossy(raw: u16) -> Self {
|
||||
let r5 = ((raw >> 11) & 0x1F) as u32;
|
||||
let g6 = ((raw >> 5) & 0x3F) as u32;
|
||||
let b5 = (raw & 0x1F) as u32;
|
||||
let r = ((r5 << 3) | (r5 >> 2)) as u8;
|
||||
let g = ((g6 << 2) | (g6 >> 4)) as u8;
|
||||
let b = ((b5 << 3) | (b5 >> 2)) as u8;
|
||||
Self::rgba(r, g, b, 255)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,11 +113,11 @@ fn serialized_single_function_module_with_consts(
|
||||
}
|
||||
|
||||
fn test_glyph_payload_size(width: usize, height: usize) -> usize {
|
||||
(width * height).div_ceil(2) + (GLYPH_BANK_PALETTE_COUNT_V1 * 16 * std::mem::size_of::<u16>())
|
||||
(width * height).div_ceil(2) + (GLYPH_BANK_PALETTE_COUNT_V1 * 16 * std::mem::size_of::<u32>())
|
||||
}
|
||||
|
||||
fn test_glyph_decoded_size(width: usize, height: usize) -> usize {
|
||||
width * height + (GLYPH_BANK_PALETTE_COUNT_V1 * 16 * std::mem::size_of::<u16>())
|
||||
width * height + (GLYPH_BANK_PALETTE_COUNT_V1 * 16 * std::mem::size_of::<u32>())
|
||||
}
|
||||
|
||||
fn test_glyph_asset_entry(asset_name: &str, data_len: usize) -> AssetEntry {
|
||||
@@ -141,8 +141,8 @@ fn test_glyph_asset_entry(asset_name: &str, data_len: usize) -> AssetEntry {
|
||||
|
||||
fn test_glyph_asset_data() -> Vec<u8> {
|
||||
let mut data =
|
||||
vec![0x11u8; test_glyph_payload_size(16, 16) - (GLYPH_BANK_PALETTE_COUNT_V1 * 16 * 2)];
|
||||
data.extend_from_slice(&[0u8; GLYPH_BANK_PALETTE_COUNT_V1 * 16 * 2]);
|
||||
vec![0x11u8; test_glyph_payload_size(16, 16) - (GLYPH_BANK_PALETTE_COUNT_V1 * 16 * 4)];
|
||||
data.extend_from_slice(&[0u8; GLYPH_BANK_PALETTE_COUNT_V1 * 16 * 4]);
|
||||
data
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ fn build_glyph_asset() -> (AssetEntry, Vec<u8>) {
|
||||
bank_type: BankType::GLYPH,
|
||||
offset: 0,
|
||||
size: payload.len() as u64,
|
||||
decoded_size: (8 * 8 + GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * 2)
|
||||
decoded_size: (8 * 8 + GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * 4)
|
||||
as u64,
|
||||
codec: AssetCodec::None,
|
||||
metadata: serde_json::json!({
|
||||
@@ -301,11 +301,11 @@ fn build_glyph_asset() -> (AssetEntry, Vec<u8>) {
|
||||
|
||||
fn build_palette_bytes() -> Vec<u8> {
|
||||
let mut bytes =
|
||||
Vec::with_capacity(GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * 2);
|
||||
Vec::with_capacity(GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * 4);
|
||||
for palette_id in 0..GLYPH_BANK_PALETTE_COUNT_V1 {
|
||||
for color_index in 0..GLYPH_BANK_COLORS_PER_PALETTE {
|
||||
let color = if color_index == 1 { stress_color(palette_id) } else { Color::BLACK };
|
||||
bytes.extend_from_slice(&color.raw().to_le_bytes());
|
||||
bytes.extend_from_slice(&color.raw().to_be_bytes());
|
||||
}
|
||||
}
|
||||
bytes
|
||||
|
||||
Reference in New Issue
Block a user