Example #1
0
void ColorizeOperator::process(int tick)
{
    if (texture == 0)
        texture = new Texture();

    Texture* srcTexture = getInput(0)->texture;
    texture->lock();
    srcTexture->lock();

    float hue = getByteProperty(0) / 256.0f;
    float saturation = getByteProperty(1) / 256.0f ;
    float light = (getByteProperty(2) - 128) / 128.0f;

    for (int y = 0; y < 256; y++)
    {
        for (int x = 0; x < 256; x++)
        {
            float h, s, l;
            D3DCOLOR srcColor = srcTexture->getPixel(x, y);
            RGB2HSL(D3DCOLOR_R(srcColor),
                    D3DCOLOR_G(srcColor),
                    D3DCOLOR_B(srcColor),
                    h,
                    s,
                    l);
            int r, g, b;
            HSL2RGB(hue, saturation, l + light, r, g, b);
            texture->putPixel(x, y, D3DCOLOR_XRGB(r, g, b));
        }
    }

    texture->unlock();
    srcTexture->unlock();
    texture->setDirty();
}
Example #2
0
Color RGBAdjustHSL(Color col, double h, double s, double l) {
	ColorHSL hsl;
	Color rgb = col;
	hsl = RGB2HSL(rgb);
	hsl.h = hsl.h + h / 360.0;
	while (hsl.h > 1) hsl.h -= 1;
	while (hsl.h < 0) hsl.h += 1;
	hsl.s = hsl.s + s;
	if (hsl.s > 1) hsl.s = 1;
	if (hsl.s < 0) hsl.s = 0;
	hsl.l = hsl.l * l;
	if (hsl.l > 1) hsl.l = 1;
	if (hsl.l < 0) hsl.l = 0;
	rgb = HSL2RGB(hsl);
	rgb.alpha = col.alpha;
	return rgb;
}
bool is_in_range(guint8 * pixel, color l, color h, COLOR_SPACE space) {
    color c = make_color(pixel[0], pixel[1], pixel[2]);
    switch (space) {
    case COLOR_SPACE::HSL:
        c = RGB2HSL(c);
        break;
    case COLOR_SPACE::HSI:
        c = RGB2HSI(c);
        break;
    case COLOR_SPACE::HSV:
        c = RGB2HSV(c);
        break;
    case COLOR_SPACE::RGB:
        //we're good
        break;
    default:
        //invalid - throw exception?
        return false;
    };
    return
    (
        ( //hue
            ((l[0] < h[0]) && ( //low < high
                (c[0] >= l[0]) && (c[0] <= h[0])
            ))
            ||
            ((l[0] >= h[0]) && ( //low > high
                (c[0] >= l[0]) || (c[0] <= h[0])
            ))
        )
        &&
        ( //saturation
            (c[1] >= l[1]) && (c[1] <= h[1])
        )
        &&
        ( //value
            (c[2] >= l[2]) && (c[2] <= h[2])
        )
    );
}