diff options
author | Jason Sams <rjsams@android.com> | 2010-02-10 18:07:37 -0800 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2010-02-10 18:07:37 -0800 |
commit | 586f3b5d32c0464a4e69c92f89865eea672ab665 (patch) | |
tree | 5ee6dbfb9e195cf9b5060e4c3936ac286489250d /libs/rs | |
parent | 1d317d1453348d66e41c8b677a27340803139d4b (diff) | |
download | frameworks_base-586f3b5d32c0464a4e69c92f89865eea672ab665.zip frameworks_base-586f3b5d32c0464a4e69c92f89865eea672ab665.tar.gz frameworks_base-586f3b5d32c0464a4e69c92f89865eea672ab665.tar.bz2 |
Add java benchmark to imageProcessing.
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/java/ImageProcessing/res/raw/threshold.rs | 13 | ||||
-rw-r--r-- | libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java | 43 |
2 files changed, 46 insertions, 10 deletions
diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold.rs b/libs/rs/java/ImageProcessing/res/raw/threshold.rs index 72f12355..888b5cd 100644 --- a/libs/rs/java/ImageProcessing/res/raw/threshold.rs +++ b/libs/rs/java/ImageProcessing/res/raw/threshold.rs @@ -15,16 +15,17 @@ void main() { int i; float threshold = (Params->threshold * 255.f); + //testFnc(count, threshold, in, out); + for (i = 0; i < count; i++) { float luminance = 0.2125f * in->r + 0.7154f * in->g + 0.0721f * in->b; - luminance = maxf(0.0f, luminance - threshold); - vec3Scale(&pixel, luminance > 0); - out->a = in->a; - out->r = pixel.x; - out->g = pixel.y; - out->b = pixel.z; + if (luminance > threshold) { + *out = *in; + } else { + *((int *)out) = *((int *)in) & 0xff000000; + } in++; out++; diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index 568d3ab..60d562b 100644 --- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -31,11 +31,13 @@ import android.view.SurfaceView; import android.view.SurfaceHolder; import android.widget.ImageView; import android.widget.SeekBar; +import java.lang.Math; public class ImageProcessingActivity extends Activity implements SurfaceHolder.Callback { private Bitmap mBitmap; private Params mParams; private Script.Invokable mInvokable; + private int[] mInData; private int[] mOutData; @SuppressWarnings({"FieldCanBeLocal"}) @@ -87,6 +89,31 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C } } + private void javaFilter() { + long t = java.lang.System.currentTimeMillis(); + int count = mParams.inWidth * mParams.inHeight; + float threshold = mParams.threshold * 255.f; + + for (int i = 0; i < count; i++) { + final float r = (float)((mInData[i] >> 0) & 0xff); + final float g = (float)((mInData[i] >> 8) & 0xff); + final float b = (float)((mInData[i] >> 16) & 0xff); + + final float luminance = 0.2125f * r + + 0.7154f * g + + 0.0721f * b; + if (luminance > threshold) { + mOutData[i] = mInData[i]; + } else { + mOutData[i] = mInData[i] & 0xff000000; + } + } + + t = java.lang.System.currentTimeMillis() - t; + + android.util.Log.v("Img", "frame time ms " + t); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -106,7 +133,15 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C if (fromUser) { mParams.threshold = progress / 100.0f; mParamsAllocation.data(mParams); - mInvokable.execute(); + + if (false) { + mInvokable.execute(); + } else { + javaFilter(); + mBitmap.setPixels(mOutData, 0, mParams.outWidth, 0, 0, + mParams.outWidth, mParams.outHeight); + mDisplayView.invalidate(); + } } } @@ -149,9 +184,9 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C Element.createUser(mRS, Element.DataType.SIGNED_32), pixelCount); - final int[] data = new int[pixelCount]; - mBitmap.getPixels(data, 0, mParams.inWidth, 0, 0, mParams.inWidth, mParams.inHeight); - mInPixelsAllocation.data(data); + mInData = new int[pixelCount]; + mBitmap.getPixels(mInData, 0, mParams.inWidth, 0, 0, mParams.inWidth, mParams.inHeight); + mInPixelsAllocation.data(mInData); mOutData = new int[pixelCount]; mOutPixelsAllocation.data(mOutData); |