From 264c71677b8dd6877e98df76dff91e0cb56a17b1 Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 21 May 2022 16:40:09 -0400 Subject: [PATCH] add helper/debug method to draw a palette to a bitmap --- libretrogd/src/graphics/palette.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libretrogd/src/graphics/palette.rs b/libretrogd/src/graphics/palette.rs index 2258f75..5c3480c 100644 --- a/libretrogd/src/graphics/palette.rs +++ b/libretrogd/src/graphics/palette.rs @@ -8,6 +8,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt}; use thiserror::Error; use crate::NUM_COLORS; +use crate::graphics::*; use crate::utils::abs_diff; // silly "hack" (???) which allows us to alias the generic constraint `RangeBounds + Iterator` to `ColorRange` @@ -454,6 +455,20 @@ impl Palette { closest } + + /// Debug helper that draws this palette to the given bitmap as a 16x16 pixel grid, where each + /// pixel is one of the colors from this palette, in ascending order, left-to-right, + /// top-to-bottom. The coordinates given specify the top-left coordinate on the destination + /// bitmap to begin drawing the palette at. + pub fn draw(&self, dest: &mut Bitmap, x: i32, y: i32) { + let mut color = 0; + for yd in 0..16 { + for xd in 0..16 { + dest.set_pixel(x + xd, y + yd, color); + color = color.wrapping_add(1); + } + } + } } impl Index for Palette {