implements PLN-0071
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::input::HostInputHandler;
|
||||
use crate::log_sink::HostConsoleSink;
|
||||
use crate::overlay::{capture_snapshot, draw_overlay};
|
||||
use crate::stats::HostStats;
|
||||
use crate::utilities::draw_rgb565_to_rgba8;
|
||||
use crate::utilities::draw_rgba8888_to_rgba8;
|
||||
use pixels::wgpu::PresentMode;
|
||||
use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
|
||||
use prometeu_drivers::AudioCommand;
|
||||
@@ -285,7 +285,7 @@ impl ApplicationHandler for HostRunner {
|
||||
// Immutable borrow of prometeu-core (different field, ok)
|
||||
let src = self.hardware.gfx.front_buffer();
|
||||
|
||||
draw_rgb565_to_rgba8(src, frame);
|
||||
draw_rgba8888_to_rgba8(src, frame);
|
||||
|
||||
if let Some(snapshot) = overlay_snapshot.as_ref() {
|
||||
draw_overlay(frame, Hardware::W, Hardware::H, snapshot);
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
/// Copies RGB565 (u16) -> RGBA8888 (u8[4]) to the pixels frame.
|
||||
/// Pixels format: RGBA8.
|
||||
pub fn draw_rgb565_to_rgba8(src: &[u16], dst_rgba: &mut [u8]) {
|
||||
/// Copies RGBA8888 pixels in canonical RGBA raw order into the `pixels` RGBA8 frame.
|
||||
pub fn draw_rgba8888_to_rgba8(src: &[u32], dst_rgba: &mut [u8]) {
|
||||
for (i, &px) in src.iter().enumerate() {
|
||||
let (r8, g8, b8) = rgb565_to_rgb888(px);
|
||||
let o = i * 4;
|
||||
dst_rgba[o] = r8;
|
||||
dst_rgba[o + 1] = g8;
|
||||
dst_rgba[o + 2] = b8;
|
||||
dst_rgba[o + 3] = 0xFF;
|
||||
dst_rgba[o] = ((px >> 24) & 0xFF) as u8;
|
||||
dst_rgba[o + 1] = ((px >> 16) & 0xFF) as u8;
|
||||
dst_rgba[o + 2] = ((px >> 8) & 0xFF) as u8;
|
||||
dst_rgba[o + 3] = (px & 0xFF) as u8;
|
||||
}
|
||||
}
|
||||
|
||||
/// Expands RGB565 to RGB888 (high bit replication).
|
||||
#[inline(always)]
|
||||
pub fn rgb565_to_rgb888(px: u16) -> (u8, u8, u8) {
|
||||
let r5 = ((px >> 11) & 0x1F) as u8;
|
||||
let g6 = ((px >> 5) & 0x3F) as u8;
|
||||
let b5 = (px & 0x1F) as u8;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::draw_rgba8888_to_rgba8;
|
||||
|
||||
let r8 = (r5 << 3) | (r5 >> 2);
|
||||
let g8 = (g6 << 2) | (g6 >> 4);
|
||||
let b8 = (b5 << 3) | (b5 >> 2);
|
||||
#[test]
|
||||
fn draw_rgba8888_to_rgba8_preserves_channel_order_and_alpha() {
|
||||
let src = [0x12345678, 0xABCDEF01];
|
||||
let mut dst = [0; 8];
|
||||
|
||||
(r8, g8, b8)
|
||||
draw_rgba8888_to_rgba8(&src, &mut dst);
|
||||
|
||||
assert_eq!(dst, [0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x01]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user