core: Switch from libflate to flate2

This commit is contained in:
Mike Welsh 2020-10-11 03:09:23 -07:00
parent 2c2aa82730
commit a6b952e44e
4 changed files with 14 additions and 15 deletions

2
Cargo.lock generated
View File

@ -2682,6 +2682,7 @@ dependencies = [
"chrono",
"downcast-rs",
"enumset",
"flate2",
"fnv",
"gc-arena",
"gc-arena-derive",
@ -2691,7 +2692,6 @@ dependencies = [
"instant",
"jpeg-decoder",
"json",
"libflate",
"log",
"minimp3",
"num-traits 0.2.12",

View File

@ -7,13 +7,13 @@ license = "MIT OR Apache-2.0"
[dependencies]
bitstream-io = "0.9.0"
flate2 = "1.0.18"
fnv = "1.0.7"
gc-arena = "0.2.0"
gc-arena-derive = "0.2.0"
generational-arena = "0.2.8"
gif = "0.11.1"
indexmap = "1.6.0"
libflate = "1.0.2"
log = "0.4"
minimp3 = { version = "0.5.0", optional = true }
png = { version = "0.16.7" }

View File

@ -265,12 +265,7 @@ pub fn decode_jpeg(
// Decompress the alpha data (DEFLATE compression).
if let Some(alpha_data) = alpha_data {
let alpha_data = {
let mut data = vec![];
let mut decoder = libflate::zlib::Decoder::new(alpha_data)?;
decoder.read_to_end(&mut data)?;
data
};
let alpha_data = decompress_zlib(alpha_data)?;
if alpha_data.len() == decoded_data.len() / 3 {
let mut rgba = Vec::with_capacity((decoded_data.len() / 3) * 4);
@ -315,12 +310,7 @@ pub fn decode_define_bits_lossless(
swf_tag: &swf::DefineBitsLossless,
) -> Result<Bitmap, Box<dyn std::error::Error>> {
// Decompress the image data (DEFLATE compression).
let mut decoded_data = {
let mut data = vec![];
let mut decoder = libflate::zlib::Decoder::new(&swf_tag.data[..])?;
decoder.read_to_end(&mut data)?;
data
};
let mut decoded_data = decompress_zlib(&swf_tag.data[..])?;
// Swizzle/de-palettize the bitmap.
let out_data = match (swf_tag.version, swf_tag.format) {
@ -513,3 +503,12 @@ pub fn srgb_to_linear(color: [f32; 4]) -> [f32; 4] {
color[3],
]
}
/// Decodes zlib-compressed data.
fn decompress_zlib(data: &[u8]) -> Result<Vec<u8>, std::io::Error> {
let mut out_data = Vec::new();
let mut decoder = flate2::bufread::ZlibDecoder::new(data);
decoder.read_to_end(&mut out_data)?;
out_data.shrink_to_fit();
Ok(out_data)
}

View File

@ -23,5 +23,5 @@ xz2 = {version = "0.1.6", optional = true}
approx = "0.3.2"
[features]
default = ["libflate"]
default = ["flate2"]
lzma = ["xz2"]