/// A lightweight per-thread pixel accumulator.
///
/// Stores already-adjusted 7-byte pixel entries `[x_lo, x_hi, y_lo, y_hi, r, g, b]`
/// ready to be merged into the main Display buffer. No packets, no flushing,
/// no queue -- just a growable buffer that each draw thread fills independently.
use crate::pixel::Pixel;
pub struct PixelBuf {
    pub pixels: Vec<[u8;7]>,
}

impl PixelBuf {
    /// Creates a new empty PixelBuf with the given initial capacity.
    pub fn new(capacity: usize) -> Self {
        PixelBuf {
            pixels: Vec::with_capacity(capacity),
        }
    }

    /// Clears the buffer for reuse without deallocating.
    #[inline]
    pub fn clear(&mut self) {
        self.pixels.clear();
    }

    #[inline]
    pub fn set_pixel(&mut self, pixel: Pixel) {
        self.pixels.push(pixel.format0());
    }

    #[inline]
    pub fn set_pixels(&mut self, pixels: Vec<Pixel>) {
        self.pixels.reserve(pixels.len());
        for pixel in pixels {
            self.pixels.push(pixel.format0())
        }
    }

    /// Appends pixels from a borrowed slice (avoids cloning precomputed data).
    #[inline]
    pub fn set_pixels_ref(&mut self, pixels: &[Pixel]) {
        self.pixels.reserve(pixels.len());
        for pixel in pixels {
            self.pixels.push(pixel.format0())
        }
    }
}
