Implement image surfaces

This commit is contained in:
Patrick Walton 2012-03-27 17:10:05 -07:00
parent b6f3bda0a4
commit 65fea92d7d
2 changed files with 29 additions and 2 deletions

View file

@ -5,6 +5,12 @@ type rect<A> = { mut origin: point<A>, mut size: size<A> };
enum au = int; enum au = int;
impl size for size<int> {
fn area() -> int {
self.width * self.height
}
}
fn point<A:copy>(x: A, y: A) -> point<A> { fn point<A:copy>(x: A, y: A) -> point<A> {
{mut x: x, mut y: y} {mut x: x, mut y: y}
} }

View file

@ -1,9 +1,30 @@
import gfx::geom;
import gfx::geom::size;
enum format { enum format {
fo_rgba_8888 fo_rgba_8888
// TODO: RGB 565, others? // TODO: RGB 565, others?
} }
type surface = { type image_surface = {
format: format size: geom::size<int>,
format: format,
buffer: [u8]
}; };
impl format for format {
fn bpp() -> uint {
alt self {
fo_rgba_8888 { 32u }
}
}
}
fn image_surface(size: geom::size<int>, format: format) -> image_surface {
{
size: size,
format: format,
buffer: vec::from_elem((size.area() as uint) * format.bpp(), 0u8)
}
}