Struct image::codecs::tga::TgaDecoder
source · pub struct TgaDecoder<R> {
r: R,
width: usize,
height: usize,
bytes_per_pixel: usize,
has_loaded_metadata: bool,
image_type: ImageType,
color_type: ColorType,
original_color_type: Option<ExtendedColorType>,
header: Header,
color_map: Option<ColorMap>,
line_read: Option<usize>,
line_remain_buff: Vec<u8>,
}
Expand description
A decoder for TGA images
Currently this decoder does not support 8, 15 and 16 bit color images. The representation of a TGA decoder
Fields§
§r: R
§width: usize
§height: usize
§bytes_per_pixel: usize
§has_loaded_metadata: bool
§image_type: ImageType
§color_type: ColorType
§original_color_type: Option<ExtendedColorType>
§header: Header
§color_map: Option<ColorMap>
§line_read: Option<usize>
§line_remain_buff: Vec<u8>
Implementations§
source§impl<R: Read + Seek> TgaDecoder<R>
impl<R: Read + Seek> TgaDecoder<R>
sourcepub fn new(r: R) -> ImageResult<TgaDecoder<R>>
pub fn new(r: R) -> ImageResult<TgaDecoder<R>>
Create a new decoder that decodes from the stream r
fn read_header(&mut self) -> ImageResult<()>
fn read_metadata(&mut self) -> ImageResult<()>
sourcefn read_color_information(&mut self) -> ImageResult<()>
fn read_color_information(&mut self) -> ImageResult<()>
Loads the color information for the decoder
To keep things simple, we won’t handle bit depths that aren’t divisible by 8 and are larger than 32.
sourcefn read_image_id(&mut self) -> ImageResult<()>
fn read_image_id(&mut self) -> ImageResult<()>
Read the image id field
We’re not interested in this field, so this function skips it if it is present
fn read_color_map(&mut self) -> ImageResult<()>
sourcefn expand_color_map(&self, pixel_data: &[u8]) -> Result<Vec<u8>>
fn expand_color_map(&self, pixel_data: &[u8]) -> Result<Vec<u8>>
Expands indices into its mapped color
sourcefn read_encoded_data(&mut self, num_bytes: usize) -> Result<Vec<u8>>
fn read_encoded_data(&mut self, num_bytes: usize) -> Result<Vec<u8>>
Reads a run length encoded data for given number of bytes
sourcefn read_all_encoded_data(&mut self) -> ImageResult<Vec<u8>>
fn read_all_encoded_data(&mut self) -> ImageResult<Vec<u8>>
Reads a run length encoded packet
sourcefn read_encoded_line(&mut self) -> Result<Vec<u8>>
fn read_encoded_line(&mut self) -> Result<Vec<u8>>
Reads a run length encoded line
sourcefn reverse_encoding_in_output(&mut self, pixels: &mut [u8])
fn reverse_encoding_in_output(&mut self, pixels: &mut [u8])
Reverse from BGR encoding to RGB encoding
TGA files are stored in the BGRA encoding. This function swaps
the blue and red bytes in the pixels
array.
sourcefn flip_vertically(&mut self, pixels: &mut [u8])
fn flip_vertically(&mut self, pixels: &mut [u8])
Flip the image vertically depending on the screen origin bit
The bit in position 5 of the image descriptor byte is the screen origin bit. If it’s 1, the origin is in the top left corner. If it’s 0, the origin is in the bottom left corner. This function checks the bit, and if it’s 0, flips the image vertically.
sourcefn is_flipped_vertically(&self) -> bool
fn is_flipped_vertically(&self) -> bool
Check whether the image is vertically flipped
The bit in position 5 of the image descriptor byte is the screen origin bit. If it’s 1, the origin is in the top left corner. If it’s 0, the origin is in the bottom left corner. This function checks the bit, and if it’s 0, flips the image vertically.
fn read_scanline(&mut self, buf: &mut [u8]) -> Result<usize>
Trait Implementations§
source§impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TgaDecoder<R>
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TgaDecoder<R>
source§fn dimensions(&self) -> (u32, u32)
fn dimensions(&self) -> (u32, u32)
source§fn color_type(&self) -> ColorType
fn color_type(&self) -> ColorType
source§fn original_color_type(&self) -> ExtendedColorType
fn original_color_type(&self) -> ExtendedColorType
source§fn scanline_bytes(&self) -> u64
fn scanline_bytes(&self) -> u64
total_bytes()
.source§fn into_reader(self) -> ImageResult<Self::Reader>
fn into_reader(self) -> ImageResult<Self::Reader>
scanline_bytes
from the reader at a time. Reading
fewer bytes will cause the reader to perform internal buffering.source§fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
source§fn icc_profile(&mut self) -> Option<Vec<u8>>
fn icc_profile(&mut self) -> Option<Vec<u8>>
source§fn total_bytes(&self) -> u64
fn total_bytes(&self) -> u64
source§fn read_image_with_progress<F: Fn(Progress)>(
self,
buf: &mut [u8],
progress_callback: F,
) -> ImageResult<()>
fn read_image_with_progress<F: Fn(Progress)>( self, buf: &mut [u8], progress_callback: F, ) -> ImageResult<()>
read_image
but periodically calls the provided callback to give updates on loading
progress.source§fn set_limits(&mut self, limits: Limits) -> ImageResult<()>
fn set_limits(&mut self, limits: Limits) -> ImageResult<()>
Auto Trait Implementations§
impl<R> Freeze for TgaDecoder<R>where
R: Freeze,
impl<R> RefUnwindSafe for TgaDecoder<R>where
R: RefUnwindSafe,
impl<R> Send for TgaDecoder<R>where
R: Send,
impl<R> Sync for TgaDecoder<R>where
R: Sync,
impl<R> Unpin for TgaDecoder<R>where
R: Unpin,
impl<R> UnwindSafe for TgaDecoder<R>where
R: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more