Esempio n. 1
0
static status
toRBG(Int *r, Int *g, Int *b, Name model)
{ if ( isDefault(*r) || isDefault(*g) || isDefault(*b) )
    fail;

  if ( model == NAME_hsv )
  { int	ih = valInt(*r) % 360;
    int is = valInt(*g);
    int iv = valInt(*b);
    float R,G,B;

    if ( is > 100 )
      return errorPce(*g, NAME_unexpectedType, CtoType("0..100"));
    if ( iv > 100 )
      return errorPce(*g, NAME_unexpectedType, CtoType("0..100"));

    if ( ih < 0 )
      ih += 360;

    HSVToRGB((float)ih/360.0, (float)is/100.0, (float)iv/100.0,
	     &R, &G, &B);
    *r = toInt((int)(R*65535));
    *g = toInt((int)(G*65535));
    *b = toInt((int)(B*65535));
  }

  succeed;
}
Esempio n. 2
0
bool KnobModulo::setHSV(float h, float s, float v) {
    float r,g,b;
    HSVToRGB(h,s,v,&r,&g,&b);
    setColor(r, g, b);
}
Esempio n. 3
0
COLORREF COptionDialog::GetTitleColor(int Page) const
{
	return HSVToRGB((double)Page/(double)NUM_PAGES,0.4,0.9);
}
Esempio n. 4
0
KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coordinates, bool cursor)
{
    //qDebug() << this  << ">>>>>>>>> convertShapeCoordinateToKoColor()" << coordinates;

    KoColor c = m_d->currentColor;
    QVector <float> channelValues (c.colorSpace()->channelCount());
    channelValues.fill(1.0);
    c.colorSpace()->normalisedChannelsValue(c.data(), channelValues);
    QVector <float> channelValuesDisplay = channelValues;
    QVector <qreal> maxvalue(c.colorSpace()->channelCount());
    maxvalue.fill(1.0);

    if (m_d->displayRenderer
            && (m_d->colorSpace->colorDepthId() == Float16BitsColorDepthID
                || m_d->colorSpace->colorDepthId() == Float32BitsColorDepthID
                || m_d->colorSpace->colorDepthId() == Float64BitsColorDepthID)
            && m_d->colorSpace->colorModelId() != LABAColorModelID
            && m_d->colorSpace->colorModelId() != CMYKAColorModelID) {

        for (int ch = 0; ch < maxvalue.size(); ch++) {
            KoChannelInfo *channel = m_d->colorSpace->channels()[ch];
            maxvalue[ch] = m_d->displayRenderer->maxVisibleFloatValue(channel);
            channelValues[ch] = channelValues[ch]/(maxvalue[ch]);
            channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(ch, m_d->colorSpace->channels())] = channelValues[ch];
        }
    }
    else {
        for (int i =0; i < channelValues.size();i++) {
            channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(i, m_d->colorSpace->channels())] = qBound((float)0.0,channelValues[i], (float)1.0);
        }
    }

    qreal huedivider = 1.0;
    qreal huedivider2 = 1.0;

    if (m_d->channel1 == 0) {
        huedivider = 360.0;
    }

    if (m_d->channel2 == 0) {
        huedivider2 = 360.0;
    }

    if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") {

        if (m_d->model == ColorModel::HSV) {
            /*
             * RGBToHSV has a undefined hue possibility. This means that hue will be -1.
             * This can be annoying for dealing with a selector, but I understand it is being
             * used for the KoColorSelector... For now implement a qMax here.
             */
            QVector <float> inbetween(3);
            RGBToHSV(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
            inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
            inbetween[m_d->channel1] = coordinates.x()*huedivider;
            if (m_d->dimension == Dimensions::twodimensional) {
                inbetween[m_d->channel2] = coordinates.y()*huedivider2;
            }
            if (cursor) {
                setHSX(convertvectorfloatToqreal(inbetween));
                Q_EMIT sigHSXchange();
            }
            HSVToRGB(qMax(inbetween[0],(float)0.0), inbetween[1], inbetween[2], &channelValuesDisplay[0], &channelValuesDisplay[1], &channelValuesDisplay[2]);
        }
        else if (m_d->model == ColorModel::HSL) {
            /*
             * HSLToRGB can give negative values on the grey. I fixed the fromNormalisedChannel function to clamp,
             * but you might want to manually clamp for floating point values.
             */
            QVector <float> inbetween(3);
            RGBToHSL(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
            inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
            inbetween[m_d->channel1] = fmod(coordinates.x()*huedivider, 360.0);
            if (m_d->dimension == Dimensions::twodimensional) {
                inbetween[m_d->channel2] = coordinates.y()*huedivider2;
            }
            if (cursor) {
                setHSX(convertvectorfloatToqreal(inbetween));
                Q_EMIT sigHSXchange();
            }
            HSLToRGB(qMax(inbetween[0], (float)0.0), inbetween[1], inbetween[2], &channelValuesDisplay[0], &channelValuesDisplay[1], &channelValuesDisplay[2]);
        }
        else if (m_d->model == ColorModel::HSI) {
            /*
             * HSI is a modified HSY function.
             */
            QVector <qreal> chan2 = convertvectorfloatToqreal(channelValuesDisplay);
            QVector <qreal> inbetween(3);
            RGBToHSI(chan2[0],chan2[1], chan2[2], &inbetween[0], &inbetween[1], &inbetween[2]);
            inbetween = getHSX(inbetween);
            inbetween[m_d->channel1] = coordinates.x();
            if (m_d->dimension == Dimensions::twodimensional) {
                inbetween[m_d->channel2] = coordinates.y();
            }
            if (cursor) {
                setHSX(inbetween);
                Q_EMIT sigHSXchange();
            }
            HSIToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[0],&chan2[1], &chan2[2]);
            channelValuesDisplay = convertvectorqrealTofloat(chan2);
        }
        else /*if (m_d->model == ColorModel::HSY)*/ {
            /*
             * HSY is pretty slow to render due being a pretty over-the-top function.
             * Might be worth investigating whether HCY can be used instead, but I have had
             * some weird results with that.
             */
            QVector <qreal> luma= m_d->colorSpace->lumaCoefficients();
            QVector <qreal> chan2 = convertvectorfloatToqreal(channelValuesDisplay);
            QVector <qreal> inbetween(3);
            RGBToHSY(chan2[0],chan2[1], chan2[2], &inbetween[0], &inbetween[1], &inbetween[2],
                    luma[0], luma[1], luma[2]);
            inbetween = getHSX(inbetween);
            inbetween[m_d->channel1] = coordinates.x();
            if (m_d->dimension == Dimensions::twodimensional) {
                inbetween[m_d->channel2] = coordinates.y();
            }
            if (cursor) {
                setHSX(inbetween);
                Q_EMIT sigHSXchange();
            }
            HSYToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[0],&chan2[1], &chan2[2],
                    luma[0], luma[1], luma[2]);
            channelValuesDisplay = convertvectorqrealTofloat(chan2);
        }

    }
    else {
        channelValuesDisplay[m_d->channel1] = coordinates.x();
        if (m_d->dimension == Dimensions::twodimensional) {
            channelValuesDisplay[m_d->channel2] = coordinates.y();
        }
    }

    for (int i=0; i<channelValues.size();i++) {
        channelValues[i] = channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(i, m_d->colorSpace->channels())]*(maxvalue[i]);
    }

    c.colorSpace()->fromNormalisedChannelsValue(c.data(), channelValues);

    return c;
}
Esempio n. 5
0
    void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const
    {

        //if (m_model="RGBA" || m_colorize) {
        /*It'd be nice to have LCH automatically selector for LAB in the future, but I don't know how to select LAB 
         * */
            const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8);
            RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8);
            float h, s, v, r, g, b;
            qreal lumaR, lumaG, lumaB;
            //Default to rec 709 when there's no coefficients given//
            if (m_lumaRed<=0 || m_lumaGreen<=0 || m_lumaBlue<=0) {
                lumaR   = 0.2126;
                lumaG   = 0.7152;
                lumaB   = 0.0722;
            } else {
                lumaR   = m_lumaRed;
                lumaG   = m_lumaGreen;
                lumaB   = m_lumaBlue;
            }
            while (nPixels > 0) {

                if (m_colorize) {
                    h = m_adj_h * 360;
                    if (h >= 360.0) h = 0;

                    s = m_adj_s;

                    r = SCALE_TO_FLOAT(src->red);
                    g = SCALE_TO_FLOAT(src->green);
                    b = SCALE_TO_FLOAT(src->blue);

                    float luminance = r * lumaR + g * lumaG + b * lumaB;

                    if (m_adj_v > 0) {
                        luminance *= (1.0 - m_adj_v);
                        luminance += 1.0 - (1.0 - m_adj_v);
                    }
                    else if (m_adj_v < 0 ){
                        luminance *= (m_adj_v + 1.0);
                    }
                    v = luminance;
                    HSLToRGB(h, s, v, &r, &g, &b);

                }
                else {

                    if (m_type == 0) {
                        RGBToHSV(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v);
                        h += m_adj_h * 180;
                        if (h > 360) h -= 360;
                        if (h < 0) h += 360;
                        s += m_adj_s;
                        v += m_adj_v;
                        HSVToRGB(h, s, v, &r, &g, &b);
                    } else if (m_type == 1) {

                        RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v);

                        h += m_adj_h * 180;
                        if (h > 360) h -= 360;
                        if (h < 0) h += 360;

                        s *= (m_adj_s + 1.0);
                        if (s < 0.0) s = 0.0;
                        if (s > 1.0) s = 1.0;

                        if (m_adj_v < 0)
                            v *= (m_adj_v + 1.0);
                        else
                            v += (m_adj_v * (1.0 - v));


                        HSLToRGB(h, s, v, &r, &g, &b);
                    } else if (m_type == 2){

                        qreal red = SCALE_TO_FLOAT(src->red);
                        qreal green = SCALE_TO_FLOAT(src->green);
                        qreal blue = SCALE_TO_FLOAT(src->blue);
                        qreal hue, sat, intensity;
                        RGBToHCI(red, green, blue, &hue, &sat, &intensity);

                        hue *=360.0;
                        hue += m_adj_h * 180;
                        //if (intensity+m_adj_v>1.0){hue+=180.0;}
                        if (hue < 0) hue += 360;
                        hue = fmod(hue, 360.0);

                        sat *= (m_adj_s + 1.0);
                        //sat = qBound(0.0, sat, 1.0);
                        
                        intensity += (m_adj_v);

                        HCIToRGB(hue/360.0, sat, intensity, &red, &green, &blue);

                        r = red;
                        g = green;
                        b = blue;
                    } else if (m_type == 3){

                        qreal red = SCALE_TO_FLOAT(src->red);
                        qreal green = SCALE_TO_FLOAT(src->green);
                        qreal blue = SCALE_TO_FLOAT(src->blue);
                        qreal hue, sat, luma;
                        RGBToHCY(red, green, blue, &hue, &sat, &luma, lumaR, lumaG, lumaB);

                        hue *=360.0;
                        hue += m_adj_h * 180;
                        //if (luma+m_adj_v>1.0){hue+=180.0;}
                        if (hue < 0) hue += 360;
                        hue = fmod(hue, 360.0);

                        sat *= (m_adj_s + 1.0);
                        //sat = qBound(0.0, sat, 1.0);

                        luma += m_adj_v;


                        HCYToRGB(hue/360.0, sat, luma, &red, &green, &blue, lumaR, lumaG, lumaB);
                        r = red;
                        g = green;
                        b = blue;
                        
                    } else if (m_type == 4){

                        qreal red = SCALE_TO_FLOAT(src->red);
                        qreal green = SCALE_TO_FLOAT(src->green);
                        qreal blue = SCALE_TO_FLOAT(src->blue);
                        qreal y, cb, cr;
                        RGBToYUV(red, green, blue, &y, &cb, &cr, lumaR, lumaG, lumaB);

                        cb *= (m_adj_h + 1.0);
                        //cb = qBound(0.0, cb, 1.0);

                        cr *= (m_adj_s + 1.0);
                        //cr = qBound(0.0, cr, 1.0);

                        
                        
                        y += (m_adj_v);


                        YUVToRGB(y, cb, cr, &red, &green, &blue, lumaR, lumaG, lumaB);
                        r = red;
                        g = green;
                        b = blue;
                    }
                }

                clamp< _channel_type_ >(&r, &g, &b);
                dst->red = SCALE_FROM_FLOAT(r);
                dst->green = SCALE_FROM_FLOAT(g);
                dst->blue = SCALE_FROM_FLOAT(b);
                dst->alpha = src->alpha;

                --nPixels;
                ++src;
                ++dst;
            }
        /*} else if (m_model="LABA"){
            const LABPixel* src = reinterpret_cast<const LABPixel*>(srcU8);
            LABPixel* dst = reinterpret_cast<LABPixel*>(dstU8);
            qreal lightness = SCALE_TO_FLOAT(src->L);
            qreal a = SCALE_TO_FLOAT(src->a);
            qreal b = SCALE_TO_FLOAT(src->b);
            qreal L, C, H;
            
            while (nPixels > 0) {
                if (m_type = 4) {
                    a *= (m_adj_h + 1.0);
                    a = qBound(0.0, a, 1.0);

                    b *= (m_adj_s + 1.0);
                    b = qBound(0.0, b, 1.0);

                    if (m_adj_v < 0)
                        lightness *= (m_adj_v + 1.0);
                    else
                        lightness += (m_adj_v * (1.0 - lightness));
                } else {//lch
                    LABToLCH(lightness, a, b, &L, &C, &H);
                    H *=360;
                    H += m_adj_h * 180;
                    if (H > 360) h -= 360;
                    if (H < 0) h += 360;
                    C += m_adj_s;
                    C = qBound(0.0,C,1.0);
                    L += m_adj_v;
                    L = qBound(0.0,L,1.0);
                    LCHToLAB(L, C, H/360.0, &lightness, &a, &b);
                }
                clamp< _channel_type_ >(&lightness, &a, &b);
                dst->L = SCALE_FROM_FLOAT(lightness);
                dst->a = SCALE_FROM_FLOAT(a);
                dst->b = SCALE_FROM_FLOAT(b);
                dst->alpha = src->alpha;

                --nPixels;
                ++src;
                ++dst;
                }
        }*/
    }
Esempio n. 6
0
void BuildLeafPolygons(bsptree_t *tree)
{
	bspnode_t *leaf;

	FILE *fp = fopen("leaf_polygons.gld", "w");

	int leafnum = 0;
	for (leaf = tree->leafs; leaf; leaf = leaf->leafnext)
	{
		polygon_t *p = MakeLeafPolygon(leaf);

		if (!p)
		{
			printf("leaf was clipped away!\n");
			continue;
		}

		{
			float f = (float)leafnum / tree->numleafs;
			//f *= 10.0f;
			//f = f - floor(f);

			float rgb[3];
			HSVToRGB(rgb, f, 1.0f, 1.0f);
			float grey = (0.33f * rgb[0]) + (0.33f * rgb[1]) + (0.33f * rgb[2]);
			//fprintf(fp, "color %f %f %f 1\n", rgb[0], rgb[1], rgb[2]);
			fprintf(fp, "color %f %f %f 1\n", grey, grey, grey);

			//fprintf(fp, "color 1 0 0 1\n");
		}
	
		//if(leaf->empty)
		//	continue;

		if (leaf->empty)
			continue;

		if (leaf->empty)
			fprintf(fp, "polyline\n");
		else
			fprintf(fp, "polygon\n");

		fprintf(fp, "%i\n", p->numvertices + 1);

		for (int i = 0; i < p->numvertices + 1; i++)
		{
			vec2 v = p->vertices[i % p->numvertices];

#if 0			
			{
				vec2 center = Polygon_BoundingBox(p).Center();
				v = center + (0.95f * (v - center));
			}
#endif			

			fprintf(fp, "%f %f 0\n",
					v[0],
					v[1]);
		}

		fflush(fp);

		leafnum++;
	}

	fclose(fp);
}
Esempio n. 7
0
Color Color::Convert(COLOR_SOURCE target)
{
	double in[4], out[4];
	if(m_source == target){
		return *this;
	}
	for(int i=0;i<4;i++){
			in[i]  = m_val[i];
			out[i] = 0.0;
		}
	if(m_source == COLOR_SOURCE_WHEEL){
        switch (m_wheelType) {
            case WHEEL_TYPE_HSV:
            {
                Vector tmp = HSVToRGB(Vector(in[0],in[1],in[2]));
                in[0] = tmp.x; in[1] = tmp.y; in[2] = tmp.z;
            }
            break;
            case WHEEL_TYPE_HSB:
            {
                Vector tmp = HSLtoRGB(Vector(in[0],in[1],in[2]));
                in[0] = tmp.x; in[1] = tmp.y; in[2] = tmp.z;
            }
                break;
            case WHEEL_TYPE_LCH:
            {
                double tmp[] = {in[0],in[1],in[2]};
                in[0] = tmp[2]*100.0;
#ifdef _WINDOWS
                in[1] = tmp[1]*cos(tmp[0]*M_PI_2)*128.0;
                in[2] = tmp[1]*sin(tmp[0]*M_PI_2)*128.0;
#else
				in[1] = tmp[1]*cos(tmp[0]*M_PI_2)*128.0;
                in[2] = tmp[1]*sin(tmp[0]*M_PI_2)*128.0;
#endif
            }
            break;
                
        }
		if(target == COLOR_SOURCE_RGB)     cmsDoTransform(m_wheelToRGB,     in, out, 1);
		if(target == COLOR_SOURCE_CMYK)    cmsDoTransform(m_wheelToCMYK,    in, out, 1);
		if(target == COLOR_SOURCE_DISPLAY) cmsDoTransform(m_wheelToDisplay, in, out, 1);
        if(target == COLOR_SOURCE_LAB)     cmsDoTransform(m_wheelToLAB,     in, out, 1);
	}
	if(m_source == COLOR_SOURCE_RGB){
		if(target == COLOR_SOURCE_WHEEL)   cmsDoTransform(m_RGBToWheel,     in, out, 1);
		if(target == COLOR_SOURCE_CMYK)    cmsDoTransform(m_RGBToCMYK,      in, out, 1);
		if(target == COLOR_SOURCE_DISPLAY) cmsDoTransform(m_RGBToDisplay,   in, out, 1);
        if(target == COLOR_SOURCE_LAB)     cmsDoTransform(m_RGBToLAB,       in, out, 1);
	}
	if(m_source == COLOR_SOURCE_CMYK){
		if(target == COLOR_SOURCE_WHEEL)   cmsDoTransform(m_CMYKToWheel,    in, out, 1);
		if(target == COLOR_SOURCE_RGB)     cmsDoTransform(m_CMYKToRGB,      in, out, 1);
		if(target == COLOR_SOURCE_DISPLAY) cmsDoTransform(m_CMYKToDisplay,  in, out, 1);
        if(target == COLOR_SOURCE_LAB)     cmsDoTransform(m_CMYKToLAB,      in, out, 1);
	}
	if(m_source == COLOR_SOURCE_DISPLAY){
		if(target == COLOR_SOURCE_WHEEL)   cmsDoTransform(m_displayToWheel, in, out, 1);
		if(target == COLOR_SOURCE_RGB)     cmsDoTransform(m_displayToRGB,   in, out, 1);
		if(target == COLOR_SOURCE_CMYK)    cmsDoTransform(m_displayToCMYK,  in, out, 1);
        if(target == COLOR_SOURCE_LAB)     cmsDoTransform(m_displayToLAB,   in, out, 1);
	}
    if(m_source == COLOR_SOURCE_LAB){
        if(target == COLOR_SOURCE_RGB)     cmsDoTransform(m_LABToRGB,       in, out, 1);
		if(target == COLOR_SOURCE_WHEEL)   cmsDoTransform(m_LABToWheel,     in, out, 1);
		if(target == COLOR_SOURCE_DISPLAY) cmsDoTransform(m_LABToDisplay,   in, out, 1);
		if(target == COLOR_SOURCE_CMYK)    cmsDoTransform(m_LABToCMYK,      in, out, 1);
	}
	if(target == COLOR_SOURCE_WHEEL){
        switch (m_wheelType) {
            case WHEEL_TYPE_HSV:
                {
                    Vector tmp = RGBToHSV(Vector(out[0],out[1],out[2]));
                    out[0] = tmp.x;out[1] = tmp.y;out[2] = tmp.z;
                }
                break;
            case WHEEL_TYPE_HSB:
            {
                Vector tmp = RGBToHSL(Vector(out[0],out[1],out[2]));
                out[0] = tmp.x;out[1] = tmp.y;out[2] = tmp.z;
            }
                break;
            case WHEEL_TYPE_LCH:
                {
                    double tmp[] = {out[0],out[1],out[2]};
                    out[1] = Sqrt(tmp[1]*tmp[1] + tmp[2]*tmp[2])/128.0;
#ifdef _WINDOWS
                    out[0] = ATan2(tmp[2], tmp[1])/M_PI_2;
#else
                    out[0] = ATan2(tmp[2], tmp[1])/M_PI_2;
#endif
                    while(out[0] < 0.0){
                        out[0] += 1.0;
                    }
                    while(out[0] > 1.0){
                        out[0] -= 1.0;
                    }
                    out[2] = tmp[0]/100.0;
                }
                break;
                
        }
		
	}
	return Color(out[0], out[1], out[2], out[3]).SetSource(target);
}