Method: Magick::Image#posterize

Defined in:
ext/RMagick/rmimage.cpp

#posterize(levels = 4, dither = false) ⇒ Object

Reduces the image to a limited number of colors for a “poster” effect.

Returns a new image.

Parameters:

  • levels (Numeric) (defaults to: 4)

    number of input arguments

  • dither (Boolean) (defaults to: false)

    array of input arguments

Returns:

  • a new image



10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
# File 'ext/RMagick/rmimage.cpp', line 10886

VALUE
Image_posterize(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    MagickBooleanType dither = MagickFalse;
    unsigned long levels = 4;
#if defined(IMAGEMAGICK_7)
    DitherMethod dither_method;
    ExceptionInfo *exception;
#endif

    image = rm_check_destroyed(self);
    switch (argc)
    {
        case 2:
            dither = (MagickBooleanType) RTEST(argv[1]);
            /* fall through */
        case 1:
            levels = NUM2ULONG(argv[0]);
            /* fall through */
        case 0:
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc);
    }

    new_image = rm_clone_image(image);

#if defined(IMAGEMAGICK_7)
    exception = AcquireExceptionInfo();
    dither_method = dither ? RiemersmaDitherMethod : NoDitherMethod;
    GVL_STRUCT_TYPE(PosterizeImage) args = { new_image, levels, dither_method, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(PosterizeImage), &args);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);
#else
    GVL_STRUCT_TYPE(PosterizeImage) args = { new_image, levels, dither };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(PosterizeImage), &args);
    rm_check_image_exception(new_image, DestroyOnError);
#endif

    return rm_image_new(new_image);
}