Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing C libraries with Rust equivalents - student project #4215

Closed
wants to merge 29 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c4156d4
Initial commit for migrating to freetype-rs library from rust-freetype
ankit3005 Nov 29, 2014
66623ea
added constant to freetype_rs library ft_sfnt_os2
ankit3005 Nov 29, 2014
ff891d8
Changed freetyp-rs dependency to local fork on github
ankit3005 Nov 29, 2014
754a841
Changes to use DynamicImage type from the new rust image library
anishashetty Nov 30, 2014
254e9c9
fix in Cargo.lock after updating freetype-rs dependency
ankit3005 Nov 30, 2014
552cc7b
Replaced png::Image references with DynamicImage
ynandak Dec 1, 2014
f712870
Small fix in gfx/render_context.rs
ynandak Dec 1, 2014
dbd681a
Replaced certain instances of png::Image use - build successful
ynandak Dec 1, 2014
82d3720
Minor change to render_context.rs::draw_image()
ynandak Dec 2, 2014
61557e5
Added changes to accept ImageFormat
anishashetty Dec 2, 2014
d2d9a99
Changes to fix runtime data.len() assertion crash
ynandak Dec 3, 2014
1a0f513
Minor fix in render_context
ynandak Dec 3, 2014
1bca917
Changes to base.rs to resolve ImageFormat based on file extension
anishashetty Dec 3, 2014
0954f6d
Merge branch 'master' of https://github.com/ankit3005/servo
anishashetty Dec 3, 2014
8ce5e11
Updated RGB in draw_image()
ynandak Dec 3, 2014
169160a
net component compiles with profiler in place
ankit3005 Dec 3, 2014
91f719e
whitespace changes to clean up mach test-tidy
ankit3005 Dec 3, 2014
7f20adc
Minor cleanup. Removed unnecessary line
ankit3005 Dec 3, 2014
4c33555
Changed freetype-rs dependency from fork to upstream repo
ankit3005 Dec 3, 2014
b7b50f8
Changed freetype-rs version to old working commit
ankit3005 Dec 4, 2014
ba24947
Clean up commented code
ankit3005 Dec 4, 2014
3d518cd
Add profiling to image decoding
ankit3005 Dec 4, 2014
d6bb6b4
Code clean up. Removed unused functions and imports
ankit3005 Dec 4, 2014
ad709d6
minor cleanup
ankit3005 Dec 4, 2014
d1aaa2c
Remove a println statement
ankit3005 Dec 4, 2014
dfa0b92
Fixed image rendering. Now working as intended
ynandak Dec 4, 2014
85b5efc
Updated Cargo.lock
ynandak Dec 4, 2014
9e2b0c7
Removed debugging println!
ynandak Dec 4, 2014
768709a
whitespace changes to clean up test-tidy
ankit3005 Dec 4, 2014
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Changes to use DynamicImage type from the new rust image library

  • Loading branch information
anishashetty committed Nov 30, 2014
commit 754a84186ad92f96b0520c3260452ef838f7f21c

Some generated files are not rendered by default. Learn more.

@@ -27,7 +27,7 @@ use libc::uintptr_t;
use render_task::RenderLayer;
use script_traits::UntrustedNodeAddress;
use servo_msg::compositor_msg::LayerId;
use servo_net::image::base::Image;
use servo_net::image::base::DynamicImage;
use servo_util::dlist as servo_dlist;
use servo_util::geometry::{mod, Au};
use servo_util::range::Range;
@@ -447,7 +447,7 @@ pub enum TextOrientation {
#[deriving(Clone)]
pub struct ImageDisplayItem {
pub base: BaseDisplayItem,
pub image: Arc<Box<Image>>,
pub image: Arc<Box<DynamicImage>>,

/// The dimensions to which the image display item should be stretched. If this is smaller than
/// the bounds of this display item, then the image will be repeated in the appropriate
@@ -20,7 +20,7 @@ use geom::size::Size2D;
use libc::size_t;
use libc::types::common::c99::{uint16_t, uint32_t};
use png::{RGB8, RGBA8, K8, KA8};
use servo_net::image::base::Image;
use servo_net::image::base::DynamicImage;
use servo_util::geometry::Au;
use servo_util::opts;
use servo_util::range::Range;
@@ -109,7 +109,7 @@ impl<'a> RenderContext<'a> {
self.draw_target.pop_clip();
}

pub fn draw_image(&self, bounds: Rect<Au>, image: Arc<Box<Image>>) {
pub fn draw_image(&self, bounds: Rect<Au>, image: Arc<Box<DynamicImage>>) {
let size = Size2D(image.width as i32, image.height as i32);
let (pixel_width, pixels, source_format) = match image.pixels {
RGBA8(ref pixels) => (4, pixels.as_slice(), B8G8R8A8),
@@ -25,3 +25,6 @@ git = "https://github.com/servo/rust-stb-image"

[dependencies.url]
git = "https://github.com/servo/rust-url"

[dependencies.image]
git = "https://github.com/PistonDevelopers/image"
@@ -3,12 +3,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::iter::range_step;
use stb_image::image as stb_image;
use png;
//use stb_image::image as stb_image;
use servo_image;
//use png;

// FIXME: Images must not be copied every frame. Instead we should atomically
// reference count them.
pub type Image = png::Image;
pub type DynamicImage = servo_image::DynamicImage;


static TEST_IMAGE: &'static [u8] = include_bin!("test.jpeg");
@@ -41,48 +42,19 @@ fn byte_swap_and_premultiply(data: &mut [u8]) {
}
}

pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
pub fn load_from_memory(buffer: &[u8]) -> Option<DynamicImage> {
if buffer.len() == 0 {
return None;
}
else {
let result = servo_image::load_from_memory(buffer,servo_image::ImageFormat::JPEG);
if (result.is_ok()) {
let v = result.unwrap();
return Some(v);
}
else {
return None;

}}

if png::is_png(buffer) {
match png::load_png_from_memory(buffer) {
Ok(mut png_image) => {
match png_image.pixels {
png::RGB8(ref mut data) => byte_swap(data.as_mut_slice()),
png::RGBA8(ref mut data) => {
byte_swap_and_premultiply(data.as_mut_slice())
}
_ => {}
}
Some(png_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: uint = 4;

match stb_image::load_from_memory_with_depth(buffer, FORCE_DEPTH, true) {
stb_image::ImageU8(mut image) => {
assert!(image.depth == 4);
byte_swap(image.data.as_mut_slice());
Some(png::Image {
width: image.width as u32,
height: image.height as u32,
pixels: png::RGBA8(image.data)
})
}
stb_image::ImageF32(_image) => {
error!("HDR images not implemented");
None
}
stb_image::Error(e) => {
error!("stb_image failed: {}", e);
None
}
}
}
}
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use image::base::Image;
use image::base::DynamicImage;
use image_cache_task::{ImageReady, ImageNotReady, ImageFailed};
use local_image_cache::LocalImageCache;

@@ -11,6 +11,7 @@ use std::mem;
use sync::{Arc, Mutex};
use url::Url;


// FIXME: Nasty coupling here This will be a problem if we want to factor out image handling from
// the network stack. This should probably be factored out into an interface and use dependency
// injection.
@@ -20,7 +21,7 @@ use url::Url;
#[deriving(Clone)]
pub struct ImageHolder<NodeAddress> {
url: Url,
image: Option<Arc<Box<Image>>>,
image: Option<Arc<Box<DynamicImage>>>,
cached_size: Size2D<int>,
local_image_cache: Arc<Mutex<LocalImageCache<NodeAddress>>>,
}
@@ -63,19 +64,21 @@ impl<NodeAddress: Send> ImageHolder<NodeAddress> {
/// Query and update the current image size.
pub fn get_size(&mut self, node_address: NodeAddress) -> Option<Size2D<int>> {
debug!("get_size() {}", self.url.serialize());

self.get_image(node_address).map(|img| {
self.cached_size = Size2D(img.width as int,
img.height as int);
let (img_width,img_height) = img.dimensions();
self.cached_size = Size2D(img_width as int,
img_height as int);
self.cached_size.clone()
})
}

pub fn get_image_if_present(&self) -> Option<Arc<Box<Image>>> {
pub fn get_image_if_present(&self) -> Option<Arc<Box<DynamicImage>>> {
debug!("get_image_if_present() {}", self.url.serialize());
self.image.clone()
}

pub fn get_image(&mut self, node_address: NodeAddress) -> Option<Arc<Box<Image>>> {
pub fn get_image(&mut self, node_address: NodeAddress) -> Option<Arc<Box<DynamicImage>>> {
debug!("get_image() {}", self.url.serialize());

// If this is the first time we've called this function, load
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use image::base::{Image, load_from_memory};
use image::base::{DynamicImage, load_from_memory};
use resource_task;
use resource_task::{LoadData, ResourceTask};

@@ -39,7 +39,7 @@ pub enum Msg {
StorePrefetchedImageData(Url, Result<Vec<u8>, ()>),

/// Used by the decoder tasks to post decoded images back to the cache
StoreImage(Url, Option<Arc<Box<Image>>>),
StoreImage(Url, Option<Arc<Box<DynamicImage>>>),

/// For testing
WaitForStore(Sender<()>),
@@ -50,7 +50,7 @@ pub enum Msg {

#[deriving(Clone)]
pub enum ImageResponseMsg {
ImageReady(Arc<Box<Image>>),
ImageReady(Arc<Box<DynamicImage>>),
ImageNotReady,
ImageFailed
}
@@ -78,7 +78,7 @@ impl<E, S: Encoder<E>> Encodable<S, E> for ImageCacheTask {
}
}

type DecoderFactory = fn() -> (proc(&[u8]) : 'static -> Option<Image>);
type DecoderFactory = fn() -> (proc(&[u8]) : 'static -> Option<DynamicImage>);

impl ImageCacheTask {
pub fn new(resource_task: ResourceTask, task_pool: TaskPool) -> ImageCacheTask {
@@ -152,7 +152,7 @@ enum ImageState {
Prefetching(AfterPrefetch),
Prefetched(Vec<u8>),
Decoding,
Decoded(Arc<Box<Image>>),
Decoded(Arc<Box<DynamicImage>>),
Failed
}

@@ -328,7 +328,7 @@ impl ImageCache {
}
}

fn store_image(&mut self, url: Url, image: Option<Arc<Box<Image>>>) {
fn store_image(&mut self, url: Url, image: Option<Arc<Box<DynamicImage>>>) {

match self.get_state(&url) {
Decoding => {
@@ -19,6 +19,7 @@ extern crate stb_image;
extern crate sync;
extern crate time;
extern crate url;
extern crate "image" as servo_image;

/// Image handling.
///
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.