<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Apjoshi</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Apjoshi"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Apjoshi"/>
	<updated>2026-06-04T19:21:19Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Report001.PNG&amp;diff=92490</id>
		<title>File:Report001.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Report001.PNG&amp;diff=92490"/>
		<updated>2014-12-04T04:45:13Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: uploaded a new version of &amp;amp;quot;File:Report001.PNG&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92482</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92482"/>
		<updated>2014-12-04T04:24:18Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:M1455newcrop.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see the image is not being rendered as intended. It is suspected to be a bud in the rust image library developed by the PistonDevelopers. We have been asked by servo representatives to raise an issue with the developers of the rust image library.&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:M1455newcrop.png&amp;diff=92481</id>
		<title>File:M1455newcrop.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:M1455newcrop.png&amp;diff=92481"/>
		<updated>2014-12-04T04:21:34Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92480</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92480"/>
		<updated>2014-12-04T04:21:22Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:M1455newcrop.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92473</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92473"/>
		<updated>2014-12-04T04:14:28Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:M1455new.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92472</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92472"/>
		<updated>2014-12-04T04:14:12Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:M1455_new.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92470</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92470"/>
		<updated>2014-12-04T04:13:12Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:New.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92468</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92468"/>
		<updated>2014-12-04T04:12:03Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:New.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92467</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92467"/>
		<updated>2014-12-04T04:11:12Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:new.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92465</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92465"/>
		<updated>2014-12-04T04:10:21Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:new_lena_jpg.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:New_lena_jpg.png&amp;diff=92463</id>
		<title>File:New lena jpg.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:New_lena_jpg.png&amp;diff=92463"/>
		<updated>2014-12-04T04:09:48Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92462</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92462"/>
		<updated>2014-12-04T04:09:29Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library: &amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:new_lena_jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92460</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92460"/>
		<updated>2014-12-04T04:08:59Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
Below you can see the image being rendered after importing the new rust image library:&lt;br /&gt;
[[File:new_lena_jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92453</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92453"/>
		<updated>2014-12-04T04:04:45Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92418</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92418"/>
		<updated>2014-12-04T03:16:08Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Report001.PNG]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92417</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92417"/>
		<updated>2014-12-04T03:15:40Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
[[File:Report001.PNG]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Report001.PNG&amp;diff=92416</id>
		<title>File:Report001.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Report001.PNG&amp;diff=92416"/>
		<updated>2014-12-04T03:14:41Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: uploaded a new version of &amp;amp;quot;File:Report001.PNG&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Report001.PNG&amp;diff=92415</id>
		<title>File:Report001.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Report001.PNG&amp;diff=92415"/>
		<updated>2014-12-04T03:13:41Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92414</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92414"/>
		<updated>2014-12-04T03:11:10Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
[[File:Report001.png]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92413</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92413"/>
		<updated>2014-12-04T03:10:43Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
[[File:Report1.png]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92412</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92412"/>
		<updated>2014-12-04T03:10:18Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Our test cases include reporting the timing differences for loading PNGs and non-PNG images. The following report has been made with respect to the same:&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92411</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92411"/>
		<updated>2014-12-04T03:08:44Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.http://optipng.sourceforge.net/pngtech/img/lena.png&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92406</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92406"/>
		<updated>2014-12-04T02:46:47Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run http://simple.wikipedia.org/wiki/Main_Page&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92405</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92405"/>
		<updated>2014-12-04T02:40:29Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Proposed Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes printing the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command which gives the decoding time for the image passed as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. After replacing the rust-freetype library by the freetype-rs library, we have tested that it works as expected by passing a webpage url and checking that the text renders correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run https://www. &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. After replacing the rust-stb-image and stb-image libraries with rust-image library and rewriting the load_from_memory function, we tested the the imports worked as expected by passing in different formats of images as urls and rendering them. &lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run https://www.&amp;lt;/pre&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92403</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92403"/>
		<updated>2014-12-04T02:30:39Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Proposed Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes priniting the decoding time for various image formates and has been included in the wiki: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step]&lt;br /&gt;
&lt;br /&gt;
2. The profiler is meant to capture the image decoding time take by the load_from_memory function. The profiler is run using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt; &amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92402</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92402"/>
		<updated>2014-12-04T02:28:58Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Proposed Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
1. The initial step test case includes priniting the decoding time for various image formates and has been included in the wiki: &lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Profiler.png&amp;diff=92396</id>
		<title>File:Profiler.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Profiler.png&amp;diff=92396"/>
		<updated>2014-12-04T01:32:56Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: uploaded a new version of &amp;amp;quot;File:Profiler.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Profiler.png&amp;diff=92395</id>
		<title>File:Profiler.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Profiler.png&amp;diff=92395"/>
		<updated>2014-12-04T01:31:26Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: uploaded a new version of &amp;amp;quot;File:Profiler.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Profiler.png&amp;diff=92394</id>
		<title>File:Profiler.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Profiler.png&amp;diff=92394"/>
		<updated>2014-12-04T01:23:37Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92393</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92393"/>
		<updated>2014-12-04T01:22:46Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92392</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92392"/>
		<updated>2014-12-04T01:17:36Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92391</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92391"/>
		<updated>2014-12-04T01:15:15Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Import the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Import the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92390</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92390"/>
		<updated>2014-12-04T01:15:00Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Import the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Import the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.[5]&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92389</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92389"/>
		<updated>2014-12-04T01:14:05Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Import the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92388</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92388"/>
		<updated>2014-12-04T01:13:25Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Import the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check this accepted pull on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92387</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92387"/>
		<updated>2014-12-04T01:11:53Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
# Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Import the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check this accepted pull on [https://github.com/PistonDevelopers/freetype-rs/pull/70] for more info.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92386</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92386"/>
		<updated>2014-12-04T01:03:55Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
# Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92385</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92385"/>
		<updated>2014-12-04T00:56:28Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
# Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92384</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92384"/>
		<updated>2014-12-04T00:53:37Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
# Add Image Decoding time to the Profiler&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91819</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91819"/>
		<updated>2014-11-11T23:43:09Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Background Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our initial step, implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91818</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91818"/>
		<updated>2014-11-11T23:42:41Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our initial step, implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91817</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91817"/>
		<updated>2014-11-11T23:42:13Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our initial step, implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa]&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90403</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90403"/>
		<updated>2014-10-29T04:05:29Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/a/ncsu.edu/document/d/18VECpUuVmEaC4Xew4EsIAmOsRKdIeXaTA42tLlNwIho/edit Project Description Page]&lt;br /&gt;
== EVALUATE REPLACING [http://en.wikipedia.org/wiki/C_%28programming_language%29 C] IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs], we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
Factory Pattern: Using Factory Patterns, the class hierarchy or prototypes can be changed or refactored without needing to change code that uses them – they abstract from the class hierarchy or prototypes. Since we will be replacing the existing C libraries with equivalent rust libraries, factory pattern is applicable here. &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.oodesign.com/factory-pattern.html &amp;lt;br/&amp;gt;&lt;br /&gt;
[https://www.youtube.com/watch?v=pZ5dwgo5W6E A Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90401</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90401"/>
		<updated>2014-10-29T04:01:42Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/a/ncsu.edu/document/d/18VECpUuVmEaC4Xew4EsIAmOsRKdIeXaTA42tLlNwIho/edit Project Description Page]&lt;br /&gt;
== EVALUATE REPLACING [http://en.wikipedia.org/wiki/C_%28programming_language%29 C] IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs], we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
Factory Pattern: Using Factory Patterns, the class hierarchy or prototypes can be changed or refactored without needing to change code that uses them – they abstract from the class hierarchy or prototypes. Since we will be replacing the existing C libraries with equivalent rust libraries, factory pattern is applicable here. &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/ &amp;lt;br/&amp;gt;&lt;br /&gt;
[https://www.youtube.com/watch?v=pZ5dwgo5W6E A Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90386</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90386"/>
		<updated>2014-10-29T03:42:30Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/a/ncsu.edu/document/d/18VECpUuVmEaC4Xew4EsIAmOsRKdIeXaTA42tLlNwIho/edit Project Description Page]&lt;br /&gt;
== EVALUATE REPLACING [http://en.wikipedia.org/wiki/C_%28programming_language%29 C] IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs], we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/ &amp;lt;br/&amp;gt;&lt;br /&gt;
[https://www.youtube.com/watch?v=pZ5dwgo5W6E A Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90384</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90384"/>
		<updated>2014-10-29T03:42:12Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/a/ncsu.edu/document/d/18VECpUuVmEaC4Xew4EsIAmOsRKdIeXaTA42tLlNwIho/edit Project Description Page]&lt;br /&gt;
== EVALUATE REPLACING [http://en.wikipedia.org/wiki/C_%28programming_language%29 C] IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs], we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/ &amp;lt;br/&amp;gt;&lt;br /&gt;
[https://www.youtube.com/watch?v=pZ5dwgo5W6E A walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90382</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90382"/>
		<updated>2014-10-29T03:38:43Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/a/ncsu.edu/document/d/18VECpUuVmEaC4Xew4EsIAmOsRKdIeXaTA42tLlNwIho/edit Project Description Page]&lt;br /&gt;
== EVALUATE REPLACING [http://en.wikipedia.org/wiki/C_%28programming_language%29 C] IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs], we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90379</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90379"/>
		<updated>2014-10-29T03:37:58Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/a/ncsu.edu/document/d/18VECpUuVmEaC4Xew4EsIAmOsRKdIeXaTA42tLlNwIho/edit Project Description Page]&lt;br /&gt;
== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs], we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90373</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90373"/>
		<updated>2014-10-29T03:34:52Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs], we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90369</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90369"/>
		<updated>2014-10-29T03:33:04Z</updated>

		<summary type="html">&lt;p&gt;Apjoshi: /* Introduction to Servo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS [http://en.wikipedia.org/wiki/Mozilla Mozilla] Project.&lt;br /&gt;
It required us to make changes to the [http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from [http://en.wikipedia.org/wiki/Git_%28software%29 git] using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along with the dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in [https://github.com/servo/servo/blob/master/components/net/image/base.rs base.rs]. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code around this function call in [https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs image_cache_task.rs]&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./mach run image_url&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:report1455.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/guide.html &amp;lt;br/&amp;gt;&lt;br /&gt;
http://doc.rust-lang.org/ &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust &amp;lt;br/&amp;gt;&lt;br /&gt;
https://github.com/servo/servo/wiki/Replace-C-libraries-student-project/&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf &amp;lt;br/&amp;gt;&lt;br /&gt;
https://blog.mozilla.org/research/ &amp;lt;br/&amp;gt;&lt;br /&gt;
http://www.creativebloq.com/mobile/mozilla-provides-servo-browser-engine-insight-4135713&lt;/div&gt;</summary>
		<author><name>Apjoshi</name></author>
	</entry>
</feed>