Method: Magick::Image#opaque_channel
- Defined in:
- ext/RMagick/rmimage.cpp
#opaque_channel(target, fill, invert = false, fuzz = self.fuzz, channel = Magick::AllChannels) ⇒ Magick::Image #opaque_channel(target, fill, invert, fuzz, *channels) ⇒ Magick::Image
Changes all pixels having the target color to the fill color. If invert is true, changes all the pixels that are not the target color to the fill color.
10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 |
# File 'ext/RMagick/rmimage.cpp', line 10239
VALUE
Image_opaque_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
MagickPixel target_pp, fill_pp;
ChannelType channels;
double keep, fuzz;
MagickBooleanType okay, invert = MagickFalse;
#if defined(IMAGEMAGICK_7)
ExceptionInfo *exception;
#endif
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 4)
{
raise_ChannelType_error(argv[argc-1]);
}
// Default fuzz value is image's fuzz attribute.
fuzz = image->fuzz;
switch (argc)
{
case 4:
fuzz = NUM2DBL(argv[3]);
if (fuzz < 0.0)
{
rb_raise(rb_eArgError, "fuzz must be >= 0.0 (%g given)", fuzz);
}
case 3:
invert = (MagickBooleanType)RTEST(argv[2]);
case 2:
// Allow color name or Pixel
Color_to_MagickPixel(image, &fill_pp, argv[1]);
Color_to_MagickPixel(image, &target_pp, argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (got %d, expected 2 or more)", argc);
break;
}
new_image = rm_clone_image(image);
keep = new_image->fuzz;
new_image->fuzz = fuzz;
#if defined(IMAGEMAGICK_7)
exception = AcquireExceptionInfo();
BEGIN_CHANNEL_MASK(new_image, channels);
GVL_STRUCT_TYPE(OpaquePaintImage) args = { new_image, &target_pp, &fill_pp, invert, exception };
void *ret = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OpaquePaintImage), &args);
okay = static_cast<MagickBooleanType>(reinterpret_cast<intptr_t &>(ret));
END_CHANNEL_MASK(new_image);
new_image->fuzz = keep;
rm_check_exception(exception, new_image, DestroyOnError);
DestroyExceptionInfo(exception);
#else
GVL_STRUCT_TYPE(OpaquePaintImageChannel) args = { new_image, channels, &target_pp, &fill_pp, invert };
void *ret = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OpaquePaintImageChannel), &args);
okay = static_cast<MagickBooleanType>(reinterpret_cast<intptr_t &>(ret));
new_image->fuzz = keep;
rm_check_image_exception(new_image, DestroyOnError);
#endif
if (!okay)
{
// Force exception
DestroyImage(new_image);
rm_ensure_result(NULL);
}
return rm_image_new(new_image);
}
|