-
Notifications
You must be signed in to change notification settings - Fork 9
/
fmt_sd_dlt.py
88 lines (62 loc) · 2.44 KB
/
fmt_sd_dlt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from inc_noesis import *
def registerNoesisTypes():
handle = noesis.register("Sea Dogs (2000) island image", ".dlt")
noesis.setHandlerTypeCheck(handle, dltCheckType)
noesis.setHandlerLoadRGBA(handle, sdDLTLoadRGBA)
noesis.setHandlerWriteRGBA(handle, sdDLTWriteRGBA)
return 1
class DLTImage:
def __init__(self, reader):
self.filereader = reader
def parseHeader(self):
self.size = self.filereader.readUInt()
self.width = self.filereader.readUInt()
self.height = self.filereader.readUInt()
self.mapCount = self.filereader.readUInt()
self.filereader.seek(4, NOESEEK_REL)
return 0
def getImageData(self):
imageBuffer = self.filereader.readBytes(self.width * self.height * 2)
self.data = rapi.imageDecodeRaw(imageBuffer, self.width, self.height, \
"b5g6r5")
def read(self):
self.getImageData()
def dltCheckType(data):
dltImage = DLTImage(NoeBitStream(data))
if dltImage.parseHeader() != 0:
return 0
return 1
def sdDLTLoadRGBA(data, texList):
dltImage = DLTImage(NoeBitStream(data))
if dltImage.parseHeader() != 0:
return 0
dltImage.read()
# 16 bit texture RGB565
texList.append(NoeTexture("seadogsislandimage", dltImage.width, dltImage.height, \
dltImage.data, noesis.NOESISTEX_RGBA32))
return 1
class DLTHeader():
def __init__(self, width, height):
self.width = width
self.height = height
def toBytes(self):
result = bytearray()
imageSize = 174740
param = 0.9
result += (imageSize).to_bytes(4, byteorder='little')
result += self.width.to_bytes(4, byteorder='little')
result += self.height.to_bytes(4, byteorder='little')
result += (6).to_bytes(4, byteorder='little')
result += bytearray(noePack("f", param))
return result
def sdDLTWriteRGBA(data, imageWidth, imageHeight, filewriter):
header = DLTHeader(imageWidth, imageHeight)
filewriter.writeBytes(header.toBytes())
width = imageWidth
height = imageHeight
for i in range(6):
imageData = rapi.imageEncodeRaw(data, width, height, "b5g6r5")
filewriter.writeBytes(imageData)
width = int(width / 2)
height = int(height / 2)
return 1