ACME-1236 : Add lines as a new type of vignette and Brightscan as an example

master
Merov Linden 2014-01-09 21:58:30 -08:00
parent a2f9aea3b4
commit 0c7cab771c
4 changed files with 55 additions and 10 deletions

View File

@ -158,11 +158,15 @@ void execute_filter(const LLSD& filter_data, LLPointer<LLImageRaw> raw_image)
// Execute the filter described on this line
if (filter_name == "blend")
{
raw_image->setVignette(VIGNETTE_MODE_BLEND,(float)(filter_data[i][1].asReal()),(float)(filter_data[i][2].asReal()));
raw_image->setVignette(VIGNETTE_MODE_BLEND,VIGNETTE_TYPE_CENTER,(float)(filter_data[i][1].asReal()),(float)(filter_data[i][2].asReal()));
}
else if (filter_name == "fade")
{
raw_image->setVignette(VIGNETTE_MODE_FADE,(float)(filter_data[i][1].asReal()),(float)(filter_data[i][2].asReal()));
raw_image->setVignette(VIGNETTE_MODE_FADE,VIGNETTE_TYPE_CENTER,(float)(filter_data[i][1].asReal()),(float)(filter_data[i][2].asReal()));
}
else if (filter_name == "lines")
{
raw_image->setVignette(VIGNETTE_MODE_BLEND,VIGNETTE_TYPE_LINES,(float)(filter_data[i][1].asReal()),(float)(filter_data[i][2].asReal()));
}
else if (filter_name == "sepia")
{
@ -780,11 +784,11 @@ int main(int argc, char** argv)
// Set the vignette if any
if (vignette_name == "blend")
{
raw_image->setVignette(VIGNETTE_MODE_BLEND,(float)(vignette_param_1),(float)(vignette_param_2));
raw_image->setVignette(VIGNETTE_MODE_BLEND,VIGNETTE_TYPE_CENTER,(float)(vignette_param_1),(float)(vignette_param_2));
}
else if (vignette_name == "fade")
{
raw_image->setVignette(VIGNETTE_MODE_FADE,(float)(vignette_param_1),(float)(vignette_param_2));
raw_image->setVignette(VIGNETTE_MODE_FADE,VIGNETTE_TYPE_CENTER,(float)(vignette_param_1),(float)(vignette_param_2));
}
// Apply filter if any

View File

@ -1372,9 +1372,10 @@ void LLImageRaw::filterScreen(EScreenMode mode, const S32 wave_length, const F32
}
}
void LLImageRaw::setVignette(EVignetteMode mode, F32 gamma, F32 min)
void LLImageRaw::setVignette(EVignetteMode mode, EVignetteType type, F32 gamma, F32 min)
{
mVignetteMode = mode;
mVignetteType = type;
mVignetteGamma = gamma;
mVignetteMin = llclampf(min);
// We always center the vignette on the image and fits it in the image smallest dimension
@ -1385,10 +1386,20 @@ void LLImageRaw::setVignette(EVignetteMode mode, F32 gamma, F32 min)
F32 LLImageRaw::getVignetteAlpha(S32 i, S32 j)
{
// alpha is a modified gaussian value, with a center and fading in a circular pattern toward the edges
// The gamma parameter controls the intensity of the drop down from alpha 1.0 (center) to 0.0
F32 d_center_square = (i - mVignetteCenterX)*(i - mVignetteCenterX) + (j - mVignetteCenterY)*(j - mVignetteCenterY);
F32 alpha = powf(F_E, -(powf((d_center_square/(mVignetteWidth*mVignetteWidth)),mVignetteGamma)/2.0f));
F32 alpha = 1.0;
if (mVignetteType == VIGNETTE_TYPE_CENTER)
{
// alpha is a modified gaussian value, with a center and fading in a circular pattern toward the edges
// The gamma parameter controls the intensity of the drop down from alpha 1.0 (center) to 0.0
F32 d_center_square = (i - mVignetteCenterX)*(i - mVignetteCenterX) + (j - mVignetteCenterY)*(j - mVignetteCenterY);
alpha = powf(F_E, -(powf((d_center_square/(mVignetteWidth*mVignetteWidth)),mVignetteGamma)/2.0f));
}
else if (mVignetteType == VIGNETTE_TYPE_LINES)
{
// alpha varies according to a squared sine function vertically.
// gamma is interpreted as the wavelength (in pixels) of the sine in that case.
alpha = (sinf(2*F_PI*j/mVignetteGamma) > 0.0 ? 1.0 : 0.0);
}
// We rescale alpha between min and 1.0 so to avoid complete fading if so desired.
return (mVignetteMin + alpha * (1.0 - mVignetteMin));
}

View File

@ -95,6 +95,12 @@ typedef enum e_vignette_mode
VIGNETTE_MODE_FADE = 2
} EVignetteMode;
typedef enum e_vignette_type
{
VIGNETTE_TYPE_CENTER = 0,
VIGNETTE_TYPE_LINES = 1
} EVignetteType;
typedef enum e_screen_mode
{
SCREEN_MODE_2DSINE = 0,
@ -173,6 +179,7 @@ protected:
// Vignette filtering
EVignetteMode mVignetteMode;
EVignetteType mVignetteType;
S32 mVignetteCenterX;
S32 mVignetteCenterY;
S32 mVignetteWidth;
@ -306,7 +313,7 @@ public:
void colorTransform(const LLMatrix3 &transform);
void colorCorrect(const U8* lut_red, const U8* lut_green, const U8* lut_blue);
void filterScreen(EScreenMode mode, const S32 wave_length, const F32 angle);
void setVignette(EVignetteMode mode, F32 gamma, F32 min);
void setVignette(EVignetteMode mode, EVignetteType type, F32 gamma, F32 min);
U32* getBrightnessHistogram();
protected:

View File

@ -0,0 +1,23 @@
<llsd>
<array>
<array>
<string>linearize</string>
<real>0.01</real>
<real>1.0</real>
<real>1.0</real>
<real>1.0</real>
</array>
<array>
<string>lines</string>
<real>10.0</real>
<real>0.0</real>
</array>
<array>
<string>brighten</string>
<real>100.0</real>
<real>1.0</real>
<real>1.0</real>
<real>1.0</real>
</array>
</array>
</llsd>