Esempio n. 1
0
 def _column1():
     if role == Qt.DecorationRole:
         continuous_palette = ContinuousPaletteGenerator(*var.colors)
         line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256))
         data = np.arange(0, 256, dtype=np.int8).reshape(
             (1, 256)).repeat(16, 0)
         img = QImage(data, 256, 16, QImage.Format_Indexed8)
         img.setColorCount(256)
         img.setColorTable([qRgb(*x) for x in line])
         img.data = data
         return img
     if role == Qt.ToolTipRole:
         return "{} - {}".format(self._encode_color(var.colors[0]),
                                 self._encode_color(var.colors[1]))
     if role == ColorRole:
         return var.colors
Esempio n. 2
0
 def _column1():
     if role == Qt.DecorationRole:
         continuous_palette = ContinuousPaletteGenerator(*var.colors)
         line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256))
         data = np.arange(0, 256, dtype=np.int8). \
             reshape((1, 256)). \
             repeat(16, 0)
         img = QImage(data, 256, 16, QImage.Format_Indexed8)
         img.setColorCount(256)
         img.setColorTable([qRgb(*x) for x in line])
         img.data = data
         return img
     if role == Qt.ToolTipRole:
         return "{} - {}".format(self._encode_color(var.colors[0]),
                                 self._encode_color(var.colors[1]))
     if role == ColorRole:
         return var.colors
Esempio n. 3
0
 def _column1():
     if role == Qt.DecorationRole:
         continuous_palette = \
             ContinuousPaletteGenerator(*desc.get_colors())
         line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256))
         data = np.arange(0, 256, dtype=np.int8). \
             reshape((1, 256)). \
             repeat(16, 0)
         img = QImage(data, 256, 16, QImage.Format_Indexed8)
         img.setColorCount(256)
         img.setColorTable([qRgb(*x) for x in line])
         img.data = data
         return img
     if role == Qt.ToolTipRole:
         colors = desc.get_colors()
         return f"{self._encode_color(colors[0])} " \
                f"- {self._encode_color(colors[1])}"
     if role == ColorRole:
         return desc.get_colors()
     return None
Esempio n. 4
0
def qimage_indexed_from_array(arr: np.ndarray,
                              colortable: Sequence[Sequence[int]]) -> QImage:
    arr = np.asarray(arr, dtype=np.uint8)
    h, w = arr.shape
    colortable = np.asarray(colortable, dtype=np.uint8)
    ncolors, nchannels = colortable.shape
    img = QImage(w, h, QImage.Format_Indexed8)
    img.setColorCount(ncolors)
    if nchannels == 4:
        qrgb_ = qrgba
    elif nchannels == 3:
        qrgb_ = qrgb
    else:
        raise ValueError

    for i, c in enumerate(colortable):
        img.setColor(i, qrgb_(*c))

    buffer = img.bits().asarray(w * h)
    view = np.frombuffer(buffer, np.uint8).reshape((h, w))
    view[:, :] = arr
    return img