From 1a5542b325e945f93336920ee0813ee0aa57ac7c Mon Sep 17 00:00:00 2001 From: Genny Date: Sun, 11 Dec 2022 17:30:16 -0600 Subject: OMG actually say what it is --- gifed/src/gif.rs | 61 +++++++++++++++++++++++++++++++++------------------- recolor-extension.md | 5 +++-- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/gifed/src/gif.rs b/gifed/src/gif.rs index fd3a322..563f37e 100644 --- a/gifed/src/gif.rs +++ b/gifed/src/gif.rs @@ -5,7 +5,7 @@ use crate::{ encode_block, extension::{DisposalMethod, GraphicControl}, packed::ImagePacked, - Block, Palette, ScreenDescriptor, Version, + Block, CompressedImage, ImageDescriptor, IndexedImage, Palette, ScreenDescriptor, Version, }, writer::GifBuilder, }; @@ -81,36 +81,37 @@ impl<'a> Iterator for ImageIterator<'a> { self.block_index += 1; }; - let palette = img - .local_color_table - .as_ref() - .unwrap_or(self.gif.global_color_table.as_ref().unwrap()); - Some(Image { - width: img.image_descriptor.width, - height: img.image_descriptor.height, - left_offset: img.image_descriptor.left, - top_offset: img.image_descriptor.top, - packed: img.image_descriptor.packed, - palette, - image_blocks: &img.blocks, + compressed: &img, + global_palette: self.gif.global_color_table.as_ref(), blocks: &self.gif.blocks[starting_block..self.block_index], }) } } pub struct Image<'a> { - pub width: u16, - pub height: u16, - pub left_offset: u16, - pub top_offset: u16, - pub packed: ImagePacked, - pub palette: &'a Palette, - pub image_blocks: &'a [Vec], + pub compressed: &'a CompressedImage, + pub global_palette: Option<&'a Palette>, pub blocks: &'a [Block], } impl<'a> Image<'a> { + pub fn width(&self) -> u16 { + self.compressed.image_descriptor.width + } + + pub fn height(&self) -> u16 { + self.compressed.image_descriptor.height + } + + pub fn top(&self) -> u16 { + self.compressed.image_descriptor.top + } + + pub fn left(&self) -> u16 { + self.compressed.image_descriptor.left + } + pub fn graphic_control(&self) -> Option<&GraphicControl> { for block in self.blocks { if let Block::GraphicControlExtension(gce) = block { @@ -151,11 +152,21 @@ impl<'a> Image<'a> { } } + pub fn palette(&self) -> &Palette { + if let Some(plt) = self.compressed.local_color_table.as_ref() { + plt + } else { + //FIXME: Maybe don't panic here + self.global_palette.unwrap() + } + } + pub fn png_trns(&self) -> Option> { + let palette = self.palette(); if let Some(trans_idx) = self.transparent_index() { - let mut trns = Vec::with_capacity(self.palette.len()); + let mut trns = Vec::with_capacity(palette.len()); - for idx in 0..self.palette.len() as u8 { + for idx in 0..palette.len() as u8 { if idx == trans_idx { trns.push(0u8); } else { @@ -168,6 +179,12 @@ impl<'a> Image<'a> { None } + + /// Clones the CompressedImage and decompresses it. + pub fn decompess(&self) -> IndexedImage { + //FIXME: unwrap + self.compressed.clone().decompress().unwrap() + } } pub enum FrameControl { diff --git a/recolor-extension.md b/recolor-extension.md index 30c21c5..aac82f6 100644 --- a/recolor-extension.md +++ b/recolor-extension.md @@ -1,11 +1,12 @@ # Recolor Extension DRAFT - -I want to assume that if the decoder does not know the type of an extension, IE the extension label does not match with graphic control/comment/plain text/application, that it will silently ignore it. The decoder can always know the size, so it seems plausbile. But I cannot find any indication of so in the spec for 87a or 89a. +An extension to replace the currently active global colour table. There is no limit on how many may appear in a data stream. ## Extension Scope The scope of this extension is every block following this one. ## Extension Type +I want to assume that if the decoder does not know the type of an extension, IE the extension label does not match with graphic control/comment/plain text/application, that it will silently ignore it. The decoder can always know the size, so it seems plausbile. But I cannot find any indication of so in the spec for 87a or 89a. + ### Regular Extension In the case where we determine that we don't need to "wrap" it in an application extension this extension's label shall be `0xF8`. This positions it directly below the Graphic Control Extension, `0xF9`. -- cgit 1.4.1-3-g733a5