Skip to content

IL.ClearColour broken #12

Description

@tobim-zz

In 1.7.8 the underlying function ilClearColour expects color values as floating point factors (0.0 - 1.0), but the ruby wrapper is handing it bytes.

Setting the background color to some basic colors like black/white or a solid red or green actually works, as every color value above zero will be clamped to 1.0. Values in the 0x01-0xfe range will be treated as if 0xff was provided, hence setting wrong colors when used.

In example #120034 produces #FF00FF, orange #e6762b will set the clear color to white #FFFFFF.

I was unable to download older DevIL versions, so don't know if this also applies to earlier versions. Edit: Same applies to DevIL 1.1.1


DevIL 1.7.8 - src-IL/src/il_devil.c - Lines 251-268:

void ILAPIENTRY ilClearColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha)
{
    // Clamp to 0.0f - 1.0f.
    ClearRed    = Red < 0.0f ? 0.0f : (Red > 1.0f ? 1.0f : Red);
    ClearGreen  = Green < 0.0f ? 0.0f : (Green > 1.0f ? 1.0f : Green);
    ClearBlue   = Blue < 0.0f ? 0.0f : (Blue > 1.0f ? 1.0f : Blue);
    ClearAlpha  = Alpha < 0.0f ? 0.0f : (Alpha > 1.0f ? 1.0f : Alpha);

    if ((Red == Green) && (Red == Blue) && (Green == Blue)) {
        ClearLum = Red < 0.0f ? 0.0f : (Red > 1.0f ? 1.0f : Red);
    }
    else {
        ClearLum = 0.212671f * ClearRed + 0.715160f * ClearGreen + 0.072169f * ClearBlue;
        ClearLum = ClearLum < 0.0f ? 0.0f : (ClearLum > 1.0f ? 1.0f : ClearLum);
    }

    return;
}

rdevil - /ext/devil/ruby_il.c - Lines 362-372:

static VALUE il_ClearColour(VALUE obj, VALUE rb_red, VALUE rb_green, VALUE rb_blue, VALUE rb_alpha)
{
    ILubyte red = NUM2INT(rb_red);
    ILubyte green = NUM2INT(rb_green);
    ILubyte blue = NUM2INT(rb_blue);
    ILubyte alpha = NUM2INT(rb_alpha);

    ilClearColour(red, green, blue, alpha);

    return Qnil;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions