Method: Magick::Image#transparent_chroma
- Defined in:
- ext/RMagick/rmimage.cpp
#transparent_chroma(low, high, invert, alpha: Magick::TransparentAlpha) ⇒ Magick::Image
Changes the opacity value associated with any pixel between low and high to the value defined by opacity.
As there is one fuzz value for the all the channels, the transparent method is not suitable for the operations like chroma, where the tolerance for similarity of two color components (RGB) can be different, Thus we define this method take two target pixels (one low and one high) and all the pixels of an image which are lying between these two pixels are made transparent.
14760 14761 14762 14763 14764 14765 14766 14767 14768 14769 14770 14771 14772 14773 14774 14775 14776 14777 14778 14779 14780 14781 14782 14783 14784 14785 14786 14787 14788 14789 14790 14791 14792 14793 14794 14795 14796 14797 14798 14799 14800 14801 14802 14803 14804 14805 14806 14807 14808 14809 14810 14811 14812 14813 14814 14815 14816 14817 14818 14819 |
# File 'ext/RMagick/rmimage.cpp', line 14760
VALUE
Image_transparent_chroma(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
Quantum alpha = TransparentAlpha;
MagickPixel low, high;
MagickBooleanType invert = MagickFalse;
MagickBooleanType okay;
#if defined(IMAGEMAGICK_7)
ExceptionInfo *exception;
#endif
image = rm_check_destroyed(self);
switch (argc)
{
case 4:
if (TYPE(argv[argc - 1]) == T_HASH)
{
invert = (MagickBooleanType)RTEST(argv[3]);
}
else
{
invert = (MagickBooleanType)RTEST(argv[2]);
}
case 3:
alpha = get_named_alpha_value(argv[argc - 1]);
case 2:
Color_to_MagickPixel(image, &high, argv[1]);
Color_to_MagickPixel(image, &low, argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2, 3 or 4)", argc);
break;
}
new_image = rm_clone_image(image);
#if defined(IMAGEMAGICK_7)
exception = AcquireExceptionInfo();
GVL_STRUCT_TYPE(TransparentPaintImageChroma) args = { new_image, &low, &high, alpha, invert, exception };
void *ret = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImageChroma), &args);
okay = static_cast<MagickBooleanType>(reinterpret_cast<intptr_t &>(ret));
rm_check_exception(exception, new_image, DestroyOnError);
DestroyExceptionInfo(exception);
#else
GVL_STRUCT_TYPE(TransparentPaintImageChroma) args = { new_image, &low, &high, (Quantum)(QuantumRange - alpha), invert };
void *ret = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImageChroma), &args);
okay = static_cast<MagickBooleanType>(reinterpret_cast<intptr_t &>(ret));
rm_check_image_exception(new_image, DestroyOnError);
#endif
if (!okay)
{
// Force exception
DestroyImage(new_image);
rm_magick_error("TransparentPaintImageChroma failed with no explanation");
}
return rm_image_new(new_image);
}
|