Method: Magick::Image#level_channel

Defined in:
ext/RMagick/rmimage.cpp

#level_channel(aChannelType, black = 0.0, white = 1.0, gamma = Magick::QuantumRange) ⇒ Magick::Image

Similar to #level2 but applies to a single channel only.

Returns a new image.

Parameters:

  • aChannelType (Magick::ChannelType)

    A ChannelType value.

  • black (Numeric) (defaults to: 0.0)

    A black point level in the range 0..QuantumRange.

  • white (Numeric) (defaults to: 1.0)

    A white point level in the range 0..QuantumRange.

  • gamma (Numeric) (defaults to: Magick::QuantumRange)

    A gamma correction in the range 0.0 - 10.0.

Returns:

See Also:



8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
# File 'ext/RMagick/rmimage.cpp', line 8556

VALUE
Image_level_channel(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    double black_point = 0.0, gamma_val = 1.0, white_point = (double)QuantumRange;
    ChannelType channel;
#if defined(IMAGEMAGICK_7)
    ExceptionInfo *exception;
#endif

    image = rm_check_destroyed(self);
    switch (argc)
    {
        case 1:             // take all the defaults
            break;
        case 2:
            black_point = NUM2DBL(argv[1]);
            white_point = QuantumRange - black_point;
            break;
        case 3:
            black_point = NUM2DBL(argv[1]);
            white_point = NUM2DBL(argv[2]);
            break;
        case 4:
            black_point = NUM2DBL(argv[1]);
            white_point = NUM2DBL(argv[2]);
            gamma_val   = NUM2DBL(argv[3]);
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc);
            break;
    }

    VALUE_TO_ENUM(argv[0], channel, ChannelType);

    new_image = rm_clone_image(image);

#if defined(IMAGEMAGICK_7)
    exception = AcquireExceptionInfo();
    BEGIN_CHANNEL_MASK(new_image, channel);
    GVL_STRUCT_TYPE(LevelImage) args = { new_image, black_point, white_point, gamma_val, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelImage), &args);
    END_CHANNEL_MASK(new_image);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);
#else
    GVL_STRUCT_TYPE(LevelImageChannel) args = { new_image, channel, black_point, white_point, gamma_val };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelImageChannel), &args);
    rm_check_image_exception(new_image, DestroyOnError);
#endif

    return rm_image_new(new_image);
}