From b649246fe2a14eacbf4e390c3161d980fc845773 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 8 Oct 2015 15:15:31 -0700 Subject: [PATCH] Replace stb_image with PistonDevelopers/image Fixes #3368 --- components/net_traits/Cargo.toml | 5 +-- components/net_traits/image/base.rs | 65 +++++++++++++---------------- components/net_traits/lib.rs | 2 +- components/servo/Cargo.lock | 60 +++++++++++++++++++++++++- ports/cef/Cargo.lock | 61 +++++++++++++++++++++++++-- ports/cef/Cargo.toml | 3 -- ports/cef/lib.rs | 1 - ports/gonk/Cargo.lock | 60 +++++++++++++++++++++++++- python/tidy.py | 5 ++- 9 files changed, 209 insertions(+), 53 deletions(-) diff --git a/components/net_traits/Cargo.toml b/components/net_traits/Cargo.toml index 35c7d3c10cd..f9c4fbd148c 100644 --- a/components/net_traits/Cargo.toml +++ b/components/net_traits/Cargo.toml @@ -7,10 +7,6 @@ authors = ["The Servo Project Developers"] name = "net_traits" path = "lib.rs" -[dependencies.png] -git = "https://github.com/servo/rust-png" -features = [ "serde-serialization" ] - [dependencies.util] path = "../util" @@ -37,6 +33,7 @@ path = "../plugins" [dependencies] log = "0.3" euclid = "0.2" +image = "0.3.14" regex = "0.1.33" regex_macros = "0.1.19" serde = "0.6" diff --git a/components/net_traits/image/base.rs b/components/net_traits/image/base.rs index e0f52592250..fd6ee5620a0 100644 --- a/components/net_traits/image/base.rs +++ b/components/net_traits/image/base.rs @@ -3,9 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use ipc_channel::ipc::IpcSharedMemory; -use png; +use piston_image::{self, DynamicImage, GenericImage}; use stb_image::image as stb_image2; -use std::mem; +use std::error::Error; use util::mem::HeapSizeOf; use util::vec::byte_swap; @@ -48,41 +48,10 @@ pub fn load_from_memory(buffer: &[u8]) -> Option { return None; } - if png::is_png(buffer) { - match png::load_png_from_memory(buffer) { - Ok(mut png_image) => { - let (bytes, format) = match png_image.pixels { - png::PixelsByColorType::K8(ref mut data) => { - (data, PixelFormat::K8) - } - png::PixelsByColorType::KA8(ref mut data) => { - (data, PixelFormat::KA8) - } - png::PixelsByColorType::RGB8(ref mut data) => { - byte_swap(data); - (data, PixelFormat::RGB8) - } - png::PixelsByColorType::RGBA8(ref mut data) => { - byte_swap_and_premultiply(data); - (data, PixelFormat::RGBA8) - } - }; + if is_jpeg(buffer) { + // For JPEG images, we use stb_image because piston_image does not yet support progressive + // JPEG. - let bytes = mem::replace(bytes, Vec::new()); - let bytes = IpcSharedMemory::from_bytes(&bytes[..]); - let image = Image { - width: png_image.width, - height: png_image.height, - format: format, - bytes: bytes, - }; - - Some(image) - } - Err(_err) => None, - } - } else { - // For non-png images, we use stb_image // Can't remember why we do this. Maybe it's what cairo wants static FORCE_DEPTH: usize = 4; @@ -111,6 +80,26 @@ pub fn load_from_memory(buffer: &[u8]) -> Option { None } } + } else { + match piston_image::load_from_memory(buffer) { + Ok(image) => { + let mut rgba = match image { + DynamicImage::ImageRgba8(rgba) => rgba, + image => image.to_rgba() + }; + byte_swap_and_premultiply(&mut *rgba); + Some(Image { + width: rgba.width(), + height: rgba.height(), + format: PixelFormat::RGBA8, + bytes: IpcSharedMemory::from_bytes(&*rgba), + }) + } + Err(e) => { + debug!("Image decoding error: {:?}", e); + None + } + } } } @@ -120,3 +109,7 @@ fn is_gif(buffer: &[u8]) -> bool { _ => false } } + +fn is_jpeg(buffer: &[u8]) -> bool { + buffer.starts_with(&[0xff, 0xd8, 0xff]) +} diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 3aa81ddbd20..aa38d2a0a3f 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -18,8 +18,8 @@ extern crate log; extern crate euclid; extern crate hyper; extern crate ipc_channel; +extern crate image as piston_image; extern crate msg; -extern crate png; extern crate regex; extern crate serde; extern crate stb_image; diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 0c29175b7de..916d5316ee1 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -239,6 +239,11 @@ dependencies = [ "objc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "color_quant" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "compositing" version = "0.0.1" @@ -494,6 +499,14 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "enum_primitive" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "env_logger" version = "0.3.1" @@ -653,6 +666,15 @@ dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", ] +[[package]] +name = "gif" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lzw 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gl_common" version = "0.0.4" @@ -692,6 +714,11 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glob" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "glutin" version = "0.3.6" @@ -866,6 +893,19 @@ dependencies = [ "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "image" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", + "enum_primitive 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gif 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "png 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "io-surface" version = "0.1.0" @@ -1042,6 +1082,11 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lzw" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "mac" version = "0.0.2" @@ -1174,11 +1219,11 @@ version = "0.0.1" dependencies = [ "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "image 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "log 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "plugins 0.0.1", - "png 0.1.0 (git+https://github.com/servo/rust-png)", "regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1347,6 +1392,17 @@ dependencies = [ "serde_macros 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "png" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "png-sys" version = "1.6.16" @@ -1638,7 +1694,7 @@ dependencies = [ [[package]] name = "stb_image" version = "0.1.0" -source = "git+https://github.com/servo/rust-stb-image#f4c5380cd586bfe16326e05e2518aa044397894b" +source = "git+https://github.com/servo/rust-stb-image#a6831a4e0ce78ec7393d6e9c5b3a26f2f4dc4249" dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index fb822dbb449..f8d9f30c099 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -22,7 +22,6 @@ dependencies = [ "net_traits 0.0.1", "objc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", - "png 0.1.0 (git+https://github.com/servo/rust-png)", "script 0.0.1", "script_traits 0.0.1", "servo 0.0.1", @@ -231,6 +230,11 @@ dependencies = [ "objc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "color_quant" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "compositing" version = "0.0.1" @@ -452,6 +456,14 @@ name = "encoding_index_tests" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "enum_primitive" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "env_logger" version = "0.3.1" @@ -604,6 +616,15 @@ dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", ] +[[package]] +name = "gif" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lzw 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gl_common" version = "0.0.4" @@ -643,6 +664,11 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glob" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "glutin" version = "0.3.6" @@ -817,6 +843,19 @@ dependencies = [ "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "image" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", + "enum_primitive 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gif 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "png 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "io-surface" version = "0.1.0" @@ -993,6 +1032,11 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lzw" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "mac" version = "0.0.2" @@ -1109,11 +1153,11 @@ version = "0.0.1" dependencies = [ "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "image 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "log 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "plugins 0.0.1", - "png 0.1.0 (git+https://github.com/servo/rust-png)", "regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1282,6 +1326,17 @@ dependencies = [ "serde_macros 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "png" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "png-sys" version = "1.6.16" @@ -1596,7 +1651,7 @@ dependencies = [ [[package]] name = "stb_image" version = "0.1.0" -source = "git+https://github.com/servo/rust-stb-image#f4c5380cd586bfe16326e05e2518aa044397894b" +source = "git+https://github.com/servo/rust-stb-image#a6831a4e0ce78ec7393d6e9c5b3a26f2f4dc4249" dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ports/cef/Cargo.toml b/ports/cef/Cargo.toml index a9e3948a3e7..9a012820aa4 100644 --- a/ports/cef/Cargo.toml +++ b/ports/cef/Cargo.toml @@ -60,9 +60,6 @@ git = "https://github.com/servo/rust-mozjs" [dependencies.layers] git = "https://github.com/servo/rust-layers" -[dependencies.png] -git = "https://github.com/servo/rust-png" - [dependencies.stb_image] git = "https://github.com/servo/rust-stb-image" diff --git a/ports/cef/lib.rs b/ports/cef/lib.rs index 3ff93d0041a..1b47986327c 100644 --- a/ports/cef/lib.rs +++ b/ports/cef/lib.rs @@ -31,7 +31,6 @@ extern crate gleam; extern crate glutin_app; extern crate js; extern crate layers; -extern crate png; extern crate rustc_unicode; extern crate script; extern crate script_traits; diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index ca305ba9cae..17ca79a1cdd 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -201,6 +201,11 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "color_quant" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "compositing" version = "0.0.1" @@ -397,6 +402,14 @@ name = "encoding_index_tests" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "enum_primitive" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "env_logger" version = "0.3.1" @@ -551,6 +564,15 @@ dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", ] +[[package]] +name = "gif" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lzw 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gl_common" version = "0.0.4" @@ -580,6 +602,11 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glob" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "glx" version = "0.0.1" @@ -701,6 +728,19 @@ dependencies = [ "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "image" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", + "enum_primitive 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gif 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "png 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "io-surface" version = "0.1.0" @@ -872,6 +912,11 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lzw" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "mac" version = "0.0.2" @@ -979,11 +1024,11 @@ version = "0.0.1" dependencies = [ "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "image 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "log 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "plugins 0.0.1", - "png 0.1.0 (git+https://github.com/servo/rust-png)", "regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1143,6 +1188,17 @@ dependencies = [ "serde_macros 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "png" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "png-sys" version = "1.6.16" @@ -1437,7 +1493,7 @@ dependencies = [ [[package]] name = "stb_image" version = "0.1.0" -source = "git+https://github.com/servo/rust-stb-image#f4c5380cd586bfe16326e05e2518aa044397894b" +source = "git+https://github.com/servo/rust-stb-image#a6831a4e0ce78ec7393d6e9c5b3a26f2f4dc4249" dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/python/tidy.py b/python/tidy.py index 93b30e147f9..9b09c0fd9bf 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -149,7 +149,10 @@ def check_lock(file_name, contents): contents = contents.splitlines(True) idx = 1 packages = {} - exceptions = ["glutin", "wayland-kbd"] # package names to be neglected (as named by cargo) + + # package names to be neglected (as named by cargo) + # - `png` is used by PistonDevelopers/image-png and servo/rust-png + exceptions = ["glutin", "wayland-kbd", "png"] while idx < len(contents): content = contents[idx].strip()