am e65afdb1: Merge "Lighten grain and make live preview gpu friendly." into jb-mr1-dev
* commit 'e65afdb179c319b654ae2e77d34d6d5d09709966': Lighten grain and make live preview gpu friendly.
This commit is contained in:
@@ -45,19 +45,40 @@ public class Grain extends TestBase {
|
|||||||
mScript.set_gNoiseStrength(s);
|
mScript.set_gNoiseStrength(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int findHighBit(int v) {
|
||||||
|
int bit = 0;
|
||||||
|
while (v > 1) {
|
||||||
|
bit++;
|
||||||
|
v >>= 1;
|
||||||
|
}
|
||||||
|
return bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void createTest(android.content.res.Resources res) {
|
public void createTest(android.content.res.Resources res) {
|
||||||
int width = mInPixelsAllocation.getType().getX();
|
int width = mInPixelsAllocation.getType().getX();
|
||||||
int height = mInPixelsAllocation.getType().getY();
|
int height = mInPixelsAllocation.getType().getY();
|
||||||
|
|
||||||
|
int noiseW = findHighBit(width);
|
||||||
|
int noiseH = findHighBit(height);
|
||||||
|
if (noiseW > 9) {
|
||||||
|
noiseW = 9;
|
||||||
|
}
|
||||||
|
if (noiseH > 9) {
|
||||||
|
noiseH = 9;
|
||||||
|
}
|
||||||
|
noiseW = 1 << noiseW;
|
||||||
|
noiseH = 1 << noiseH;
|
||||||
|
|
||||||
Type.Builder tb = new Type.Builder(mRS, Element.U8(mRS));
|
Type.Builder tb = new Type.Builder(mRS, Element.U8(mRS));
|
||||||
tb.setX(width);
|
tb.setX(noiseW);
|
||||||
tb.setY(height);
|
tb.setY(noiseH);
|
||||||
mNoise = Allocation.createTyped(mRS, tb.create());
|
mNoise = Allocation.createTyped(mRS, tb.create());
|
||||||
mNoise2 = Allocation.createTyped(mRS, tb.create());
|
mNoise2 = Allocation.createTyped(mRS, tb.create());
|
||||||
|
|
||||||
mScript = new ScriptC_grain(mRS, res, R.raw.grain);
|
mScript = new ScriptC_grain(mRS, res, R.raw.grain);
|
||||||
mScript.set_gWidth(width);
|
mScript.set_gWMask(noiseW - 1);
|
||||||
mScript.set_gHeight(height);
|
mScript.set_gHMask(noiseH - 1);
|
||||||
mScript.set_gNoiseStrength(0.5f);
|
mScript.set_gNoiseStrength(0.5f);
|
||||||
mScript.set_gBlendSource(mNoise);
|
mScript.set_gBlendSource(mNoise);
|
||||||
mScript.set_gNoise(mNoise2);
|
mScript.set_gNoise(mNoise2);
|
||||||
|
|||||||
@@ -38,15 +38,15 @@ void genRand(uchar *out) {
|
|||||||
* 1 2 1
|
* 1 2 1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t gWidth;
|
int32_t gWMask;
|
||||||
int32_t gHeight;
|
int32_t gHMask;
|
||||||
|
|
||||||
rs_allocation gBlendSource;
|
rs_allocation gBlendSource;
|
||||||
void blend9(uchar *out, uint32_t x, uint32_t y) {
|
void blend9(uchar *out, uint32_t x, uint32_t y) {
|
||||||
uint32_t x1 = min((int32_t)x+1, (int32_t)(gWidth -1));
|
uint32_t x1 = (x-1) & gWMask;
|
||||||
uint32_t x2 = max((int32_t)x-1, (int32_t)0);
|
uint32_t x2 = (x+1) & gWMask;
|
||||||
uint32_t y1 = min((int32_t)y+1, (int32_t)(gHeight -1));
|
uint32_t y1 = (y-1) & gHMask;
|
||||||
uint32_t y2 = max((int32_t)y-1, (int32_t)0);
|
uint32_t y2 = (y+1) & gHMask;
|
||||||
|
|
||||||
uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1);
|
uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1);
|
||||||
uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1);
|
uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1);
|
||||||
@@ -78,7 +78,7 @@ float gNoiseStrength;
|
|||||||
rs_allocation gNoise;
|
rs_allocation gNoise;
|
||||||
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
||||||
float4 ip = convert_float4(*in);
|
float4 ip = convert_float4(*in);
|
||||||
float pnoise = (float) rsGetElementAt_uchar(gNoise, x, y);
|
float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask);
|
||||||
|
|
||||||
float energy_level = ip.r + ip.g + ip.b;
|
float energy_level = ip.r + ip.g + ip.b;
|
||||||
float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f;
|
float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f;
|
||||||
|
|||||||
@@ -305,8 +305,7 @@ public class CameraPreviewActivity extends Activity
|
|||||||
|
|
||||||
long t1 = java.lang.System.currentTimeMillis();
|
long t1 = java.lang.System.currentTimeMillis();
|
||||||
|
|
||||||
mFilterYuv.execute(data);
|
mFilterYuv.execute(data, mCallbackBitmap);
|
||||||
mFilterYuv.copyOut(mCallbackBitmap);
|
|
||||||
|
|
||||||
long t2 = java.lang.System.currentTimeMillis();
|
long t2 = java.lang.System.currentTimeMillis();
|
||||||
mTiming[mTimingSlot++] = t2 - t1;
|
mTiming[mTimingSlot++] = t2 - t1;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public class RsYuv
|
|||||||
private Allocation mAllocationOut;
|
private Allocation mAllocationOut;
|
||||||
private Allocation mAllocationIn;
|
private Allocation mAllocationIn;
|
||||||
private ScriptC_yuv mScript;
|
private ScriptC_yuv mScript;
|
||||||
|
private ScriptIntrinsicYuvToRGB mYuv;
|
||||||
|
|
||||||
RsYuv(RenderScript rs, Resources res, int width, int height) {
|
RsYuv(RenderScript rs, Resources res, int width, int height) {
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
@@ -50,6 +51,8 @@ public class RsYuv
|
|||||||
mScript = new ScriptC_yuv(mRS, res, R.raw.yuv);
|
mScript = new ScriptC_yuv(mRS, res, R.raw.yuv);
|
||||||
mScript.invoke_setSize(mWidth, mHeight);
|
mScript.invoke_setSize(mWidth, mHeight);
|
||||||
|
|
||||||
|
mYuv = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(mRS));
|
||||||
|
|
||||||
Type.Builder tb = new Type.Builder(mRS, Element.RGBA_8888(mRS));
|
Type.Builder tb = new Type.Builder(mRS, Element.RGBA_8888(mRS));
|
||||||
tb.setX(mWidth);
|
tb.setX(mWidth);
|
||||||
tb.setY(mHeight);
|
tb.setY(mHeight);
|
||||||
@@ -58,34 +61,16 @@ public class RsYuv
|
|||||||
mAllocationIn = Allocation.createSized(rs, Element.U8(mRS), (mHeight * mWidth) +
|
mAllocationIn = Allocation.createSized(rs, Element.U8(mRS), (mHeight * mWidth) +
|
||||||
((mHeight / 2) * (mWidth / 2) * 2));
|
((mHeight / 2) * (mWidth / 2) * 2));
|
||||||
|
|
||||||
mScript.bind_gYuvIn(mAllocationIn);
|
mYuv.setInput(mAllocationIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long mTiming[] = new long[50];
|
private long mTiming[] = new long[50];
|
||||||
private int mTimingSlot = 0;
|
private int mTimingSlot = 0;
|
||||||
|
|
||||||
void execute(byte[] yuv) {
|
void execute(byte[] yuv, Bitmap b) {
|
||||||
mAllocationIn.copyFrom(yuv);
|
mAllocationIn.copyFrom(yuv);
|
||||||
mRS.finish();
|
mYuv.forEach(mAllocationOut);
|
||||||
|
mScript.forEach_root(mAllocationOut, mAllocationOut);
|
||||||
long t1 = java.lang.System.currentTimeMillis();
|
|
||||||
mScript.forEach_root(mAllocationOut);
|
|
||||||
mRS.finish();
|
|
||||||
long t2 = java.lang.System.currentTimeMillis();
|
|
||||||
|
|
||||||
mTiming[mTimingSlot++] = t2 - t1;
|
|
||||||
if (mTimingSlot >= mTiming.length) {
|
|
||||||
float total = 0;
|
|
||||||
for (int i=0; i<mTiming.length; i++) {
|
|
||||||
total += (float)mTiming[i];
|
|
||||||
}
|
|
||||||
total /= mTiming.length;
|
|
||||||
Log.e("yuv", "core time = " + total);
|
|
||||||
mTimingSlot = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void copyOut(Bitmap b) {
|
|
||||||
mAllocationOut.copyTo(b);
|
mAllocationOut.copyTo(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
#pragma rs java_package_name(com.android.rs.livepreview)
|
#pragma rs java_package_name(com.android.rs.livepreview)
|
||||||
#pragma rs_fp_relaxed
|
#pragma rs_fp_relaxed
|
||||||
|
|
||||||
uchar *gYuvIn;
|
|
||||||
|
|
||||||
static int gWidth;
|
static int gWidth;
|
||||||
static int gHeight;
|
static int gHeight;
|
||||||
static uchar crossProcess_tableR[256];
|
static uchar crossProcess_tableR[256];
|
||||||
@@ -80,13 +78,9 @@ static uchar4 vignette(uchar4 color, uint32_t x, uint32_t y) {
|
|||||||
return convert_uchar4(c);
|
return convert_uchar4(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void root(uchar4 *out, uint32_t x, uint32_t y) {
|
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
||||||
uchar Y = gYuvIn[(y * gWidth) + x];
|
uchar4 p;
|
||||||
uchar *uv = &gYuvIn[gWidth * gHeight];
|
p = crossProcess_i(*in);
|
||||||
uv += (((x>>1)<<1) + (y>>1) * gWidth);
|
|
||||||
|
|
||||||
uchar4 p = rsYuvToRGBA_uchar4(Y, uv[1], uv[0]);
|
|
||||||
p = crossProcess_i(p);
|
|
||||||
p = vignette(p, x, y);
|
p = vignette(p, x, y);
|
||||||
|
|
||||||
out->rgba = p;
|
out->rgba = p;
|
||||||
|
|||||||
Reference in New Issue
Block a user