本文整理匯總了Python中Struct.Struct.uint16方法的典型用法代碼示例。如果您正苦於以下問題:Python Struct.uint16方法的具體用法?Python Struct.uint16怎麽用?Python Struct.uint16使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Struct.Struct
的用法示例。
在下文中一共展示了Struct.uint16方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MAT1
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def MAT1(self, data):
pos = 8
matCount = Struct.uint16(data[pos:pos+2], endian='>')
pos += 4
for i in xrange(matCount):
nameOff = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
name = data[nameOff:].split('\0', 1)[0]
wii.chexdump(data[nameOff:nameOff+0x60])
texid = Struct.uint16(data[nameOff + 0x40:nameOff + 0x42], endian='>')
wrap_s = Struct.uint8(data[nameOff + 0x42:nameOff + 0x43], endian='>')
wrap_t = Struct.uint8(data[nameOff + 0x43:nameOff + 0x44], endian='>')
texid2 = Struct.uint16(data[nameOff + 0x44:nameOff + 0x46], endian='>')
colorA = [Struct.uint16(data[nameOff + 0x1c + x:nameOff + 0x20 + x], endian='>')/255.0 for x in range(0,8,2)]
colorB = [Struct.uint16(data[nameOff + 0x22 + x:nameOff + 0x24 + x], endian='>')/255.0 for x in range(0,8,2)]
flags = Struct.uint32(data[nameOff + 0x3c:nameOff + 0x40], endian='>')
#numtex = 1 # Hardcoded for her pleasure #(flags>>8) & 0xf #guess
numtex = bit_extract(flags, 28, 31)
if numtex == 1:
img = self.Textures[texid]
tex = img[1].create_texture(Texture)
#print 'Material 0x%02x (%s) maps to texture %s' % (i, name, img[0])
elif numtex == 2:
img = self.Textures[texid]
alpha = self.Textures[texid2]
combo = self.ApplyMask(img[1],alpha[1])
tex = combo.create_texture(Texture)
#print 'Material 0x%02x (%s) maps to texture %s and mask %s' % (i, name, img[0], alpha[0])
else:
print "Bad num textures: %d"%numtex
self.Materials.append((name, tex, (colorA,colorB)))
示例2: Atom
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def Atom(self, name, fourcc, data):
#print '\t' + fourcc
count = Struct.uint16(data[0x10:0x12], endian='>')
# file('rlat/%s.%s' % (name, fourcc), 'wb').write(data[:0x18])
triplets = []
# Calculate offset to triplets (added by dasda).
off = Struct.uint16(data[4:6], endian='<') * 8 + 16;
for i in xrange(count):
af = Struct.float(data[off:off+4], endian='>')
bf = Struct.float(data[off+4:off+8], endian='>')
cf = Struct.float(data[off+8:off+0xC], endian='>')
triplets.append((af, bf, cf))
off += 0xC
if fourcc == 'RLPA':
self.brlyt.Objects[name].RLPA(triplets, self.Loop)
elif fourcc == 'RLVC':
self.brlyt.Objects[name].RLVC(triplets, self.Loop)
elif fourcc == 'RLTS':
self.brlyt.Objects[name].RLTS(triplets, self.Loop)
elif fourcc == 'RLMC':
self.brlyt.Objects[name].RLMC(triplets, self.Loop)
else:
for trip in triplets:
print '\t\tTriplet: %f %f %f' % trip
示例3: Unpack
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def Unpack(self, data, outfile=None, debug=False):
if outfile != None:
file = open(outfile, 'wb')
pos = 0
version = Struct.uint16(data[pos:pos+2], endian='>')
pos += 2
if debug == True:
print "Version: %04x" % version
print
self.string_list = []
while pos < len(data):
string = nullterm(data[pos:])
string = unicode(string, 'utf_16_be')
if debug == True:
print "String: %s" % string
pos += len(string) * 2 + 2
self.string_list.append(string)
file.write(string.encode('utf-8'))
file.write('\n')
if pos < len(data):
file.write('\n')
file.close()
示例4: TXL1
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def TXL1(self, data):
pos = 8
texCount = Struct.uint16(data[pos:pos+2], endian='>')
pos += 4
for i in xrange(texCount):
fnOff = Struct.uint32(data[pos:pos+4], endian='>')
pos += 8
fn = data[fnOff+0xC:].split('\0', 1)[0]
tex = TPL(self.Archive.Files['./arc/timg/' + fn]).Textures[0]
self.Textures.append((fn, tex))
示例5: PIC1
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def PIC1(self, data):
wii.chexdump(data)
name = data[0xC:].split('\0', 1)[0]
mat = Struct.uint16(data[0x5C:0x5E], endian='>')
mat = self.Materials[mat]
xs = Struct.float(data[0x44:0x48], endian='>')
ys = Struct.float(data[0x48:0x4C], endian='>')
x = Struct.float(data[0x24:0x28], endian='>')
y = Struct.float(data[0x28:0x2C], endian='>')
#print 'Picture %s maps to material %s' % (name, mat[0])
#print '\t%fx%f (%f, %f)' % (xs, ys, x, y)
p=Picture(name, mat, [x, y, xs, ys])
self.PanePath[-1].Add(p)
self.Objects[name] = p
示例6: GRP1
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def GRP1(self, data):
wii.chexdump(data)
if len(data) < 0x1c:
pass
lang = data[0x8:0x18].split('\0', 1)[0]
nitems = Struct.uint16(data[0x18:0x1a], endian='>')
p = 0x1c
items = []
for i in xrange(nitems):
items.append(data[p:].split('\0', 1)[0])
p += 0x10
for i in items:
if lang != self.Language:
self.Objects[i].Enabled = False
else:
self.Objects[i].Enabled = True
示例7: RGB5A3
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
a = (texel) & 0xff
r = (texel2) & 0xff
out[m + (l * x)] |= ((r << 0) | (a << 24))
else: # GBGBGBGB
g = (texel) & 0xff
b = (texel2) & 0xff
out[m + (l * x)] |= ((g << 8) | (b << 16))
return ''.join(Struct.uint32(p) for p in out)
def RGB5A3(self, (w, h), jar):
out = [0 for i in xrange(w * h)]
i = 0
for y in xrange(0, h, 4):
for x in xrange(0, w, 4):
for y1 in xrange(y, y + 4):
for x1 in xrange(x, x + 4):
pixel = Struct.uint16(jar[i * 2:i * 2 + 2], endian='>')
i += 1
if(y1 >= h or x1 >= w):
continue
if(pixel & (1 << 15)): #RGB555
b = (((pixel >> 10) & 0x1F) * 255) / 31
g = (((pixel >> 5) & 0x1F) * 255) / 31
r = (((pixel >> 0) & 0x1F) * 255) / 31
a = 255
else: #RGB4A3
a = (((pixel >> 12) & 0x07) * 255) / 7
b = (((pixel >> 8) & 0x0F) * 255) / 15
g = (((pixel >> 4) & 0x0F) * 255) / 15
r = (((pixel >> 0) & 0x0F) * 255)/ 15
示例8: IA8
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
out[outp + ofs + sub + 1] = (low << 4) | (low << 20) | (low << 12) | 0xFF<<24
inp += 1
ofs += x
inp += (8 - off) / 2
outp += off
outp += x * 7
return ''.join(Struct.uint32(p) for p in out)
def IA8(self, data, (y, x)):
out = [0 for i in xrange(x * y)]
inp = 0
for i in xrange(0, y, 4):
for j in xrange(0, x, 4):
for k in xrange(i, i + 4, 1):
for l in xrange(j, j + 4, 1):
texel = Struct.uint16(data[inp*2:inp*2+2], endian='>')
inp += 1
if (l>=x) or (k>=y):
continue
b = texel >> 8
g = texel >> 8
r = texel >> 8
a = texel & 0xff
out[l + (k * x)] = (r << 0) | (g << 8) | (b << 16) | (a << 24)
return ''.join(Struct.uint32(p) for p in out)
def I8(self, data, (y, x)):
out = [0 for i in xrange(x * y)]
outp = 0
inp = 0
for i in xrange(0, y, 4):
示例9: RGB5A3
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
outp += off
outp += x * 3
return "".join(Struct.uint32(p) for p in out)
def RGB5A3(self, data, (y, x)):
out = [0 for i in xrange(x * y)]
outp = 0
inp = 0
for i in xrange(0, y, 4):
for j in xrange(0, x, 4):
ofs = 0
for k in xrange(4):
off = min(x - j, 4)
for sub in xrange(off):
texel = Struct.uint16(data[inp : inp + 2], endian=">")
if texel & 0x8000:
p = ((texel >> 10) & 0x1F) << 3
p |= ((texel >> 5) & 0x1F) << 11
p |= (texel & 0x1F) << 19
p |= 0xFF << 24
else:
p = ((texel >> 12) & 0x07) << 29
p |= ((texel >> 8) & 0x0F) << 4
p |= ((texel >> 4) & 0x0F) << 12
p |= (texel & 0x0F) << 20
out[outp + ofs + sub] = p
inp += 2
ofs += x
inp += (4 - off) * 2
示例10: Unpack
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def Unpack(self, data):
pos = 0
header = self.BREFT_Header()
header.unpack(data[pos:pos+len(header)])
pos += len(header)
print header
assert header.magic == "REFT"
assert header.version == 0xfeff0004
reft = self.BREFT_REFT()
reft.unpack(data[pos:pos+len(reft)])
pos += len(reft)
print reft
assert reft.magic == "REFT"
print "\n%08x\n" % pos
reft_project = self.BREFT_REFT_Project()
reft_project.unpack(data[pos:pos+len(reft_project)])
pos += len(reft_project)
print reft_project
string = nullterm(data[pos:pos+reft_project.str_length])
pos += reft_project.str_length
print "String: %s\n" % string
while pos %2:
unknown = Struct.uint8(data[pos:pos+1])
pos += 1
print "Padding: %02x" % unknown
print "\n%08x\n" % pos
for x in xrange(0x30):
pad = Struct.uint8(data[pos:pos+1])
pos += 1
#print "Padding: %08x" % pad
print "\n%08x\n" % pos
temp = pos
reft_string_header = self.BREFT_REFT_StringHeader()
reft_string_header.unpack(data[pos:pos+len(reft_string_header)])
pos += len(reft_string_header)
print reft_string_header
print "\n%08x\n" % pos
string_groups = []
for x in xrange(reft_string_header.string_cnt):
str_length = Struct.uint16(data[pos:pos+2], endian='>')
pos += 2
print "String Length with null added: %04x" % str_length
string = nullterm(data[pos:pos+str_length])
pos += str_length
print "String: %s" % string
string_section1 = self.BREFT_REFT_StringSection1()
string_section1.unpack(data[pos:pos+len(string_section1)])
pos += len(string_section1)
print string_section1
string_groups.append(string_section1)
for x in xrange(reft_string_header.string_cnt):
pos = temp + string_groups[x].offset
print "\n%08x\n" % pos
reft_section2 = self.BREFT_REFT_Section2()
reft_section2.unpack(data[pos:pos+len(reft_section2)])
pos += len(reft_section2)
print reft_section2
print "\n%08x\n" % pos
#''' BEGIN TEST DATA
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
#.........這裏部分代碼省略.........
示例11: Unpack
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def Unpack(self, data):
pos = 0
header = self.BREFF_Header()
header.unpack(data[pos:pos+len(header)])
pos += len(header)
print header
assert header.magic == "REFF"
assert header.version == 0xfeff0004
reff = self.BREFF_REFF()
reff.unpack(data[pos:pos+len(reff)])
pos += len(reff)
print reff
assert reff.magic == "REFF"
reff_project = self.BREFF_REFF_Project()
reff_project.unpack(data[pos:pos+len(reff_project)])
pos += len(reft_project)
print reff_project
string = nullterm(data[pos:pos+reff_project.str_length])
pos += reff_project.str_length
print "String: %s\n" % string
while pos %2:
unknown = Struct.uint8(data[pos:pos+1])
pos += 1
print "Padding: %02x" % unknown
print "\n%08x\n" % pos
temp = pos
reff_string_header = self.BREFF_REFF_StringHeader()
reff_string_header.unpack(data[pos:pos+len(reff_string_header)])
pos += len(reff_string_header)
print reff_string_header
print "\n%08x\n" % pos
string_groups = []
for x in xrange(reff_string_header.string_cnt):
str_length = Struct.uint16(data[pos:pos+2], endian='>')
pos += 2
print "String Length with null added: %04x" % str_length
string = nullterm(data[pos:pos+str_length])
pos += str_length
print "String: %s" % string
string_section1 = self.BREFF_REFF_StringSection1()
string_section1.unpack(data[pos:pos+len(string_section1)])
pos += len(string_section1)
print string_section1
string_groups.append(string_section1)
print "\n%08x\n" % pos
while pos % 0x04:
padding = Struct.uint8(data[pos:pos+1])
pos += 1
print "Padding: %02x" % padding
print "\n%08x\n" % pos
assert pos == string_groups[0].offset + temp
for x in xrange(reff_string_header.string_cnt):
pos = temp + string_groups[x].offset
reff_section2 = self.BREFF_REFF_Section2()
reff_section2.unpack(data[pos:pos+len(reff_section2)])
pos += len(reff_section2)
print reff_section2
print "\n%08x\n" % pos
''' LARGE TEST DATA
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown01: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown02: %08x" % unknown
unknown = Struct.float(data[pos:pos+4], endian='>')
pos += 4
print "Unknown03: %f" % unknown
unknown = Struct.float(data[pos:pos+4], endian='>')
pos += 4
print "Unknown04: %f" % unknown
unknown = Struct.float(data[pos:pos+4], endian='>')
pos += 4
print "Unknown05: %f" % unknown
unknown = Struct.float(data[pos:pos+4], endian='>')
pos += 4
print "Unknown06: %f" % unknown
unknown = Struct.float(data[pos:pos+4], endian='>')
pos += 4
print "Unknown07: %f" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown08: %08x" % unknown
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
print "Unknown09: %08x" % unknown
unknown = Struct.float(data[pos:pos+4], endian='>')
pos += 4
print "Size Outer Radius X: %f" % unknown
#.........這裏部分代碼省略.........
示例12: Unpack
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint16 [as 別名]
def Unpack(self, data, out_file, debug):
file = open(out_file, 'wb')
if file:
pos = 0
header = self.BMG_Header()
header.unpack(data[pos:pos+len(header)])
pos += len(header)
if debug == True:
print header
print "\n%08x\n" % pos
info = self.BMG_INF1()
info.unpack(data[pos:pos+len(info)])
pos += len(info)
if debug == True:
print info
unknown = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
if debug == True:
print "Unknown: %08x" % unknown
print "\n%08x\n" % pos
offset_list = []
for x in xrange(info.count):
offset = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
if debug == True:
print "Offset: %08x" % offset
offset_list.append(offset)
while pos % 0x10:
padding = Struct.uint32(data[pos:pos+4], endian='>')
pos += 4
if debug == True:
print "Padding: %08x" % padding
if debug == True:
print "\n%08x\n" % pos
dat1 = self.BMG_DAT1()
dat1.unpack(data[pos:pos+len(dat1)])
pos += len(dat1)
if debug == True:
print dat1
if debug == True:
print "\n%08x\n" % pos
temp = pos
unknown = Struct.uint16(data[pos:pos+2], endian='>')
pos += 2
if debug == True:
print "Unknown: %04x" % unknown
for x in xrange(info.count):
pos = temp + offset_list[x]
string = nullterm(data[pos:])
string = unicode(string, 'utf_16_be')
file.write(string.encode('utf-8'))
file.write('\r')
file.write('\n')
if debug == True:
print "String: %s" % string.encode('utf-8')
file.close()
else:
print "Could not open file for writing"
sys.exit(1)