am c31c5433: Merge "fix blend intrinsics, add tests" into jb-mr1-dev
* commit 'c31c54332ece2053f8c03fa171d8702234f13df7': fix blend intrinsics, add tests
This commit is contained in:
@@ -36,17 +36,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic {
|
||||
* @return ScriptIntrinsicBlend
|
||||
*/
|
||||
public static ScriptIntrinsicBlend create(RenderScript rs, Element e) {
|
||||
int id = rs.nScriptIntrinsicCreate(6, e.getID(rs));
|
||||
// 7 comes from RS_SCRIPT_INTRINSIC_ID_BLEND in rsDefines.h
|
||||
int id = rs.nScriptIntrinsicCreate(7, e.getID(rs));
|
||||
return new ScriptIntrinsicBlend(id, rs);
|
||||
|
||||
}
|
||||
|
||||
private void blend(int id, Allocation ain, Allocation aout) {
|
||||
if (ain.getElement() != Element.U8_4(mRS)) {
|
||||
throw new RSIllegalArgumentException("Input not of expected format.");
|
||||
if (!ain.getElement().isCompatible(Element.U8_4(mRS))) {
|
||||
throw new RSIllegalArgumentException("Input is not of expected format.");
|
||||
}
|
||||
if (aout.getElement() != Element.U8_4(mRS)) {
|
||||
throw new RSIllegalArgumentException("Output not of expected format.");
|
||||
if (!aout.getElement().isCompatible(Element.U8_4(mRS))) {
|
||||
throw new RSIllegalArgumentException("Output is not of expected format.");
|
||||
}
|
||||
forEach(id, ain, aout, null);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,10 @@
|
||||
android:id="@+id/filterselection"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<Spinner
|
||||
android:id="@+id/spinner1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider1Text"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.rs.image;
|
||||
|
||||
import java.lang.Math;
|
||||
import java.lang.Short;
|
||||
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.Matrix4f;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.ScriptGroup;
|
||||
import android.renderscript.ScriptIntrinsicBlend;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.view.View;
|
||||
import android.widget.Spinner;
|
||||
|
||||
public class Blend extends TestBase {
|
||||
private ScriptIntrinsicBlend mBlend;
|
||||
private ScriptC_blend mBlendHelper;
|
||||
private short image1Alpha = 128;
|
||||
private short image2Alpha = 128;
|
||||
|
||||
String mIntrinsicNames[];
|
||||
|
||||
private Allocation image1;
|
||||
private Allocation image2;
|
||||
private int currentIntrinsic = 0;
|
||||
|
||||
private AdapterView.OnItemSelectedListener mIntrinsicSpinnerListener =
|
||||
new AdapterView.OnItemSelectedListener() {
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||
currentIntrinsic = pos;
|
||||
runTest();
|
||||
act.updateDisplay();
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView parent) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mBlend = ScriptIntrinsicBlend.create(mRS, Element.U8_4(mRS));
|
||||
mBlendHelper = new ScriptC_blend(mRS);
|
||||
mBlendHelper.set_alpha((short)128);
|
||||
|
||||
image1 = Allocation.createTyped(mRS, mInPixelsAllocation.getType());
|
||||
image2 = Allocation.createTyped(mRS, mInPixelsAllocation2.getType());
|
||||
|
||||
mIntrinsicNames = new String[14];
|
||||
mIntrinsicNames[0] = "Source";
|
||||
mIntrinsicNames[1] = "Destination";
|
||||
mIntrinsicNames[2] = "Source Over";
|
||||
mIntrinsicNames[3] = "Destination Over";
|
||||
mIntrinsicNames[4] = "Source In";
|
||||
mIntrinsicNames[5] = "Destination In";
|
||||
mIntrinsicNames[6] = "Source Out";
|
||||
mIntrinsicNames[7] = "Destination Out";
|
||||
mIntrinsicNames[8] = "Source Atop";
|
||||
mIntrinsicNames[9] = "Destination Atop";
|
||||
mIntrinsicNames[10] = "XOR";
|
||||
mIntrinsicNames[11] = "Add";
|
||||
mIntrinsicNames[12] = "Subtract";
|
||||
mIntrinsicNames[13] = "Multiply";
|
||||
}
|
||||
|
||||
public boolean onSpinner1Setup(Spinner s) {
|
||||
s.setAdapter(new ArrayAdapter<String>(
|
||||
act, R.layout.spinner_layout, mIntrinsicNames));
|
||||
s.setOnItemSelectedListener(mIntrinsicSpinnerListener);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
t.setText("Image 1 Alpha");
|
||||
b.setMax(255);
|
||||
b.setProgress(image1Alpha);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
image1Alpha = (short)progress;
|
||||
}
|
||||
|
||||
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||
t.setText("Image 2 Alpha");
|
||||
b.setMax(255);
|
||||
b.setProgress(image2Alpha);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar2Changed(int progress) {
|
||||
image2Alpha = (short)progress;
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
image1.copy2DRangeFrom(0, 0, mInPixelsAllocation.getType().getX(), mInPixelsAllocation.getType().getY(), mInPixelsAllocation, 0, 0);
|
||||
image2.copy2DRangeFrom(0, 0, mInPixelsAllocation2.getType().getX(), mInPixelsAllocation2.getType().getY(), mInPixelsAllocation2, 0, 0);
|
||||
|
||||
mBlendHelper.set_alpha(image1Alpha);
|
||||
mBlendHelper.forEach_setImageAlpha(image1);
|
||||
|
||||
mBlendHelper.set_alpha(image2Alpha);
|
||||
mBlendHelper.forEach_setImageAlpha(image2);
|
||||
|
||||
switch (currentIntrinsic) {
|
||||
case 0:
|
||||
mBlend.forEachSrc(image1, image2);
|
||||
break;
|
||||
case 1:
|
||||
mBlend.forEachDst(image1, image2);
|
||||
break;
|
||||
case 2:
|
||||
mBlend.forEachSrcOver(image1, image2);
|
||||
break;
|
||||
case 3:
|
||||
mBlend.forEachDstOver(image1, image2);
|
||||
break;
|
||||
case 4:
|
||||
mBlend.forEachSrcIn(image1, image2);
|
||||
break;
|
||||
case 5:
|
||||
mBlend.forEachDstIn(image1, image2);
|
||||
break;
|
||||
case 6:
|
||||
mBlend.forEachSrcOut(image1, image2);
|
||||
break;
|
||||
case 7:
|
||||
mBlend.forEachDstOut(image1, image2);
|
||||
break;
|
||||
case 8:
|
||||
mBlend.forEachSrcAtop(image1, image2);
|
||||
break;
|
||||
case 9:
|
||||
mBlend.forEachDstAtop(image1, image2);
|
||||
break;
|
||||
case 10:
|
||||
mBlend.forEachXor(image1, image2);
|
||||
break;
|
||||
case 11:
|
||||
mBlend.forEachAdd(image1, image2);
|
||||
break;
|
||||
case 12:
|
||||
mBlend.forEachSubtract(image1, image2);
|
||||
break;
|
||||
case 13:
|
||||
mBlend.forEachMultiply(image1, image2);
|
||||
break;
|
||||
}
|
||||
|
||||
mOutPixelsAllocation.copy2DRangeFrom(0, 0, image2.getType().getX(), image2.getType().getY(), image2, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,9 +55,11 @@ public class ImageProcessingActivity extends Activity
|
||||
private final String RESULT_FILE = "image_processing_result.csv";
|
||||
|
||||
Bitmap mBitmapIn;
|
||||
Bitmap mBitmapIn2;
|
||||
Bitmap mBitmapOut;
|
||||
String mTestNames[];
|
||||
|
||||
private Spinner mSpinner;
|
||||
private SeekBar mBar1;
|
||||
private SeekBar mBar2;
|
||||
private SeekBar mBar3;
|
||||
@@ -81,6 +83,10 @@ public class ImageProcessingActivity extends Activity
|
||||
|
||||
private TestBase mTest;
|
||||
|
||||
public void updateDisplay() {
|
||||
mTest.updateBitmap(mBitmapOut);
|
||||
mDisplayView.invalidate();
|
||||
}
|
||||
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (fromUser) {
|
||||
@@ -98,8 +104,7 @@ public class ImageProcessingActivity extends Activity
|
||||
}
|
||||
|
||||
mTest.runTest();
|
||||
mTest.updateBitmap(mBitmapOut);
|
||||
mDisplayView.invalidate();
|
||||
updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +115,9 @@ public class ImageProcessingActivity extends Activity
|
||||
}
|
||||
|
||||
void setupBars() {
|
||||
mSpinner.setVisibility(View.VISIBLE);
|
||||
mTest.onSpinner1Setup(mSpinner);
|
||||
|
||||
mBar1.setVisibility(View.VISIBLE);
|
||||
mText1.setVisibility(View.VISIBLE);
|
||||
mTest.onBar1Setup(mBar1, mText1);
|
||||
@@ -221,19 +229,21 @@ public class ImageProcessingActivity extends Activity
|
||||
case 27:
|
||||
mTest = new Mandelbrot();
|
||||
break;
|
||||
case 28:
|
||||
mTest = new Blend();
|
||||
break;
|
||||
}
|
||||
|
||||
mTest.createBaseTest(this, mBitmapIn);
|
||||
mTest.createBaseTest(this, mBitmapIn, mBitmapIn2);
|
||||
setupBars();
|
||||
|
||||
mTest.runTest();
|
||||
mTest.updateBitmap(mBitmapOut);
|
||||
mDisplayView.invalidate();
|
||||
updateDisplay();
|
||||
mBenchmarkResult.setText("Result: not run");
|
||||
}
|
||||
|
||||
void setupTests() {
|
||||
mTestNames = new String[28];
|
||||
mTestNames = new String[29];
|
||||
mTestNames[0] = "Levels Vec3 Relaxed";
|
||||
mTestNames[1] = "Levels Vec4 Relaxed";
|
||||
mTestNames[2] = "Levels Vec3 Full";
|
||||
@@ -262,6 +272,7 @@ public class ImageProcessingActivity extends Activity
|
||||
mTestNames[25] = "Convolve 5x5";
|
||||
mTestNames[26] = "Intrinsics Convolve 5x5";
|
||||
mTestNames[27] = "Mandelbrot";
|
||||
mTestNames[28] = "Intrinsics Blend";
|
||||
|
||||
mTestSpinner.setAdapter(new ArrayAdapter<String>(
|
||||
this, R.layout.spinner_layout, mTestNames));
|
||||
@@ -284,6 +295,7 @@ public class ImageProcessingActivity extends Activity
|
||||
setContentView(R.layout.main);
|
||||
|
||||
mBitmapIn = loadBitmap(R.drawable.img1600x1067);
|
||||
mBitmapIn2 = loadBitmap(R.drawable.img1600x1067b);
|
||||
mBitmapOut = loadBitmap(R.drawable.img1600x1067);
|
||||
|
||||
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
|
||||
@@ -291,6 +303,8 @@ public class ImageProcessingActivity extends Activity
|
||||
mDisplayView = (ImageView) findViewById(R.id.display);
|
||||
mDisplayView.setImageBitmap(mBitmapOut);
|
||||
|
||||
mSpinner = (Spinner) findViewById(R.id.spinner1);
|
||||
|
||||
mBar1 = (SeekBar) findViewById(R.id.slider1);
|
||||
mBar2 = (SeekBar) findViewById(R.id.slider2);
|
||||
mBar3 = (SeekBar) findViewById(R.id.slider3);
|
||||
|
||||
@@ -36,14 +36,18 @@ import android.widget.TextView;
|
||||
import android.view.View;
|
||||
import android.util.Log;
|
||||
import java.lang.Math;
|
||||
import android.widget.Spinner;
|
||||
|
||||
public class TestBase {
|
||||
protected final String TAG = "Img";
|
||||
|
||||
protected RenderScript mRS;
|
||||
protected Allocation mInPixelsAllocation;
|
||||
protected Allocation mInPixelsAllocation2;
|
||||
protected Allocation mOutPixelsAllocation;
|
||||
|
||||
protected ImageProcessingActivity act;
|
||||
|
||||
// Override to use UI elements
|
||||
public void onBar1Changed(int progress) {
|
||||
}
|
||||
@@ -84,11 +88,20 @@ public class TestBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void createBaseTest(ImageProcessingActivity act, Bitmap b) {
|
||||
public boolean onSpinner1Setup(Spinner s) {
|
||||
s.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void createBaseTest(ImageProcessingActivity ipact, Bitmap b, Bitmap b2) {
|
||||
act = ipact;
|
||||
mRS = RenderScript.create(act);
|
||||
mInPixelsAllocation = Allocation.createFromBitmap(mRS, b,
|
||||
Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mInPixelsAllocation2 = Allocation.createFromBitmap(mRS, b2,
|
||||
Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mOutPixelsAllocation = Allocation.createFromBitmap(mRS, b,
|
||||
Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
|
||||
Reference in New Issue
Block a user