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)
def __getitem__(self, point): point = Vector.coerce(point) px = ffi.new("PixelPacket *") # TODO retval is t/f with magick_try() as exc: lib.GetOneCacheViewAuthenticPixel(self._ptr, point.x, point.y, px, exc.ptr) array = ffi.new("double[]", 4) lib.sanpera_pixel_to_doubles(px, array) return RGBColor(*array)
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)