mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
parent
ab42ca4296
commit
b649246fe2
9 changed files with 209 additions and 53 deletions
|
@ -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"
|
||||
|
|
|
@ -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<Image> {
|
|||
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<Image> {
|
|||
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])
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
60
components/servo/Cargo.lock
generated
60
components/servo/Cargo.lock
generated
|
@ -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)",
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue