Exemple #1
0
            def onUpdate(self, destLeft, destTop, destRight, destBottom, width,
                         height, bitsPerPixel, isCompress, data):
                """
                @summary: Notify bitmap update
                @param destLeft: xmin position
                @param destTop: ymin position
                @param destRight: xmax position because RDP can send bitmap with padding
                @param destBottom: ymax position because RDP can send bitmap with padding
                @param width: width of bitmap
                @param height: height of bitmap
                @param bitsPerPixel: number of bit per pixel
                @param isCompress: use RLE compression
                @param data: bitmap data
                """
                if isCompress:
                    if bitsPerPixel < 24:
                        sz = 2
                    elif bitsPerPixel < 32:
                        sz = 3
                    else:
                        sz = 4
                    buf = bytearray(width * height * sz)
                    rle.bitmap_decompress(buf, width, height, data, sz)
                    data = bytes(buf)

                i = Image.frombytes("RGB", (width, height), data, 'raw',
                                    'BGR;16')

                self.lastUpdate = datetime.now()
                if not self.inittimer:
                    self.inittimer = self.reactor.callLater(
                        .1, self.checkUpdate)

                if self.do_final:
                    self.final.paste(i, (destLeft, destTop))
                else:
                    self.initial.paste(i, (destLeft, destTop))
Exemple #2
0
Fichier : qt4.py Projet : zha0/rdpy
def RDPBitmapToQtImage(width, height, bitsPerPixel, isCompress, data):
    """
    @summary: Bitmap transformation to Qt object
    @param width: width of bitmap
    @param height: height of bitmap
    @param bitsPerPixel: number of bit per pixel
    @param isCompress: use RLE compression
    @param data: bitmap data
    """
    image = None
    #allocate
    
    if bitsPerPixel == 15:
        if isCompress:
            buf = bytearray(width * height * 2)
            rle.bitmap_decompress(buf, width, height, data, 2)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB555)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB555).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    
    elif bitsPerPixel == 16:
        if isCompress:
            buf = bytearray(width * height * 2)
            rle.bitmap_decompress(buf, width, height, data, 2)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB16)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB16).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    
    elif bitsPerPixel == 24:
        if isCompress:
            buf = bytearray(width * height * 3)
            rle.bitmap_decompress(buf, width, height, data, 3)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB888)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB888).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
            
    elif bitsPerPixel == 32:
        if isCompress:
            buf = bytearray(width * height * 4)
            rle.bitmap_decompress(buf, width, height, data, 4)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB32)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB32).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    else:
        log.error("Receive image in bad format")
        image = QtGui.QImage(width, height, QtGui.QImage.Format_RGB32)
    return image
Exemple #3
0
def RDPBitmapToQtImage(width, height, bitsPerPixel, isCompress, data):
    """
    @summary: Bitmap transformation to Qt object
    @param width: width of bitmap
    @param height: height of bitmap
    @param bitsPerPixel: number of bit per pixel
    @param isCompress: use RLE compression
    @param data: bitmap data
    """
    image = None
    #allocate
    
    if bitsPerPixel == 15:
        if isCompress:
            buf = bytearray(width * height * 2)
            rle.bitmap_decompress(buf, width, height, data, 2)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB555)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB555).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    
    elif bitsPerPixel == 16:
        if isCompress:
            buf = bytearray(width * height * 2)
            rle.bitmap_decompress(buf, width, height, data, 2)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB16)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB16).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    
    elif bitsPerPixel == 24:
        if isCompress:
            buf = bytearray(width * height * 3)
            rle.bitmap_decompress(buf, width, height, data, 3)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB888)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB888).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
            
    elif bitsPerPixel == 32:
        if isCompress:
            buf = bytearray(width * height * 4)
            rle.bitmap_decompress(buf, width, height, data, 4)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB32)
        else:
            image = QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB32).transformed(QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    else:
        log.error("Receive image in bad format")
        image = QtGui.QImage(width, height, QtGui.QImage.Format_RGB32)
    return image
Exemple #4
0
def RDPBitmapToQtImage(width, height, bitsPerPixel, isCompressed, data):
    """
    @summary: Bitmap transformation to Qt object
    @param width: width of bitmap
    @param height: height of bitmap
    @param bitsPerPixel: number of bit per pixel
    @param isCompressed: use RLE compression
    @param data: bitmap data
    """
    image = None
    #allocate

    if bitsPerPixel == 15:
        if isCompressed:
            buf = bytearray(width * height * 2)
            rle.bitmap_decompress(buf, width, height, data, 2)
            image = QtGui.QImage(buf, width, height,
                                 QtGui.QImage.Format_RGB555)
        else:
            image = QtGui.QImage(data, width, height,
                                 QtGui.QImage.Format_RGB555).transformed(
                                     QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0,
                                                   0.0))

    elif bitsPerPixel == 16:
        if isCompressed:
            buf = bytearray(width * height * 2)
            rle.bitmap_decompress(buf, width, height, data, 2)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB16)
        else:
            image = QtGui.QImage(data, width, height,
                                 QtGui.QImage.Format_RGB16).transformed(
                                     QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0,
                                                   0.0))

    elif bitsPerPixel == 24:
        if isCompressed:
            buf = bytearray(width * height * 3)
            rle.bitmap_decompress(buf, width, height, data, 3)

            # This is a ugly patch because there is a bug in the 24bpp decompression in rle.c
            # where the red and the blue colors are inverted. Fixing this in python causes a performance
            # issue, but at least it shows the good colors.
            buf2 = BytesIO(buf)
            while buf2.tell() < len(buf2.getvalue()):
                pixel = buf2.read(3)
                buf[buf2.tell() - 3] = pixel[2]
                buf[buf2.tell() - 1] = pixel[0]

            image = QtGui.QImage(buf, width, height,
                                 QtGui.QImage.Format_RGB888)
        else:
            image = QtGui.QImage(data, width, height,
                                 QtGui.QImage.Format_RGB888).transformed(
                                     QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0,
                                                   0.0))

    elif bitsPerPixel == 32:
        if isCompressed:
            buf = bytearray(width * height * 4)
            rle.bitmap_decompress(buf, width, height, data, 4)
            image = QtGui.QImage(buf, width, height, QtGui.QImage.Format_RGB32)
        else:
            image = QtGui.QImage(data, width, height,
                                 QtGui.QImage.Format_RGB32).transformed(
                                     QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0,
                                                   0.0))
    elif bitsPerPixel == 8:
        if isCompressed:
            buf = bytearray(width * height * 1)
            rle.bitmap_decompress(buf, width, height, data, 1)
            buf2 = convert8bppTo16bpp(buf)
            image = QtGui.QImage(buf2, width, height,
                                 QtGui.QImage.Format_RGB16)
        else:
            buf2 = convert8bppTo16bpp(data)
            image = QtGui.QImage(buf2, width, height,
                                 QtGui.QImage.Format_RGB16).transformed(
                                     QtGui.QMatrix(1.0, 0.0, 0.0, -1.0, 0.0,
                                                   0.0))
    else:
        log.error("Receive image in bad format")
        image = QtGui.QImage(width, height, QtGui.QImage.Format_RGB32)
    return image
Exemple #5
0
def RDPBitmapToQtImage(width: int, height: int, bitsPerPixel: int,
                       isCompressed: bool, data: bytes):
    """
    Bitmap transformation to Qt object
    :param width: width of bitmap
    :param height: height of bitmap
    :param bitsPerPixel: number of bit per pixel
    :param isCompressed: use RLE compression
    :param data: bitmap data
    """
    image = None
    buf = None

    if bitsPerPixel == 15:
        if isCompressed:
            buf = rle.bitmap_decompress(data, width, height, 2)
            image = QImage(buf, width, height, QImage.Format_RGB555)
        else:
            buf = data
            image = QImage(buf, width, height,
                           QImage.Format_RGB555).transformed(
                               QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))

    elif bitsPerPixel == 16:
        if isCompressed:
            buf = rle.bitmap_decompress(data, width, height, 2)
            image = QImage(buf, width, height, QImage.Format_RGB16)
        else:
            buf = data
            image = QImage(buf, width, height,
                           QImage.Format_RGB16).transformed(
                               QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))

    elif bitsPerPixel == 24:
        if isCompressed:
            buf = rle.bitmap_decompress(data, width, height, 3)

            # This is a ugly patch because there is a bug in the 24bpp decompression in rle.c
            # where the red and the blue colors are inverted. Fixing this in python causes a performance
            # issue, but at least it shows the good colors.
            buf2 = BytesIO(buf)
            while buf2.tell() < len(buf2.getvalue()):
                pixel = buf2.read(3)
                buf[buf2.tell() - 3] = pixel[2]
                buf[buf2.tell() - 1] = pixel[0]

            image = QImage(buf, width, height, QImage.Format_RGB888)
        else:
            buf = data
            image = QImage(buf, width, height,
                           QImage.Format_RGB888).transformed(
                               QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))

    elif bitsPerPixel == 32:
        if isCompressed:
            buf = rle.bitmap_decompress(data, width, height, 4)
            image = QImage(buf, width, height, QImage.Format_RGB32)
        else:
            buf = data
            image = QImage(buf, width, height,
                           QImage.Format_RGB32).transformed(
                               QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    elif bitsPerPixel == 8:
        if isCompressed:
            _buf = rle.bitmap_decompress(data, width, height, 1)
            buf = convert8bppTo16bpp(_buf)
            image = QImage(buf, width, height, QImage.Format_RGB16)
        else:
            buf = convert8bppTo16bpp(data)
            image = QImage(buf, width, height,
                           QImage.Format_RGB16).transformed(
                               QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0))
    else:
        log.error("Receive image in bad format")
        image = QImage(width, height, QImage.Format_RGB32)
    return (image, buf)