Exemplo n.º 1
0
int32_t CxImage::Histogram(int32_t* red, int32_t* green, int32_t* blue, int32_t* gray, int32_t colorspace)
{
	if (!pDib) return 0;
	RGBQUAD color;

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

	int32_t 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(int32_t y=ymin; y<ymax; y++){
		for(int32_t x=xmin; x<xmax; x++){
#if CXIMAGE_SUPPORT_SELECTION
			if (BlindSelectionIsInside(x,y))
#endif //CXIMAGE_SUPPORT_SELECTION
			{
				switch (colorspace){
				case 1:
					color = HSLtoRGB(BlindGetPixelColor(x,y));
					break;
				case 2:
					color = YUVtoRGB(BlindGetPixelColor(x,y));
					break;
				case 3:
					color = YIQtoRGB(BlindGetPixelColor(x,y));
					break;
				case 4:
					color = XYZtoRGB(BlindGetPixelColor(x,y));
					break;
				default:
					color = BlindGetPixelColor(x,y);
				}

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

	int32_t n=0;
	for (int32_t 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;
}
Exemplo n.º 2
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 - 1; ymax=head.biHeight - 1;
	}

	for(long y=ymin; y<=ymax; y++){
		for(long x=xmin; x<=xmax; x++){
#if CXIMAGE_SUPPORT_SELECTION
			if (BlindSelectionIsInside(x,y))
#endif //CXIMAGE_SUPPORT_SELECTION
			{
				switch (colorspace){
				case 1:
					color = HSLtoRGB(BlindGetPixelColor(x,y));
					break;
				case 2:
					color = YUVtoRGB(BlindGetPixelColor(x,y));
					break;
				case 3:
					color = YIQtoRGB(BlindGetPixelColor(x,y));
					break;
				case 4:
					color = XYZtoRGB(BlindGetPixelColor(x,y));
					break;
				default:
					color = BlindGetPixelColor(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;
	long nMed=(long)((xmax*ymax)/3);
	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) {
			n+=gray[i];
			if(n>nMed)
				return i;
		}
	}

	return n;
}
Exemplo n.º 3
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;
}