OpenLiberty/scripts/renderware/rw_raster.gd

96 lines
2.3 KiB
GDScript3
Raw Normal View History

2022-11-09 04:29:26 +07:00
class_name RWRaster
extends RWChunk
2022-11-09 05:55:25 +07:00
enum {
FORMAT_DEFAULT = 0x0000,
FORMAT_1555 = 0x0100,
FORMAT_565 = 0x0200,
FORMAT_4444 = 0x0300,
FORMAT_LUM8 = 0x0400,
FORMAT_8888 = 0x0500,
FORMAT_888 = 0x0600,
FORMAT_555 = 0x0A00,
FORMAT_EXT_AUTO_MIPMAP = 0x1000,
FORMAT_EXT_PAL8 = 0x2000,
FORMAT_EXT_PAL4 = 0x4000,
FORMAT_EXT_MIPMAP = 0x8000
}
2022-11-09 04:29:26 +07:00
var platform_id: int
var filter_mode: int
var u_addressing: int
var v_addressing: int
var name: String
var mask_name: String
var raster_format: int
var has_alpha: bool
var width: int
var height: int
var depth: int
var num_levels: int
var raster_type: int
var compression: int
2022-11-09 05:55:25 +07:00
var image: Image
2022-11-09 04:29:26 +07:00
func _init(file: FileAccess):
super(file)
assert(type == 0x15)
RWChunk.new(file)
platform_id = file.get_32()
filter_mode = file.get_8()
var uv_addressing = file.get_8()
u_addressing = uv_addressing >> 4
v_addressing = uv_addressing & 0xf
file.get_16()
name = file.get_buffer(32).get_string_from_ascii()
mask_name = file.get_buffer(32).get_string_from_ascii()
raster_format = file.get_32()
has_alpha = (true if file.get_32() > 0 else false)
width = file.get_16()
height = file.get_16()
depth = file.get_8()
num_levels = file.get_8()
raster_type = file.get_8()
compression = file.get_8()
2022-11-09 05:55:25 +07:00
# Image loading starts here
var ifmt: Image.Format
2022-11-09 06:38:55 +07:00
var bpc: int
2022-11-09 05:55:25 +07:00
match (raster_format >> 8) & 0xf:
0x5:
ifmt = Image.FORMAT_RGBA8
2022-11-09 06:38:55 +07:00
bpc = 4
2022-11-09 05:55:25 +07:00
0x6:
ifmt = Image.FORMAT_RGB8
2022-11-09 06:38:55 +07:00
bpc = 3
2022-11-09 05:55:25 +07:00
_:
assert(false, "unknown raster format")
2022-11-09 06:38:55 +07:00
if raster_format & (FORMAT_EXT_PAL8 | FORMAT_EXT_PAL4):
image = Image.create(width, height, false, ifmt)
image.fill(Color.PURPLE)
2022-11-09 05:55:25 +07:00
2022-11-09 06:38:55 +07:00
if raster_format & FORMAT_EXT_PAL8 > 0:
var palette := Image.create_from_data(256, 1, false, ifmt, file.get_buffer(256 * bpc))
for i in width * height:
var x := int(i % width)
var y := int(i / width)
var col := palette.get_pixel(file.get_8(), 0)
image.set_pixel(x, y, col)
else:
assert(false, "implement")
elif raster_format & (FORMAT_EXT_PAL8 | FORMAT_EXT_PAL4) == 0:
var raster_size := file.get_32()
image = Image.create_from_data(width, height, false, ifmt, file.get_buffer((width * height) * bpc))
#
2022-11-09 05:55:25 +07:00
file.seek(_start + size)