pub fn new(image_type: TgaImageType, width: u16, height: u16, bit_depth: u8) -> Result<TgaImage, TgaError> {
        // Ensure the pixel depth is valid
        if !image_type.valid_depth(bit_depth) {
            return Err(InvalidPixelDepth);
        }

        // Create header
        let header = TgaHeader {
            id_size: 0,
            has_color_map: false,
            image_type,
            color_map_first_index: 0,
            color_map_size: 0,
            color_map_bit_depth: 0,
            x_origin: 0,
            y_origin: 0,
            width,
            height,
            image_bit_depth: bit_depth,
            descriptor: 0
        };

        Ok(TgaImage {
            header,
            state: TgaImageState::Uncompressed,
            id: vec![].into_boxed_slice(),
            color_map: vec![].into_boxed_slice(),
            data: vec![0; image_size(width, height, bit_depth)].into_boxed_slice()
        })
    }
/// Tries to create a new color with black pixels.
/// 
/// # Errors
/// If `bit_depth` is invalid for `image_type`, returns `InvalidPixelDepth` error.
Tries to create a new color with black pixels.
Tries to create a new color with black pixels .
pub fn new(image_type: TgaImageType, width: u16, height: u16, bit_depth: u8) -> Result<TgaImage, TgaError> {
        // Ensure the pixel depth is valid
        if !image_type.valid_depth(bit_depth) {
            return Err(InvalidPixelDepth);
        }
        // Create header
        let header = TgaHeader {
            id_size: 0,
            has_color_map: false,
            image_type,
            color_map_first_index: 0,
            color_map_size: 0,
            color_map_bit_depth: 0,
            x_origin: 0,
            y_origin: 0,
            width,
            height,
            image_bit_depth: bit_depth,
            descriptor: 0
        };
        Ok(TgaImage {
            header,
            state: TgaImageState::Uncompressed,
            id: vec![].into_boxed_slice(),
            color_map: vec![].into_boxed_slice(),
            data: vec![0; image_size(width, height, bit_depth)].into_boxed_slice()
        })
    }
pub fn new ( image_type : TgaImageType , width : u16 , height : u16 , bit_depth : u8 ) -> Result < TgaImage , TgaError > { // Ensure the pixel depth is valid if ! image_type . valid_depth ( bit_depth ) { return Err ( InvalidPixelDepth ) ; } // Create header let header = TgaHeader { id_size : 0 , has_color_map : false , image_type , color_map_first_index : 0 , color_map_size : 0 , color_map_bit_depth : 0 , x_origin : 0 , y_origin : 0 , width , height , image_bit_depth : bit_depth , descriptor : 0 } ; Ok ( TgaImage { header , state : TgaImageState :: Uncompressed , id : vec ! [ ] . into_boxed_slice ( ) , color_map : vec ! [ ] . into_boxed_slice ( ) , data : vec ! [ 0 image_size ( width height bit_depth ) ] . into_boxed_slice ( ) } ) }
Tries to create a new color with black pixels.
Tries to create a new color with black pixels .
image_type
TgaImageType
width
u16
height
u16
bit_depth
u8
image_type
TgaImageType
width
u16
height
u16
bit_depth
u8
errors
If `bit_depth` is invalid for `image_type`, returns `InvalidPixelDepth` error.
If ` bit_depth ` is invalid for ` image_type ` returns ` InvalidPixelDepth ` error .