forked from AbleOS/ableos
34 lines
678 B
Plaintext
34 lines
678 B
Plaintext
|
.{log} := @use("../../../stn/src/lib.hb");
|
||
|
.{Surface} := @use("../lib.hb")
|
||
|
bmp := @use("bmp.hb")
|
||
|
qoi := @use("qoi.hb")
|
||
|
|
||
|
BMP := 0x4D42
|
||
|
QOI := 0x66696F71
|
||
|
// stand-in for null until bugfix
|
||
|
DOES_NOT_EXIST := 1 << 32
|
||
|
|
||
|
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 DOES_NOT_EXIST
|
||
|
}
|
||
|
}
|
||
|
|
||
|
from := fn(file: ^u8): ?Surface {
|
||
|
format := get_format(file)
|
||
|
|
||
|
if format == DOES_NOT_EXIST {
|
||
|
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
|
||
|
}
|