Make the value for shadowRadius less than 1.0 work

Shadow effect is not visible if the shadowRadius is set
between 0.1 and 1.0.

Change-Id: Ifff71f44d66ba604bd751bb1df96a9904ae7998e
This commit is contained in:
huanhuan.x.wang
2015-04-14 16:23:15 +02:00
committed by Zoran Jovanovic
parent 8f0e0c1f3d
commit 8d9b5fbdf0
3 changed files with 11 additions and 9 deletions

View File

@ -773,7 +773,7 @@ void FontRenderer::blurImage(uint8_t** image, int32_t width, int32_t height, flo
#endif
float *gaussian = new float[2 * intRadius + 1];
Blur::generateGaussianWeights(gaussian, intRadius);
Blur::generateGaussianWeights(gaussian, radius);
uint8_t* scratch = new uint8_t[width * height];
Blur::horizontal(gaussian, intRadius, *image, scratch, width, height);

View File

@ -60,7 +60,9 @@ static float legacyConvertRadiusToSigma(float radius) {
return radius > 0 ? 0.3f * radius + 0.6f : 0.0f;
}
void Blur::generateGaussianWeights(float* weights, int32_t radius) {
void Blur::generateGaussianWeights(float* weights, float radius) {
int32_t intRadius = convertRadiusToInt(radius);
// Compute gaussian weights for the blur
// e is the euler's number
static float e = 2.718281828459045f;
@ -68,7 +70,7 @@ void Blur::generateGaussianWeights(float* weights, int32_t radius) {
// g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 )
// x is of the form [-radius .. 0 .. radius]
// and sigma varies with radius.
float sigma = legacyConvertRadiusToSigma((float) radius);
float sigma = legacyConvertRadiusToSigma(radius);
// Now compute the coefficints
// We will store some redundant values to save some math during
@ -78,16 +80,16 @@ void Blur::generateGaussianWeights(float* weights, int32_t radius) {
float coeff2 = - 1.0f / (2.0f * sigma * sigma);
float normalizeFactor = 0.0f;
for (int32_t r = -radius; r <= radius; r ++) {
for (int32_t r = -intRadius; r <= intRadius; r ++) {
float floatR = (float) r;
weights[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2);
normalizeFactor += weights[r + radius];
weights[r + intRadius] = coeff1 * pow(e, floatR * floatR * coeff2);
normalizeFactor += weights[r + intRadius];
}
//Now we need to normalize the weights because all our coefficients need to add up to one
normalizeFactor = 1.0f / normalizeFactor;
for (int32_t r = -radius; r <= radius; r ++) {
weights[r + radius] *= normalizeFactor;
for (int32_t r = -intRadius; r <= intRadius; r ++) {
weights[r + intRadius] *= normalizeFactor;
}
}

View File

@ -34,7 +34,7 @@ public:
// accounts for that error and snaps to the appropriate integer boundary.
static uint32_t convertRadiusToInt(float radius);
static void generateGaussianWeights(float* weights, int32_t radius);
static void generateGaussianWeights(float* weights, float radius);
static void horizontal(float* weights, int32_t radius, const uint8_t* source,
uint8_t* dest, int32_t width, int32_t height);
static void vertical(float* weights, int32_t radius, const uint8_t* source,