Example #1
0
 def get_image_contents(self, target):
     types = filter_targets(self.pasteboard.types())
     if target == "image/png" and NSPasteboardTypePNG in types:
         src_dtype = target
         img_data = self.pasteboard.dataForType_(NSPasteboardTypePNG)
     elif target == "image/tiff" and NSTIFFPboardType in types:
         src_dtype = target
         img_data = self.pasteboard.dataForType_(NSTIFFPboardType)
     elif NSPasteboardTypePNG in types:
         src_dtype = "image/png"
         img_data = self.pasteboard.dataForType_(NSPasteboardTypePNG)
     elif NSTIFFPboardType in types:
         src_dtype = "image/tiff"
         img_data = self.pasteboard.dataForType_(NSTIFFPboardType)
     else:
         log("image target '%s' not found in %s", target, types)
         return None
     if not img_data:
         return None
     l = CFDataGetLength(img_data)
     img_data = CFDataGetBytes(img_data, (0, l), None)
     img_data = self.filter_data(dtype=src_dtype,
                                 dformat=8,
                                 data=img_data,
                                 trusted=False,
                                 output_dtype=target)
     log("get_image_contents(%s)=%i %s", target, len(img_data or ()),
         type(img_data))
     return img_data
Example #2
0
 def pixels_to_bytes(v):
     if type(v) in btypes:
         return memoryview_to_bytes(v)
     l = CFDataGetLength(v)
     return CFDataGetBytes(v, (0, l), None)
Example #3
0
 def pixels_to_bytes(v):
     if isinstance(v, BTYPES):
         return memoryview_to_bytes(v)
     l = CFDataGetLength(v)
     return CFDataGetBytes(v, (0, l), None)