def _propertiesDecode_(self,io: IO) -> int: """ decode a list of properties """ while True: try: propertyType=io.u32 dataLength=io.u32 except struct.error: # end of data, so that's that. break if propertyType==0: break self._propertyDecode_(propertyType,io.getBytes(dataLength)) return io.index
def _decode_(self, data: bytes, index: int = 0): """ decode a byte buffer :param data: data buffer to decode :param index: index within the buffer to start at """ io = IO(data, index) if io.getBytes(9) != "gimp xcf ".encode('ascii'): raise Exception('Not a valid GIMP file') version = io.cString if version == 'file': self.version = 0 else: self.version = int(version[1:]) self.width = io.u32 self.height = io.u32 self.baseColorMode = io.u32 self.precision = Precision() self.precision.decode(self.version, io) self._propertiesDecode_(io) self._layerPtr = [] self._layers = [] while True: ptr = self._pointerDecode_(io) if ptr == 0: break self._layerPtr.append(ptr) l = GimpLayer(self) l._decode_(io.data, ptr) self._layers.append(l) self._channelPtr = [] self.channels = [] while True: ptr = self._pointerDecode_(io) if ptr == 0: break self._channelPtr.append(ptr) c = GimpChannel(self) c.fromBytes(io.data, ptr) self.channels.append(c) return io.index