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
def encode(self): """Encode to byte array. Steps: Create a new IO buffer (array of binary values) Set attributes as outlined in the spec List of properties Set the image hierarchy and mask pointers Return the data """ # Create a new IO buffer (array of binary values) dataAreaIO = IO() ioBuf = IO() # Set attributes as outlined in the spec ioBuf.u32 = self.width ioBuf.u32 = self.height ioBuf.u32 = self.colorMode ioBuf.sz754 = self.name # Layer properties ioBuf.addBytes(self._propertiesEncode()) # Pointer to the image heirachy structure dataAreaIndex = ioBuf.index + self.pointerSize * 2 ioBuf.addBytes(self._pointerEncode(dataAreaIndex)) dataAreaIO.addBytes(self.imageHierarchy.encode()) # ioBuf.addBytes(self._pointerEncode_(dataAreaIndex)) # Pointer to the layer mask if self.mask is not None: dataAreaIO.addBytes(self.mask.encode()) ioBuf.addBytes(self._pointerEncode(dataAreaIndex + dataAreaIO.index)) ioBuf.addBytes(dataAreaIO) # Return the data return ioBuf.data
def encode(self) -> bytearray: """Encode this object to a byte buffer.""" ioBuf = IO() ioBuf.u32 = self.width ioBuf.u32 = self.height ioBuf.sz754 = self.name ioBuf.addBytes(self._propertiesEncode()) imgH = self._imageHierarchyPtr if imgH is None: imgH = 0 ioBuf.addBytes(self._pointerEncode(imgH)) return ioBuf.data
def encode(self): """Encode a byte buffer :param data: data buffer to encode :param index: index within the buffer to start at """ ioBuf = IO() ioBuf.sz754 = self.name ioBuf.u32 = self.flags ioBuf.u32 = len(self.data) ioBuf.addBytes(self.data) return ioBuf.data
def encode(self): """Encode to binary data.""" ioBuf = IO(boolSize=32) ioBuf.sz754 = self.name ioBuf.u32 = self.uniqueId ioBuf.boolean = self.visible ioBuf.boolean = self.linked ioBuf.u32 = len(self.parasites) ioBuf.u32 = len(self.strokes) for parasite in self.parasites: ioBuf.addBytes(parasite.encode()) for gimpstroke in self.strokes: ioBuf.addBytes(gimpstroke.encode()) return ioBuf.data