mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
move stb to src/stb, add stb_image for png decoding
This commit is contained in:
11
build.zig
11
build.zig
@ -24,7 +24,6 @@ const libpng = @import("pkg/libpng/build.zig");
|
||||
const macos = @import("pkg/macos/build.zig");
|
||||
const objc = @import("vendor/zig-objc/build.zig");
|
||||
const pixman = @import("pkg/pixman/build.zig");
|
||||
const stb_image_resize = @import("pkg/stb_image_resize/build.zig");
|
||||
const utf8proc = @import("pkg/utf8proc/build.zig");
|
||||
const zlib = @import("pkg/zlib/build.zig");
|
||||
const tracylib = @import("pkg/tracy/build.zig");
|
||||
@ -670,6 +669,11 @@ fn addDeps(
|
||||
step.addLibraryPath(.{ .path = b.fmt("/usr/lib/{s}", .{triple}) });
|
||||
}
|
||||
|
||||
// C files
|
||||
step.linkLibC();
|
||||
step.addIncludePath(.{ .path = "src/stb" });
|
||||
step.addCSourceFiles(&.{"src/stb/stb.c"}, &.{});
|
||||
|
||||
// If we're building a lib we have some different deps
|
||||
const lib = step.kind == .lib;
|
||||
|
||||
@ -693,7 +697,6 @@ fn addDeps(
|
||||
}));
|
||||
step.addModule("xev", mod_libxev);
|
||||
step.addModule("pixman", pixman.module(b));
|
||||
step.addModule("stb_image_resize", stb_image_resize.module(b));
|
||||
step.addModule("utf8proc", utf8proc.module(b));
|
||||
|
||||
// Mac Stuff
|
||||
@ -713,10 +716,6 @@ fn addDeps(
|
||||
system_sdk.include(b, tracy_step, .{});
|
||||
}
|
||||
|
||||
// stb_image_resize
|
||||
const stb_image_resize_step = try stb_image_resize.link(b, step, .{});
|
||||
try static_libs.append(stb_image_resize_step.getEmittedBin());
|
||||
|
||||
// utf8proc
|
||||
const utf8proc_step = try utf8proc.link(b, step);
|
||||
try static_libs.append(utf8proc_step.getEmittedBin());
|
||||
|
@ -1,65 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// Directories with our includes.
|
||||
const root = thisDir();
|
||||
pub const include_paths = [_][]const u8{
|
||||
root,
|
||||
};
|
||||
|
||||
pub fn module(b: *std.Build) *std.build.Module {
|
||||
return b.createModule(.{
|
||||
.source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" },
|
||||
});
|
||||
}
|
||||
|
||||
fn thisDir() []const u8 {
|
||||
return std.fs.path.dirname(@src().file) orelse ".";
|
||||
}
|
||||
|
||||
pub const Options = struct {};
|
||||
|
||||
pub fn link(
|
||||
b: *std.Build,
|
||||
step: *std.build.LibExeObjStep,
|
||||
opt: Options,
|
||||
) !*std.build.LibExeObjStep {
|
||||
const lib = try buildStbImageResize(b, step, opt);
|
||||
step.linkLibrary(lib);
|
||||
inline for (include_paths) |path| step.addIncludePath(.{ .path = path });
|
||||
return lib;
|
||||
}
|
||||
|
||||
pub fn buildStbImageResize(
|
||||
b: *std.Build,
|
||||
step: *std.build.LibExeObjStep,
|
||||
opt: Options,
|
||||
) !*std.build.LibExeObjStep {
|
||||
_ = opt;
|
||||
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "stb_image_resize",
|
||||
.target = step.target,
|
||||
.optimize = step.optimize,
|
||||
});
|
||||
|
||||
// Include
|
||||
inline for (include_paths) |path| lib.addIncludePath(.{ .path = path });
|
||||
|
||||
// Link
|
||||
lib.linkLibC();
|
||||
|
||||
// Compile
|
||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||
defer flags.deinit();
|
||||
try flags.appendSlice(&.{
|
||||
//"-fno-sanitize=undefined",
|
||||
});
|
||||
|
||||
// C files
|
||||
lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "/stb_image_resize.c" },
|
||||
.flags = flags.items,
|
||||
});
|
||||
|
||||
return lib;
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include <stb_image_resize.h>
|
@ -8,7 +8,7 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const freetype = @import("freetype");
|
||||
const harfbuzz = @import("harfbuzz");
|
||||
const resize = @import("stb_image_resize");
|
||||
const stb = @import("../../stb/main.zig");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
@ -204,7 +204,7 @@ pub const Face = struct {
|
||||
result.buffer = buf.ptr;
|
||||
errdefer alloc.free(buf);
|
||||
|
||||
if (resize.stbir_resize_uint8(
|
||||
if (stb.stbir_resize_uint8(
|
||||
bm.buffer,
|
||||
@intCast(bm.width),
|
||||
@intCast(bm.rows),
|
||||
|
@ -1,7 +1,4 @@
|
||||
pub usingnamespace @cImport({
|
||||
@cInclude("stb_image.h");
|
||||
@cInclude("stb_image_resize.h");
|
||||
});
|
||||
|
||||
test {
|
||||
// Needed to not crash on test
|
||||
}
|
13
src/stb/stb.c
Normal file
13
src/stb/stb.c
Normal file
@ -0,0 +1,13 @@
|
||||
// For STBI we only need PNG because the only use case we have right now
|
||||
// is the Kitty Graphics protocol which only supports PNG as a format
|
||||
// besides raw RGB/RGBA buffers.
|
||||
#define STBI_ONLY_PNG
|
||||
|
||||
// We don't want to support super large images.
|
||||
#define STBI_MAX_DIMENSIONS 131072
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include <stb_image_resize.h>
|
7987
src/stb/stb_image.h
Normal file
7987
src/stb/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user