akern-gkgoat-fork/sysdata/libraries/render/src/image/lib.hb

31 lines
600 B
Plaintext
Raw Normal View History

.{log} := @use("../../../stn/src/lib.hb");
.{Surface} := @use("../lib.hb")
bmp := @use("bmp.hb")
qoi := @use("qoi.hb")
2024-11-10 04:09:02 -06:00
$BMP := 0x4D42
$QOI := 0x66696F71
2024-11-10 04:09:02 -06:00
get_format := fn(file: ^u8): ?uint {
if *@as(^u16, @bitcast(file)) == BMP {
return BMP
} else if *@as(^u32, @bitcast(file)) == QOI {
return QOI
} else {
2024-11-10 04:09:02 -06:00
return null
}
}
from := fn(file: ^u8): ?Surface {
format := get_format(file)
2024-11-10 04:09:02 -06:00
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
}