From 1cf390729e5f85f90aff4255a97c874562c17024 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 9 Oct 2022 16:29:19 -0700 Subject: [PATCH] pkg/macos: bitmap info arg --- pkg/macos/graphics.zig | 1 + pkg/macos/graphics/bitmap_context.zig | 5 +++-- pkg/macos/graphics/context.zig | 9 +++++++- pkg/macos/graphics/image.zig | 31 +++++++++++++++++++++++++++ pkg/macos/text/font.zig | 2 +- 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 pkg/macos/graphics/image.zig diff --git a/pkg/macos/graphics.zig b/pkg/macos/graphics.zig index ba8be1657..2ea5d7b7f 100644 --- a/pkg/macos/graphics.zig +++ b/pkg/macos/graphics.zig @@ -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 { diff --git a/pkg/macos/graphics/bitmap_context.zig b/pkg/macos/graphics/bitmap_context.zig index 0516df417..742c82c2a 100644 --- a/pkg/macos/graphics/bitmap_context.zig +++ b/pkg/macos/graphics/bitmap_context.zig @@ -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); diff --git a/pkg/macos/graphics/context.zig b/pkg/macos/graphics/context.zig index c3516ba7e..be93546f2 100644 --- a/pkg/macos/graphics/context.zig +++ b/pkg/macos/graphics/context.zig @@ -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), + ); + } }; } diff --git a/pkg/macos/graphics/image.zig b/pkg/macos/graphics/image.zig new file mode 100644 index 000000000..0c4954c11 --- /dev/null +++ b/pkg/macos/graphics/image.zig @@ -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, + + _, +}; diff --git a/pkg/macos/text/font.zig b/pkg/macos/text/font.zig index 38577c3dc..988d0e666 100644 --- a/pkg/macos/text/font.zig +++ b/pkg/macos/text/font.zig @@ -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 }};