Exemple #1
0
    def __setitem__(self, point, color):
        """Set a single pixel to a given color.

        This is "slow", in the sense that you probably don't want to do this to
        edit every pixel in an entire image.
        """
        point = Vector.coerce(point)
        rgb = color.rgb()

        # TODO retval is t/f
        with magick_try() as exc:
            # Surprise!  GetOneCacheViewAuthenticPixel doesn't actually respect
            # writes, even though the docs explicitly says it does.
            # So get a view of this single pixel instead.
            px = lib.GetCacheViewAuthenticPixels(self._ptr, point.x, point.y,
                                                 1, 1, exc.ptr)
            exc.check(px == ffi.NULL)

        array = ffi.new("double[]",
                        [rgb._red, rgb._green, rgb._blue, rgb._opacity])
        lib.sanpera_pixel_from_doubles(px, array)
        #print(repr(ffi.buffer(ffi.cast("char*", ffi.cast("void*", px)), 16)[:]))

        with magick_try() as exc:
            assert lib.SyncCacheViewAuthenticPixels(self._ptr, exc.ptr)
Exemple #2
0
 def color(self, value):
     if self._pixel == ffi.NULL:
         raise ValueError("Pixel has expired")
     array = ffi.new(
         "double[]",
         [value._red, value._green, value._blue, value._opacity])
     lib.sanpera_pixel_from_doubles(self._pixel, array)
Exemple #3
0
    def __setitem__(self, point, color):
        """Set a single pixel to a given color.

        This is "slow", in the sense that you probably don't want to do this to
        edit every pixel in an entire image.
        """
        point = Vector.coerce(point)
        rgb = color.rgb()

        # TODO retval is t/f
        with magick_try() as exc:
            # Surprise!  GetOneCacheViewAuthenticPixel doesn't actually respect
            # writes, even though the docs explicitly says it does.
            # So get a view of this single pixel instead.
            px = lib.GetCacheViewAuthenticPixels(
                self._ptr, point.x, point.y, 1, 1, exc.ptr)
            exc.check(px == ffi.NULL)

        array = ffi.new("double[]", [rgb._red, rgb._green, rgb._blue, rgb._opacity])
        lib.sanpera_pixel_from_doubles(px, array)
        #print(repr(ffi.buffer(ffi.cast("char*", ffi.cast("void*", px)), 16)[:]))

        with magick_try() as exc:
            assert lib.SyncCacheViewAuthenticPixels(self._ptr, exc.ptr)
Exemple #4
0
 def color(self, value):
     if self._pixel == ffi.NULL:
         raise ValueError("Pixel has expired")
     array = ffi.new("double[]", [value._red, value._green, value._blue, value._opacity])
     lib.sanpera_pixel_from_doubles(self._pixel, array)
Exemple #5
0
 def _populate_pixel(self, pixel):
     """Copy values to a PixelPacket."""
     rgb = self.rgb()
     lib.sanpera_pixel_from_doubles(pixel, rgb._array)
Exemple #6
0
 def _populate_pixel(self, pixel):
     """Copy values to a PixelPacket."""
     rgb = self.rgb()
     lib.sanpera_pixel_from_doubles(pixel, rgb._array)