Exemplo n.º 1
0
 def __init__(self, path = None, width = 0, height = 0, bitsPerPixel = 32, components = None, data = None):
     if path is not None:
         if isinstance(path, Image):
             # Create a copy of the image.
             self._data = path.data.copy()
         elif isinstance(path, image_qt.QtGui.QPixmap):
             qimg = path.toImage()
             self._data = image_qt.load(qimg)
         else:   # Path string / QImage.
             self._data = image_qt.load(path)
     elif data is not None:
         if isinstance(data, Image):
             # Share data between images.
             self._data = data.data
         elif isinstance(data, str):
             self._data = image_qt.load(data)
         else:   # Data array.
             self._data = data
     else:
         if components is None:
             if bitsPerPixel == 32:
                 components = 4
             elif bitsPerPixel == 24:
                 components = 3
             else:
                 raise NotImplementedError("bitsPerPixel must be 24 or 32")
         self._data = np.empty((height, width, components), dtype=np.uint8)
     self._data = np.ascontiguousarray(self._data)
Exemplo n.º 2
0
    def __init__(self,
                 path=None,
                 width=0,
                 height=0,
                 bitsPerPixel=32,
                 components=None,
                 data=None):
        if path is not None:
            self._is_empty = False
            if isinstance(path, Image):
                # Create a copy of the image.
                self._data = path.data.copy()
            elif isinstance(path, image_qt.QtGui.QPixmap):
                qimg = path.toImage()
                self._data = image_qt.load(qimg)
            else:  # Path string / QImage.
                self._data = image_qt.load(path)
                self.sourcePath = path
        elif data is not None:
            self._is_empty = False
            if isinstance(data, Image):
                # Share data between images.
                self._data = data.data
            elif isinstance(data, basestring):
                self._data = image_qt.load(data)
            else:  # Data array.
                self._data = data
        else:
            self._is_empty = True
            if components is None:
                if bitsPerPixel == 32:
                    components = 4
                elif bitsPerPixel == 24:
                    components = 3
                else:
                    raise NotImplementedError("bitsPerPixel must be 24 or 32")
            self._data = np.empty((height, width, components), dtype=np.uint8)
        self._data = np.ascontiguousarray(self._data)

        self.modified = time.time()
Exemplo n.º 3
0
 def __init__(self, path=None, width=0, height=0, bitsPerPixel=32, components=None, data=None):
     if path is not None:
         self._data = image_qt.load(path)
     elif data is not None:
         self._data = data
     else:
         if components is None:
             if bitsPerPixel == 32:
                 components = 4
             elif bitsPerPixel == 24:
                 components = 3
             else:
                 raise NotImplementedError("bitsPerPixel must be 24 or 32")
         self._data = np.empty((height, width, components), dtype=np.uint8)
     self._data = np.ascontiguousarray(self._data)
Exemplo n.º 4
0
 def __init__(self, path = None, width = 0, height = 0, bitsPerPixel = 32, components = None, data = None):
     if path is not None:
         self._data = image_qt.load(path)
     elif data is not None:
         self._data = data
     else:
         if components is None:
             if bitsPerPixel == 32:
                 components = 4
             elif bitsPerPixel == 24:
                 components = 3
             else:
                 raise NotImplementedError("bitsPerPixel must be 24 or 32")
         self._data = np.empty((height, width, components), dtype=np.uint8)
     self._data = np.ascontiguousarray(self._data)
Exemplo n.º 5
0
    def __init__(self, path=None,
            width=0, height=0, bitsPerPixel=32,
            components=None, data=None):
        """Image constructor.

        The Image can be constructed by an existing Image, a QPixmap, a
        QImage, loaded from a file path, or created empty.

        To construct the Image by copying the data from the source,
        pass the source as the first argument of the constructor.
        ``dest = Image(source)``

        To create the Image by sharing the data of another Image, pass
        the source Image as the data argument.
        ``dest = Image(data=sharedsource)``

        The data argument can be a numpy array of 3 dimensions (w, h, c) which
        will be used directly as the image's data, where w is the width, h is
        the height, and c is the number of channels.
        The data argument can also be a path to load.

        To create an empty Image, leave path=None, and specify the width and
        height. You can then optionally adjust the new Image's channels by
        setting bitsPerPixel = 8, 16, 24, 32, or components = 1, 2, 3, 4,
        which are equivalent to W (Grayscale), WA (Grayscale with Alpha),
        RGB, and RGBA respectively.
        """
        import image_qt as image_lib

        if path is not None:
            self._is_empty = False
            if isinstance(path, Image):
                # Create a copy of the image.
                self._data = path.data.copy()
            elif _isQPixmap(path):
                qimg = path.toImage()
                self._data = image_lib.load(qimg)
            else:   # Path string / QImage.
                self._data = image_lib.load(path)
                self.sourcePath = path
        elif data is not None:
            self._is_empty = False
            if isinstance(data, Image):
                # Share data between images.
                self._data = data.data
            elif isinstance(data, str):
                self._data = image_lib.load(data)
            else:   # Data array.
                self._data = data
        else:
            self._is_empty = True
            if components is None:
                if bitsPerPixel == 32:
                    components = 4
                elif bitsPerPixel == 24:
                    components = 3
                else:
                    raise NotImplementedError("bitsPerPixel must be 24 or 32")
            self._data = np.empty((height, width, components), dtype=np.uint8)
        self._data = np.ascontiguousarray(self._data)

        self.modified = time.time()