Merge "Make the value for shadowRadius less than 1.0 work"

This commit is contained in:
Chris Craik
2015-08-14 22:02:19 +00:00
committed by Gerrit Code Review
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 #endif
float *gaussian = new float[2 * intRadius + 1]; float *gaussian = new float[2 * intRadius + 1];
Blur::generateGaussianWeights(gaussian, intRadius); Blur::generateGaussianWeights(gaussian, radius);
uint8_t* scratch = new uint8_t[width * height]; uint8_t* scratch = new uint8_t[width * height];
Blur::horizontal(gaussian, intRadius, *image, scratch, 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; 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 // Compute gaussian weights for the blur
// e is the euler's number // e is the euler's number
static float e = 2.718281828459045f; 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 ) // g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 )
// x is of the form [-radius .. 0 .. radius] // x is of the form [-radius .. 0 .. radius]
// and sigma varies with radius. // and sigma varies with radius.
float sigma = legacyConvertRadiusToSigma((float) radius); float sigma = legacyConvertRadiusToSigma(radius);
// Now compute the coefficints // Now compute the coefficints
// We will store some redundant values to save some math during // 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 coeff2 = - 1.0f / (2.0f * sigma * sigma);
float normalizeFactor = 0.0f; float normalizeFactor = 0.0f;
for (int32_t r = -radius; r <= radius; r ++) { for (int32_t r = -intRadius; r <= intRadius; r ++) {
float floatR = (float) r; float floatR = (float) r;
weights[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2); weights[r + intRadius] = coeff1 * pow(e, floatR * floatR * coeff2);
normalizeFactor += weights[r + radius]; normalizeFactor += weights[r + intRadius];
} }
//Now we need to normalize the weights because all our coefficients need to add up to one //Now we need to normalize the weights because all our coefficients need to add up to one
normalizeFactor = 1.0f / normalizeFactor; normalizeFactor = 1.0f / normalizeFactor;
for (int32_t r = -radius; r <= radius; r ++) { for (int32_t r = -intRadius; r <= intRadius; r ++) {
weights[r + radius] *= normalizeFactor; weights[r + intRadius] *= normalizeFactor;
} }
} }

View File

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