Method: Magick::Image#function_channel

Defined in:
ext/RMagick/rmimage.cpp

#function_channel(function, *args, channel = Magick::AllChannels) ⇒ Magick::Image #function_channel(function, *args, *channels) ⇒ Magick::Image

Set the function on a channel.

Overloads:

  • #function_channel(function, *args, channel = Magick::AllChannels) ⇒ Magick::Image

    Parameters:

    • function (Magick::MagickFunction)

      the function

    • *args (Numeric)

      One or more floating-point numbers. The number of parameters depends on the function. See the ImageMagick documentation for details.

    • channel (Magick::ChannelType) (defaults to: Magick::AllChannels)

      a ChannelType arguments.

  • #function_channel(function, *args, *channels) ⇒ Magick::Image

    Parameters:

    • function (Magick::MagickFunction)

      the function

    • *args (Numeric)

      One or more floating-point numbers. The number of parameters depends on the function. See the ImageMagick documentation for details.

    • *channels (Magick::ChannelType)

      one or more ChannelType arguments.

Returns:

See Also:



7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
# File 'ext/RMagick/rmimage.cpp', line 7333

VALUE
Image_function_channel(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    MagickFunction function;
    unsigned long n, nparms;
    double *parms;
    ChannelType channels;
    ExceptionInfo *exception;

    image = rm_check_destroyed(self);
    channels = extract_channels(&argc, argv);

    // The number of parameters depends on the function.
    if (argc == 0)
    {
        rb_raise(rb_eArgError, "no function specified");
    }

    VALUE_TO_ENUM(argv[0], function, MagickFunction);
    argc -= 1;
    argv += 1;

    switch (function)
    {
        case PolynomialFunction:
            if (argc == 0)
            {
                rb_raise(rb_eArgError, "PolynomialFunction requires at least one argument.");
            }
            break;
        case SinusoidFunction:
        case ArcsinFunction:
        case ArctanFunction:
           if (argc < 1 || argc > 4)
           {
               rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc);
           }
           break;
        default:
            rb_raise(rb_eArgError, "undefined function");
            break;
    }

    nparms = argc;
    parms = ALLOC_N(double, nparms);

    for (n = 0; n < nparms; n++)
    {
        VALUE element = argv[n];
        if (rm_check_num2dbl(element))
        {
            parms[n] = NUM2DBL(element);
        }
        else
        {
            xfree(parms);
            rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(element)));
        }
    }

    exception = AcquireExceptionInfo();
    new_image = rm_clone_image(image);
#if defined(IMAGEMAGICK_7)
    BEGIN_CHANNEL_MASK(new_image, channels);
    GVL_STRUCT_TYPE(FunctionImage) args = { new_image, function, nparms, parms, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FunctionImage), &args);
    END_CHANNEL_MASK(new_image);
#else
    GVL_STRUCT_TYPE(FunctionImageChannel) args = { new_image, channels, function, nparms, parms, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FunctionImageChannel), &args);
#endif
    xfree(parms);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);

    return rm_image_new(new_image);
}