示例#1
0
color ColorUtils_mix(const color *c1, const color *c2, double bias)
{
    if (bias <= 0.0) return *c1;
    if (bias >= 1.0) return *c2;
    if (isnan(bias)) return *c1;

    {
    double r = ColorUtils_mixQreal(FLOAT_COLOR(*c1, red),   FLOAT_COLOR(*c2, red),    bias);
    double g = ColorUtils_mixQreal(FLOAT_COLOR(*c1, green), FLOAT_COLOR(*c2, green), bias);
    double b = ColorUtils_mixQreal(FLOAT_COLOR(*c1, blue),  FLOAT_COLOR(*c2, blue),  bias);
    /*double a = ColorUtils_mixQreal(FLOAT_COLOR(*c1, alpha),   FLOAT_COLOR(*c2, alpha),   bias);*/

    return TO_COLOR(r, g, b);
    }
}
示例#2
0
		void fill_gradient_rect(const Rect* r, const Color* c1, const Color* c2, const Point* p1, const Point* p2)
		{ 
			Gdiplus::LinearGradientBrush* brush = new Gdiplus::LinearGradientBrush(TO_POINT(p1), TO_POINT(p2), TO_COLOR(c1), TO_COLOR(c2));
			graphics->FillRectangle(brush, TO_RECT(r));
			delete brush;
		}
示例#3
0
static color ColorUtils_HCY_toColor(ColorUtils_HCY *hcy)
{
    // start with sane component values
    double _h = ColorUtils_wrap(hcy->h);
    double _c = ColorUtils_normalize(hcy->c);
    double _y = ColorUtils_normalize(hcy->y);

    // calculate some needed variables
    double _hs = _h * 6.0, th, tm;
    if (_hs < 1.0) {
        th = _hs;
        tm = yc[0] + yc[1] * th;
    }
    else if (_hs < 2.0) {
        th = 2.0 - _hs;
        tm = yc[1] + yc[0] * th;
    }
    else if (_hs < 3.0) {
        th = _hs - 2.0;
        tm = yc[1] + yc[2] * th;
    }
    else if (_hs < 4.0) {
        th = 4.0 - _hs;
        tm = yc[2] + yc[1] * th;
    }
    else if (_hs < 5.0) {
        th = _hs - 4.0;
        tm = yc[2] + yc[0] * th;
    }
    else {
        th = 6.0 - _hs;
        tm = yc[0] + yc[2] * th;
    }

    // calculate RGB channels in sorted order
    double tn, to, tp;
    if (tm >= _y) {
        tp = _y + _y * _c * (1.0 - tm) / tm;
        to = _y + _y * _c * (th - tm) / tm;
        tn = _y - (_y * _c);
    }
    else {
        tp = _y + (1.0 - _y) * _c;
        to = _y + (1.0 - _y) * _c * (th - tm) / (1.0 - tm);
        tn = _y - (1.0 - _y) * _c * tm / (1.0 - tm);
    }

    // return RGB channels in appropriate order
    if (_hs < 1.0)
        return TO_COLOR(ColorUtils_HCY_igamma(tp), ColorUtils_HCY_igamma(to), ColorUtils_HCY_igamma(tn));
    else if (_hs < 2.0)
        return TO_COLOR(ColorUtils_HCY_igamma(to), ColorUtils_HCY_igamma(tp), ColorUtils_HCY_igamma(tn));
    else if (_hs < 3.0)
        return TO_COLOR(ColorUtils_HCY_igamma(tn), ColorUtils_HCY_igamma(tp), ColorUtils_HCY_igamma(to));
    else if (_hs < 4.0)
        return TO_COLOR(ColorUtils_HCY_igamma(tn), ColorUtils_HCY_igamma(to), ColorUtils_HCY_igamma(tp));
    else if (_hs < 5.0)
        return TO_COLOR(ColorUtils_HCY_igamma(to), ColorUtils_HCY_igamma(tn), ColorUtils_HCY_igamma(tp));
    else
        return TO_COLOR(ColorUtils_HCY_igamma(tp), ColorUtils_HCY_igamma(tn), ColorUtils_HCY_igamma(to));
}