pkg/pixman: rasterize trapezoids

This commit is contained in:
Mitchell Hashimoto
2022-11-25 13:23:00 -08:00
parent 179f5e6283
commit f1a052640c
2 changed files with 46 additions and 0 deletions

View File

@ -61,6 +61,20 @@ pub const Image = opaque {
@ptrCast([*c]const c.pixman_box32_t, boxes.ptr), @ptrCast([*c]const c.pixman_box32_t, boxes.ptr),
) == 0) return pixman.Error.PixmanFailure; ) == 0) return pixman.Error.PixmanFailure;
} }
pub fn rasterizeTrapezoid(
self: *Image,
trap: pixman.Trapezoid,
x_off: c_int,
y_off: c_int,
) void {
c.pixman_rasterize_trapezoid(
@ptrCast(*c.pixman_image_t, self),
@ptrCast(*const c.pixman_trapezoid_t, &trap),
x_off,
y_off,
);
}
}; };
test "create and destroy" { test "create and destroy" {

View File

@ -68,6 +68,38 @@ pub const Color = extern struct {
alpha: u16, alpha: u16,
}; };
pub const Fixed = enum(i32) {
_,
pub fn init(v: anytype) Fixed {
return switch (@TypeOf(v)) {
comptime_int, u32 => @intToEnum(Fixed, v << 16),
f64 => @intToEnum(Fixed, @floatToInt(i32, v * 65536)),
else => {
@compileLog(@TypeOf(v));
@compileError("unsupported type");
},
};
}
};
pub const PointFixed = extern struct {
x: Fixed,
y: Fixed,
};
pub const LineFixed = extern struct {
p1: PointFixed,
p2: PointFixed,
};
pub const Trapezoid = extern struct {
top: Fixed,
bottom: Fixed,
left: LineFixed,
right: LineFixed,
};
pub const Box32 = extern struct { pub const Box32 = extern struct {
x1: i32, x1: i32,
y1: i32, y1: i32,