Method: Magick::Image#quantize

Defined in:
ext/RMagick/rmimage.c

#quantize(*args) ⇒ Object

Call QuantizeImage.

Ruby usage:

- @verbatim Image#quantize @endverbatim
- @verbatim Image#quantize(number_colors) @endverbatim
- @verbatim Image#quantize(number_colors, colorspace) @endverbatim
- @verbatim Image#quantize(number_colors, colorspace, dither) @endverbatim
- @verbatim Image#quantize(number_colors, colorspace, dither, tree_depth) @endverbatim
- @verbatim Image#quantize(number_colors, colorspace, dither, tree_depth, measure_error) @endverbatim

Notes:

- Default number_colors is 256
- Default colorspace is Magick::RGBColorspace
- Default dither is true
- Default tree_depth is 0
- Default measure_error is false

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • a new image


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
# File 'ext/RMagick/rmimage.c', line 10249

VALUE
Image_quantize(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    QuantizeInfo quantize_info;

    image = rm_check_destroyed(self);
    GetQuantizeInfo(&quantize_info);

    switch (argc)
    {
        case 5:
            quantize_info.measure_error = (MagickBooleanType) RTEST(argv[4]);
        case 4:
            quantize_info.tree_depth = NUM2UINT(argv[3]);
        case 3:
            if (rb_obj_is_kind_of(argv[2], Class_DitherMethod))
            {
                VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod);
                quantize_info.dither = quantize_info.dither_method != NoDitherMethod;
            }
            else
            {
                quantize_info.dither = (MagickBooleanType) RTEST(argv[2]);
            }
        case 2:
            VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType);
        case 1:
            quantize_info.number_colors = NUM2UINT(argv[0]);
        case 0:
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 5)", argc);
            break;
    }

    new_image = rm_clone_image(image);

    (void) QuantizeImage(&quantize_info, new_image);
    rm_check_image_exception(new_image, DestroyOnError);

    return rm_image_new(new_image);
}