Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] reader_type + type_size #44

Open
lublak opened this issue Dec 19, 2024 · 1 comment
Open

[feature request] reader_type + type_size #44

lublak opened this issue Dec 19, 2024 · 1 comment

Comments

@lublak
Copy link
Contributor

lublak commented Dec 19, 2024

currently there is only "reader_size" which calls "formats::image_type()" which also supports a reader.
So an "reader_type" would be useful.
Another function would also be useful: "type_size(image_type, reader)" if we need both data, so we don't look up the size two times.

/// [`ImageError`]: enum.ImageError.html
pub fn reader_size<R: BufRead + Seek>(mut reader: R) -> ImageResult<ImageSize> {
    dispatch_header(&mut reader)
}

/// Calls the correct image size method based on the image type
///
/// # Arguments
/// * `reader` - A reader for the data
/// * `header` - The header of the file
fn dispatch_header<R: BufRead + Seek>(reader: &mut R) -> ImageResult<ImageSize> {
    match formats::image_type(reader)? {
        ImageType::Aseprite => aesprite::size(reader),
        ImageType::Bmp => bmp::size(reader),
        ImageType::Dds => dds::size(reader),
@lublak lublak changed the title [feature request] [feature request] reader_type + type_size Dec 19, 2024
@TaeHagen
Copy link

This absolutely would be useful.

For reference, the amount of bytes you need to read for the header is 12:

let mut header = [0; 12];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants