Method: Magick::Image#matte_flood_fill
- Defined in:
- ext/RMagick/rmimage.cpp
#Image ⇒ Magick::Image
Makes transparent all the pixels that are the same color as the pixel at x, y, and are neighbors.
9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 |
# File 'ext/RMagick/rmimage.cpp', line 9352
VALUE
Image_matte_flood_fill(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
PixelColor target;
Quantum alpha;
long x, y;
PaintMethod method;
DrawInfo *draw_info;
MagickPixel target_mpp;
MagickBooleanType invert;
#if defined(IMAGEMAGICK_7)
ExceptionInfo *exception;
#endif
image = rm_check_destroyed(self);
if (argc != 5)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 5)", argc);
}
alpha = get_named_alpha_value(argv[4]);
Color_to_PixelColor(&target, argv[0]);
VALUE_TO_ENUM(argv[3], method, PaintMethod);
if (!(method == FloodfillMethod || method == FillToBorderMethod))
{
rb_raise(rb_eArgError, "paint method_obj must be FloodfillMethod or "
"FillToBorderMethod (%d given)", method);
}
x = NUM2LONG(argv[1]);
y = NUM2LONG(argv[2]);
if ((unsigned long)x > image->columns || (unsigned long)y > image->rows)
{
rb_raise(rb_eArgError, "target out of range. %ldx%ld given, image is %" RMIuSIZE "x%" RMIuSIZE "",
x, y, image->columns, image->rows);
}
new_image = rm_clone_image(image);
// FloodfillPaintImage looks for the opacity in the DrawInfo.fill field.
draw_info = CloneDrawInfo(NULL, NULL);
if (!draw_info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
#if defined(IMAGEMAGICK_7)
rm_set_pixelinfo_alpha(&draw_info->fill, alpha);
#else
draw_info->fill.opacity = QuantumRange - alpha;
#endif
if (method == FillToBorderMethod)
{
invert = MagickTrue;
target_mpp.red = (MagickRealType) image->border_color.red;
target_mpp.green = (MagickRealType) image->border_color.green;
target_mpp.blue = (MagickRealType) image->border_color.blue;
#if defined(IMAGEMAGICK_7)
rm_set_pixelinfo_alpha(&target_mpp, (MagickRealType) image->border_color.alpha);
#else
target_mpp.opacity = (MagickRealType) image->border_color.opacity;
#endif
}
else
{
invert = MagickFalse;
target_mpp.red = (MagickRealType) target.red;
target_mpp.green = (MagickRealType) target.green;
target_mpp.blue = (MagickRealType) target.blue;
#if defined(IMAGEMAGICK_7)
rm_set_pixelinfo_alpha(&target_mpp, (MagickRealType) target.alpha);
#else
target_mpp.opacity = (MagickRealType) target.opacity;
#endif
}
#if defined(IMAGEMAGICK_7)
exception = AcquireExceptionInfo();
BEGIN_CHANNEL_MASK(new_image, OpacityChannel);
GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, draw_info, &target_mpp, x, y, invert, exception };
CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args);
END_CHANNEL_MASK(new_image);
DestroyDrawInfo(draw_info);
rm_check_exception(exception, new_image, DestroyOnError);
DestroyExceptionInfo(exception);
#else
GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, OpacityChannel, draw_info, &target_mpp, x, y, invert };
CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args);
DestroyDrawInfo(draw_info);
rm_check_image_exception(new_image, DestroyOnError);
#endif
return rm_image_new(new_image);
}
|