Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

split image in separate types #6

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions pixman/examples/alpha.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use pixman::{Fixed, FormatCode, GradientStop, Image, Operation, Point, Repeat, Transform};
use pixman::{
Fixed, FormatCode, GradientStop, Image, LinearGradient, Operation, Point, Repeat, Transform,
};

const WIDTH: usize = 400;
const HEIGHT: usize = 200;
Expand All @@ -19,7 +21,7 @@ pub fn main() {
]);

let mut alpha = [0x4f00004fu32; WIDTH * HEIGHT]; /* pale blue */
let mut alpha_img = Image::from_bits(
let alpha_img = Image::from_slice_mut(
FormatCode::A8R8G8B8,
WIDTH,
HEIGHT,
Expand All @@ -30,7 +32,7 @@ pub fn main() {
.unwrap();

let mut dest = [0xffffff00u32; WIDTH * HEIGHT]; /* yellow */
let mut dest_img = Image::from_bits(
let dest_img = Image::from_slice_mut(
FormatCode::A8R8G8B8,
WIDTH,
HEIGHT,
Expand All @@ -41,17 +43,10 @@ pub fn main() {
.unwrap();

let mut src = [0xffff0000; WIDTH * HEIGHT];
let mut src_img = Image::from_bits(
FormatCode::A8R8G8B8,
WIDTH,
HEIGHT,
&mut src,
WIDTH * 4,
false,
)
.unwrap();
let src_img =
Image::from_slice(FormatCode::A8R8G8B8, WIDTH, HEIGHT, &mut src, WIDTH * 4).unwrap();

let mut grad_img = Image::linear_gradient(p1, p2, &stops).unwrap();
let grad_img = LinearGradient::new(p1, p2, &stops).unwrap();
grad_img.set_transform(transform).unwrap();
grad_img.set_repeat(Repeat::Pad);

Expand All @@ -69,7 +64,7 @@ pub fn main() {
HEIGHT as u16,
);

src_img.set_alpha_map(Some(&alpha_img), 10, 10);
let src_img = src_img.set_alpha_map(&alpha_img, 10, 10);

dest_img.composite(
Operation::Over,
Expand All @@ -85,7 +80,7 @@ pub fn main() {
HEIGHT as u16,
);

let mut out_img = Image::new(
let out_img = Image::new(
FormatCode::A8B8G8R8,
dest_img.width(),
dest_img.height(),
Expand Down
10 changes: 5 additions & 5 deletions pixman/examples/checkerboard.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use pixman::{Color, Filter, FormatCode, Image, Operation, Repeat};
use pixman::{Color, Filter, FormatCode, Image, Operation, Repeat, Solid};

const WIDTH: usize = 400;
const HEIGHT: usize = 400;
const TILE_SIZE: usize = 25;

pub fn main() {
let mut checkerboard = Image::new(FormatCode::A8R8G8B8, WIDTH, HEIGHT, false).unwrap();
let mut destination = Image::new(FormatCode::A8R8G8B8, WIDTH, HEIGHT, false).unwrap();
let checkerboard = Image::new(FormatCode::A8R8G8B8, WIDTH, HEIGHT, false).unwrap();
let destination = Image::new(FormatCode::A8R8G8B8, WIDTH, HEIGHT, false).unwrap();

// let transform = Transform::new([
// [-1.96830, -1.82250, 512.12250],
Expand All @@ -28,7 +28,7 @@ pub fn main() {

let c = if (j & 1) != (i & 1) { black } else { white };

let fill = Image::solid_fill(c).unwrap();
let fill = Solid::new(c).unwrap();

checkerboard.composite(
Operation::Src,
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn main() {
HEIGHT as u16,
);

let mut out_img = Image::new(
let out_img = Image::new(
FormatCode::A8B8G8R8,
destination.width(),
destination.height(),
Expand Down
11 changes: 6 additions & 5 deletions pixman/examples/clip.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use pixman::{
Fixed, FormatCode, GradientStop, Image, Operation, Point, Region32, Repeat, Transform,
Fixed, FormatCode, GradientStop, Image, Operation, Point, RadialGradient, Region32, Repeat,
Transform,
};

const WIDTH: usize = 200;
Expand All @@ -19,7 +20,7 @@ pub fn main() {
let r_outer = Fixed::from(100.0);

let mut src = [0xff0000ffu32; WIDTH * HEIGHT];
let mut src_img = Image::from_bits(
let src_img = Image::from_slice_mut(
FormatCode::A8R8G8B8,
WIDTH,
HEIGHT,
Expand All @@ -29,7 +30,7 @@ pub fn main() {
)
.unwrap();

let gradient_img = Image::radial_gradient(c_inner, c_outer, r_inner, r_outer, &stops).unwrap();
let gradient_img = RadialGradient::new(c_inner, c_outer, r_inner, r_outer, &stops).unwrap();

src_img.composite(
Operation::Over,
Expand All @@ -53,7 +54,7 @@ pub fn main() {
src_img.set_repeat(Repeat::Normal);

let mut dst = [0xffff0000u32; WIDTH * HEIGHT];
let mut dst_img = Image::from_bits(
let dst_img = Image::from_slice_mut(
FormatCode::A8R8G8B8,
WIDTH,
HEIGHT,
Expand All @@ -77,7 +78,7 @@ pub fn main() {
HEIGHT as u16,
);

let mut out_img = Image::new(
let out_img = Image::new(
FormatCode::A8B8G8R8,
dst_img.width(),
dst_img.height(),
Expand Down
18 changes: 10 additions & 8 deletions pixman/examples/conical.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use pixman::{FormatCode, GradientStop, Image, Operation, Repeat, Transform};
use pixman::{
ConicalGradient, FormatCode, GradientStop, Image, Operation, Repeat, Solid, Transform,
};

const SIZE: usize = 128;
const GRADIENTS_PER_ROW: usize = 7;
Expand All @@ -24,7 +26,7 @@ pub fn main() {
let column = i % GRADIENTS_PER_ROW;
let row = i / GRADIENTS_PER_ROW;

let mut src_img = create_conical(i);
let src_img = create_conical(i);
src_img.set_repeat(Repeat::Normal);
src_img.set_transform(transform).unwrap();

Expand All @@ -43,7 +45,7 @@ pub fn main() {
);
}

let mut out_img = Image::new(
let out_img = Image::new(
FormatCode::A8B8G8R8,
dest_img.width(),
dest_img.height(),
Expand Down Expand Up @@ -76,9 +78,9 @@ pub fn main() {
.unwrap();
}

fn create_conical(index: usize) -> Image<'static> {
fn create_conical(index: usize) -> ConicalGradient<'static> {
let angle = (0.5 / NUM_GRADIENTS as f64 + index as f64 / NUM_GRADIENTS as f64) * 720.0 - 180.0;
Image::conical_gradient(
ConicalGradient::new(
(0.0, 0.0),
angle,
&[
Expand All @@ -91,9 +93,9 @@ fn create_conical(index: usize) -> Image<'static> {
.unwrap()
}

fn draw_checkerboard(image: &mut Image, check_size: usize, color1: u32, color2: u32) {
let c1 = Image::solid_fill(color1).unwrap();
let c2 = Image::solid_fill(color2).unwrap();
fn draw_checkerboard(image: &Image<'_, '_, true>, check_size: usize, color1: u32, color2: u32) {
let c1 = Solid::new(color1).unwrap();
let c2 = Solid::new(color2).unwrap();

let n_checks_x = (image.width() + check_size - 1) / check_size;
let n_checks_y = (image.height() + check_size - 1) / check_size;
Expand Down
10 changes: 6 additions & 4 deletions pixman/examples/gradient.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use pixman::{Fixed, FormatCode, GradientStop, Image, Operation, Point, Repeat, Transform};
use pixman::{
Fixed, FormatCode, GradientStop, Image, LinearGradient, Operation, Point, Repeat, Transform,
};

const WIDTH: usize = 400;
const HEIGHT: usize = 200;
Expand All @@ -19,7 +21,7 @@ pub fn main() {
]);

let mut dest = [0xff00ff00u32; WIDTH * HEIGHT];
let mut dest_img = Image::from_bits(
let dest_img = Image::from_slice_mut(
FormatCode::A8R8G8B8,
WIDTH,
HEIGHT,
Expand All @@ -29,7 +31,7 @@ pub fn main() {
)
.unwrap();

let mut src_img = Image::linear_gradient(p1, p2, &stops).unwrap();
let src_img = LinearGradient::new(p1, p2, &stops).unwrap();

src_img.set_transform(transform).unwrap();
src_img.set_repeat(Repeat::None);
Expand All @@ -48,7 +50,7 @@ pub fn main() {
HEIGHT as u16,
);

let mut out_img = Image::new(
let out_img = Image::new(
FormatCode::A8B8G8R8,
dest_img.width(),
dest_img.height(),
Expand Down
8 changes: 4 additions & 4 deletions pixman/examples/solid_fill.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use pixman::{FormatCode, Image, Operation, Repeat};
use pixman::{FormatCode, Image, Operation, Repeat, Solid};

pub fn main() {
let mut dst = Image::new(FormatCode::A8R8G8B8, 800, 600, true).unwrap();
let mut solid = Image::solid_fill([0xffff, 0xffff, 0xffff, 0xffff]).unwrap();
let dst = Image::new(FormatCode::A8R8G8B8, 800, 600, true).unwrap();
let solid = Solid::new([0xffff, 0xffff, 0xffff, 0xffff]).unwrap();
solid.set_repeat(Repeat::Normal);
dst.composite(Operation::Over, &solid, None, 0, 0, 0, 0, 50, 0, 50, 50);

let mut out_img = Image::new(FormatCode::A8B8G8R8, dst.width(), dst.height(), false).unwrap();
let out_img = Image::new(FormatCode::A8B8G8R8, dst.width(), dst.height(), false).unwrap();
out_img.composite(
Operation::Src,
&dst,
Expand Down
14 changes: 7 additions & 7 deletions pixman/examples/trap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pixman::{Color, Fixed, FormatCode, Image, Operation, Span, Trap};
use pixman::{Color, Fixed, FormatCode, Image, Operation, Solid, Span, Trap};

const WIDTH: usize = 200;
const HEIGHT: usize = 200;
Expand All @@ -24,11 +24,11 @@ pub fn main() {
),
);

let mut mask_img =
Image::from_bits(FormatCode::A8, WIDTH, HEIGHT, &mut mbits, WIDTH, false).unwrap();
let src_img = Image::solid_fill(white).unwrap();
let mut dest_img =
Image::from_bits(FormatCode::A8R8G8B8, WIDTH, HEIGHT, bits, WIDTH * 4, false).unwrap();
let mask_img =
Image::from_slice_mut(FormatCode::A8, WIDTH, HEIGHT, &mut mbits, WIDTH, false).unwrap();
let src_img = Solid::new(white).unwrap();
let dest_img =
Image::from_slice_mut(FormatCode::A8R8G8B8, WIDTH, HEIGHT, bits, WIDTH * 4, false).unwrap();

mask_img.add_traps(0, 0, &[trap]);

Expand All @@ -46,7 +46,7 @@ pub fn main() {
HEIGHT as u16,
);

let mut out_img = Image::new(
let out_img = Image::new(
FormatCode::A8B8G8R8,
dest_img.width(),
dest_img.height(),
Expand Down
8 changes: 4 additions & 4 deletions pixman/examples/tri.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pixman::{Color, FormatCode, Image, Operation, Triangle};
use pixman::{Color, FormatCode, Image, Operation, Solid, Triangle};

const WIDTH: usize = 200;
const HEIGHT: usize = 200;
Expand All @@ -18,8 +18,8 @@ pub fn main() {
bits[i] = ((i / HEIGHT) as u32) * 0x01010000;
}

let src_img = Image::solid_fill(color).unwrap();
let mut dest_img = Image::from_bits(
let src_img = Solid::new(color).unwrap();
let dest_img = Image::from_slice_mut(
FormatCode::A8R8G8B8,
WIDTH,
HEIGHT,
Expand All @@ -40,7 +40,7 @@ pub fn main() {
&tris,
);

let mut out_img = Image::new(
let out_img = Image::new(
FormatCode::A8B8G8R8,
dest_img.width(),
dest_img.height(),
Expand Down
Loading