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

whitespace changes to clean up mach test-tidy

  • Loading branch information
ankit3005 committed Dec 3, 2014
commit 91f719e2f858614e5ad563ac52a17ceefc283003
@@ -553,8 +553,8 @@ impl DisplayItem {
bounds.origin.x = bounds.origin.x + x_offset;
bounds.origin.y = bounds.origin.y + y_offset;
bounds.size = image_item.stretch_size;
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Bounds is {} and image_item.image.clone() is {} ", bounds, image_item.stretch_size);//, source_format);
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Bounds is {} and image_item.image.clone() is {} ", bounds, image_item.stretch_size);//, source_format);
render_context.draw_image(bounds, image_item.image.clone());

x_offset = x_offset + image_item.stretch_size.width;
@@ -112,34 +112,34 @@ impl<'a> RenderContext<'a> {
}

pub fn draw_image(&self, bounds: Rect<Au>, image: Arc<Box<DynamicImage>>) {
let (image_width, image_height) = image.dimensions();
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Height is {} and width is {}", image_height, image_width);
let (image_width, image_height) = image.dimensions();
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Height is {} and width is {}", image_height, image_width);
let size = Size2D(image_width as i32, image_height as i32);
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Size is {}", size);
let raw_pixels = image.raw_pixels();
//let option_img_pixels = image.as_rgb8();
//let img_pixels = match option_img_pixels {
// Some(pixels) => pixels,
// None => {return;}
//};
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Color is {}", image.color().to_string());
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Size is {}", size);
let raw_pixels = image.raw_pixels();
//let option_img_pixels = image.as_rgb8();
//let img_pixels = match option_img_pixels {
// Some(pixels) => pixels,
// None => {return;}
//};
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("Color is {}", image.color().to_string());
let (pixel_width, pixels, source_format) = match image.color() {
RGBA(_) => (4, raw_pixels.as_slice(), B8G8R8A8),
Grey(_) => (1, raw_pixels.as_slice(), A8),
RGB(_) => (3, raw_pixels.as_slice(), B8G8R8X8),
GreyA(_) => (2, raw_pixels.as_slice(), A8),
Palette(_) => panic!("Palette color type not supported"),
Palette(_) => panic!("Palette color type not supported"),
};
let stride = image_width * pixel_width;
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("pixel_width is {}", pixel_width);
println!("Stride is {} and first 200 pixels are:", stride);
for e in range(0i as uint, 200i as uint) {
print!("{} ", pixels[e]);
}
//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
println!("pixel_width is {}", pixel_width);
println!("Stride is {} and first 200 pixels are:", stride);
for e in range(0i as uint, 200i as uint) {
print!("{} ", pixels[e]);
}
self.draw_target.make_current();
let draw_target_ref = &self.draw_target;
let azure_surface = draw_target_ref.create_source_surface_from_data(pixels,
@@ -219,7 +219,7 @@ impl FragmentDisplayListBuilding for Fragment {
};
debug!("(building display list) building background image");

let (img_width, img_height) = image.dimensions();
let (img_width, img_height) = image.dimensions();

let image_width = Au::from_px(img_width as int);
let image_height = Au::from_px(img_height as int);
@@ -45,39 +45,34 @@ fn byte_swap_and_premultiply(data: &mut [u8]) {
pub fn load_from_memory(buffer: &[u8],ext: &str) -> Option<DynamicImage> {
if buffer.len() == 0 {
return None;
}
else {
//let new_image_type: servo_image::ImageFormat = servo_image::ImageFormat::PNG;

} else {
//let new_image_type: servo_image::ImageFormat = servo_image::ImageFormat::PNG;

let image_type: Option< servo_image::ImageFormat > = get_format(ext);
if image_type == None
{
panic!("Image format not supported!");
}
else{
let new_image_type: servo_image::ImageFormat = image_type.unwrap();


let result = servo_image::load_from_memory(buffer,new_image_type);
if (result.is_ok()) {
let v = result.unwrap();
return Some(v);
}
else {
return None;
}
}
}
}
if image_type == None {
panic!("Image format not supported!");
} else{
let new_image_type: servo_image::ImageFormat = image_type.unwrap();

let result = servo_image::load_from_memory(buffer,new_image_type);
if result.is_ok() {
let v = result.unwrap();
return Some(v);
} else {
return None;
}
}
}
}
fn get_format(ext: &str) -> Option<servo_image::ImageFormat> {
match ext.to_ascii().to_uppercase().as_str_ascii() {
match ext.to_ascii().to_uppercase().as_str_ascii() {
"PNG" => {(return Some(servo_image::ImageFormat::PNG));},
"JPEG" => {(return Some(servo_image::ImageFormat::JPEG));},
"JPG" => {(return Some(servo_image::ImageFormat::JPEG));},
"GIF"=> {(return Some(servo_image::ImageFormat::GIF));},
"WEBP" => {(return Some(servo_image::ImageFormat::WEBP));},
"PPM" => {(return Some(servo_image::ImageFormat::PPM));},
_ => {return None ;},
}
}
}
}

@@ -68,7 +68,7 @@ impl<NodeAddress: Send> ImageHolder<NodeAddress> {
debug!("get_size() {}", self.url.serialize());

self.get_image(node_address).map(|img| {
let (img_width,img_height) = img.dimensions();
let (img_width,img_height) = img.dimensions();
self.cached_size = Size2D(img_width as int,
img_height as int);
self.cached_size.clone()
@@ -323,7 +323,7 @@ impl ImageCache {
let mut ext="";
for x in s.as_slice().split('.') { ext=x; }
println!("{}",ext);

let image = profile(time::ImageDecodingCategory, None, time_profiler_chan_clone, || {
load_from_memory(data.as_slice(),ext)
});
@@ -994,7 +994,7 @@ mod tests {
#[test]
fn sync_cache_should_wait_for_images() {
let mock_resource_task = mock_resource_task(box SendTestImage);

let image_cache_task = ImageCacheTask::new_sync(mock_resource_task.clone(), TaskPool::new(4));
let url = Url::parse("file:///").unwrap();

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