def image(self): """Returns RGBA QImage with only the changed pixels non-transparent.""" assert self._labels, "don't call with FLAG_RECT" result = QtGui.QImage(self._rect.width(), self._rect.height(), QtGui.QImage.Format_ARGB32) if self.flag(Patch.FLAG_MONOCHROME): qimage2ndarray.rgb_view(result)[:] = self._color.getRgb()[:3] qimage2ndarray.alpha_view(result)[:] = self.subarray(self._alphaImage) * self.changed() else: qimage2ndarray.rgb_view(result)[:] = self.subarray(self._originalImage) qimage2ndarray.alpha_view(result)[:] = numpy.uint8(255) * self.changed() return result
def __setstate__(self, state): (x, y), patch, self._flags, self._occurrenceCount, color = state if self.flag(self.FLAG_RECT): self._pos = QtCore.QPointF(x, y) # (float pos) w, h = patch self._image = QtCore.QSizeF(w, h) else: self._pos = QtCore.QPoint(x, y) # (integer pos) h, w = patch.shape self._image = QtGui.QImage(w, h, QtGui.QImage.Format_ARGB32) if self.flag(self.FLAG_MONOCHROME): qimage2ndarray.raw_view(self._image)[:] = color qimage2ndarray.alpha_view(self._image)[:] = patch else: qimage2ndarray.raw_view(self._image)[:] = patch self._pixmap = None self._color = QtGui.QColor(color)
def ndarray(self): assert not self.flag(self.FLAG_RECT) if self.flag(self.FLAG_MONOCHROME): return qimage2ndarray.alpha_view(self._image) return qimage2ndarray.raw_view(self._image)