def getRGBData(self):
     "Return byte array of RGB data as string"
     if self._data is None:
         self._dataA = None
         if sys.platform[0:4] == 'java':
             import jarray  # TODO: Move to top.
             from java.awt.image import PixelGrabber
             width, height = self.getSize()
             buffer = jarray.zeros(width * height, 'i')
             pg = PixelGrabber(self._image, 0, 0, width, height, buffer, 0, width)
             pg.grabPixels()
             # there must be a way to do this with a cast not a byte-level loop,
             # I just haven't found it yet...
             pixels = []
             a = pixels.append
             for i in range(len(buffer)):
                 rgb = buffer[i]
                 a(chr((rgb >> 16) & 0xff))
                 a(chr((rgb >> 8) & 0xff))
                 a(chr(rgb & 0xff))
             self._data = ''.join(pixels)
             self.mode = 'RGB'
         else:
             im = self._image
             mode = self.mode = im.mode
             if mode == 'RGBA':
                 im.load()
                 self._dataA = PmlImageReader(im.split()[3])
                 im = im.convert('RGB')
                 self.mode = 'RGB'
             elif mode not in ('L', 'RGB', 'CMYK'):
                 im = im.convert('RGB')
                 self.mode = 'RGB'
             self._data = im.tostring()
     return self._data
 def getRGBData(self):
     "Return byte array of RGB data as string"
     if self._data is None:
         self._dataA = None
         if sys.platform[0:4] == 'java':
             import jarray  # TODO: Move to top.
             from java.awt.image import PixelGrabber
             width, height = self.getSize()
             buffer = jarray.zeros(width * height, 'i')
             pg = PixelGrabber(self._image, 0, 0, width, height, buffer, 0, width)
             pg.grabPixels()
             # there must be a way to do this with a cast not a byte-level loop,
             # I just haven't found it yet...
             pixels = []
             a = pixels.append
             for rgb in buffer:
                 a(chr((rgb >> 16) & 0xff))
                 a(chr((rgb >> 8) & 0xff))
                 a(chr(rgb & 0xff))
             self._data = ''.join(pixels)
             self.mode = 'RGB'
         else:
             im = self._image
             mode = self.mode = im.mode
             if mode == 'RGBA':
                 im.load()
                 self._dataA = PmlImageReader(im.split()[3])
                 im = im.convert('RGB')
                 self.mode = 'RGB'
             elif mode not in ('L', 'RGB', 'CMYK'):
                 im = im.convert('RGB')
                 self.mode = 'RGB'
             self._data = im.tostring()
     return self._data
Beispiel #3
0
    def getRGBData(self):
        "Return byte array of RGB data as string"
        if self._data is None:
            self._dataA = None
            if sys.platform[0:4] == "java":
                import jarray
                from java.awt.image import PixelGrabber

                width, height = self.getSize()
                buffer = jarray.zeros(width * height, "i")
                pg = PixelGrabber(self._image, 0, 0, width, height, buffer, 0, width)
                pg.grabPixels()
                # there must be a way to do this with a cast not a byte-level loop,
                # I just haven't found it yet...
                pixels = []
                a = pixels.append
                for i in range(len(buffer)):
                    rgb = buffer[i]
                    a(chr((rgb >> 16) & 0xFF))
                    a(chr((rgb >> 8) & 0xFF))
                    a(chr(rgb & 0xFF))
                self._data = "".join(pixels)
                self.mode = "RGB"
            else:
                im = self._image
                mode = self.mode = im.mode
                if mode == "RGBA":
                    self._dataA = ImageReader(im.split()[3])
                    im = im.convert("RGB")
                    self.mode = "RGB"
                elif mode not in ("L", "RGB", "CMYK"):
                    im = im.convert("RGB")
                    self.mode = "RGB"
                self._data = im.tostring()
        return self._data
Beispiel #4
0
 def getRGBData(self):
     "Return byte array of RGB data as string"
     if self._data is None:
         if sys.platform[0:4] == 'java':
             import jarray
             from java.awt.image import PixelGrabber
             width, height = self.getSize()
             buffer = jarray.zeros(width*height, 'i')
             pg = PixelGrabber(self._image, 0,0,width,height,buffer,0,width)
             pg.grabPixels()
             # there must be a way to do this with a cast not a byte-level loop,
             # I just haven't found it yet...
             pixels = []
             a = pixels.append
             for i in range(len(buffer)):
                 rgb = buffer[i]
                 a(chr((rgb>>16)&0xff))
                 a(chr((rgb>>8)&0xff))
                 a(chr(rgb&0xff))
             self._data = ''.join(pixels)
             self.mode = 'RGB'
         else:
             im = self._image
             mode = self.mode = im.mode
             if mode not in ('L','RGB','CMYK'):
                 im = im.convert('RGB')
                 self.mode = 'RGB'
             self._data = im.tostring()
     return self._data
 def getRGBData(self):
     "Return byte array of RGB data as string"
     try:
         if self._data is None:
             self._dataA = None
             if sys.platform[0:4] == 'java':
                 import jarray
                 from java.awt.image import PixelGrabber
                 width, height = self.getSize()
                 buffer = jarray.zeros(width * height, 'i')
                 pg = PixelGrabber(self._image, 0, 0, width, height, buffer,
                                   0, width)
                 pg.grabPixels()
                 # there must be a way to do this with a cast not a byte-level loop,
                 # I just haven't found it yet...
                 pixels = []
                 a = pixels.append
                 for i in range(len(buffer)):
                     rgb = buffer[i]
                     a(chr((rgb >> 16) & 0xff))
                     a(chr((rgb >> 8) & 0xff))
                     a(chr(rgb & 0xff))
                 self._data = ''.join(pixels)
                 self.mode = 'RGB'
             else:
                 im = self._image
                 mode = self.mode = im.mode
                 if mode in ('LA', 'RGBA'):
                     if getattr(Image, 'VERSION', '').startswith('1.1.7'):
                         im.load()
                     self._dataA = ImageReader(
                         im.split()[3 if mode == 'RGBA' else 1])
                     nm = mode[:-1]
                     im = im.convert(nm)
                     self.mode = nm
                 elif mode not in ('L', 'RGB', 'CMYK'):
                     if im.format == 'PNG' and im.mode == 'P' and 'transparency' in im.info:
                         im = im.convert('RGBA')
                         self._dataA = ImageReader(im.split()[3])
                         im = im.convert('RGB')
                     else:
                         im = im.convert('RGB')
                     self.mode = 'RGB'
                 self._data = (im.tobytes
                               if hasattr(im, 'tobytes') else im.tostring
                               )()  #make pillow and PIL both happy, for now
         return self._data
     except:
         annotateException('\nidentity=%s' % self.identity())
Beispiel #6
0
    def getRGBData(self):
        "Return byte array of RGB data as string"
        try:
            return self._data_cache[self]
        except KeyError:
            pass
        
        if self._data is None:
            self._dataA = None
            if sys.platform[0:4] == 'java':
                import jarray
                from java.awt.image import PixelGrabber
                width, height = self.getSize()
                buffer = jarray.zeros(width*height, 'i')
                pg = PixelGrabber(self._image, 0,0,width,height,buffer,0,width)
                pg.grabPixels()
                # there must be a way to do this with a cast not a byte-level loop,
                # I just haven't found it yet...
                pixels = []
                a = pixels.append
                for i in range(len(buffer)):
                    rgb = buffer[i]
                    a(chr((rgb>>16)&0xff))
                    a(chr((rgb>>8)&0xff))
                    a(chr(rgb&0xff))
                self._data = ''.join(pixels)
                self.mode = 'RGB'
            else:
                im = self._image
                mode = self.mode = im.mode
                if mode=='RGBA':
                    im.load()
                    self._dataA = ImageReader(im.split()[3])
                    im = im.convert('RGB')
                    self.mode = 'RGB'
                elif mode not in ('L','RGB','CMYK'):
                    im = im.convert('RGB')
                    self.mode = 'RGB'
                self._data = im.tostring()

        if len(self._data)<128*1024:
            return self._data
        
        retval = self._data
        self._data_cache[self] = retval
        self._data = None
        return retval
Beispiel #7
0
    def getRGBData(self):
        "Return byte array of RGB data as string"
        try:
            if self._data is None:
                self._dataA = None
                if sys.platform[0:4] == "java":
                    import jarray
                    from java.awt.image import PixelGrabber

                    width, height = self.getSize()
                    buffer = jarray.zeros(width * height, "i")
                    pg = PixelGrabber(self._image, 0, 0, width, height, buffer, 0, width)
                    pg.grabPixels()
                    # there must be a way to do this with a cast not a byte-level loop,
                    # I just haven't found it yet...
                    pixels = []
                    a = pixels.append
                    for i in range(len(buffer)):
                        rgb = buffer[i]
                        a(chr((rgb >> 16) & 0xFF))
                        a(chr((rgb >> 8) & 0xFF))
                        a(chr(rgb & 0xFF))
                    self._data = "".join(pixels)
                    self.mode = "RGB"
                else:
                    im = self._image
                    mode = self.mode = im.mode
                    if mode == "RGBA":
                        if Image.VERSION.startswith("1.1.7"):
                            im.load()
                        self._dataA = ImageReader(im.split()[3])
                        im = im.convert("RGB")
                        self.mode = "RGB"
                    elif mode not in ("L", "RGB", "CMYK"):
                        if im.format == "PNG" and im.mode == "P" and "transparency" in im.info:
                            im = im.convert("RGBA")
                            self._dataA = ImageReader(im.split()[3])
                            im = im.convert("RGB")
                        else:
                            im = im.convert("RGB")
                        self.mode = "RGB"
                    self._data = (
                        im.tobytes if hasattr(im, "tobytes") else im.tostring
                    )()  # make pillow and PIL both happy, for now
            return self._data
        except:
            annotateException("\nidentity=%s" % self.identity())
Beispiel #8
0
 def getRGBData(self):
     "Return byte array of RGB data as string"
     try:
         if self._data is None:
             self._dataA = None
             if sys.platform[0:4] == 'java':
                 import jarray
                 from java.awt.image import PixelGrabber
                 width, height = self.getSize()
                 buffer = jarray.zeros(width*height, 'i')
                 pg = PixelGrabber(self._image, 0,0,width,height,buffer,0,width)
                 pg.grabPixels()
                 # there must be a way to do this with a cast not a byte-level loop,
                 # I just haven't found it yet...
                 pixels = []
                 a = pixels.append
                 for i in range(len(buffer)):
                     rgb = buffer[i]
                     a(chr((rgb>>16)&0xff))
                     a(chr((rgb>>8)&0xff))
                     a(chr(rgb&0xff))
                 self._data = ''.join(pixels)
                 self.mode = 'RGB'
             else:
                 im = self._image
                 mode = self.mode = im.mode
                 if mode in ('LA','RGBA'):
                     if Image.VERSION.startswith('1.1.7'): im.load()
                     self._dataA = ImageReader(im.split()[3 if mode=='RGBA' else 1])
                     nm = mode[:-1]
                     im = im.convert(nm)
                     self.mode = nm
                 elif mode not in ('L','RGB','CMYK'):
                     if im.format=='PNG' and im.mode=='P' and 'transparency' in im.info:
                         im = im.convert('RGBA')
                         self._dataA = ImageReader(im.split()[3])
                         im = im.convert('RGB')
                     else:
                         im = im.convert('RGB')
                     self.mode = 'RGB'
                 self._data = (im.tobytes if hasattr(im, 'tobytes') else im.tostring)()  #make pillow and PIL both happy, for now
         return self._data
     except:
         annotateException('\nidentity=%s'%self.identity())
    def getRGBData(self):
        "Return byte array of RGB data as string"
        if self._data is None:
            self._dataA = None
            if sys.platform[0:4] == "java":
                import jarray  # TODO: Move to top.
                from java.awt.image import PixelGrabber

                width, height = self.getSize()
                buffer = jarray.zeros(width * height, "i")
                pg = PixelGrabber(self._image, 0, 0, width, height, buffer, 0, width)
                pg.grabPixels()
                # there must be a way to do this with a cast not a byte-level loop,
                # I just haven't found it yet...
                pixels = []
                a = pixels.append
                for rgb in buffer:
                    a(chr((rgb >> 16) & 0xFF))
                    a(chr((rgb >> 8) & 0xFF))
                    a(chr(rgb & 0xFF))
                self._data = "".join(pixels)
                self.mode = "RGB"
            else:
                im = self._image
                mode = self.mode = im.mode
                if mode == "RGBA":
                    im.load()
                    self._dataA = PmlImageReader(im.split()[3])
                    im = im.convert("RGB")
                    self.mode = "RGB"
                elif mode not in ("L", "RGB", "CMYK"):
                    im = im.convert("RGB")
                    self.mode = "RGB"
                if hasattr(im, "tobytes"):
                    self._data = im.tobytes()
                else:
                    # PIL compatibility
                    self._data = im.tostring()
        return self._data