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

Commit 0d0c4e13 authored by Jason Sams's avatar Jason Sams Committed by Android (Google) Code Review
Browse files

Merge "Minor cleanup of a few RS filter ports."

parents 1d42a097 f914db7c
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@ public class Contrast extends TestBase {
    }
    }


    public void runTest() {
    public void runTest() {
        mScript.set_bright(50.f);
        mScript.invoke_setBright(50.f);
        mScript.forEach_contrast(mInPixelsAllocation, mOutPixelsAllocation);
        mScript.forEach_contrast(mInPixelsAllocation, mOutPixelsAllocation);
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@ public class Exposure extends TestBase {
    }
    }


    public void runTest() {
    public void runTest() {
        mScript.set_bright(50.f);
        mScript.invoke_setBright(50.f);
        mScript.forEach_exposure(mInPixelsAllocation, mOutPixelsAllocation);
        mScript.forEach_exposure(mInPixelsAllocation, mOutPixelsAllocation);
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -48,6 +48,6 @@ void bwFilterKernel(const uchar4 *in, uchar4 *out) {
    localMin = fmin(r,localMin);
    localMin = fmin(r,localMin);
    localMax = fmax(g,b);
    localMax = fmax(g,b);
    localMax = fmax(r,localMax);
    localMax = fmax(r,localMax);
    avg =(localMin+localMax)/2;
    avg = (localMin+localMax) * 0.5f;
    out->r = out->g = out->b = rsClamp(avg, 0, 255);
    out->r = out->g = out->b = rsClamp(avg, 0, 255);
}
}
+14 −17
Original line number Original line Diff line number Diff line
@@ -16,27 +16,24 @@


#pragma version(1)
#pragma version(1)
#pragma rs java_package_name(com.android.rs.image)
#pragma rs java_package_name(com.android.rs.image)
#pragma rs_fp_relaxed
#pragma rs_fp_full


float bright = 0.f;
static float brightM = 0.f;
static float brightC = 0.f;


static unsigned char contrastClamp(int c)
void setBright(float v) {
{
    brightM = pow(2.f, v / 100.f);
    int N = 255;
    brightC = 127.f - brightM * 127.f;
    c &= ~(c >> 31);
    c -= N;
    c &= (c >> 31);
    c += N;
    return  (unsigned char) c;
}
}


void contrast(const uchar4 *in, uchar4 *out)
void contrast(const uchar4 *in, uchar4 *out)
{
{
    float m =  (float)pow(2, bright/100.f);
#if 0
    float c =  127-m*127;
    out->r = rsClamp((int)(brightM * in->r + brightC), 0, 255);

    out->g = rsClamp((int)(brightM * in->g + brightC), 0, 255);
    out->r = contrastClamp((int)(m*in->r+c));
    out->b = rsClamp((int)(brightM * in->b + brightC), 0, 255);
    out->g = contrastClamp((int)(m*in->g+c));
#else
    out->b = contrastClamp((int)(m*in->b+c));
    float3 v = convert_float3(in->rgb) * brightM + brightC;

    out->rgb = convert_uchar3(clamp(v, 0.f, 255.f));
#endif
}
}
+8 −14
Original line number Original line Diff line number Diff line
@@ -16,24 +16,18 @@


#pragma version(1)
#pragma version(1)
#pragma rs java_package_name(com.android.rs.image)
#pragma rs java_package_name(com.android.rs.image)
#pragma rs_fp_relaxed
#pragma rs_fp_full


float bright = 0.f;
static float bright = 0.f;


static unsigned char contrastClamp(int c)
void setBright(float v) {
{
    bright = 255.f / (255.f - v);
    int N = 255;
    c &= ~(c >> 31);
    c -= N;
    c &= (c >> 31);
    c += N;
    return  (unsigned char) c;
}
}


void exposure(const uchar4 *in, uchar4 *out)
void exposure(const uchar4 *in, uchar4 *out)
{
{
    int m = 255 - bright;
    out->r = rsClamp((int)(bright * in->r), 0, 255);
    out->r = contrastClamp((255 * in->r)/m);
    out->g = rsClamp((int)(bright * in->g), 0, 255);
    out->g = contrastClamp((255 * in->g)/m);
    out->b = rsClamp((int)(bright * in->b), 0, 255);
    out->b = contrastClamp((255 * in->b)/m);
}
}