Skip to content

Commit

Permalink
Added chroma key support
Browse files Browse the repository at this point in the history
  • Loading branch information
stringflow committed Oct 12, 2020
1 parent 10b6a1f commit 00b6edc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# GBC Input Display

A lightweight input display written in Rust that can be utilized for GameBoy and GameBoy Color games.
This was the first Rust code I wrote, so expect it to not be very nice.
This was the first Rust code I wrote, so expect it to not be very nice.


# Chroma Keying

The background will be drawn with +1 in the green channel, meaning that it is able to be chroma keyed out using a similarity and smoothness values of 1.
12 changes: 10 additions & 2 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn draw_background() {

update_dpad();

app.platform.offscreen_buffer.clear(app.palette[3]);
app.platform.offscreen_buffer.clear(app.palette[4]);
for key in app.keys.iter() {
draw!(&app.keyset, key.x, key.y, key.idx);
}
Expand Down Expand Up @@ -204,7 +204,15 @@ pub fn change_palette(index: usize) {
return;
}

app.palette = app.palettes[index].1.clone();
let mut new_palette = app.palettes[index].1.clone();

// 2 palette entries are inserted:
// The first one is reserved for the future
// The second one is the background color + 1 green for chromakey purposes
new_palette.insert(3, [0, 0, 0]);
new_palette.insert(4, [new_palette[4][0], new_palette[4][1] + 1, new_palette[4][2]]);

app.palette = new_palette;
app.palette_index = index;
draw_background();
}
Expand Down
4 changes: 2 additions & 2 deletions src/bmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Index<usize> for Bitmap {
}

const BMP_SIGNATURE: u16 = 0x424d;
const BPP: u8 = 4;
const NUM_COLORS: u8 = 5;

pub fn bmp_load(data: &[u8]) -> Result<Bitmap, BMPError> {
let mut pointer = Cursor::new(data);
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn bmp_load(data: &[u8]) -> Result<Bitmap, BMPError> {
for y in 0..header.height {
for x in 0..header.width {
pointer.read(&mut px)?;
data[(x + (header.height - y - 1) * header.width) as usize] = px[0] / (BPP << 4);
data[(x + (header.height - y - 1) * header.width) as usize] = px[0] / (255 / NUM_COLORS);
}
}

Expand Down
Binary file modified src/gfx/arrows.bmp
Binary file not shown.
Binary file modified src/gfx/keys.bmp
Binary file not shown.

0 comments on commit 00b6edc

Please sign in to comment.