-
-
Save paultag/60334e9f6c06388cc4b1c2cf12d85085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_main] | |
#![no_std] | |
extern crate alloc; | |
const KIER: &[u8] = include_bytes!("../kier.bin"); | |
const KIER_WIDTH: usize = 1280; | |
const KIER_HEIGHT: usize = 641; | |
const KIER_PIXEL_SIZE: usize = 4; | |
use alloc::{vec, vec::Vec}; | |
use core::ops::{Index, IndexMut}; | |
use uefi::{ | |
prelude::*, | |
proto::console::gop::{BltOp, BltPixel, BltRegion, GraphicsOutput}, | |
Result, | |
}; | |
struct RgbImage { | |
/// width, height | |
size: (usize, usize), | |
/// raw pixels | |
inner: Vec<BltPixel>, | |
} | |
impl Index<(usize, usize)> for RgbImage { | |
type Output = BltPixel; | |
fn index(&self, idx: (usize, usize)) -> &BltPixel { | |
let (x, y) = idx; | |
&self.inner[y * self.size.0 + x] | |
} | |
} | |
impl IndexMut<(usize, usize)> for RgbImage { | |
fn index_mut(&mut self, idx: (usize, usize)) -> &mut BltPixel { | |
let (x, y) = idx; | |
&mut self.inner[y * self.size.0 + x] | |
} | |
} | |
impl RgbImage { | |
/// Create a new `RgbImage`. | |
fn new(width: usize, height: usize) -> Self { | |
RgbImage { | |
size: (width, height), | |
inner: vec![BltPixel::new(0, 0, 0); width * height], | |
} | |
} | |
fn write(&self, gop: &mut GraphicsOutput) -> Result { | |
gop.blt(BltOp::BufferToVideo { | |
buffer: &self.inner, | |
src: BltRegion::Full, | |
dest: (0, 0), | |
dims: self.size, | |
}) | |
} | |
} | |
fn praise() -> Result { | |
let gop_handle = boot::get_handle_for_protocol::<GraphicsOutput>()?; | |
let mut gop = boot::open_protocol_exclusive::<GraphicsOutput>(gop_handle)?; | |
let (width, height) = gop.current_mode_info().resolution(); | |
let (width, height) = (width.min(KIER_WIDTH), height.min(KIER_HEIGHT)); | |
let mut buffer = RgbImage::new(width, height); | |
for y in 0..height { | |
for x in 0..width { | |
let idx_r = ((y * KIER_WIDTH) + x) * KIER_PIXEL_SIZE; | |
let pixel = &mut buffer[(x, y)]; | |
pixel.red = KIER[idx_r]; | |
pixel.green = KIER[idx_r + 1]; | |
pixel.blue = KIER[idx_r + 2]; | |
} | |
} | |
buffer.write(&mut gop)?; | |
Ok(()) | |
} | |
#[entry] | |
fn main() -> Status { | |
uefi::helpers::init().unwrap(); | |
praise().unwrap(); | |
boot::stall(100_000_000); | |
Status::SUCCESS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment