diff options
author | Genny <gen@nyble.dev> | 2021-09-23 20:33:50 -0500 |
---|---|---|
committer | Genny <gen@nyble.dev> | 2021-09-23 20:33:50 -0500 |
commit | 637441239434fabedfe83f5abc1af4232c802f7a (patch) | |
tree | dbc84cd1a31686077fc046fd42d223f1ca08f890 /src/reader/mod.rs | |
parent | 7b8081a79fb3db4a76f9e4cca8f8a88e6e7f873c (diff) | |
download | gifed-637441239434fabedfe83f5abc1af4232c802f7a.tar.gz gifed-637441239434fabedfe83f5abc1af4232c802f7a.zip |
Improve API, monocommit, sorry
Diffstat (limited to 'src/reader/mod.rs')
-rw-r--r-- | src/reader/mod.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 606de11..7653216 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -9,9 +9,10 @@ use std::{ use crate::{ block::{ extension::{Application, Extension, GraphicControl}, - Block, BlockedImage, ColorTable, ImageDescriptor, ScreenDescriptor, Version, + Block, ColorTable, CompressedImage, ImageDescriptor, IndexedImage, ScreenDescriptor, + Version, }, - Gif, + color, Gif, }; pub struct GifReader {} @@ -100,8 +101,8 @@ impl GifReader { } } - fn read_extension(mut reader: &mut SmartReader) -> Block { - let mut extension_id = reader.u8().expect("File ended early"); + fn read_extension(reader: &mut SmartReader) -> Block { + let extension_id = reader.u8().expect("File ended early"); match extension_id { 0xF9 => { @@ -149,13 +150,17 @@ impl GifReader { let lzw_csize = reader.u8().expect("Failed to read LZW Minimum Code Size"); - let blocks = reader.take_data_subblocks(); + let compressed_data = reader.take_and_collapse_subblocks(); + println!("c{}", compressed_data.len()); - Block::BlockedImage(BlockedImage { + let mut decompress = weezl::decode::Decoder::new(weezl::BitOrder::Lsb, lzw_csize); + //TODO: remove unwrap + let mut decompressed_data = decompress.decode(&compressed_data).unwrap(); + + Block::IndexedImage(IndexedImage { image_descriptor: descriptor, local_color_table: color_table, - lzw_minimum_code_size: lzw_csize, - blocks, + indicies: decompressed_data, }) } } |