pkg/macos: bitmap info arg

This commit is contained in:
Mitchell Hashimoto
2022-10-09 16:29:19 -07:00
parent 276ae4f788
commit 1cf390729e
5 changed files with 44 additions and 4 deletions

View File

@ -4,6 +4,7 @@ pub usingnamespace @import("graphics/bitmap_context.zig");
pub usingnamespace @import("graphics/color_space.zig");
pub usingnamespace @import("graphics/font.zig");
pub usingnamespace @import("graphics/geometry.zig");
pub usingnamespace @import("graphics/image.zig");
pub usingnamespace @import("graphics/path.zig");
test {

View File

@ -15,6 +15,7 @@ pub const BitmapContext = opaque {
bits_per_component: usize,
bytes_per_row: usize,
space: *graphics.ColorSpace,
opts: c_uint,
) Allocator.Error!*BitmapContext {
return @intToPtr(
?*BitmapContext,
@ -25,7 +26,7 @@ pub const BitmapContext = opaque {
bits_per_component,
bytes_per_row,
@ptrCast(c.CGColorSpaceRef, space),
0,
opts,
)),
) orelse Allocator.Error.OutOfMemory;
}
@ -36,7 +37,7 @@ test {
const cs = try graphics.ColorSpace.createDeviceGray();
defer cs.release();
const ctx = try BitmapContext.create(null, 80, 80, 8, 80, cs);
const ctx = try BitmapContext.create(null, 80, 80, 8, 80, cs, 0);
defer ctx.release();
ctx.setShouldAntialias(true);

View File

@ -49,7 +49,7 @@ pub fn Context(comptime T: type) type {
);
}
pub fn setRGBFillColor(self: *T, r: f64, g: f64, b: 64, alpha: f64) void {
pub fn setRGBFillColor(self: *T, r: f64, g: f64, b: f64, alpha: f64) void {
c.CGContextSetRGBFillColor(
@ptrCast(c.CGContextRef, self),
r,
@ -80,6 +80,13 @@ pub fn Context(comptime T: type) type {
y,
);
}
pub fn fillRect(self: *T, rect: graphics.Rect) void {
c.CGContextFillRect(
@ptrCast(c.CGContextRef, self),
@bitCast(c.CGRect, rect),
);
}
};
}

View File

@ -0,0 +1,31 @@
const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const graphics = @import("../graphics.zig");
const context = @import("context.zig");
const c = @import("c.zig");
pub const ImageAlphaInfo = enum(c_uint) {
none = c.kCGImageAlphaNone,
premultiplied_last = c.kCGImageAlphaPremultipliedLast,
premultiplied_first = c.kCGImageAlphaPremultipliedFirst,
last = c.kCGImageAlphaLast,
first = c.kCGImageAlphaFirst,
none_skip_last = c.kCGImageAlphaNoneSkipLast,
none_skip_first = c.kCGImageAlphaNoneSkipFirst,
only = c.kCGImageAlphaOnly,
};
pub const BitmapInfo = enum(c_uint) {
alpha_mask = c.kCGBitmapAlphaInfoMask,
float_mask = c.kCGBitmapFloatInfoMask,
float_components = c.kCGBitmapFloatComponents,
byte_order_mask = c.kCGBitmapByteOrderMask,
byte_order_default = c.kCGBitmapByteOrderDefault,
byte_order_16_little = c.kCGBitmapByteOrder16Little,
byte_order_32_little = c.kCGBitmapByteOrder32Little,
byte_order_16_big = c.kCGBitmapByteOrder16Big,
byte_order_32_big = c.kCGBitmapByteOrder32Big,
_,
};

View File

@ -193,7 +193,7 @@ test {
{
const cs = try graphics.ColorSpace.createDeviceGray();
defer cs.release();
const ctx = try graphics.BitmapContext.create(null, 80, 80, 8, 80, cs);
const ctx = try graphics.BitmapContext.create(null, 80, 80, 8, 80, cs, 0);
defer ctx.release();
var pos = [_]graphics.Point{.{ .x = 0, .y = 0 }};