示例#1
0
	def doParse(self, inStream, length, parent):
		startPos = inStream.tell()
		c = self._data
		c['states'] = []
		animationObjects = self.tagInContext('TagDefineAnimationObjects')[0]['content']['objects']
		readU32(inStream) # read count. Unused here
		totalFrames = self.header()['frameCount']
		frameNumber = readU32(inStream)
		for i in range(0, totalFrames):
			frame = []
			currentStates = {}
			frameState = {}
			if (frameNumber - 1) == i:
				objectsCount = readU32(inStream)
				stateList = []
				for obj in range(0, objectsCount):
					state = self.extractState(inStream)
					stateList.append(state)
				for st in stateList:
					currentStates[st['objectIdRef']] = st
				if startPos + length > inStream.tell():
					frameNumber = readU32(inStream)
				c['states'].append(currentStates)

			#states[]
		self._data = c
示例#2
0
	def readHeader(self, inStream):
		footprint = readU32(inStream)
		valid = (footprint == 0x00474146) or (footprint == 0x00474143)
		compressed = (footprint == 0x00474143)


		majorVersion = readU8(inStream)
		minorVersion = readU8(inStream)
		#print("GAF v{0}.{1}".format(majorVersion, minorVersion))
		fileLength = readU32(inStream)

		if compressed:
			decompressed = zlib.decompress(inStream.read())
			_inStream = io.BytesIO(decompressed)
		else:
			_inStream = inStream

		h = {}
		h['valid'] = valid
		h['compressed'] = compressed
		h['majorVersion'] = majorVersion
		h['minorVersion'] = minorVersion

		self._context['header'] = h
		if(majorVersion < 4):
			self.readHeaderEndV3(_inStream)
		else:
			self.readHeaderEndV4(_inStream)

		return _inStream
示例#3
0
	def doParse(self, inStream, length, parent):
		count = readU32(inStream)
		self.data['parts'] = []

		for i in range(0, count):
			part = {}
			part['objectIdRef'] = readU32(inStream)
			part['name'] = readString(inStream)
			self.data['parts'].append(part)
示例#4
0
	def doParse(self, inStream, length, parent):
		c = self._data
		scale = readFloat(inStream)
		c['scale'] = scale
		atlasesCount = readU8(inStream)
		c['atlasesCount'] = atlasesCount
		atlases = []
		for i in range(0, atlasesCount):
			atlas = {}
			atlasId = readU32(inStream)
			atlas['atlasId'] = atlasId
			sources = readU8(inStream)
			atlas['atlasSourcesCount'] = sources
			atlas['atlasSources'] = []
			for i in range(0, sources):
				atlasSource = {}
				fileName = readString(inStream)
				atlasSource['fileName'] = fileName
				csf = readFloat(inStream)
				atlasSource['CSF'] = csf
				atlas['atlasSources'].append(atlasSource)
			atlases.append(atlas)
		c['atlases'] = atlases

		elements = []
		elementsCount = readU32(inStream)
		for i in range(0, elementsCount):
			element = {}
			element['pivot'] = readVec(inStream)
			element['origin'] = readVec(inStream)
			
			element['scale'] = readFloat(inStream)

			element['width'] = readFloat(inStream)
			element['height'] = readFloat(inStream)

			atlasIndex = readU32(inStream)
			if atlasIndex > 0:
				atlasIndex -= 1
			element['atlasIndex'] = atlasIndex

			elementAtlasIndex = readU32(inStream)
			element['elementAtlasIndex'] = elementAtlasIndex

			if self.version() >= 4:
				hasScale9Grid = readU8(inStream)
				element['hasScale9Grid'] = hasScale9Grid
				if hasScale9Grid:
					# scale9GridRect
					element['scale9Grid'] = readRect(inStream)

			elements.append(element)
		c['elements'] = elements
		self._data = c
示例#5
0
	def doParse(self, inStream, length, parent):
		masksCount = readU32(inStream)
		masks = []
		for i in range(0, masksCount):
			mask = {}
			mask['objectId'] = readU32(inStream)
			mask['elementAtlasIdRef'] = readU32(inStream)
			objectType = 0
			if self.version() >= 4:
				objectType = readU16(inStream)
			mask['objectType'] = objectType
			masks.append(mask)
		self._data['masks'] = masks
示例#6
0
	def doParse(self, inStream, length, parent):
		readU32(inStream)
		readU32(inStream)
		aabb = readRect(inStream)
		pivot = readVec(inStream)
		self.header()['pivot'] = pivot
		self.header()['frameSize'] = aabb
		hasLinkage = readU8(inStream)
		if hasLinkage:
			linkageName = readString(inStream)
		d = []
		lastTag = Tag(self)
		while type(lastTag) is not TagEnd:
			lastTag = readTag(inStream, d, self._context)
		self._data['tags'] = d
示例#7
0
	def doParse(self, inStream, length, parent):
		count = readU32(inStream)
		self.data['sequences'] = []
		for i in range (0, count):
			seq = {}
			seq['name'] = readString(inStream)
			seq['start'] = readU16(inStream)
			seq['end'] = readU16(inStream)
			self.data['sequences'].append(seq)
示例#8
0
	def doParse(self, inStream, length, parent):
		c = self._data
		count = readU32(inStream)
		c["objectsCount"] = count
		objects = []
		while count:
			obj = {}
			objectId = readU32(inStream)
			obj["id"] = objectId
			atlasIdRef = readU32(inStream)
			obj['atlasIdRef'] = atlasIdRef
			if self.version() >= 4:
				objType = readU16(inStream)
				obj['type'] = objType
			objects.append(obj)
			count -= 1
		c["objects"] = objects
		self._data = c
示例#9
0
	def readHeaderEndV4(self, inStream):
		h = self._context['header']

		scaleValuesCount = readU32(inStream)		
		h['scaleValuesCount'] = scaleValuesCount
		scaleValues = []
		#print("scaleValuesCount = {0}".format(scaleValuesCount))
		while scaleValuesCount != 0:
			scaleValues.append(readFloat(inStream))
			scaleValuesCount -= 1
		h['scaleValues'] = scaleValues

		CSFValuesCount = readU32(inStream)
		CSFValues = []
		#print("CSFValuesCount = {0}".format(CSFValuesCount))
		h['CSFValuesCount'] = CSFValuesCount
		while CSFValuesCount != 0:
			CSFValues.append(readFloat(inStream))
			CSFValuesCount -= 1
		h['CSFValues'] = CSFValues
		
		self._context['header'] = h
		
示例#10
0
	def doParse(self, inStream, length, parent):
		startPos = inStream.tell()
		c = self._data
		
		count = readU32(inStream)
		c["states"] = []

		
		frameNumber = readU32(inStream)

		for i in range(0, count):
			frameState = {}
			hasChangesInDisplayList = readU8(inStream)
			hasActions = readU8(inStream)
			frameState['hasChangesInDisplayList'] = hasChangesInDisplayList
			frameState['hasActions'] = hasActions

			if hasChangesInDisplayList:
				frameState['changesInDisplayList'] = []
				numObjects = readU32(inStream)
				for j in range(0, numObjects):
					frameState['changesInDisplayList'].append(self.extractState(inStream))


			if hasActions:
				frameState['actionParams'] = []
				frameState['actionType'] = readU32(inStream)
				paramsCount = readU32(inStream)
				for i in range(0, paramsCount):
					frameState['actionParams'].append(readString(inStream))

			c["states"].append(frameState)

			#print "expected end:{1} current: {1}".format(startPos + length, inStream.tell())
			if startPos + length > inStream.tell():
				frameNumber = readU32(inStream)

		self._data = c
示例#11
0
	def extractState2(self, inStream):
		state = {}
		hasColorTransform = readU8(inStream)
		hasMasks = readU8(inStream)
		hasEffect = readU8(inStream)
		state['objectIdRef'] = readU32(inStream)
		state['zIndex'] = readS32(inStream)
		state['colorOffsets'] = {}
		state['colorMults'] = {'a' :readFloat(inStream)}
		state['affineTransform'] = readAffineTransform(inStream)
		if hasColorTransform:
			state['colorOffsets']['a'] = readFloat(inStream)
			state['colorMults']['r'] = readFloat(inStream)
			state['colorOffsets']['r'] = readFloat(inStream)
			state['colorMults']['g'] = readFloat(inStream)
			state['colorOffsets']['g'] = readFloat(inStream)
			state['colorMults']['b'] = readFloat(inStream)
			state['colorOffsets']['b'] = readFloat(inStream)
		else:			
			state['colorOffsets']['a'] = 0
			state['colorMults']['r'] = 1
			state['colorOffsets']['r'] = 0
			state['colorMults']['g'] = 1
			state['colorOffsets']['g'] = 0
			state['colorMults']['b'] = 1
			state['colorOffsets']['b'] = 0

		if hasEffect:
			state['effects'] = []
			effects = readU8(inStream)
			for e in range(0, effects):
				filterType = readU32(inStream)
				filt = {'type' : 'none'}
				if filterType == self.GFT_Blur:
					filt['type'] = 'blur'
					filt['blurSize'] = readVec(inStream)					
				elif filt == self.GFT_Glow:
					filt['type'] = 'glow'
					filt['color'] = readColor(inStream)
					filt['blurSize'] = readVec(inStream)
					filt['strength'] = readFloat(inStream)
					filt['innerGlow'] = bool(readU8(inStream))
					filt['knockout'] = bool(readU8(inStream))
				elif filt == self.GFT_DropShadow:
					filt['type'] = 'dropShadow'
					filt['color'] = readColor(inStream)
					filt['angle'] = readFloat(inStream)
					filt['distance'] = readFloat(inStream)
					filt['strength'] = readFloat(inStream)
					filt['innerShadow'] = readFloat(inStream)
					filt['knockout'] = readFloat(inStream)
				elif filt == self.GFT_ColorMatrix:
					filt['type'] = 'colorMatrix'
					matrix = []
					for i in range(0, 4):
						for j in range(0, 4):
							matrix[j * 4 + i] = readFloat(inStream)
						matrix2[i] = readFloat(inStream) / 256


				state['effects'].append(filt)

		if hasMasks:
			state['maskObjectIdRef'] = readU32(inStream)
		return state
示例#12
0
	def parse(self, inStream, parent):
		length = readU32(inStream)
		#print("{1} length is {0}".format(length, self.type()))
		self.doParse(inStream, length, parent)