mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
remove font conversion stuff
This commit is contained in:
@ -16,7 +16,6 @@ const Atlas = @import("../Atlas.zig");
|
|||||||
const Glyph = @import("main.zig").Glyph;
|
const Glyph = @import("main.zig").Glyph;
|
||||||
const Library = @import("main.zig").Library;
|
const Library = @import("main.zig").Library;
|
||||||
const Presentation = @import("main.zig").Presentation;
|
const Presentation = @import("main.zig").Presentation;
|
||||||
const convert = @import("convert.zig");
|
|
||||||
|
|
||||||
const log = std.log.scoped(.font_face);
|
const log = std.log.scoped(.font_face);
|
||||||
|
|
||||||
@ -148,7 +147,7 @@ pub fn renderGlyph(self: Face, alloc: Allocator, atlas: *Atlas, glyph_index: u32
|
|||||||
// or color depth is as expected on the texture atlas. If format is null
|
// or color depth is as expected on the texture atlas. If format is null
|
||||||
// it means there is no native color format for our Atlas and we must try
|
// it means there is no native color format for our Atlas and we must try
|
||||||
// conversion.
|
// conversion.
|
||||||
const format: ?Atlas.Format = switch (bitmap_ft.pixel_mode) {
|
const format: Atlas.Format = switch (bitmap_ft.pixel_mode) {
|
||||||
freetype.c.FT_PIXEL_MODE_GRAY => .greyscale,
|
freetype.c.FT_PIXEL_MODE_GRAY => .greyscale,
|
||||||
freetype.c.FT_PIXEL_MODE_BGRA => .rgba,
|
freetype.c.FT_PIXEL_MODE_BGRA => .rgba,
|
||||||
else => {
|
else => {
|
||||||
@ -156,26 +155,9 @@ pub fn renderGlyph(self: Face, alloc: Allocator, atlas: *Atlas, glyph_index: u32
|
|||||||
@panic("unsupported pixel mode");
|
@panic("unsupported pixel mode");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
assert(atlas.format == format);
|
||||||
|
|
||||||
// If our atlas format doesn't match, look for conversions if possible.
|
const bitmap = bitmap_ft;
|
||||||
const bitmap_converted = if (format == null or atlas.format != format.?) blk: {
|
|
||||||
const func = convert.map[bitmap_ft.pixel_mode].get(atlas.format) orelse {
|
|
||||||
log.warn("glyph={} pixel mode={}", .{ glyph_index, bitmap_ft.pixel_mode });
|
|
||||||
return error.UnsupportedPixelMode;
|
|
||||||
};
|
|
||||||
|
|
||||||
log.warn("converting from pixel_mode={} to atlas_format={}", .{
|
|
||||||
bitmap_ft.pixel_mode,
|
|
||||||
atlas.format,
|
|
||||||
});
|
|
||||||
break :blk try func(alloc, bitmap_ft);
|
|
||||||
} else null;
|
|
||||||
defer if (bitmap_converted) |bm| {
|
|
||||||
const len = bm.width * bm.rows * atlas.format.depth();
|
|
||||||
alloc.free(bm.buffer[0..len]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const bitmap = bitmap_converted orelse bitmap_ft;
|
|
||||||
const tgt_w = bitmap.width;
|
const tgt_w = bitmap.width;
|
||||||
const tgt_h = bitmap.rows;
|
const tgt_h = bitmap.rows;
|
||||||
|
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
//! Various conversions from Freetype formats to Atlas formats. These are
|
|
||||||
//! currently implemented naively. There are definitely MUCH faster ways
|
|
||||||
//! to do this (likely using SIMD), but I started simple.
|
|
||||||
const std = @import("std");
|
|
||||||
const freetype = @import("freetype");
|
|
||||||
const Atlas = @import("../Atlas.zig");
|
|
||||||
const assert = std.debug.assert;
|
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
|
|
||||||
/// The mapping from freetype format to atlas format.
|
|
||||||
pub const map = genMap();
|
|
||||||
|
|
||||||
/// The map type.
|
|
||||||
pub const Map = [freetype.c.FT_PIXEL_MODE_MAX]AtlasArray;
|
|
||||||
|
|
||||||
/// Conversion function type. The returning bitmap buffer is guaranteed
|
|
||||||
/// to be exactly `width * rows * depth` long for freeing it. The caller must
|
|
||||||
/// free the bitmap buffer. The depth is the depth of the atlas format in the
|
|
||||||
/// map.
|
|
||||||
pub const Func = fn (Allocator, Bitmap) Allocator.Error!Bitmap;
|
|
||||||
|
|
||||||
/// Alias for the freetype FT_Bitmap type to make it easier to type.
|
|
||||||
pub const Bitmap = freetype.c.struct_FT_Bitmap_;
|
|
||||||
|
|
||||||
const AtlasArray = std.EnumArray(Atlas.Format, ?Func);
|
|
||||||
|
|
||||||
fn genMap() Map {
|
|
||||||
var result: Map = undefined;
|
|
||||||
|
|
||||||
// Initialize to no converter
|
|
||||||
var i: usize = 0;
|
|
||||||
while (i < freetype.c.FT_PIXEL_MODE_MAX) : (i += 1) {
|
|
||||||
result[i] = AtlasArray.initFill(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map our converters
|
|
||||||
result[freetype.c.FT_PIXEL_MODE_MONO].set(.rgba, monoToRGBA);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn monoToRGBA(alloc: Allocator, bm: Bitmap) Allocator.Error!Bitmap {
|
|
||||||
// NOTE: This was never tested and may not work. I wrote it to
|
|
||||||
// solve another issue where this ended up not being needed.
|
|
||||||
// TODO: test this!
|
|
||||||
|
|
||||||
const depth = Atlas.Format.rgba.depth();
|
|
||||||
var buf = try alloc.alloc(u8, bm.width * bm.rows * depth);
|
|
||||||
errdefer alloc.free(buf);
|
|
||||||
|
|
||||||
var i: usize = 0;
|
|
||||||
while (i < bm.width * bm.rows) : (i += 1) {
|
|
||||||
var bit: u3 = 0;
|
|
||||||
while (bit <= 7) : (bit += 1) {
|
|
||||||
const mask = @as(u8, 1) << (7 - bit);
|
|
||||||
const bitval: u8 = if (bm.buffer[i] & mask > 0) 0xFF else 0;
|
|
||||||
const buf_i = (i * 8 * depth) + (bit * depth);
|
|
||||||
buf[buf_i] = 0xFF - bitval;
|
|
||||||
buf[buf_i + 1] = 0xFF - bitval;
|
|
||||||
buf[buf_i + 2] = 0xFF - bitval;
|
|
||||||
buf[buf_i + 3] = bitval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var copy = bm;
|
|
||||||
copy.buffer = buf.ptr;
|
|
||||||
copy.pixel_mode = freetype.c.FT_PIXEL_MODE_BGRA;
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
_ = map;
|
|
||||||
}
|
|
Reference in New Issue
Block a user