VOID CDibUtil::Subtract(CDib& imgA, CDib& imgB, CDib& dest)
{
	dest.CopyDib(&imgA);
	CSize imageSize = imgA.GetDimensions();

	for (LONG y = 0; y != imageSize.cy; ++y)
		for (LONG x = 0; x != imageSize.cx; ++x)
		{
			dest.WritePixel(x, y, RGBSUB(imgA.GetPixel(x, y), imgB.GetPixel(x, y)));
		}
}
VOID CDibUtil::Graying(CDib& src, CDib& dest)
{
	dest.CopyDib(&src);
	CSize imageSize = src.GetDimensions();

	RGBQUAD color;
	for (LONG y = 0; y != imageSize.cy; ++y)
		for (LONG x = 0; x != imageSize.cx; ++x)
		{
			color = src.GetPixel(x, y);
			color.rgbRed = color.rgbGreen = color.rgbBlue
				= GRAYING(color.rgbRed, color.rgbGreen, color.rgbBlue);
			dest.WritePixel(x, y, color);
		}
}
VOID CDibUtil::Binaryzation(CDib& src, CDib& dest, BYTE threshold)
{
	dest.CopyDib(&src);
	CSize imageSize = src.GetDimensions();
	
	RGBQUAD color;
	for (LONG y = 0; y != imageSize.cy; ++y)
		for (LONG x = 0; x != imageSize.cx; ++x)
		{
			color = src.GetPixel(x, y);
			color.rgbRed = color.rgbGreen = color.rgbBlue
				= (GRAYING(color.rgbRed, color.rgbGreen, color.rgbBlue) < threshold) ? 0x00 : 0xFF;
			dest.WritePixel(x, y, color);
		}
}
VOID CDibUtil::RandomPixels(CDib& src, CDib& dest, LONG count)
{
	dest.CopyDib(&src);
	CSize imageSize = src.GetDimensions();
	
	srand( (UINT)time( NULL ) );
	
	RGBQUAD color;
	LONG x, y;
	for (LONG i = 0; i != count; ++i)
	{
		// Random color
		color.rgbRed = (BYTE)((DOUBLE)rand() / (RAND_MAX + 1) * 255);
		color.rgbGreen = (BYTE)((DOUBLE)rand() / (RAND_MAX + 1) * 255);
		color.rgbBlue = (BYTE)((DOUBLE)rand() / (RAND_MAX + 1) * 255);
		
		// Random position
		x = (LONG)((DOUBLE)rand() / (RAND_MAX + 1) * imageSize.cx);
		y = (LONG)((DOUBLE)rand() / (RAND_MAX + 1) * imageSize.cy);
		
		// Write
		dest.WritePixel(x, y, color);
	}
}