예제 #1
0
    def send_thumb(self, id):
        if not self.thumb_dirty[id]: return True

        assert self.thumb_to_send[id] is not None

        # convert image to JPEG
        jpegdata = StringIO()
        imsz = (self.thumb_to_send[id].width, self.thumb_to_send[id].height)
        if self.thumb_to_send[id].pixelformat == make_fourcc("RGB3"):
            im = Image.fromstring("RGB", imsz, self.thumb_to_send[id].data)
        elif self.thumb_to_send[id].pixelformat == make_fourcc("RGB4"):
            im = Image.fromstring("RGBA", imsz, self.thumb_to_send[id].data)
        elif self.thumb_to_send[id].pixelformat == make_fourcc("GREY"):
            im = Image.fromstring("L", imsz, self.thumb_to_send[id].data)
        else:
            print "unrecognized image format"
            print "%X %X" % (self.thumb_to_send[id].pixelformat,
                             make_fourcc("RGB3"))
            return True
        im.save(jpegdata, "JPEG")

        self.thumb_to_send[id].data = jpegdata.getvalue()
        self.thumb_to_send[id].size = len(self.thumb_to_send[id].data)
        self.thumb_to_send[id].pixelformat = make_fourcc("MJPG")

        data = self.thumb_to_send[id].encode()
        m = image_t.decode(data)
        self.send_message_to_phone("BLIT%d" % id, data)
        self.thumb_dirty[id] = False
        self.thumb_to_send[id] = None
        return True
예제 #2
0
 def on_phone_thumb3(self, channel, data):
     msg = image_t.decode(data)
     self.thumb_to_send[3] = msg
     self.thumb_dirty[3] = True