Esempio n. 1
0
	def encode(self):
		"""Encode to binary data."""
		ioBuf = IO(boolSize=32)
		ioBuf.u32 = self.pointType
		ioBuf.float32 = self.x
		ioBuf.float32 = self.y
		if self.pressure is not None:
			ioBuf.float32 = self.pressure
			if self.xTilt is not None:
				ioBuf.float32 = self.xTilt
				if self.yTilt is not None:
					ioBuf.float32 = self.yTilt
					if self.wheel is not None:
						ioBuf.float32 = self.wheel
		return ioBuf.data
Esempio n. 2
0
	def encode(self):
		"""Convert this object to raw bytes."""
		ioBuf = IO()
		ioBuf.float32 = self.factor
		ioBuf.u32 = self.numDigits
		ioBuf.sz754 = self.id
		ioBuf.sz754 = self.symbol
		ioBuf.sz754 = self.abbrev
		ioBuf.sz754 = self.sname
		ioBuf.sz754 = self.pname
		return ioBuf.data
Esempio n. 3
0
	def _propertyEncode(self, propertyType):
		"""Encode a single property.

		Many properties are in the form
		propertyType: one of PROP_
		lengthOfData: 4
		data: varies but is often ioBuf.32 or ioBuf.boolean

		If the property is the same as the default, or not specified, returns empty array
		"""
		ioBuf = IO(boolSize=32)
		if propertyType == self.PROP_COLORMAP:
			if self.colorMap is not None and self.colorMap:
				ioBuf.u32 = self.PROP_COLORMAP
				# ioBuf.addBytes(self._colormapEncode_())
		elif propertyType == self.PROP_ACTIVE_LAYER:
			if self.selected is not None and self.selected:
				ioBuf.u32 = self.PROP_ACTIVE_LAYER
		elif propertyType == self.PROP_ACTIVE_CHANNEL:
			if self.selected is not None and self.selected:
				ioBuf.u32 = self.PROP_ACTIVE_LAYER
		elif propertyType == self.PROP_SELECTION:
			if self.isSelection is not None and self.isSelection:
				ioBuf.u32 = self.PROP_SELECTION
		elif propertyType == self.PROP_FLOATING_SELECTION:
			if self.selectionAttachedTo is not None:
				ioBuf.u32 = self.PROP_FLOATING_SELECTION
				ioBuf.u32 = self.selectionAttachedTo
		elif propertyType == self.PROP_OPACITY:
			if self.opacity is not None and not isinstance(self.opacity, float):
				ioBuf.u32 = self.PROP_OPACITY
				ioBuf.u32 = self.opacity
		elif propertyType == self.PROP_MODE:
			if self.blendMode is not None:
				ioBuf.u32 = self.PROP_MODE
				ioBuf.u32 = self.blendMode
		elif propertyType == self.PROP_VISIBLE:
			if self.visible is not None:
				ioBuf.u32 = self.PROP_VISIBLE
				ioBuf.boolean = self.visible
		elif propertyType == self.PROP_LINKED:
			if self.isLinked is not None and self.isLinked:
				ioBuf.u32 = self.PROP_LINKED
				ioBuf.boolean = self.isLinked
		elif propertyType == self.PROP_LOCK_ALPHA:
			if self.lockAlpha is not None and self.lockAlpha:
				ioBuf.u32 = self.PROP_LOCK_ALPHA
				ioBuf.boolean = self.lockAlpha
		elif propertyType == self.PROP_APPLY_MASK:
			if self.applyMask is not None:
				ioBuf.u32 = self.PROP_APPLY_MASK
				ioBuf.boolean = self.applyMask
		elif propertyType == self.PROP_EDIT_MASK:
			if self.editingMask is not None and self.editingMask:
				ioBuf.u32 = self.PROP_EDIT_MASK
				ioBuf.boolean = self.editingMask
		elif propertyType == self.PROP_SHOW_MASK:
			if self.showMask is not None and self.showMask:
				ioBuf.u32 = self.PROP_SHOW_MASK
				ioBuf.boolean = self.showMask
		elif propertyType == self.PROP_SHOW_MASKED:
			if self.showMasked is not None:
				ioBuf.u32 = self.PROP_SHOW_MASKED
				ioBuf.boolean = self.showMasked
		elif propertyType == self.PROP_OFFSETS:
			if self.xOffset is not None and self.yOffset is not None:
				ioBuf.u32 = self.PROP_OFFSETS
				ioBuf.i32 = self.xOffset
				ioBuf.i32 = self.yOffset
		elif propertyType == self.PROP_COLOR:
			if (
				self.color is not None
				and not isinstance(self.color[0], float)
				and not isinstance(self.color[1], float)
				and not isinstance(self.color[2], float)
			):
				ioBuf.u32 = self.PROP_COLOR
				ioBuf.byte = self.color[0]
				ioBuf.byte = self.color[1]
				ioBuf.byte = self.color[2]
		elif propertyType == self.PROP_COMPRESSION:
			if self.compression is not None:
				ioBuf.u32 = self.PROP_COMPRESSION
				ioBuf.u32 = self.compression
		elif propertyType == self.PROP_GUIDES:
			if self.guidelines is not None and self.guidelines:
				pass
				# ioBuf.u32 = self.PROP_GUIDES
				# ioBuf.addBytes(self._guidelinesEncode_())
		elif propertyType == self.PROP_RESOLUTION:
			if self.horizontalResolution is not None and self.verticalResolution is not None:
				ioBuf.u32 = self.PROP_RESOLUTION
				ioBuf.u32 = int(self.horizontalResolution)
				ioBuf.i32 = int(self.verticalResolution)
		elif propertyType == self.PROP_TATTOO:
			if self.uniqueId is not None:
				ioBuf.u32 = int(self.uniqueId, 16)
		elif propertyType == self.PROP_PARASITES:
			if self.parasites is not None and self.parasites:
				ioBuf.u32 = self.PROP_PARASITES
				ioBuf.addBytes(self._parasitesEncode())
		elif propertyType == self.PROP_UNIT:
			if self.units is not None:
				ioBuf.u32 = self.PROP_UNIT
				ioBuf.u32 = self.units
		elif propertyType == self.PROP_PATHS:
			if self.paths is not None and self.paths:
				# ioBuf.u32 = self.PROP_PATHS
				# ioBuf.u32 = len(self.paths)
				"""
				for path in self.paths:
					ioBuf.append(self._pathEncode_(path))
				"""
		elif propertyType == self.PROP_USER_UNIT:
			if self.userUnits is not None:
				pass
				# ioBuf.u32 = self.PROP_USER_UNIT
				# ioBuf.addBytes(self._userUnitsEncode_())
		elif propertyType == self.PROP_VECTORS:
			if self.vectors is not None and self.vectors:
				pass
				# ioBuf.u32 = self.PROP_VECTORS
				# ioBuf.addBytes(self._vectorsEncode_())
		elif propertyType == self.PROP_TEXT_LAYER_FLAGS:
			if self.textLayerFlags is not None:
				ioBuf.u32 = self.PROP_TEXT_LAYER_FLAGS
				ioBuf.u32 = self.textLayerFlags
		elif propertyType == self.PROP_OLD_SAMPLE_POINTS:
			pass
		elif propertyType == self.PROP_LOCK_CONTENT:
			if self.locked is not None and self.locked:
				ioBuf.u32 = self.PROP_LOCK_CONTENT
				ioBuf.boolean = self.locked
		elif propertyType == self.PROP_GROUP_ITEM:
			if self.isGroup is not None and self.isGroup:
				ioBuf.u32 = self.PROP_GROUP_ITEM
		elif propertyType == self.PROP_ITEM_PATH:
			if self.itemPath is not None:
				pass
				# ioBuf.u32 = self.PROP_ITEM_PATH
				# ioBuf.addBytes(self._itemPathEncode_())
		elif propertyType == self.PROP_GROUP_ITEM_FLAGS:
			if self.groupItemFlags is not None:
				ioBuf.u32 = self.PROP_GROUP_ITEM_FLAGS
				ioBuf.u32 = self.groupItemFlags
		elif propertyType == self.PROP_LOCK_POSITION:
			if self.positionLocked is not None and self.positionLocked:
				ioBuf.u32 = self.PROP_LOCK_POSITION
				ioBuf.boolean = self.positionLocked
		elif propertyType == self.PROP_FLOAT_OPACITY:
			if self.opacity is not None and isinstance(self.opacity, float):
				ioBuf.u32 = self.PROP_FLOAT_OPACITY
				ioBuf.float32 = self.opacity
		elif propertyType == self.PROP_COLOR_TAG:
			if self.colorTag is not None:
				ioBuf.u32 = self.PROP_COLOR_TAG
				ioBuf.u32 = self.colorTag
		elif propertyType == self.PROP_COMPOSITE_MODE:
			if self.compositeMode is not None:
				ioBuf.u32 = self.PROP_COMPOSITE_MODE
				ioBuf.i32 = self.compositeMode
		elif propertyType == self.PROP_COMPOSITE_SPACE:
			if self.compositeSpace is not None:
				ioBuf.u32 = self.PROP_COMPOSITE_SPACE
				ioBuf.i32 = self.compositeSpace
		elif propertyType == self.PROP_BLEND_SPACE:
			if self.blendSpace is not None:
				ioBuf.u32 = self.PROP_BLEND_SPACE
				ioBuf.u32 = self.blendSpace
		elif propertyType == self.PROP_FLOAT_COLOR:
			if (
				self.color is not None
				and isinstance(self.color[0], float)
				and isinstance(self.color[1], float)
				and isinstance(self.color[2], float)
			):
				ioBuf.u32 = self.PROP_FLOAT_COLOR
				ioBuf.float32 = self.color[0]
				ioBuf.float32 = self.color[1]
				ioBuf.float32 = self.color[2]
		elif propertyType == self.PROP_SAMPLE_POINTS:
			if self.samplePoints is not None and self.samplePoints:
				pass
				# ioBuf.u32 = self.PROP_SAMPLE_POINTS
				# self.addBytes(self._samplePointsEncode_())
		else:
			raise RuntimeError(f"Unknown property id {propertyType}")
		return ioBuf.data