Skip to content

Commit

Permalink
fix: ensure pixel brightness is using the same palette
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor committed Jun 17, 2024
1 parent 8b04288 commit ad2f873
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 0 additions & 7 deletions tetanes-core/src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,6 @@ impl Ppu {
ppu
}

/// Return the system palette color for the given pixel.
#[inline]
#[must_use]
pub const fn system_palette(pixel: u16) -> (u8, u8, u8) {
Self::SYSTEM_PALETTE[(pixel as usize) & (Self::SYSTEM_PALETTE.len() - 1)]
}

/// Return the current frame buffer.
#[inline]
#[must_use]
Expand Down
5 changes: 4 additions & 1 deletion tetanes-core/src/ppu/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ impl Frame {
#[must_use]
pub fn pixel_brightness(&self, x: u32, y: u32) -> u32 {
let pixel = self.pixel(x, y);
let (red, green, blue) = Ppu::system_palette(pixel);
let index = (pixel as usize) * 3;
let red = Ppu::NTSC_PALETTE[index];
let green = Ppu::NTSC_PALETTE[index + 1];
let blue = Ppu::NTSC_PALETTE[index + 2];
u32::from(red) + u32::from(green) + u32::from(blue)
}

Expand Down

0 comments on commit ad2f873

Please sign in to comment.