Exemplo n.º 1
0
/******************************************************************************
  FUNCTION: ColorScaleHSL
  PURPOSE:     Returns the HSL linear interpolated color between 2 colors
            (more natural looking than RGB interpolation)
               For instance if the luminance is the same in Col1 and Col2,
                   then the luminance of the result will be the same
               If Ratio=0, you get Col1,
             If Ratio=1, you get Col2
  IN: Col1: low color in hex 0xBBGGRR format
        Col2: high color in hex 0xBBGGRR format
        Ratio: 0 for low color, 1 for high color, or in between
  EXAMPLE: Col1=0, Col2=0xFF00FF, Ratio=0.5 returns 0x1F5F3F
******************************************************************************/
COLORREF ColorScaleHSL(    const COLORREF Col1, const COLORREF Col2, const double Ratio)
{
    static double H1, H2, S1, S2, L1, L2;

    if (Ratio<=0) return Col1;    // Ratio parameter must be between 0 and 1
    else if (Ratio>=1) return Col2;

    RGBtoHLS( Col1, &H1, &L1, &S1);
    RGBtoHLS( Col2, &H2, &L2, &S2);
    return HLStoRGB( H1+(H2-H1)*Ratio, L1+(L2-L1)*Ratio, S1+(S2-S1)*Ratio );
}
Exemplo n.º 2
0
COLORREF ScaleLumRGB(COLORREF col1, double ratio)
{
    double H1, L1, S1;

    RGBtoHLS(col1, &H1, &L1, &S1);

    L1 += L1 * ratio;

    return HLStoRGB(H1, L1, S1);
}
Exemplo n.º 3
0
void CPalGroup::SetAddHLSA(COLORREF crSrc, COLORREF * crTarget, double fpAddH, double fpAddL, double fpAddS, int uAddA)
{

	double modH, modL, modS;

	RGBtoHLS(crSrc, &modH, &modL, &modS);

	*crTarget = HLStoRGB(
		SubHLS(modH + fpAddH), 
		LimitHLS(modL + fpAddL), 
		LimitHLS(modS + fpAddS)
		 );

	*crTarget = RGB(ROUND_R(GetRValue(*crTarget)), ROUND_G(GetGValue(*crTarget)), ROUND_B(GetBValue(*crTarget)));
	*crTarget |= (UINT32)ROUND(LimitRGB(GetAValue(crSrc) + uAddA)) << 24;
}
Exemplo n.º 4
0
void nwt_HillShade( unsigned char *r, unsigned char *g, unsigned char *b,
                    char *h )
{
    HLS hls;
    NWT_RGB rgb;
    rgb.r = *r;
    rgb.g = *g;
    rgb.b = *b;
    hls = RGBtoHLS( rgb );
    hls.l += ((short) *h) * HLSMAX / 256;
    rgb = HLStoRGB( hls );

    *r = rgb.r;
    *g = rgb.g;
    *b = rgb.b;
    return;
}
Exemplo n.º 5
0
void CPalGroup::SortPal(int nIndex, int nStartIndex, int nSortFlag)
{

	if(!rgPalettes[nIndex].bAvail)
	{
		return; //Most likeley wont happen
	}

	double * pHSLArray;
	int nPalSz = rgPalettes[nIndex].uPalSz;
	
	if(rgPalettes[nIndex].pSortTable)
	{
		delete [] rgPalettes[nIndex].pSortTable;
	}

	pHSLArray = new double[nPalSz * 3];
	rgPalettes[nIndex].pSortTable = new UINT16[nPalSz];

	for(int i = 0; i < nPalSz; i++)
	{
		rgPalettes[nIndex].pSortTable[i] = (UINT16)i;

		RGBtoHLS(rgPalettes[nIndex].pPal[i], &pHSLArray[i], &pHSLArray[i + nPalSz], &pHSLArray[i + (nPalSz*2)]);
		
		//pHSLArray[i] = (double)(rgPalettes[nIndex].pPal[i] & 0x00FFFFFF);
	}

	//Go through array again
	for(int i = 0; i < nPalSz; i++)
	{		
		//pHSLArray[i] = pHSLArray[i] * pHSLArray[i + nPalSz] / pHSLArray[i + (nPalSz*2)];

		double fpPage;
		double fpPageSz = 20.0f;
		double fpPageAmt;
		
		pHSLArray[i] *= 360.0f;

		fpPageAmt = (double)((int)(pHSLArray[i] / fpPageSz));

		//pHSLArray[i] = fpPageSz * fpPageAmt;
		pHSLArray[i] += fpPageSz;//

		fpPage = 4096.0 * fpPageAmt;

		//pHSLArray[i] /=  fabs((pHSLArray[i + nPalSz * 2])-(pHSLArray[i + nPalSz]));
		
		//pHSLArray[i] /=  pHSLArray[i + nPalSz] + ((pHSLArray[i + (nPalSz * 2)]) / 3.0);
		//pHSLArray[i] /= (double)(rgPalettes[nIndex].pPal[i] & 0x00FFFFFF);

		//if(i && pHSLArray[i -1] == pHSLArray[i])
		//{
		//	pHSLArray[i] += pHSLArray[i + nPalSz];
		//}

		
		COLORREF crCol = rgPalettes[nIndex].pPal[i];
		double nR = (double)GetRValue(rgPalettes[nIndex].pPal[i])/255.0, 
			nG = (double)GetGValue(rgPalettes[nIndex].pPal[i])/255.0, 
			nB = (double)GetBValue(rgPalettes[nIndex].pPal[i])/255.0;

		double fpX, fpY, fpZ;

		ccRGBtoXYZ(nR, nG, nB, &fpX, &fpY, &fpZ);

		//pHSLArray[i] /= sqrt(sq(fpX) + sq(fpY) + sq(fpZ));
		pHSLArray[i] /= sqrt(sq(nR - 0) + sq(nG - 0) + sq(nB- 0));
	
		//pHSLArray[i] /= 
		//	pHSLArray[i + nPalSz] + ((pHSLArray[i + (nPalSz * 2)]) / 0.5) + sqrt(sq(nR - 0) + sq(nG - 0) + sq(nB- 0)) + fpX*4;
		
	

		pHSLArray[i] += fpPage;
	}
	
	/*
    */
	

	//for(int i = 0; i < nPalSz; i++)
	//{
	//	COLORREF crCol = rgPalettes[nIndex].pPal[i];
	//	double nR = (double)GetRValue(rgPalettes[nIndex].pPal[i]), 
	//		nG = (double)GetGValue(rgPalettes[nIndex].pPal[i]), 
	//		nB = (double)GetBValue(rgPalettes[nIndex].pPal[i]);
	//
	//	pHSLArray[i] /= 
	//		sqrt(sq(nR*0.3 - 0) + sq(nG*0.6 - 0) + sq(nB*0.1 - 0));
	//	
	//}
	//Sort again

	if((nSortFlag & SORT_HUE) == SORT_HUE)
	{
		for(int i = 0; i < 10; i++)
		{
			ShellSort(
				&pHSLArray[nStartIndex], 
				
				&pHSLArray[nStartIndex + nPalSz],
				&pHSLArray[nStartIndex + (nPalSz * 2)],
				(int *)&(rgPalettes[nIndex].pPal)[nStartIndex], 
				(UINT16 *)&(rgPalettes[nIndex].pSortTable)[nStartIndex], 
				nPalSz-nStartIndex
				);
		}
	}

	delete [] pHSLArray;
	
	
}