Major rendering updates

This commit is contained in:
Zachary Levy
2026-04-22 14:49:37 -07:00
parent 37da2ea068
commit e1938f1c42
15 changed files with 1770 additions and 1736 deletions

View File

@@ -3,6 +3,10 @@ package draw_qr
import draw ".."
import "../../qrcode"
DFT_QR_DARK :: draw.BLACK // Default QR code dark module color.
DFT_QR_LIGHT :: draw.WHITE // Default QR code light module color.
DFT_QR_BOOST_ECL :: true // Default QR error correction level boost.
// Returns the number of bytes to_texture will write for the given encoded
// QR buffer. Equivalent to size*size*4 where size = qrcode.get_size(qrcode_buf).
texture_size :: #force_inline proc(qrcode_buf: []u8) -> int {
@@ -21,8 +25,8 @@ texture_size :: #force_inline proc(qrcode_buf: []u8) -> int {
to_texture :: proc(
qrcode_buf: []u8,
texture_buf: []u8,
dark: draw.Color = draw.BLACK,
light: draw.Color = draw.WHITE,
dark: draw.Color = DFT_QR_DARK,
light: draw.Color = DFT_QR_LIGHT,
) -> (
desc: draw.Texture_Desc,
ok: bool,
@@ -65,8 +69,8 @@ to_texture :: proc(
@(require_results)
register_texture_from_raw :: proc(
qrcode_buf: []u8,
dark: draw.Color = draw.BLACK,
light: draw.Color = draw.WHITE,
dark: draw.Color = DFT_QR_DARK,
light: draw.Color = DFT_QR_LIGHT,
temp_allocator := context.temp_allocator,
) -> (
texture: draw.Texture_Id,
@@ -96,9 +100,9 @@ register_texture_from_text :: proc(
min_version: int = qrcode.VERSION_MIN,
max_version: int = qrcode.VERSION_MAX,
mask: Maybe(qrcode.Mask) = nil,
boost_ecl: bool = true,
dark: draw.Color = draw.BLACK,
light: draw.Color = draw.WHITE,
boost_ecl: bool = DFT_QR_BOOST_ECL,
dark: draw.Color = DFT_QR_DARK,
light: draw.Color = DFT_QR_LIGHT,
temp_allocator := context.temp_allocator,
) -> (
texture: draw.Texture_Id,
@@ -135,9 +139,9 @@ register_texture_from_binary :: proc(
min_version: int = qrcode.VERSION_MIN,
max_version: int = qrcode.VERSION_MAX,
mask: Maybe(qrcode.Mask) = nil,
boost_ecl: bool = true,
dark: draw.Color = draw.BLACK,
light: draw.Color = draw.WHITE,
boost_ecl: bool = DFT_QR_BOOST_ECL,
dark: draw.Color = DFT_QR_DARK,
light: draw.Color = DFT_QR_LIGHT,
temp_allocator := context.temp_allocator,
) -> (
texture: draw.Texture_Id,
@@ -163,13 +167,13 @@ register_texture_from_binary :: proc(
register_texture_from :: proc {
register_texture_from_text,
register_texture_from_binary
register_texture_from_binary,
}
// Default fit=.Fit preserves the QR's square aspect; override as needed.
clay_image :: #force_inline proc(
texture: draw.Texture_Id,
tint: draw.Color = draw.WHITE,
tint: draw.Color = draw.DFT_TINT,
) -> draw.Clay_Image_Data {
return draw.clay_image_data(texture, fit = .Fit, tint = tint)
}