Beispiel #1
0
/* Tonemap operator, tonemaps the hdr image and stores the
 * tonemapped image in result.  Use the value key as the 
 * key of the photograph.  This function should:
 * 1) Calculate the log-average luminance, Lavg
 * 2) Calculate the tonemapped image using the equation
 *    L(x,y) = L_w(x,y) * key / Lavg;
 *    C_tm(x,y) = L(x,y) / (1 + L(x,y));
 * 3) Store those tonemapped values to the result image,
 *    scaling appropriately.
 */
void tonemap(STHDRImage* hdr, float key, STImage* result) {
    float logAverageLuminance = 0;
    float delta = 0.001;
    
    for (int i=0;i<hdr->GetWidth();i++)
    {
        for (int j=0;j<hdr->GetHeight();j++)
        {
            STColor3f currentPixel = hdr->GetPixel(i, j);
            logAverageLuminance += logf(currentPixel.r*0.299 + currentPixel.g*0.587 +currentPixel.b*0.114 + delta);
        }
    }
    logAverageLuminance /= (hdr->GetWidth()*hdr->GetHeight());
    logAverageLuminance = expf(logAverageLuminance);
    
    for (int i=0;i<hdr->GetWidth();i++)
    {
        for (int j=0;j<hdr->GetHeight();j++)
        {
            STColor3f currentPixel = hdr->GetPixel(i, j);
            STColor3f currentPixelScaled = currentPixel * (key/logAverageLuminance);
            STColor3f compressedCurrentPixelScaled = currentPixelScaled / (STColor3f(1) + currentPixelScaled);
            STColor4ub resultPixel(compressedCurrentPixelScaled);
            result->SetPixel(i, j, resultPixel);
        }
    }
    
}
Beispiel #2
0
Light::Light() {
  color = STColor3f(0,0,0);
}
Beispiel #3
0
/* Luminance. Applies to color components only. */
float STColor4f::Y() const
{
    return STColor3f(*this).Y();
}