Method: Magick::Image#negate

Defined in:
ext/RMagick/rmimage.cpp

#negate(grayscale = false) ⇒ Magick::Image

Negate the colors in the reference image. The grayscale option means that only grayscale values within the image are negated.

Returns a new image.

Parameters:

  • grayscale (Boolean) (defaults to: false)

    If the grayscale argument is true, only the grayscale values are negated.

Returns:



9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
# File 'ext/RMagick/rmimage.cpp', line 9737

VALUE
Image_negate(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    MagickBooleanType grayscale = MagickFalse;
#if defined(IMAGEMAGICK_7)
    ExceptionInfo *exception;
#endif

    image = rm_check_destroyed(self);
    if (argc == 1)
    {
        grayscale = (MagickBooleanType)RTEST(argv[0]);
    }
    else if (argc > 1)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
    }

    new_image = rm_clone_image(image);

#if defined(IMAGEMAGICK_7)
    exception = AcquireExceptionInfo();
    GVL_STRUCT_TYPE(NegateImage) args = { new_image, grayscale, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImage), &args);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);
#else
    GVL_STRUCT_TYPE(NegateImage) args = { new_image, grayscale };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImage), &args);
    rm_check_image_exception(new_image, DestroyOnError);
#endif

    return rm_image_new(new_image);
}