mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Do colorspace conversion during image decode
This commit is contained in:
parent
7bf10c8e06
commit
818152c2ca
5 changed files with 24 additions and 19 deletions
|
@ -130,20 +130,7 @@ fn draw_image(draw_target: &DrawTarget, item: dl::display_item, image: arc<~Imag
|
|||
let size = Size2D(image.width as i32, image.height as i32);
|
||||
let stride = image.width * 4;
|
||||
|
||||
// Do color space conversion :(
|
||||
let data = do vec::from_fn(image.width * image.height * 4) |i| {
|
||||
let color = i % 4;
|
||||
let pixel = i / 4;
|
||||
match color {
|
||||
0 => image.data[pixel * 3 + 2],
|
||||
1 => image.data[pixel * 3 + 1],
|
||||
2 => image.data[pixel * 3 + 0],
|
||||
3 => 0xffu8,
|
||||
_ => fail
|
||||
}
|
||||
};
|
||||
|
||||
let azure_surface = draw_target.create_source_surface_from_data(data, size, stride as i32,
|
||||
let azure_surface = draw_target.create_source_surface_from_data(image.data, size, stride as i32,
|
||||
B8G8R8A8);
|
||||
let source_rect = Rect(Point2D(0 as AzFloat, 0 as AzFloat),
|
||||
Size2D(image.width as AzFloat, image.height as AzFloat));
|
||||
|
|
|
@ -4,15 +4,35 @@ export load;
|
|||
export load_from_memory;
|
||||
export test_image_bin;
|
||||
|
||||
import stb_image::image::{image, load, load_from_memory};
|
||||
import stb_image = stb_image::image;
|
||||
|
||||
// FIXME: Images must not be copied every frame. Instead we should atomically
|
||||
// reference count them.
|
||||
|
||||
type Image = image;
|
||||
type Image = stb_image::image;
|
||||
|
||||
const TEST_IMAGE: [u8 * 4962] = #include_bin("test.jpeg");
|
||||
|
||||
fn test_image_bin() -> ~[u8] {
|
||||
return vec::from_fn(4962, |i| TEST_IMAGE[i]);
|
||||
}
|
||||
|
||||
fn load_from_memory(buffer: &[u8]) -> option<Image> {
|
||||
do stb_image::load_from_memory(buffer).map |image| {
|
||||
|
||||
// Do color space conversion :(
|
||||
let data = do vec::from_fn(image.width * image.height * 4) |i| {
|
||||
let color = i % 4;
|
||||
let pixel = i / 4;
|
||||
match color {
|
||||
0 => image.data[pixel * 3 + 2],
|
||||
1 => image.data[pixel * 3 + 1],
|
||||
2 => image.data[pixel * 3 + 0],
|
||||
3 => 0xffu8,
|
||||
_ => fail
|
||||
}
|
||||
};
|
||||
|
||||
stb_image::image(image.width, image.height, image.depth, data)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import gfx::geometry::{au, zero_size_au};
|
|||
import geom::point::Point2D;
|
||||
import geom::rect::Rect;
|
||||
import geom::size::Size2D;
|
||||
import image::base::{Image, load};
|
||||
import image::base::Image;
|
||||
import util::tree;
|
||||
import util::color::Color;
|
||||
import text::TextBox;
|
||||
|
|
|
@ -10,7 +10,6 @@ import geom::rect::Rect;
|
|||
import geom::size::Size2D;
|
||||
import gfx::geometry::{au, au_to_px, box, px_to_au};
|
||||
import gfx::renderer;
|
||||
import image::base::load;
|
||||
import util::tree;
|
||||
|
||||
import dvec::dvec;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import dom::base::{Element, HTMLImageElement, Node};
|
||||
import dom::style::{Percent, Mm, Pt, Px, Auto, PtToPx, MmToPx};
|
||||
import gfx::geometry::au_to_px;
|
||||
import image::base::load;
|
||||
import base::{Box, BTree, NTree, LayoutData, SpecifiedStyle, ImageHolder,
|
||||
BlockBox, InlineBox, IntrinsicBox, TextBox};
|
||||
import traverse::{top_down_traversal};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue