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.

Extracts a slice containing the entire internal buffer.

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")

Trait Implementations

Performs the conversion.

Returns the “default value” for a type. Read more

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.