Пример #1
0
RGB DepthOfField::sampleCircle(int x, int y, double z, double radius, double tolerance, Image* image) const {

    int int_rad = int(radius);
    double rad2 = radius*radius;

    int x_min = MAX(x - int_rad,0);
    int x_max = MIN(x + int_rad,image->getWidth() - 1);

    int y_min = MAX(y - int_rad,0);
    int y_max = MIN(y + int_rad,image->getHeight() - 1);

    int samples = 0;
    RGB result = RGB(0.0,0.0,0.0);

    for (int b = y_min; b < y_max; b++) {
	for (int a = x_min; a < x_max; a++) {
	    if ((x-a)*(x-a) + (y-b)*(y-b) <= rad2) {
		RGB depth = depth_buffer->getRGBA(a,b);
		if (fabs(depth.r() - z) < tolerance) {
		    result += image->getRGBA(a,b);
		    samples++;
		}
	    }
	}
    }
    if (samples > 0) {
	return result / double(samples);
    }

    return result;
}
Пример #2
0
std::string toHtml(const RGB &rgb) {
    char buf[32];

    // Microsoft doesn't define round(double) in <cmath>
    unsigned r = boost::numeric::converter<unsigned, double>::convert(clip(rgb.r())*255);
    unsigned g = boost::numeric::converter<unsigned, double>::convert(clip(rgb.g())*255);
    unsigned b = boost::numeric::converter<unsigned, double>::convert(clip(rgb.b())*255);

    sprintf(buf, "#%02x%02x%02x", r, g, b);
    return buf;
}
Пример #3
0
void Image::gammaCorrect(float dGamma)
{
	RGB rgbTemp;
	float fPower = 1.0 / dGamma;
	
	for(int x = 0; x < m_nWidth; x++) {
		for(int y = 0; y < m_nHeight; y++) {
			rgbTemp.set(m_rgbImage[x][y]);
			
			rgbTemp.clamp(0.0, 1.0);
						
			m_rgbImage[x][y].R = pow(rgbTemp.r(), fPower);
			m_rgbImage[x][y].G = pow(rgbTemp.g(), fPower);
			m_rgbImage[x][y].B = pow(rgbTemp.b(), fPower);
		}
	}
}