.{log} := @use("../../../stn/src/lib.hb"); .{Surface} := @use("../lib.hb") bmp := @use("bmp.hb") qoi := @use("qoi.hb") $BMP := 0x4D42 $QOI := 0x66696F71 get_format := fn(file: ^u8): ?uint { if *@as(^u16, @bitcast(file)) == BMP { return BMP } else if *@as(^u32, @bitcast(file)) == QOI { return QOI } else { return null } } from := fn(file: ^u8): ?Surface { format := get_format(file) if format == null { log.error("Could not detect image format.\0") return null } else if format == BMP { return bmp.from(file) } else if format == QOI { return qoi.from(file) } return null }