Ejemplo n.º 1
0
 def __init__(self, imagedata):
     self._imagedata = ImageData(imagedata)
     array = Ndarray(self._imagedata.data)
     array.setshape(self._imagedata.height, self._imagedata.width, 4)
     data = Uint32Array(self._imagedata.height * self._imagedata.width)
     index = 0
     for x in range(self._imagedata.width):
         for y in range(self._imagedata.height):
             data[index] = (array[y, x, 0] << 16 | array[y, x, 1] << 8
                            | array[y, x, 2] | array[y, x, 3] << 24)
             index += 1
     Ndarray.__init__(self, data, 'uint32')
     self.setshape(self._imagedata.width, self._imagedata.height)
Ejemplo n.º 2
0
class ImageInteger(Ndarray):
    """
    Array of pixel data arranged by width/height in integer color format.
    Array data derived from ImageData.
    """
    def __init__(self, imagedata):
        self._imagedata = ImageData(imagedata)
        array = Ndarray(self._imagedata.data)
        array.setshape(self._imagedata.height, self._imagedata.width, 4)
        data = Uint32Array(self._imagedata.height * self._imagedata.width)
        index = 0
        for x in range(self._imagedata.width):
            for y in range(self._imagedata.height):
                data[index] = (array[y, x, 0] << 16 | array[y, x, 1] << 8
                               | array[y, x, 2] | array[y, x, 3] << 24)
                index += 1
        Ndarray.__init__(self, data, 'uint32')
        self.setshape(self._imagedata.width, self._imagedata.height)

    shape = Ndarray.shape

    def getImageData(self):
        """
        Get ImageData.
        """
        index = 0
        for x in range(self._imagedata.height):
            for y in range(self._imagedata.width):
                dat = self[y, x]
                self._imagedata.data[index] = dat >> 16 & 0xff
                self._imagedata.data[index + 1] = dat >> 8 & 0xff
                self._imagedata.data[index + 2] = dat & 0xff
                self._imagedata.data[index + 3] = dat >> 24 & 0xff
                index += 4
        return self._imagedata.getImageData()
Ejemplo n.º 3
0
 def __init__(self, imagedata):
     self._imagedata = ImageData(imagedata)
     array = Ndarray(self._imagedata.data)
     array.setshape(self._imagedata.height, self._imagedata.width, 4)
     try:
         data = Uint8ClampedArray(self._imagedata.height *
                                  self._imagedata.width)
     except NotImplementedError:
         data = Uint8Array(self._imagedata.height * self._imagedata.width)
     index = 0
     for x in range(self._imagedata.width):
         for y in range(self._imagedata.height):
             data[index] = array[y, x, 3]
             index += 1
     try:
         Ndarray.__init__(self, data, 'uint8c')
     except NotImplementedError:
         Ndarray.__init__(self, data, 'uint8')
     self.setshape(self._imagedata.width, self._imagedata.height)
Ejemplo n.º 4
0
class ImageRGB(Ndarray):
    """
    Array of pixel data arranged by width/height in RGB format.
    Array data derived from ImageData.
    """

    def __init__(self, imagedata):
        self._imagedata = ImageData(imagedata)
        array = Ndarray(self._imagedata.data)
        array.setshape(self._imagedata.height, self._imagedata.width, 4)
        try:
            data = Uint8ClampedArray(self._imagedata.height
                                    * self._imagedata.width * 3)
        except NotImplementedError:
            data = Uint8Array(self._imagedata.height
                             * self._imagedata.width * 3)
        index = 0
        for x in range(self._imagedata.width):
            for y in range(self._imagedata.height):
                for i in range(3):
                    # __pragma__ ('opov')
                    data[index] = array[y, x, i]
                    # __pragma__ ('noopov')
                    index += 1
        try:
            Ndarray.__init__(self, data, 'uint8c')
        except NotImplementedError:
            Ndarray.__init__(self, data, 'uint8')
        self.setshape(self._imagedata.width, self._imagedata.height, 3)

    def getImageData(self):
        """
        Get ImageData.
        """
        index = 0
        for x in range(self._imagedata.height):
            for y in range(self._imagedata.width):
                for i in range(3):
                    # __pragma__ ('opov')
                    self._imagedata.data[index + i] = self[y, x, i]
                    # __pragma__ ('noopov')
                index += 4
        return self._imagedata.getImageData()
Ejemplo n.º 5
0
class ImageAlpha(Ndarray):
    """
    Array of pixel data arranged by width/height of pixel alpha value.
    Array data derived from ImageData.
    """
    def __init__(self, imagedata):
        self._imagedata = ImageData(imagedata)
        array = Ndarray(self._imagedata.data)
        array.setshape(self._imagedata.height, self._imagedata.width, 4)
        try:
            data = Uint8ClampedArray(self._imagedata.height *
                                     self._imagedata.width)
        except NotImplementedError:
            data = Uint8Array(self._imagedata.height * self._imagedata.width)
        index = 0
        for x in range(self._imagedata.width):
            for y in range(self._imagedata.height):
                data[index] = array[y, x, 3]
                index += 1
        try:
            Ndarray.__init__(self, data, 'uint8c')
        except NotImplementedError:
            Ndarray.__init__(self, data, 'uint8')
        self.setshape(self._imagedata.width, self._imagedata.height)

    shape = Ndarray.shape

    def getImageData(self):
        """
        Get ImageData.
        """
        index = 0
        for x in range(self._imagedata.height):
            for y in range(self._imagedata.width):
                self._imagedata.data[index + 3] = self[y, x]
                index += 4
        return self._imagedata.getImageData()