Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a46ca5ec authored by huanhuan.x.wang's avatar huanhuan.x.wang Committed by Chris Craik
Browse files

Make the value for shadowRadius less than 1.0 work

bug:22806069

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

Cherry-pick of 8d9b5fbd from AOSP

Change-Id: Ifff71f44d66ba604bd751bb1df96a9904ae7998e
parent eeea0d92
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -732,7 +732,7 @@ void FontRenderer::blurImage(uint8_t** image, int32_t width, int32_t height, flo
#endif

    std::unique_ptr<float[]> gaussian(new float[2 * intRadius + 1]);
    Blur::generateGaussianWeights(gaussian.get(), intRadius);
    Blur::generateGaussianWeights(gaussian.get(), radius);

    std::unique_ptr<uint8_t[]> scratch(new uint8_t[width * height]);
    Blur::horizontal(gaussian.get(), intRadius, *image, scratch.get(), width, height);
+9 −7
Original line number Diff line number Diff line
@@ -58,7 +58,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;
@@ -66,7 +68,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
@@ -76,16 +78,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;
    }
}

+1 −1
Original line number Diff line number Diff line
@@ -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,