Method: Magick::Image#color_flood_fill
- Defined in:
- ext/RMagick/rmimage.cpp
#color_flood_fill(target_color, fill_color, xv, yv, method) ⇒ Magick::Image
Change the color value of any pixel that matches target_color and is an immediate neighbor.
3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 |
# File 'ext/RMagick/rmimage.cpp', line 3076
VALUE
Image_color_flood_fill(VALUE self, VALUE target_color, VALUE fill_color,
VALUE xv, VALUE yv, VALUE method)
{
Image *image, *new_image;
PixelColor target;
DrawInfo *draw_info;
PixelColor fill;
long x, y;
int fill_method;
MagickPixel target_mpp;
MagickBooleanType invert;
#if defined(IMAGEMAGICK_7)
ExceptionInfo *exception;
#endif
image = rm_check_destroyed(self);
// The target and fill args can be either a color name or
// a Magick::Pixel.
Color_to_PixelColor(&target, target_color);
Color_to_PixelColor(&fill, fill_color);
x = NUM2LONG(xv);
y = NUM2LONG(yv);
if ((unsigned long)x > image->columns || (unsigned long)y > image->rows)
{
rb_raise(rb_eArgError, "target out of range. %lux%lu given, image is %" RMIuSIZE "x%" RMIuSIZE "",
x, y, image->columns, image->rows);
}
VALUE_TO_ENUM(method, fill_method, PaintMethod);
if (!(fill_method == FloodfillMethod || fill_method == FillToBorderMethod))
{
rb_raise(rb_eArgError, "paint method must be FloodfillMethod or "
"FillToBorderMethod (%d given)", fill_method);
}
draw_info = CloneDrawInfo(NULL, NULL);
if (!draw_info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
draw_info->fill = fill;
new_image = rm_clone_image(image);
rm_init_magickpixel(new_image, &target_mpp);
if (fill_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;
}
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)
exception = AcquireExceptionInfo();
GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, draw_info, &target_mpp, x, y, invert, exception };
CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args);
DestroyDrawInfo(draw_info);
rm_check_exception(exception, new_image, DestroyOnError);
DestroyExceptionInfo(exception);
#else
GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, DefaultChannels, 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);
}
|