CChromaMask::CChromaMask(CChromaDlg* pDlg) { int i; FRMTYPEINFO TypeInfo; BOOL EnableFade; m_pDlg = pDlg; ImgGetTypeInfo(pDlg->GetImage(), &TypeInfo); EnableFade = TypeInfo.DataType != FDT_LINEART && TypeInfo.DataType != FDT_PALETTECOLOR; ChromaCombineMode = SHAPE_ADD; Fade = EnableFade? 10 : 0; Delete = FALSE; ActiveChromaMask = Mask = 0; ChromaColorMode = IDC_CHROMA_HSL; for (i=0; i < NUM_CHROMAMASKS; i++) { MaskRange[i] = 10; MaskColor[i].rgb.red = 255; MaskColor[i].rgb.green = 255; MaskColor[i].rgb.blue = 255; RGBtoHSL(0, 0, 0, &MaskColor[i].hsl); RGBtoCMYK(0,0, 0, &MaskColor[i].cmyk); } }
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)); } } }
int CChromaMask::GetRGBMask(LPTR lpLine) { int R,G,B; int Mask1; int v,i,Final; R = *lpLine++; G = *lpLine++; B = *lpLine++; Final = 0; if (ChromaColorMode == IDC_CHROMA_HSL || ChromaColorMode == IDC_CHROMA_LUMIN) { HSLS HSL; RGBtoHSL(R, G, B, &HSL); for (i = 0; i < NUM_CHROMAMASKS; i++) { Mask1 = 255; if (!(Mask & (1 << i))) continue; if (ChromaColorMode != IDC_CHROMA_LUMIN) { v = HMask[i][HSL.hue]; if (v < Mask1) Mask1 = v; v = SMask[i][HSL.sat]; if (v < Mask1) Mask1 = v; } v = LMask[i][HSL.lum]; if (v < Mask1) Mask1 = v; if (Mask1 > Final) Final = Mask1; } } else { for (i = 0; i < NUM_CHROMAMASKS; i++) { Mask1 = 255; if (!(Mask & (1 << i))) continue; v = RMask[i][R]; if (v < Mask1) Mask1 = v; v = GMask[i][G]; if (v < Mask1) Mask1 = v; v = BMask[i][B]; if (v < Mask1) Mask1 = v; if (Mask1 > Final) Final = Mask1; } } return(Final); }
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++; } } }
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; }
bool CFloodFill2::IsColorToBeFilled(COLORREF ColorToFill, COLORREF PixelColor) { BYTE PixelColorRed, PixelColorGreen, PixelColorBlue; RGBTRIPLE PixelColorrgbt = *(RGBTRIPLE*)&PixelColor; PixelColorRed = PixelColorrgbt.rgbtRed, PixelColorGreen = PixelColorrgbt.rgbtGreen, PixelColorBlue = PixelColorrgbt.rgbtBlue; if (m_bRedEye) { float fColorRed = ((float)PixelColorRed / (float)(PixelColorRed + PixelColorGreen + PixelColorBlue)); float fColorGreen = ((float)PixelColorGreen /(float)(PixelColorRed + PixelColorGreen + PixelColorBlue)); float fColorBlue = ((float)PixelColorBlue /(float)(PixelColorRed + PixelColorGreen + PixelColorBlue)); HSL hsl; RGBtoHSL(PixelColorRed, PixelColorGreen, PixelColorBlue, &hsl); //Try to adjust the white pixels if the user clicks directly on a white part of an eye. //I need to account for this and continue. This may not be pure white in the pict. int nWhiteIndex = 0; if (PixelColorRed >= 200) nWhiteIndex++; if (PixelColorGreen >= 200) nWhiteIndex++; if (PixelColorBlue >= 200) nWhiteIndex++; //Assume that the pixel was meant to be white if (PixelColorRed && nWhiteIndex > 1) return true; if ((hsl.hue >= 0 && hsl.hue <= 10) || hsl.hue >= 200) { if (hsl.sat < 98 && hsl.lum < 98) return false; if ((PixelColorRed > 50) && (fColorRed > 0.40) && (fColorGreen < 0.31) && (fColorBlue < 0.36)) { if ((4 * PixelColorRed -(PixelColorGreen + PixelColorBlue) - min(PixelColorGreen,PixelColorBlue) - max(PixelColorGreen,PixelColorBlue))/PixelColorRed) return true; } } } else { BYTE ColorToFillRed, ColorToFillGreen, ColorToFillBlue; RGBTRIPLE ColorToFillrgbt = *(RGBTRIPLE*)&ColorToFill; ColorToFillRed = ColorToFillrgbt.rgbtRed, ColorToFillGreen = ColorToFillrgbt.rgbtGreen, ColorToFillBlue = ColorToFillrgbt.rgbtBlue; if (ColorToFill == PixelColor) return true; int nMaxDiff = max(max(abs(ColorToFillRed - PixelColorRed), abs(ColorToFillGreen - PixelColorGreen)), abs(ColorToFillBlue - PixelColorBlue)); if (nMaxDiff <= m_fTolerance) return true; } return false; }
bool CFloodFill2::IsColorToBeFilled(COLORREF FillColor, COLORREF PixelColor) { BYTE R = GetRValue(PixelColor); BYTE G = GetGValue(PixelColor); BYTE B = GetBValue(PixelColor); if (m_bRedEye) { // Try to adjust the white pixels if the user clicks directly on a white part of an eye. // I need to account for this and continue. This may not be pure white in the picture. int nWhiteIndex = 0; if (R >= 200) nWhiteIndex++; if (G >= 200) nWhiteIndex++; if (B >= 200) nWhiteIndex++; // Assume that the pixel was meant to be white if (nWhiteIndex > 1) return true; HSL hsl; RGBtoHSL(R, G, B, &hsl); if ((hsl.hue >= 0 && hsl.hue <= 10) || hsl.hue >= 200) { if (hsl.sat < 98 && hsl.lum < 98) return false; float dR = ((float)R / (float)(R + G + B)); float dG = ((float)G / (float)(R + G + B)); float dB = ((float)B / (float)(R + G + B)); if (R > 50 && dR > 0.40 && dG < 0.31 && dB < 0.36) { if ((4 * R -(G + B) - min(G,B) - max(G,B))/R) return true; } } } else { if (FillColor == PixelColor) return true; int dR = abs((int)GetRValue(FillColor) - R); int dG = abs((int)GetGValue(FillColor) - G); int dB = abs((int)GetBValue(FillColor) - B); int nMaxDiff = max(max(dR, dG), dB); if (nMaxDiff <= m_fTolerance) return true; } return false; }
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); }
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); }
void ColorSpace::RGBtoHSL (CoImage* pIn, CoImage* pOut) { assert (pIn->GetType() == MAT_Tbyte); assert (pOut->GetType() == MAT_Tfloat); BYTE** ppbR = pIn->m_matX.data.ptr; BYTE** ppbG = pIn->m_matY.data.ptr; BYTE** ppbB = pIn->m_matZ.data.ptr; float** pprR = pOut->m_matX.data.fl; float** pprG = pOut->m_matY.data.fl; float** pprB = pOut->m_matZ.data.fl; for (int iH = 0; iH < pIn->GetHeight(); iH ++) for (int iW = 0; iW < pIn->GetWidth(); iW ++) { RGBtoHSL(ppbR[iH][iW], ppbG[iH][iW], ppbB[iH][iW], &pprR[iH][iW], &pprG[iH][iW], &pprB[iH][iW]); } }
//绘制基本的含空隙的正方形 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); } }
//搜索腐蚀中心 static int SearchCentre(unsigned int *x,unsigned int *y,const TARGET_CONDI *Condition,const SEARCH_AREA *Area) { unsigned int SpaceX,SpaceY,i,j,k,FailCount=0; COLOR_RGB Rgb; COLOR_HSL Hsl; SpaceX = Condition->WIDTH_MIN/3; SpaceY = Condition->HIGHT_MIN/3; for(i=Area->Y_Start;i<Area->Y_End;i+=SpaceY) { for(j=Area->X_Start;j<Area->X_End;j+=SpaceX) { FailCount=0; for(k=0;k<SpaceX+SpaceY;k++) { if(k<SpaceX) ReadColor(j+k,i+SpaceY/2,&Rgb); else ReadColor(j+SpaceX/2,i+(k-SpaceX),&Rgb); RGBtoHSL(&Rgb,&Hsl); if(!ColorMatch(&Hsl,Condition)) FailCount++; if(FailCount>((SpaceX+SpaceY)>>ALLOW_FAIL_PER)) break; } if(k==SpaceX+SpaceY) { *x = j+SpaceX/2; *y = i+SpaceY/2; return 1; } } } return 0; }
//从腐蚀中心向外腐蚀,得到新的腐蚀中心 static int Corrode(unsigned int oldx,unsigned int oldy,const TARGET_CONDI *Condition,RESULT *Resu) { unsigned int Xmin,Xmax,Ymin,Ymax,i,FailCount=0; COLOR_RGB Rgb; COLOR_HSL Hsl; for(i=oldx;i>IMG_X;i--) { ReadColor(i,oldy,&Rgb); RGBtoHSL(&Rgb,&Hsl); if(!ColorMatch(&Hsl,Condition)) FailCount++; if(FailCount>(((Condition->WIDTH_MIN+Condition->WIDTH_MAX)>>2)>>ALLOW_FAIL_PER)) break; } Xmin=i; FailCount=0; for(i=oldx;i<IMG_X+IMG_W;i++) { ReadColor(i,oldy,&Rgb); RGBtoHSL(&Rgb,&Hsl); if(!ColorMatch(&Hsl,Condition)) FailCount++; if(FailCount>(((Condition->WIDTH_MIN+Condition->WIDTH_MAX)>>2)>>ALLOW_FAIL_PER)) break; } Xmax=i; FailCount=0; for(i=oldy;i>IMG_Y;i--) { ReadColor(oldx,i,&Rgb); RGBtoHSL(&Rgb,&Hsl); if(!ColorMatch(&Hsl,Condition)) FailCount++; if(FailCount>(((Condition->HIGHT_MIN+Condition->HIGHT_MAX)>>2)>>ALLOW_FAIL_PER)) break; } Ymin=i; FailCount=0; for(i=oldy;i<IMG_Y+IMG_H;i++) { ReadColor(oldx,i,&Rgb); RGBtoHSL(&Rgb,&Hsl); if(!ColorMatch(&Hsl,Condition)) FailCount++; if(FailCount>(((Condition->HIGHT_MIN+Condition->HIGHT_MAX)>>2)>>ALLOW_FAIL_PER)) break; } Ymax=i; FailCount=0; Resu->x = (Xmin+Xmax)/2; Resu->y = (Ymin+Ymax)/2; Resu->w = Xmax-Xmin; Resu->h = Ymax-Ymin; if(((Xmax-Xmin)>(Condition->WIDTH_MIN)) && ((Ymax-Ymin)>(Condition->HIGHT_MIN)) &&\ ((Xmax-Xmin)<(Condition->WIDTH_MAX)) && ((Ymax-Ymin)<(Condition->HIGHT_MAX)) ) return 1; else return 0; }
/* 320 * ------------------- *| | *| | *| | 240 *| | *| | * ------------------- */ void ImagDisp(void) { uint16_t i,j,m=0; uint16_t Camera_Data; for(i = 0; i < 240; i++){ for(j = 0; j < 320; j++){ READ_FIFO_PIXEL(Camera_Data); /* 从FIFO读出一个rgb565像素到Camera_Data变量 */ if((i == Mid[4].y) && (j > Mid[4].x) && (j <= Mid[4].x + pointNum)) ColorData4[0][j-Mid[4].x] = Camera_Data; if((i == Mid[4].y) && (j < Mid[4].x) && (j >= Mid[4].x - pointNum)) ColorData4[1][Mid[4].x-j] = Camera_Data; if((j == Mid[4].x) && (i >= Mid[4].y - pointNum) && (i < Mid[4].y)) ColorData4[2][Mid[4].y-i] = Camera_Data; if((j == Mid[4].x) && (i > Mid[4].y) && ( i <= Mid[4].y + pointNum)) ColorData4[3][i-Mid[4].y] = Camera_Data; if((i == Mid[2].y) && (j > Mid[2].x) && (j <= Mid[2].x + pointNum)) ColorData4[0][j-Mid[2].x] = Camera_Data; if((i == Mid[2].y) && (j < Mid[2].x) && (j >= Mid[2].x - pointNum)) ColorData4[1][Mid[2].x-j] = Camera_Data; if((j == Mid[2].x) && (i >= Mid[2].y - pointNum) && (i < Mid[2].y)) ColorData4[2][Mid[2].y-i] = Camera_Data; if((j == Mid[2].x) && (i > Mid[2].y) && ( i <= Mid[2].y + pointNum)) ColorData4[3][i-Mid[2].y] = Camera_Data; // // if(i==Mid[6].y&&j>Mid[6].x&&j<=Mid[6].x+pointNum) // ColorData6[0][j-Mid[6].x]=Camera_Data; // if(i==Mid[6].y&&j<Mid[6].x&&j>=Mid[6].x-pointNum) // ColorData6[1][Mid[6].x-j]=Camera_Data; // if(j==Mid[6].x&&i>=Mid[6].y-pointNum&&i<Mid[6].y) // ColorData6[2][Mid[6].y-i]=Camera_Data; // if(j==Mid[6].x&&i>Mid[6].y&&i<=Mid[6].y+pointNum) // ColorData6[3][i-Mid[6].y]=Camera_Data; if(i==65&&j==135) { MidColorData[0][0]=Camera_Data; Camera_Data=0; } if(i==65&&j==170) { MidColorData[0][1]=Camera_Data; Camera_Data=0; } if(i==65&&j==202) { MidColorData[0][2]=Camera_Data; Camera_Data=0; } if(i==100&&j==135) { MidColorData[1][0]=Camera_Data; Camera_Data=0; } if(i==100&&j==170) { MidColorData[1][1]=Camera_Data; Camera_Data=0; } if(i==100&&j==202) { MidColorData[1][2]=Camera_Data; Camera_Data=0; } if(i==135&&j==135) { MidColorData[2][0]=Camera_Data; Camera_Data=0; } if(i==135&&j==170) { MidColorData[2][1]=Camera_Data; Camera_Data=0; } if(i==135&&j==202) { MidColorData[2][2]=Camera_Data; Camera_Data=0; } LCD_WR_Data(Camera_Data); } } for(i=0;i<3;i++){ for(j=0;j<3;j++){ RGBtoHSL(MidColorData[i][j],hsl_l+m); outcolor(hsl_l+m); m++; } } if(ColorDataCompare(ColorData4)) { // if(ColorDataCompare(ColorData2)) Judgerubik=1; // else // Judgerubik=0; } else Judgerubik=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; }