2024-11-06 19:55:08 -06:00
|
|
|
.{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-06 19:55:08 -06:00
|
|
|
|
2024-11-10 04:09:02 -06:00
|
|
|
get_format := fn(file: ^u8): ?uint {
|
2024-11-06 19:55:08 -06:00
|
|
|
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
|
2024-11-06 19:55:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
from := fn(file: ^u8): ?Surface {
|
|
|
|
format := get_format(file)
|
|
|
|
|
2024-11-10 04:09:02 -06:00
|
|
|
if format == null {
|
2024-11-06 19:55:08 -06:00
|
|
|
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
|
|
|
|
}
|