COLORREF ScaleLumRGB(COLORREF col1, double ratio) { double H1, L1, S1; RGBtoHLS(col1, &H1, &L1, &S1); L1 += L1 * ratio; return HLStoRGB(H1, L1, S1); }
/****************************************************************************** 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 ); }
void DrawScene(HWND hwnd, HDC dc, int ticks) { PAINTSTRUCT ps; dc = BeginPaint(hwnd, &ps); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glRotatef(ticks * 0.01, 0.0, 1.0, -0.5); angle += ticks * 0.01; colorh += ticks * 0.003; if (colorh > 360.0) colorh -= 360.0; HLStoRGB(colorh, 1.0, 0.7, &rval, &gval, &bval); DrawCylinder(lvls, angle, 0.2); SwapBuffers(dc); EndPaint(hwnd, &ps); }
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; }
void CPowerColorPickerCtrl::GenerateLuminanceBar() { System::Drawing::Size size = this->luminance_label->Size; System::Drawing::Bitmap^ tempBitMap = gcnew System::Drawing::Bitmap(size.Width, size.Height); Graphics^ Gra = Graphics::FromImage(tempBitMap); Gra->Clear(Color::FromArgb(0xffff)); for (int i= 0; i<size.Height; i++) { for (int j = 0; j < size.Width; j++) { Drawing::Color color = HLStoRGB(currentHue, (double)i/(double)size.Height, currentSaturation); tempBitMap->SetPixel(j,i,color); } } this->luminance_label->BackgroundImage = tempBitMap; }
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; }
int AllocCells(Display *dsply, Colormap colorMap, int smoothHue) { unsigned long plane_masks[1]; int i, count; float lightness; RGB rgb; XColor xcolor; HLS hls; count = 0; for (i = 0; i < (smoothConst + 1); i++) { lightness = (float) (i) / (float) (smoothConst); hls.h = (float) smoothHue; hls.l = lightness; hls.s = saturation; rgb = HLStoRGB(hls); xcolor.red = rgb.r *((1<<16)-1); xcolor.green = rgb.g *((1<<16)-1); xcolor.blue = rgb.b *((1<<16)-1); xcolor.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",xcolor.red,xcolor.green,xcolor.blue); */ if (XAllocColor(dsply, colorMap, &xcolor)) { pixels[count] = xcolor.pixel; count++; } } /* count says how many succeeded */ if (count != (smoothConst+1) ) { /* we have failed to get all of them - free the ones we got */ FreePixels(dsply,colorMap,count); return (0); } if (XAllocColorCells(dsply, colorMap, False, plane_masks, 0, pixels, smoothConst + 1)) { return (smoothConst + 1); } else { return (0); } }
void CColorSpectrum::OnMouseMove(CPoint point, UINT nFlags) { CRect rcPos = m_rcPos; point.x -= rcPos.left; point.y -= rcPos.top; if (m_dragging) { COLORREF rgb; if (point.x > rcPos.Width()-20) { if (point.y < rcPos.Height()/2) { rgb = RGB(255, 255, 255); } else { rgb = RGB(0, 0, 0); } } else { int h = point.x * 255 / rcPos.Width(); int l = (rcPos.Height()-point.y)*255 / rcPos.Height(); int s = (rcPos.Height()-point.y)*255 / rcPos.Height(); if (h < 0) h = 0; else if (h > 255) h = 255; if (l < 0) l = 0; else if (l > 255) l = 255; if (s < 0) s = 0; else if (s > 255) s = 255; rgb = HLStoRGB(HLS(h, l, s)); } Fire_SetColorRGB(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)); } }
int makeNewColorMap(Display *dsply, Colormap colorMap, int smoothHue) { int count, i; float lightness; RGB rgb; XColor xcolor; HLS hls; count = 0; for (i = 0; i < (smoothConst + 1); i++) { /* i = 0 .. smoothConst */ lightness = (float) (i) / (float) (smoothConst); /* lightnes = 0.0 .. 1.0 */ hls.h = (float) smoothHue; hls.l = lightness; hls.s = saturation; rgb = HLStoRGB(hls); xcolor.red = rgb.r *((1<<16)-1); xcolor.green = rgb.g *((1<<16)-1); xcolor.blue = rgb.b *((1<<16)-1); xcolor.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",xcolor.red,xcolor.green,xcolor.blue); */ if (XAllocColor(dsply, colorMap, &xcolor)) { pixels[count] = xcolor.pixel; count++; } } /* count says how many succeeded */ if (count != (smoothConst+1) ) { /* we have failed to get all of them - free the ones we got */ FreePixels(dsply,colorMap,count); return (0); } return (1); }
void CPalGroup::SetHLSA(COLORREF * crTarget, double dH, double dL, double dS, UINT8 aVal) { *crTarget = HLStoRGB(LimitHLS(dH), LimitHLS(dL), LimitHLS(dS)); *crTarget = RGB(ROUND_R(GetRValue(*crTarget)),ROUND_G(GetGValue(*crTarget)),ROUND_B(GetBValue(*crTarget))); *crTarget |= (UINT32)aVal << 24; }
HRESULT CColorSpectrum::OnDraw(ATL_DRAWINFO& di) { CRect& rc = *(CRect*)di.prcBounds; HDC hDC = di.hdcDraw; if (m_bEnabled) { #define ROWBYTES(width,bitcount) ((((width)*(bitcount)+31) >> 3) & 0xfffc) int width = rc.Width()-20; int height = rc.Height(); FillSolidRect(hDC, rc.left+width, rc.top, 20, height/2, RGB(255, 255, 255)); FillSolidRect(hDC, rc.left+width, rc.top+height/2, 20, rc.Height()-height/2, RGB(0, 0, 0)); int bytesPerRow = ROWBYTES(width, 24); BITMAPINFOHEADER bmi; ZeroMemory(&bmi, sizeof(bmi)); bmi.biSize = sizeof(BITMAPINFOHEADER); bmi.biWidth = width; bmi.biHeight = height; bmi.biPlanes = 1; bmi.biBitCount = 24; bmi.biCompression = BI_RGB; bmi.biSizeImage = bytesPerRow*height; LPBYTE bits = (LPBYTE)GlobalAlloc(0, bmi.biSizeImage); if (bits) { for (int y = 0; y < height; y++) { RGBTRIPLE* dest = (RGBTRIPLE*)(bits + (height-y-1)*bytesPerRow); for (int x = 0; x < width; x++) { int h = (x * 255)/width; int l = ((height-y-1) * 255)/height; int s = ((height-y-1) * 255)/height; //int s = 127;//(x * width)/255; COLORREF clr = HLStoRGB(HLS(h, l, s)); dest->rgbtRed = GetRValue(clr); dest->rgbtGreen = GetGValue(clr); dest->rgbtBlue = GetBValue(clr); dest++; } } SetDIBitsToDevice(hDC, rc.left, rc.top, width, height, 0, 0, 0, height, bits, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS); GlobalFree(bits); } } return S_OK; }