Example #1
0
void DrawAni::applyHSL(NDPicture* picture, const AniModify* mod_lev2)
{
	if (!picture || !mod_lev2)
		return;

	// apply HSL (only lev2)
	const HSL_Modify& mod = mod_lev2->m_KHSLModify;
	if (mod.isValid())
	{
		if (mod.isModeSet())
		{
			COLOR_RGB rgb;
			COLOR_HSL hsl(mod.h, mod.s, mod.l);
			HSLtoRGB(hsl, rgb);
			picture->SetMaskColor(ccc4(rgb.red, rgb.green, rgb.blue, 255));
		}
		else if (mod.isModeAdd())
		{
			ccColor4B cr = picture->getMaskColor();
			COLOR_RGB rgb(cr.r, cr.g, cr.b);
			COLOR_HSL hsl;
			RGBtoHSL(rgb, hsl);

			COLOR_HSL ofs(mod.h, mod.s, mod.l);
			hsl.add(ofs);
			HSLtoRGB(hsl, rgb);

			picture->SetMaskColor(ccc4(rgb.red, rgb.green, rgb.blue, 255));
		}
	}
}
Example #2
0
// 初始化颜色
void InitColor()
{
    // 使用 HSL 颜色模式产生角度 h1 到 h2 的渐变色
    int h1 = 240, h2 = 30;
    for(int i=0; i<MAXCOLOR/2; i++)
    {
        Color[i] = HSLtoRGB((float)h1, 1.0f, i * 2.0f / MAXCOLOR);
        Color[MAXCOLOR-1-i] = HSLtoRGB((float)h2, 1.0f, i * 2.0f / MAXCOLOR);
    }
}
Example #3
0
long CxImage::Histogram(long* red, long* green, long* blue, long* gray, long colorspace)
{
	if (!pDib) return 0;
	RGBQUAD color;

	if (red) memset(red,0,256*sizeof(long));
	if (green) memset(green,0,256*sizeof(long));
	if (blue) memset(blue,0,256*sizeof(long));
	if (gray) memset(gray,0,256*sizeof(long));

	long xmin,xmax,ymin,ymax;
	if (pSelection){
		xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right;
		ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top;
	} else {
		xmin = ymin = 0;
		xmax = head.biWidth; ymax=head.biHeight;
	}

	for(long y=ymin; y<ymax; y++){
		for(long x=xmin; x<xmax; x++){
#if CXIMAGE_SUPPORT_SELECTION
			if (SelectionIsInside(x,y))
#endif //CXIMAGE_SUPPORT_SELECTION
			{
				switch (colorspace){
				case 1:
					color = HSLtoRGB(GetPixelColor(x,y));
					break;
				case 2:
					color = YUVtoRGB(GetPixelColor(x,y));
					break;
				case 3:
					color = YIQtoRGB(GetPixelColor(x,y));
					break;
				case 4:
					color = XYZtoRGB(GetPixelColor(x,y));
					break;
				default:
					color = GetPixelColor(x,y);
				}

				if (red) red[color.rgbRed]++;
				if (green) green[color.rgbGreen]++;
				if (blue) blue[color.rgbBlue]++;
				if (gray) gray[(BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue)]++;
			}
		}
	}

	long n=0;
	for (int i=0; i<256; i++){
		if (red && red[i]>n) n=red[i];
		if (green && green[i]>n) n=green[i];
		if (blue && blue[i]>n) n=blue[i];
		if (gray && gray[i]>n) n=gray[i];
	}

	return n;
}
Example #4
0
BOOL dibFilterEFFECT::AdjustHSL(int degHue,int perSaturation,int perLuminosity)
{
	if(!m_rdib->Data())
   	return FALSE;

	if(perSaturation < 0 || perLuminosity < 0)
		return FALSE;

	if(degHue == 0 && perSaturation == 100 && perLuminosity == 100)
		return TRUE;	//未作调整,直接返回
		
   LPBYTE pRed, pGrn, pBlu,pBuf=(LPBYTE)m_rdib->Data();
	UINT loop = m_rdib->Width() * m_rdib->Height();
	COLORREF *cr = (COLORREF*)m_rdib->Data();
   
   pRed=pBuf++;pGrn=pBuf++;pBlu=pBuf;	
	float H,S,L;

	for (UINT i=0;i<loop;i++)
	{
		RGBtoHSL(*pRed,*pGrn,*pBlu,&H,&S,&L);

		H += degHue;
      S = (S*perSaturation/100.0f);
		L = (L*perLuminosity/100.0f);

      *cr = HSLtoRGB(H,S,L);

		pRed+=4;
      pGrn+=4;
      pBlu+=4;
		cr ++;
	}
	return TRUE;
}
Example #5
0
void sepiaColor(int nx, int ny, RGB_PIXEL *pixM)
{
    // Variables
    int ix, iy, kp = 0;
   
    struct ColorRGB rgb;
    struct ColorHSL hsl;
    
    
    for (iy  =  0; iy < ny; iy++) {
        for (ix  =  0; ix < nx; ix++) {
            // Calculate the sepia color
            hsl = RGBtoHSL(pixM[kp].red,pixM[kp].green,pixM[kp].blue);
            rgb = HSLtoRGB (35,hsl.S,hsl.L);
            printf("\n[%d,%f,%f] -> [%d,%d,%d]",hsl.H,hsl.S,hsl.L,rgb.r,rgb.g,rgb.b);
                
            // Modified the hsl color
            pixM[kp].blue = rgb.b < 255 ? rgb.b : 255;
            pixM[kp].green = rgb.g< 255 ? rgb.g : 255;
            pixM[kp].red = rgb.r < 255 ? rgb.r : 255;
                
            kp++;
        }
    }
}
Example #6
0
static void HSLtoRGB24( LPRGB lpSrc, int iCount )
{
	while (--iCount >= 0)
	{
		HSLtoRGB(lpSrc->red, lpSrc->green, lpSrc->blue, lpSrc);
		++lpSrc;
	}
}
Example #7
0
File: slock.c Project: eepp/slock
static void gen_random_pastel(XColor* color, unsigned int hue) {
	unsigned int sat = 60, val = 55, r, g, b;

	HSLtoRGB(hue, sat, val, &r, &g, &b);

	color->red = (unsigned short) (r << 8);
	color->green = (unsigned short) (g << 8);
	color->blue = (unsigned short) (b << 8);
}
Example #8
0
//--------------------------------------------------------------------------
unsigned int colorvargen_t::get_color()
{
  if (l <= L_END)
    return 0;

  unsigned int old_l = l;
  l += L_INT;

  return HSLtoRGB(bRealRgb, h, s, old_l);
}
Example #9
0
unsigned int BrightenColor(unsigned int color,unsigned int amount)
{
	unsigned int h,s,l;

	RGBtoHSL(color,h,s,l);
	l+=amount;
	if ( l > 100 )
	{
		l = 100;
	}
	return HSLtoRGB(h,s,l);
}
Example #10
0
unsigned int DarkenColor(unsigned int color,unsigned int amount)
{
	unsigned int h,s,l;

	RGBtoHSL(color,h,s,l);
	if ( amount >= l )
	{
		l = 0;
	}
	else
	{
		l-=amount;
	}
	return HSLtoRGB(h,s,l);
}
Example #11
0
void ColorSpace::HSLtoRGB (CoImage* pIn, CoImage* pOut)
{
	assert (pIn->GetType() == MAT_Tfloat);
	assert (pOut->GetType() == MAT_Tbyte);
	float* prH = pIn->m_matX.data.fl[0];
	float* prS = pIn->m_matY.data.fl[0];
	float* prL = pIn->m_matZ.data.fl[0];
	
	BYTE* pbR = pOut->m_matX.data.ptr[0];
	BYTE* pbG = pOut->m_matY.data.ptr[0];
	BYTE* pbB = pOut->m_matZ.data.ptr[0];
	
	for (int i = 0; i < pIn->GetHeight() * pIn->GetWidth(); i ++)
	{
		HSLtoRGB(prH[i], prS[i], prL[i], &pbR[i], &pbG[i], &pbB[i]);
	}
}
Example #12
0
/**
 * \fn void newtonDrawRoots(complex *roots, complex z, int power, int x, int y, int iteration, int maxIterations);
 * \brief Dessine et colorie les racines du polynome.
 * 
 * \param *roots Tableau stockant les racines du polynome
 * \param z Suite complexe
 * \param power Degré du polynome
 * \param x Position horizontale du pixel
 * \param y Position verticale du pixel
 * \param iterations Nombre d'itérations qui à été utilisé pour calculer la suite
 * \return Rien
 */
void newtonDrawRoots(	complex *roots,
			complex z,
			int power,
			int x,
			int y,
			int iteration,
			int maxIterations)
{
	int i;
	double angle;
	colorRGB cRGB;
	colorHSL cHSL;
	
	
	
	double deltaIter = (double)(iteration)/(maxIterations);
	deltaIter = 1 - deltaIter;
	
	/* La luminosité est en fonction du nombre d'itérations */
	cHSL.saturation = 1.0;    /* entre 0 et 1*/
	cHSL.lightness = 0.5  * deltaIter ;    /* entre 0 et 0.5 et 1*/
	
	
	/* On teste chaque racine, pour retrouver pour laquelle z converge vers */
	for (i = 0; i < power; i++)
	{
		/* Des qu'on trouve la racine où z converge vers */
		if(complexAbs(complexDif(z,roots[i])) < FRACTAL_NEWTON_PRECISION)
		{
			/* L'angle est la position de la racine sur le cercle colorimétrique */
			angle = (double)i/power;
			/* Ainsi cela nous donne la valeur de la teinte */
			cHSL.hue = angle;
			/* On converti vers le RVB pour OpenGL */
			cRGB = HSLtoRGB(cHSL);
			/* On charge la couleur */
			glColor3ub( cRGB.red , cRGB.green, cRGB.blue);
			/* On dessine le point */
			glVertex2f(x,y);
		}
		
	}
	
}
Example #13
0
//绘制基本的含空隙的正方形
void drawSquare(int playerNum, Point pt, COLORREF clr, int mode1, int mode2)
{
    setorigin(0, 0);
    int i, j;
    int X = 0, Y = 0;
    float h, s, l, val,val1, val2;

    if(mode2 == NORMAL)	X = g_player[playerNum].area.areaPoint.x, Y = g_player[playerNum].area.areaPoint.y;
    else 	X = g_player[playerNum].preview.x, Y = g_player[playerNum].preview.y;
    if(mode1 == NORMAL)
    {


        RGBtoHSL(clr, &h, &s, &l);
	//	l=(float)(l*1.3);//调高亮度
        for(i = 0; i <= BLOCK_SIZE; i++)
            for(j = 0; j <= BLOCK_SIZE; j++)
            {
             /*   val1 = (float)i / BLOCK_SIZE;
                val2 = (float)j / BLOCK_SIZE;
                val = (val1 + val2) / 2;
				 putpixel(X + (pt.x - 1)*BLOCK_SIZE + i , Y + (pt.y - 1) * BLOCK_SIZE + j , HSLtoRGB(h, val, l));
				*/


				 val1 = (float)i / BLOCK_SIZE;
                val2 = (float)j / BLOCK_SIZE;
                val = (val1 + val2) / 2;
                putpixel(X + (pt.x - 1)*BLOCK_SIZE + i , Y + (pt.y - 1) * BLOCK_SIZE + j , HSLtoRGB(h, s,val));
            }

    }
    else
    {
        int x, y;
        x = (pt.x - 1) * BLOCK_SIZE + X;
        y = (pt.y - 1) * BLOCK_SIZE + Y;
        recoverBk(x, y, BLOCK_SIZE + 1, BLOCK_SIZE + 1);
    }
}
Example #14
0
RGBQUAD CxDib::HSLtoRGB(COLORREF cHSLColor)
{
	return HSLtoRGB(RGB2RGBQUAD(cHSLColor));
}
Example #15
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);
}
Example #16
0
bool CxImage::Vibrance(long strength)
{
	long xmin,xmax,ymin,ymax;
	if (pSelection){
		xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right;
		ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top;
	} else {
		xmin = ymin = 0;
		xmax = head.biWidth - 1; ymax=head.biHeight - 1;
	}

	if (xmin==xmax || ymin==ymax)
		return false;

	int size = (xmax - xmin + 1) * (ymax - ymin + 1);
	int histDistrib[256];
	::memset(histDistrib,0,256 * sizeof(int));
	BYTE maxSat = 0;
	for(long y=ymin; y<=ymax; y++){
		info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
		if (info.nEscape) break;
		for(long x=xmin; x<=xmax; x++){
#if CXIMAGE_SUPPORT_SELECTION
			if (BlindSelectionIsInside(x,y))
#endif //CXIMAGE_SUPPORT_SELECTION
			{
				BYTE curSat = RGBtoHSL(BlindGetPixelColor(x,y)).rgbGreen;
				histDistrib[curSat]++;
				if (curSat > maxSat)
					maxSat = curSat;
			}
		}
	}

	BYTE ceilSat = (BYTE)min((int)maxSat + strength, 250);
	BYTE cTable[256];
	float fCurCum = 0.0f;
	float fStdDev = 0.0f;
	float fCumDistrib[256];
	for (int i=0;i<256;i++)	{
		cTable[i] = (BYTE)max(0,min((int)ceilSat,i + strength) - i);
		fStdDev += pow((float)size / 2.0f - (float)histDistrib[i], 2.0f);
		fCurCum += (float)histDistrib[i] / (float)size;		
		fCumDistrib[i] = max(0.0f, fCurCum);
	}
	fStdDev = (sqrt(fStdDev) / (float)size) * 255.0f;
	for (int i=0;i<256;i++)
		cTable[i] = (BYTE)(fCumDistrib[i] * (float)cTable[i] * CxMath::NormalDistrib (127.0f, fStdDev, (float)i, false));
	for(long y=ymin; y<=ymax; y++){
		info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
		if (info.nEscape) break;
		for(long x=xmin; x<=xmax; x++){
#if CXIMAGE_SUPPORT_SELECTION
			if (BlindSelectionIsInside(x,y))
#endif //CXIMAGE_SUPPORT_SELECTION
			{
				RGBQUAD c = RGBtoHSL(BlindGetPixelColor(x,y));
				BYTE curSat = c.rgbGreen;
				c.rgbGreen = (BYTE)min((int)ceilSat, (int)curSat + (int)cTable[curSat]);
				c = HSLtoRGB(c);
				BlindSetPixelColor(x,y,c);
			}
		}
	}
	return true;
}