Move PixelFormat to the pixels crate

This commit is contained in:
Anthony Ramine 2018-11-19 10:42:50 +01:00
parent faee0b2b0c
commit 2c0acf6b9b
14 changed files with 38 additions and 21 deletions

6
Cargo.lock generated
View file

@ -543,6 +543,7 @@ dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"pixels 0.0.1",
"profile_traits 0.0.1",
"script_traits 0.0.1",
"servo_config 0.0.1",
@ -2872,6 +2873,9 @@ name = "pixels"
version = "0.0.1"
dependencies = [
"euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
"malloc_size_of_derive 0.0.1",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -3355,6 +3359,7 @@ dependencies = [
"malloc_size_of_derive 0.0.1",
"msg 0.0.1",
"net_traits 0.0.1",
"pixels 0.0.1",
"profile_traits 0.0.1",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
@ -4499,6 +4504,7 @@ dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"pixels 0.0.1",
"regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -13,7 +13,7 @@ path = "lib.rs"
[features]
default = []
gl = ["gleam"]
gl = ["gleam", "pixels"]
[dependencies]
crossbeam-channel = "0.3"
@ -28,6 +28,7 @@ keyboard-types = "0.4.3"
log = "0.4"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
pixels = {path = "../pixels", optional = true}
profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"}
servo_config = {path = "../config"}

View file

@ -22,7 +22,7 @@ use libc::c_void;
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
use net_traits::image::base::Image;
#[cfg(feature = "gl")]
use net_traits::image::base::PixelFormat;
use pixels::PixelFormat;
use profile_traits::time::{self as profile_time, profile, ProfilerCategory};
use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent, TouchEvent};
use script_traits::{AnimationState, AnimationTickType, ConstellationMsg, LayoutControlMsg};

View file

@ -4,11 +4,12 @@
use embedder_traits::resources::{self, Resource};
use immeta::load_from_buf;
use net_traits::image::base::{load_from_memory, Image, ImageMetadata, PixelFormat};
use net_traits::image::base::{load_from_memory, Image, ImageMetadata};
use net_traits::image_cache::{CanRequestImages, ImageCache, ImageResponder};
use net_traits::image_cache::{ImageOrMetadataAvailable, ImageResponse, ImageState};
use net_traits::image_cache::{PendingImageId, UsePlaceholder};
use net_traits::{FetchMetadata, FetchResponseMsg, NetworkError};
use pixels::PixelFormat;
use servo_url::ServoUrl;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::HashMap;

View file

@ -4,20 +4,9 @@
use ipc_channel::ipc::IpcSharedMemory;
use piston_image::{DynamicImage, ImageFormat};
use pixels::PixelFormat;
use std::fmt;
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
pub enum PixelFormat {
/// Luminance channel only
K8,
/// Luminance + alpha
KA8,
/// RGB, 8 bits per channel
RGB8,
/// RGB + alpha, 8 bits per channel
BGRA8,
}
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
pub struct Image {
pub width: u32,

View file

@ -12,3 +12,6 @@ path = "lib.rs"
[dependencies]
euclid = "0.19"
malloc_size_of = {path = "../malloc_size_of"}
malloc_size_of_derive = {path = "../malloc_size_of_derive"}
serde = {version = "1", features = ["derive"]}

View file

@ -2,9 +2,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#[macro_use]
extern crate serde;
use euclid::{Point2D, Rect, Size2D};
use malloc_size_of_derive::MallocSizeOf;
use std::borrow::Cow;
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
pub enum PixelFormat {
/// Luminance channel only
K8,
/// Luminance + alpha
KA8,
/// RGB, 8 bits per channel
RGB8,
/// RGB + alpha, 8 bits per channel
BGRA8,
}
pub fn rgba8_get_rect(pixels: &[u8], size: Size2D<u32>, rect: Rect<u32>) -> Cow<[u8]> {
assert!(!rect.is_empty());
assert!(Rect::from_size(size).contains_rect(&rect));

View file

@ -34,13 +34,13 @@ use cssparser::{Parser, ParserInput, RGBA};
use dom_struct::dom_struct;
use euclid::{vec2, Point2D, Rect, Size2D, Transform2D};
use ipc_channel::ipc::{self, IpcSender};
use net_traits::image::base::PixelFormat;
use net_traits::image_cache::CanRequestImages;
use net_traits::image_cache::ImageCache;
use net_traits::image_cache::ImageOrMetadataAvailable;
use net_traits::image_cache::ImageResponse;
use net_traits::image_cache::ImageState;
use net_traits::image_cache::UsePlaceholder;
use pixels::PixelFormat;
use profile_traits::ipc as profiled_ipc;
use script_traits::ScriptMsg;
use servo_url::ServoUrl;

View file

@ -44,8 +44,8 @@ use js::rust::wrappers::Construct1;
use js::rust::HandleValue;
use js::rust::Runtime;
use msg::constellation_msg::PipelineId;
use net_traits::image::base::PixelFormat;
use net_traits::image_cache::ImageCache;
use pixels::PixelFormat;
use profile_traits::ipc;
use script_traits::Painter;
use script_traits::{DrawAPaintImageResult, PaintWorkletError};

View file

@ -66,10 +66,9 @@ use js::typedarray::{
ArrayBufferView, CreateWith, Float32, Float32Array, Int32, Int32Array, Uint32Array,
};
use js::typedarray::{TypedArray, TypedArrayElementCreator};
use net_traits::image::base::PixelFormat;
use net_traits::image_cache::ImageResponse;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use pixels;
use pixels::{self, PixelFormat};
use script_layout_interface::HTMLCanvasDataSource;
use serde::{Deserialize, Serialize};
use servo_config::prefs::PREFS;

View file

@ -29,6 +29,7 @@ malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
pixels = {path = "../pixels"}
profile_traits = {path = "../profile_traits"}
serde = "1.0"
servo_atoms = {path = "../atoms"}

View file

@ -35,10 +35,10 @@ use libc::c_void;
use msg::constellation_msg::{BrowsingContextId, HistoryStateId, PipelineId};
use msg::constellation_msg::{PipelineNamespaceId, TopLevelBrowsingContextId, TraversalDirection};
use net_traits::image::base::Image;
use net_traits::image::base::PixelFormat;
use net_traits::image_cache::ImageCache;
use net_traits::storage_thread::StorageType;
use net_traits::{FetchResponseMsg, ReferrerPolicy, ResourceThreads};
use pixels::PixelFormat;
use profile_traits::mem;
use profile_traits::time as profile_time;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

View file

@ -22,6 +22,7 @@ keyboard-types = "0.4.3"
log = "0.4"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
pixels = {path = "../pixels"}
regex = "1.0"
serde = "1"
serde_json = "1"

View file

@ -19,7 +19,7 @@ use image::{DynamicImage, ImageFormat, RgbImage};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use keyboard_types::webdriver::{send_keys, Event as KeyEvent};
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, TraversalDirection};
use net_traits::image::base::PixelFormat;
use pixels::PixelFormat;
use regex::Captures;
use script_traits::webdriver_msg::{LoadStatus, WebDriverCookieError, WebDriverFrameId};
use script_traits::webdriver_msg::{