當前位置: 首頁>>代碼示例>>Python>>正文


Python Struct.uint8方法代碼示例

本文整理匯總了Python中Struct.Struct.uint8方法的典型用法代碼示例。如果您正苦於以下問題:Python Struct.uint8方法的具體用法?Python Struct.uint8怎麽用?Python Struct.uint8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Struct.Struct的用法示例。


在下文中一共展示了Struct.uint8方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: MAT1

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint8 [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)))
開發者ID:HACKERCHANNEL,項目名稱:benzin,代碼行數:37,代碼來源:Alameda.py

示例2: imp

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint8 [as 別名]
		img = wx.Image("tmp.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
		w = img.GetWidth()
		h = img.GetHeight()
		dialog = imp("TPL (" + str(w) + ", " + str(h) + ")", img)
		dialog.ShowModal()
		dialog.Destroy()
		os.unlink("tmp.png")
	def RGBA8(self, (x, y), data):
		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(2):
					for l in xrange(i, i + 4, 1):
						for m in xrange(j, j + 4, 1):
							texel = Struct.uint8(data[inp:inp + 1], endian = '>')
							inp += 1
							texel2 = Struct.uint8(data[inp:inp + 1], endian = '>')
							inp += 1
							if (m >= x) or (l >= y):
								continue
							if k == 0: # ARARARAR
								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):
開發者ID:delguoqing,項目名稱:LMDumper,代碼行數:33,代碼來源:image.py

示例3: Unpack

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint8 [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
#.........這裏部分代碼省略.........
開發者ID:HACKERCHANNEL,項目名稱:Wii.py,代碼行數:103,代碼來源:breft.py

示例4: Unpack

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint8 [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
#.........這裏部分代碼省略.........
開發者ID:HACKERCHANNEL,項目名稱:Wii.py,代碼行數:103,代碼來源:breff.py


注:本文中的Struct.Struct.uint8方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。