Skip to content

Commit f664f7f

Browse files
authored
fix: gif global color table size (#1348)
1 parent edeb20e commit f664f7f

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

sdk/src/asset_handlers/gif_io.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,11 @@ impl GifIO {
387387

388388
Header::from_stream(stream)?;
389389
let logical_screen_descriptor = LogicalScreenDescriptor::from_stream(stream)?;
390-
if logical_screen_descriptor.color_table_flag {
391-
GlobalColorTable::from_stream(stream, logical_screen_descriptor.color_resolution)?;
390+
if logical_screen_descriptor.global_color_table_flag {
391+
GlobalColorTable::from_stream(
392+
stream,
393+
logical_screen_descriptor.global_color_table_size,
394+
)?;
392395
}
393396

394397
Ok(())
@@ -716,10 +719,10 @@ impl Block {
716719
LogicalScreenDescriptor::from_stream(stream)?,
717720
)),
718721
Block::LogicalScreenDescriptor(logical_screen_descriptor) => {
719-
match logical_screen_descriptor.color_table_flag {
722+
match logical_screen_descriptor.global_color_table_flag {
720723
true => Some(Block::GlobalColorTable(GlobalColorTable::from_stream(
721724
stream,
722-
logical_screen_descriptor.color_resolution,
725+
logical_screen_descriptor.global_color_table_size,
723726
)?)),
724727
false => None,
725728
}
@@ -828,23 +831,23 @@ impl Header {
828831

829832
#[derive(Debug, Clone, PartialEq)]
830833
struct LogicalScreenDescriptor {
831-
color_table_flag: bool,
832-
color_resolution: u8,
834+
global_color_table_flag: bool,
835+
global_color_table_size: u8,
833836
}
834837

835838
impl LogicalScreenDescriptor {
836839
fn from_stream(stream: &mut dyn CAIRead) -> Result<LogicalScreenDescriptor> {
837840
stream.seek(SeekFrom::Current(4))?;
838841

839842
let packed = stream.read_u8()?;
840-
let color_table_flag = (packed >> 7) & 1;
841-
let color_resolution = (packed >> 4) & 0b111;
843+
let global_color_table_flag = (packed >> 7) & 1;
844+
let global_color_table_size = packed & 0b111;
842845

843846
stream.seek(SeekFrom::Current(2))?;
844847

845848
Ok(LogicalScreenDescriptor {
846-
color_table_flag: color_table_flag != 0,
847-
color_resolution,
849+
global_color_table_flag: global_color_table_flag != 0,
850+
global_color_table_size,
848851
})
849852
}
850853
}
@@ -853,10 +856,8 @@ impl LogicalScreenDescriptor {
853856
struct GlobalColorTable {}
854857

855858
impl GlobalColorTable {
856-
fn from_stream(stream: &mut dyn CAIRead, color_resolution: u8) -> Result<GlobalColorTable> {
857-
stream.seek(SeekFrom::Current(
858-
3 * (2_i64.pow(color_resolution as u32 + 1)),
859-
))?;
859+
fn from_stream(stream: &mut dyn CAIRead, size: u8) -> Result<GlobalColorTable> {
860+
stream.seek(SeekFrom::Current(3 * (2_i64.pow(size as u32 + 1))))?;
860861

861862
Ok(GlobalColorTable {})
862863
}
@@ -1168,8 +1169,8 @@ mod tests {
11681169
start: 6,
11691170
len: 7,
11701171
block: Block::LogicalScreenDescriptor(LogicalScreenDescriptor {
1171-
color_table_flag: true,
1172-
color_resolution: 7
1172+
global_color_table_flag: true,
1173+
global_color_table_size: 7
11731174
})
11741175
})
11751176
);

0 commit comments

Comments
 (0)