[][src]Struct fae::Image

pub struct Image {
    pub pixels: Vec<u8>,
    pub width: i32,
    pub height: i32,
    pub format: GLuint,
    pub pixel_type: GLuint,
    pub null_data: bool,
}

Contains the raw pixel color data of an image.

Fields

pixels: Vec<u8>

The pixels of the image.

width: i32

The width of the image.

height: i32

The height of the image.

format: GLuint

The OpenGL format of the image.

pixel_type: GLuint

The OpenGL type of the pixels of the image.

null_data: bool

Whether the image represents a null pointer for glTexImage2D. If true, the memory for the texture of width x height will be allocated on the GPU, but will probably be garbage.

Methods

impl Image[src]

pub fn with_png(bytes: &[u8]) -> Result<Image, PngLoadingError>[src]

Parses a PNG image and makes an Image out of it.

This function assumes that the image is in SRGB space, so the image format defaults to SRGB or SRGB_ALPHA if the image contains the RGB or RGBA components.

Color type note

If your image has a ColorType of Grayscale, Indexed or GrayscaleAlpha, it will not display as you would imagine with the default shaders. These images will use GL_RED, GL_RED, and GL_RG as their format when uploading the texture, so you need to take that into account in your shaders (eg. when using GrayscaleAlpha, you'd use the color.g value as your alpha, and color.r as your grayscale value).

Errors

A PngError will be returned if the data couldn't be read for some reason by the png crate (most probably, bytes doesn't describe a valid PNG image). An UnsupportedBitDepth error will be returned if the PNG bit depth isn't 8 or 16 bits per channel.

Example

let sprite = fae::Image::with_png(&std::fs::read("sprite.png")?)?;

pub fn with_color(
    width: i32,
    height: i32,
    color: &[u8]
) -> Result<Image, ImageCreationError>
[src]

Creates a solid color image.

The color can be 1-4 items long, and will be interpreted in the following order: red, green, blue, alpha.

The color is interpreted as SRGB when 3 or 4 color components are provided, to be consistent with loading images from the disk, which are assumed to be in SRGB space by default.

Based on the length of the color slice, the format of the resulting image will be gl::RED, gl::RG, gl::SRGB, or gl::SRGB_ALPHA. This can be changed with format().

Example

use fae::Image;
let image = Image::with_color(128, 128, &[0xB4, 0x6E, 0xC8, 0xFF]);
// image now represents a 128px by 128px image that consists of fully opaque violet pixels.

pub fn with_null_texture(width: i32, height: i32, format: GLuint) -> Image[src]

Creates an image with a specified width, height and a format, and signals to OpenGL that the texture will be filled in later. The memory for the texture will be allocated on the GPU, but no pixel data needs to be sent from the CPU to the GPU during initialization.

See also: Spritesheet::upload_texture_region.

pub fn format(&mut self, format: GLuint) -> &mut Self[src]

Sets the format of the pixels.

Generally: gl::RED for grayscale pixels, gl::RGB for linear non-transparent pixels, and gl::RGBA for linear and transparent pixels.

Example

use fae::{gl, Image};
let image = Image::with_color(128, 128, &[0x88])?.format(gl::RED);
// image now represents a 128px by 128px image that consists of half-red pixels taking up only one byte per pixel.

Trait Implementations

impl Clone for Image[src]

impl Debug for Image[src]

Auto Trait Implementations

impl RefUnwindSafe for Image

impl Send for Image

impl Sync for Image

impl Unpin for Image

impl UnwindSafe for Image

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.