Method: Magick::Image#levelize_channel

Defined in:
ext/RMagick/rmimage.cpp

#levelize_channel(black_point, white_point = Magick::QuantumRange-black_point, gamma = 1.0, channel = Magick::AllChannels) ⇒ Magick::Image #levelize_channel(black_point, white_point = Magick::QuantumRange-black_point, gamma = 1.0, *channels) ⇒ Magick::Image

Maps black and white to the specified points. The reverse of #level_channel.

Overloads:

  • #levelize_channel(black_point, white_point = Magick::QuantumRange-black_point, gamma = 1.0, channel = Magick::AllChannels) ⇒ Magick::Image

    Parameters:

    • black (Numeric)

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

    • white (Numeric)

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

    • gamma (Numeric) (defaults to: 1.0)

      A gamma correction in the range 0.0 - 10.0.

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

      a ChannelType arguments.

  • #levelize_channel(black_point, white_point = Magick::QuantumRange-black_point, gamma = 1.0, *channels) ⇒ Magick::Image

    Parameters:

    • black (Numeric)

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

    • white (Numeric)

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

    • gamma (Numeric) (defaults to: 1.0)

      A gamma correction in the range 0.0 - 10.0.

    • *channels (Magick::ChannelType)

      one or more ChannelType arguments.

Returns:



8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
# File 'ext/RMagick/rmimage.cpp', line 8718

VALUE
Image_levelize_channel(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    ChannelType channels;
    double black_point, white_point;
    double gamma = 1.0;
    MagickBooleanType okay;
#if defined(IMAGEMAGICK_7)
    ExceptionInfo *exception;
#endif

    image = rm_check_destroyed(self);
    channels = extract_channels(&argc, argv);
    if (argc > 3)
    {
        raise_ChannelType_error(argv[argc-1]);
    }

    switch (argc)
    {
        case 3:
            gamma = NUM2DBL(argv[2]);
        case 2:
            white_point = NUM2DBL(argv[1]);
            black_point = NUM2DBL(argv[0]);
            break;
        case 1:
            black_point = NUM2DBL(argv[0]);
            white_point = QuantumRange - black_point;
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or more)", argc);
            break;
    }

    new_image = rm_clone_image(image);

#if defined(IMAGEMAGICK_7)
    exception = AcquireExceptionInfo();
    BEGIN_CHANNEL_MASK(new_image, channels);
    GVL_STRUCT_TYPE(LevelizeImage) args = { new_image, black_point, white_point, gamma, exception };
    void *ret = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelizeImage), &args);
    okay = static_cast<MagickBooleanType>(reinterpret_cast<intptr_t &>(ret));
    END_CHANNEL_MASK(new_image);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);
#else
    GVL_STRUCT_TYPE(LevelizeImageChannel) args = { new_image, channels, black_point, white_point, gamma };
    void *ret = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelizeImageChannel), &args);
    okay = static_cast<MagickBooleanType>(reinterpret_cast<intptr_t &>(ret));
    rm_check_image_exception(new_image, DestroyOnError);
#endif

    if (!okay)
    {
        rb_raise(rb_eRuntimeError, "LevelizeImageChannel failed for unknown reason.");
    }
    return rm_image_new(new_image);
}