Struct pixelflut::PixelBuffer [−][src]
pub struct PixelBuffer { /* fields omitted */ }
Expand description
Pixel buffer is a byte buffer that guarantees to contain valid pixelflut data. It is used as an internal buffer for the sync and async clients and can also be used for pre-format an array of pixels, as the PixelBuffer can direclty be send with a client.
Examples
use pixelflut::{PixelBuffer, Pixel}; let mut buffer = PixelBuffer::new(); // Add some pixel to the buffer buffer.write_pixel(&Pixel::new((12, 34).into(), (255, 0, 10).into())); buffer.write_pixel(&Pixel::new((13, 34).into(), (255, 0, 10).into())); assert_eq!(buffer.as_slice(), b"PX 12 34 ff000a\nPX 13 34 ff000a\n"); // There is still capacity in the buffer assert!(!buffer.is_capacity_reached()); // Fill the buffer until the capacity is barely reached, without reallocating the buffer. let mut i = 0; while !buffer.is_capacity_reached() { // draw a red line buffer.write_pixel(&Pixel::new((i, 0).into(), (255, 0, 0).into())); i += 1; } // Clear the buffer buffer.clear(); assert!(buffer.is_empty());
Implementations
Constructs a new PixelBuffer with the specified capacity.
The capacity is given in bytes. If you need a Capacity in Pixels, consider with_capacity_pixels.
Constructs a new PixelfBuffer with the specified estimated capacity in Pixels.
The capacity is given in pixels. The actual capacity would be higher in most cases, as the worst-cases length of a formated Pixel is used.
Creates a new PixelBuffer with the default capacity.
Returns true
, if the internal buffer is empty.
Examples
use pixelflut::{PixelBuffer, Pixel}; let mut buffer = PixelBuffer::new(); assert_eq!(buffer.is_empty(), true); buffer.write_pixel(&Pixel::default()); assert_eq!(buffer.is_empty(), false);
Returns true
, if the internal buffer is so large,
that the buffer might need to be resized,
if another pixel is added.
Clears the contained buffer. After this, no pixels are in the buffer.
Examples
use pixelflut::{PixelBuffer, Pixel}; let mut buffer = PixelBuffer::new(); buffer.write_pixel(&Pixel::default()); buffer.clear(); assert!(buffer.is_empty());
Writes a pixel to the internal buffer.
Examples
use pixelflut::{PixelBuffer, Pixel}; let mut buffer = PixelBuffer::new(); buffer.write_pixel(&Pixel::new((12, 34).into(), (255, 0, 10).into())); buffer.write_pixel(&Pixel::new((13, 34).into(), (255, 0, 10).into())); assert_eq!(buffer.as_slice(), b"PX 12 34 ff000a\nPX 13 34 ff000a\n")