Merge "Move compute tests from frameworks/base to frameworks/rs" into jb-mr2-dev
@@ -1,26 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2008 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := RsBalls
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.android.rs.balls">
|
||||
<uses-sdk android:minSdkVersion="14" />
|
||||
<application
|
||||
android:label="RsBalls"
|
||||
android:icon="@drawable/test_pattern">
|
||||
<activity android:name="Balls"
|
||||
android:screenOrientation="landscape">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1 +0,0 @@
|
||||
<p>A brute force physics simulation that renders many balls onto the screen and moves them according to user touch and gravity.</p>
|
||||
|
Before Width: | Height: | Size: 413 B |
|
Before Width: | Height: | Size: 307 B |
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.example.android.rs.balls;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScript;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings.System;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
public class Balls extends Activity implements SensorEventListener {
|
||||
//EventListener mListener = new EventListener();
|
||||
|
||||
private static final String LOG_TAG = "libRS_jni";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean LOG_ENABLED = false;
|
||||
|
||||
private BallsView mView;
|
||||
private SensorManager mSensorManager;
|
||||
|
||||
// get the current looper (from your Activity UI thread for instance
|
||||
|
||||
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
//android.util.Log.d("rs", "sensor: " + event.sensor + ", x: " + event.values[0] + ", y: " + event.values[1] + ", z: " + event.values[2]);
|
||||
synchronized (this) {
|
||||
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
|
||||
if(mView != null) {
|
||||
mView.setAccel(event.values[0], event.values[1], event.values[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||
|
||||
// Create our Preview view and set it as the content of our
|
||||
// Activity
|
||||
mView = new BallsView(this);
|
||||
setContentView(mView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
mSensorManager.registerListener(this,
|
||||
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
|
||||
SensorManager.SENSOR_DELAY_FASTEST);
|
||||
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
super.onResume();
|
||||
mView.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mView.pause();
|
||||
onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
mSensorManager.unregisterListener(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
static void log(String message) {
|
||||
if (LOG_ENABLED) {
|
||||
Log.v(LOG_TAG, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.example.android.rs.balls;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class BallsRS {
|
||||
public static final int PART_COUNT = 4000;
|
||||
|
||||
public BallsRS() {
|
||||
}
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
private ScriptC_balls mScript;
|
||||
private ScriptC_ball_physics mPhysicsScript;
|
||||
private ProgramFragment mPFPoints;
|
||||
private ScriptField_Point mPoints;
|
||||
private ScriptField_VpConsts mVpConsts;
|
||||
private ScriptField_BallGrid mGrid;
|
||||
private ScriptField_Ball mBalls;
|
||||
private Allocation mGridCache;
|
||||
|
||||
void updateProjectionMatrices() {
|
||||
mVpConsts = new ScriptField_VpConsts(mRS, 1,
|
||||
Allocation.USAGE_SCRIPT |
|
||||
Allocation.USAGE_GRAPHICS_CONSTANTS);
|
||||
ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
|
||||
Matrix4f mvp = new Matrix4f();
|
||||
mvp.loadOrtho(0, mRS.getWidth(), mRS.getHeight(), 0, -1, 1);
|
||||
i.MVP = mvp;
|
||||
mVpConsts.set(i, 0, true);
|
||||
}
|
||||
|
||||
private void createProgramVertex() {
|
||||
updateProjectionMatrices();
|
||||
|
||||
ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS);
|
||||
String t = "varying vec4 varColor;\n" +
|
||||
"void main() {\n" +
|
||||
" vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n" +
|
||||
" pos.xy = ATTRIB_position;\n" +
|
||||
" gl_Position = UNI_MVP * pos;\n" +
|
||||
" varColor = ATTRIB_color;\n" +
|
||||
" gl_PointSize = 12.0;\n" +
|
||||
"}\n";
|
||||
sb.setShader(t);
|
||||
sb.addConstant(mVpConsts.getType());
|
||||
sb.addInput(mPoints.getElement());
|
||||
ProgramVertex pvs = sb.create();
|
||||
pvs.bindConstants(mVpConsts.getAllocation(), 0);
|
||||
mRS.bindProgramVertex(pvs);
|
||||
}
|
||||
|
||||
private Allocation loadTexture(int id) {
|
||||
final Allocation allocation =
|
||||
Allocation.createFromBitmapResource(mRS, mRes,
|
||||
id, Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
return allocation;
|
||||
}
|
||||
|
||||
ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
|
||||
ProgramStore.Builder builder = new ProgramStore.Builder(rs);
|
||||
builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
|
||||
builder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE, ProgramStore.BlendDstFunc.ONE);
|
||||
builder.setDitherEnabled(false);
|
||||
builder.setDepthMaskEnabled(false);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private void createPF(int width, int height) {
|
||||
ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
pfb.setPointSpriteTexCoordinateReplacement(true);
|
||||
pfb.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
pfb.setVaryingColor(true);
|
||||
mPFPoints = pfb.create();
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res, int width, int height) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
|
||||
createPF(width, height);
|
||||
|
||||
mPFPoints.bindTexture(loadTexture(R.drawable.flares), 0);
|
||||
|
||||
mPoints = new ScriptField_Point(mRS, PART_COUNT, Allocation.USAGE_SCRIPT);
|
||||
|
||||
Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS);
|
||||
smb.addVertexAllocation(mPoints.getAllocation());
|
||||
smb.addIndexSetType(Mesh.Primitive.POINT);
|
||||
Mesh smP = smb.create();
|
||||
|
||||
mGrid = ScriptField_BallGrid.create2D(mRS, (width + 99) / 100, (height + 99) / 100);
|
||||
mGridCache = Allocation.createSized(mRS, Element.F32_2(mRS), PART_COUNT);
|
||||
mBalls = new ScriptField_Ball(mRS, PART_COUNT, Allocation.USAGE_SCRIPT);
|
||||
|
||||
mPhysicsScript = new ScriptC_ball_physics(mRS);
|
||||
mPhysicsScript.set_gGridCache(mGridCache);
|
||||
mPhysicsScript.set_gBalls(mBalls.getAllocation());
|
||||
|
||||
mScript = new ScriptC_balls(mRS);
|
||||
mScript.set_partMesh(smP);
|
||||
mScript.set_physics_script(mPhysicsScript);
|
||||
mScript.bind_point(mPoints);
|
||||
mScript.bind_balls(mBalls);
|
||||
mScript.set_gGrid(mGrid.getAllocation());
|
||||
mScript.bind_gGridCache(mGridCache);
|
||||
|
||||
mScript.set_gPFPoints(mPFPoints);
|
||||
createProgramVertex();
|
||||
|
||||
mRS.bindProgramStore(BLEND_ADD_DEPTH_NONE(mRS));
|
||||
|
||||
mPhysicsScript.set_gMinPos(new Float2(5, 5));
|
||||
mPhysicsScript.set_gMaxPos(new Float2(width - 5, height - 5));
|
||||
mPhysicsScript.set_gGrid(mGrid.getAllocation());
|
||||
|
||||
mScript.invoke_initParts(width, height);
|
||||
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
|
||||
public void newTouchPosition(float x, float y, float pressure, int id) {
|
||||
mPhysicsScript.invoke_touch(x, y, pressure * mRS.getWidth() / 1280, id);
|
||||
}
|
||||
|
||||
public void setAccel(float x, float y) {
|
||||
mPhysicsScript.set_gGravityVector(new Float2(x, y));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.example.android.rs.balls;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class BallsView extends RSSurfaceView {
|
||||
|
||||
public BallsView(Context context) {
|
||||
super(context);
|
||||
//setFocusable(true);
|
||||
}
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private BallsRS mRender;
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
if (mRS == null) {
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
mRS = createRenderScriptGL(sc);
|
||||
mRS.setSurface(holder, w, h);
|
||||
mRender = new BallsRS();
|
||||
mRender.init(mRS, getResources(), w, h);
|
||||
}
|
||||
mRender.updateProjectionMatrices();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
if(mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev)
|
||||
{
|
||||
int act = ev.getActionMasked();
|
||||
if (act == ev.ACTION_UP) {
|
||||
mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
|
||||
return false;
|
||||
} else if (act == MotionEvent.ACTION_POINTER_UP) {
|
||||
// only one pointer going up, we can get the index like this
|
||||
int pointerIndex = ev.getActionIndex();
|
||||
int pointerId = ev.getPointerId(pointerIndex);
|
||||
mRender.newTouchPosition(0, 0, 0, pointerId);
|
||||
return false;
|
||||
}
|
||||
int count = ev.getHistorySize();
|
||||
int pcount = ev.getPointerCount();
|
||||
|
||||
for (int p=0; p < pcount; p++) {
|
||||
int id = ev.getPointerId(p);
|
||||
mRender.newTouchPosition(ev.getX(p),
|
||||
ev.getY(p),
|
||||
ev.getPressure(p),
|
||||
id);
|
||||
|
||||
for (int i=0; i < count; i++) {
|
||||
mRender.newTouchPosition(ev.getHistoricalX(p, i),
|
||||
ev.getHistoricalY(p, i),
|
||||
ev.getHistoricalPressure(p, i),
|
||||
id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void setAccel(float x, float y, float z) {
|
||||
if ((mRender == null) || (mRS == null)) {
|
||||
return;
|
||||
}
|
||||
mRender.setAccel(x, -y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.example.android.rs.balls)
|
||||
|
||||
#include "balls.rsh"
|
||||
|
||||
float2 gGravityVector = {0.f, 9.8f};
|
||||
|
||||
float2 gMinPos = {0.f, 0.f};
|
||||
float2 gMaxPos = {1280.f, 700.f};
|
||||
|
||||
static float2 touchPos[10];
|
||||
static float touchPressure[10];
|
||||
static const float gDT = 1.f / 30.f;
|
||||
|
||||
rs_allocation gGrid;
|
||||
rs_allocation gGridCache;
|
||||
rs_allocation gBalls;
|
||||
|
||||
float gScale = 1.f;
|
||||
|
||||
void touch(float x, float y, float pressure, int id) {
|
||||
if (id >= 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
touchPos[id].x = x;
|
||||
touchPos[id].y = y;
|
||||
touchPressure[id] = pressure;
|
||||
}
|
||||
|
||||
void root(Ball_t *ball, uint32_t x) {
|
||||
float2 fv = 0;
|
||||
float pressure = 0;
|
||||
float2 pos = ball->position;
|
||||
int2 gridPos[9];
|
||||
|
||||
gridPos[0] = convert_int2((ball->position / 100.f) /*- 0.4999f*/);
|
||||
gridPos[1] = (int2){gridPos[0].x - 1, gridPos[0].y - 1};
|
||||
gridPos[2] = (int2){gridPos[0].x + 0, gridPos[0].y - 1};
|
||||
gridPos[3] = (int2){gridPos[0].x + 1, gridPos[0].y - 1};
|
||||
gridPos[4] = (int2){gridPos[0].x - 1, gridPos[0].y};
|
||||
gridPos[5] = (int2){gridPos[0].x + 1, gridPos[0].y};
|
||||
gridPos[6] = (int2){gridPos[0].x - 1, gridPos[0].y + 1};
|
||||
gridPos[7] = (int2){gridPos[0].x + 0, gridPos[0].y + 1};
|
||||
gridPos[8] = (int2){gridPos[0].x + 1, gridPos[0].y + 1};
|
||||
|
||||
for (int gct=0; gct < 9; gct++) {
|
||||
if ((gridPos[gct].x >= rsAllocationGetDimX(gGrid)) ||
|
||||
(gridPos[gct].x < 0) ||
|
||||
(gridPos[gct].y >= rsAllocationGetDimY(gGrid)) ||
|
||||
(gridPos[gct].y < 0)) {
|
||||
continue;
|
||||
}
|
||||
//rsDebug("grid ", gridPos[gct]);
|
||||
const BallGrid_t *bg = (const BallGrid_t *)rsGetElementAt(gGrid, gridPos[gct].x, gridPos[gct].y);
|
||||
|
||||
for (int cidx = 0; cidx < bg->count; cidx++) {
|
||||
float2 bcptr = rsGetElementAt_float2(gGridCache, bg->cacheIdx + cidx);
|
||||
float2 vec = bcptr - pos;
|
||||
float2 vec2 = vec * vec;
|
||||
float len2 = vec2.x + vec2.y;
|
||||
|
||||
if ((len2 < 10000.f) && (len2 > 0.f)) {
|
||||
float t = native_powr(len2, 1.5f) + 16.0f;
|
||||
float2 pfv = (vec / t) * 16000.f;
|
||||
pressure += length(pfv);
|
||||
fv -= pfv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//fv /= ball->size * ball->size * ball->size;
|
||||
fv -= gGravityVector * 4.f * gScale;
|
||||
fv *= gDT;
|
||||
|
||||
for (int i=0; i < 10; i++) {
|
||||
if (touchPressure[i] > 0.1f) {
|
||||
float2 vec = touchPos[i] - ball->position;
|
||||
float2 vec2 = vec * vec;
|
||||
float len2 = max(2.f, vec2.x + vec2.y);
|
||||
float2 pfv = (vec / len2) * touchPressure[i] * 500.f * gScale;
|
||||
pressure += length(pfv);
|
||||
fv -= pfv;
|
||||
}
|
||||
}
|
||||
|
||||
ball->delta = (ball->delta * (1.f - 0.008f)) + fv;
|
||||
ball->position = ball->position + (ball->delta * gDT);
|
||||
|
||||
const float wallForce = 400.f * gScale;
|
||||
if (ball->position.x > (gMaxPos.x - 20.f)) {
|
||||
float d = gMaxPos.x - ball->position.x;
|
||||
if (d < 0.f) {
|
||||
if (ball->delta.x > 0) {
|
||||
ball->delta.x *= -0.7f;
|
||||
}
|
||||
ball->position.x = gMaxPos.x - 1.f;
|
||||
} else {
|
||||
ball->delta.x -= min(wallForce / (d * d), 10.f);
|
||||
}
|
||||
}
|
||||
|
||||
if (ball->position.x < (gMinPos.x + 20.f)) {
|
||||
float d = ball->position.x - gMinPos.x;
|
||||
if (d < 0.f) {
|
||||
if (ball->delta.x < 0) {
|
||||
ball->delta.x *= -0.7f;
|
||||
}
|
||||
ball->position.x = gMinPos.x + 1.f;
|
||||
} else {
|
||||
ball->delta.x += min(wallForce / (d * d), 10.f);
|
||||
}
|
||||
}
|
||||
|
||||
if (ball->position.y > (gMaxPos.y - 20.f)) {
|
||||
float d = gMaxPos.y - ball->position.y;
|
||||
if (d < 0.f) {
|
||||
if (ball->delta.y > 0) {
|
||||
ball->delta.y *= -0.7f;
|
||||
}
|
||||
ball->position.y = gMaxPos.y - 1.f;
|
||||
} else {
|
||||
ball->delta.y -= min(wallForce / (d * d), 10.f);
|
||||
}
|
||||
}
|
||||
|
||||
if (ball->position.y < (gMinPos.y + 20.f)) {
|
||||
float d = ball->position.y - gMinPos.y;
|
||||
if (d < 0.f) {
|
||||
if (ball->delta.y < 0) {
|
||||
ball->delta.y *= -0.7f;
|
||||
}
|
||||
ball->position.y = gMinPos.y + 1.f;
|
||||
} else {
|
||||
ball->delta.y += min(wallForce / (d * d * d), 10.f);
|
||||
}
|
||||
}
|
||||
|
||||
// low pressure ~500, high ~2500
|
||||
pressure = max(pressure - 400.f, 0.f);
|
||||
ball->pressure = pressure;
|
||||
|
||||
//rsDebug("p ", pressure);
|
||||
|
||||
float4 color = 1.f;
|
||||
color.r = pow(pressure, 0.25f) / 12.f;
|
||||
color.b = 1.f - color.r;
|
||||
color.g = sin(pressure / 1500.f * 3.14f);
|
||||
color.rgb = max(color.rgb, (float3)0);
|
||||
color.rgb = normalize(color.rgb);
|
||||
ball->color = rsPackColorTo8888(color);
|
||||
|
||||
//rsDebug("physics pos out", ball->position);
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.example.android.rs.balls)
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
#include "balls.rsh"
|
||||
|
||||
#pragma stateVertex(parent)
|
||||
#pragma stateStore(parent)
|
||||
|
||||
rs_program_fragment gPFPoints;
|
||||
rs_mesh partMesh;
|
||||
|
||||
rs_allocation gGrid;
|
||||
BallGrid_t *unused1;
|
||||
float2 *gGridCache;
|
||||
|
||||
typedef struct __attribute__((packed, aligned(4))) Point {
|
||||
float2 position;
|
||||
uchar4 color;
|
||||
} Point_t;
|
||||
Point_t *point;
|
||||
|
||||
typedef struct VpConsts {
|
||||
rs_matrix4x4 MVP;
|
||||
} VpConsts_t;
|
||||
VpConsts_t *vpConstants;
|
||||
|
||||
rs_script physics_script;
|
||||
|
||||
|
||||
void initParts(int w, int h)
|
||||
{
|
||||
uint32_t dimX = rsAllocationGetDimX(rsGetAllocation(balls));
|
||||
|
||||
for (uint32_t ct=0; ct < dimX; ct++) {
|
||||
balls[ct].position.x = rsRand(0.f, (float)w);
|
||||
balls[ct].position.y = rsRand(0.f, (float)h);
|
||||
balls[ct].delta.x = 0.f;
|
||||
balls[ct].delta.y = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
int root() {
|
||||
rsgClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
int2 gridDims = (int2){ rsAllocationGetDimX(gGrid),
|
||||
rsAllocationGetDimY(gGrid) };
|
||||
|
||||
rs_allocation ain = rsGetAllocation(balls);
|
||||
int32_t dimX = rsAllocationGetDimX(ain);
|
||||
|
||||
// Binning
|
||||
// Clear the particle list
|
||||
for (uint32_t ct=0; ct < dimX; ct++) {
|
||||
balls[ct].next = -1;
|
||||
}
|
||||
|
||||
// Clear the grid
|
||||
for (uint32_t y=0; y < gridDims.y; y++) {
|
||||
for (uint32_t x=0; x < gridDims.x; x++) {
|
||||
BallGrid_t *bg = (BallGrid_t *)rsGetElementAt(gGrid, x, y);
|
||||
bg->count = 0;
|
||||
bg->idx = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the particle list per grid
|
||||
for (uint32_t ct=0; ct < dimX; ct++) {
|
||||
int2 p = convert_int2(balls[ct].position / 100.f);
|
||||
p.x = rsClamp(p.x, 0, (int)(gridDims.x-1));
|
||||
p.y = rsClamp(p.y, 0, (int)(gridDims.y-1));
|
||||
BallGrid_t *bg = (BallGrid_t *)rsGetElementAt(gGrid, p.x, p.y);
|
||||
bg->count ++;
|
||||
balls[ct].next = bg->idx;
|
||||
bg->idx = ct;
|
||||
}
|
||||
|
||||
// Create the sorted grid cache
|
||||
uint32_t gridIdx = 0;
|
||||
for (uint32_t y=0; y < gridDims.y; y++) {
|
||||
for (uint32_t x=0; x < gridDims.x; x++) {
|
||||
BallGrid_t *bg = (BallGrid_t *)rsGetElementAt(gGrid, x, y);
|
||||
bg->cacheIdx = gridIdx;
|
||||
|
||||
int idx = bg->idx;
|
||||
while (idx >= 0) {
|
||||
const Ball_t * bPtr = &balls[idx];
|
||||
gGridCache[gridIdx++] = bPtr->position;
|
||||
idx = bPtr->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rsForEach(physics_script, ain, ain);
|
||||
|
||||
for (uint32_t ct=0; ct < dimX; ct++) {
|
||||
point[ct].position = balls[ct].position;
|
||||
point[ct].color = balls[ct].color;
|
||||
}
|
||||
|
||||
rsgBindProgramFragment(gPFPoints);
|
||||
rsgDrawMesh(partMesh);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
|
||||
typedef struct __attribute__((packed, aligned(4))) Ball {
|
||||
float2 delta;
|
||||
float2 position;
|
||||
uchar4 color;
|
||||
float pressure;
|
||||
//float size;
|
||||
int32_t next;
|
||||
//int arcID;
|
||||
//float arcStr;
|
||||
} Ball_t;
|
||||
Ball_t *balls;
|
||||
|
||||
|
||||
typedef struct BallGrid {
|
||||
int32_t idx;
|
||||
int32_t count;
|
||||
int32_t cacheIdx;
|
||||
} BallGrid_t;
|
||||
@@ -1,27 +0,0 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
|
||||
$(call all-renderscript-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := RsComputeBenchmark
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.android.rs.computebench">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-sdk android:minSdkVersion="17" />
|
||||
<application android:label="_RS_Compute_Bench">
|
||||
<activity android:name="ComputeBench">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/displayin"
|
||||
android:layout_width="320dip"
|
||||
android:layout_height="266dip" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/displayout"
|
||||
android:layout_width="320dip"
|
||||
android:layout_height="266dip" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.example.android.rs.computebench;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
|
||||
public class Benchmark implements Runnable {
|
||||
private final RenderScript mRS;
|
||||
private ScriptC_compute_benchmark mScript;
|
||||
|
||||
public Benchmark(RenderScript rs, Resources res) {
|
||||
mRS = rs;
|
||||
mScript = new ScriptC_compute_benchmark(mRS, res, R.raw.compute_benchmark);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
long t = java.lang.System.currentTimeMillis();
|
||||
mScript.invoke_bench();
|
||||
mRS.finish();
|
||||
t = java.lang.System.currentTimeMillis() - t;
|
||||
android.util.Log.v("ComputeBench", "Total benchmark took " + t + " ms");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.example.android.rs.computebench;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.renderscript.RenderScript;
|
||||
|
||||
public class ComputeBench extends Activity {
|
||||
private RenderScript mRS;
|
||||
private Benchmark mBenchmark;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
mRS = RenderScript.create(this);
|
||||
|
||||
mBenchmark = new Benchmark(mRS, getResources());
|
||||
mBenchmark.run();
|
||||
}
|
||||
}
|
||||
@@ -1,407 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.example.android.rs.computebench)
|
||||
|
||||
// Test configuration (accessible from Java)
|
||||
uint priming_runs = 1000000;
|
||||
uint timing_runs = 5000000;
|
||||
|
||||
// Reused variables
|
||||
|
||||
static volatile int64_t bench_time;
|
||||
static float inv_timing_runs;
|
||||
|
||||
#define DECL_VAR_SET(prefix) \
|
||||
static volatile float prefix##_f_1 = 1; \
|
||||
static volatile float2 prefix##_f_2 = 1; \
|
||||
static volatile float3 prefix##_f_3 = 1; \
|
||||
static volatile float4 prefix##_f_4 = 1; \
|
||||
static volatile char prefix##_c_1 = 1; \
|
||||
static volatile char2 prefix##_c_2 = 1; \
|
||||
static volatile char3 prefix##_c_3 = 1; \
|
||||
static volatile char4 prefix##_c_4 = 1; \
|
||||
static volatile uchar prefix##_uc_1 = 1; \
|
||||
static volatile uchar2 prefix##_uc_2 = 1; \
|
||||
static volatile uchar3 prefix##_uc_3 = 1; \
|
||||
static volatile uchar4 prefix##_uc_4 = 1; \
|
||||
static volatile short prefix##_s_1 = 1; \
|
||||
static volatile short2 prefix##_s_2 = 1; \
|
||||
static volatile short3 prefix##_s_3 = 1; \
|
||||
static volatile short4 prefix##_s_4 = 1; \
|
||||
static volatile ushort prefix##_us_1 = 1; \
|
||||
static volatile ushort2 prefix##_us_2 = 1; \
|
||||
static volatile ushort3 prefix##_us_3 = 1; \
|
||||
static volatile ushort4 prefix##_us_4 = 1; \
|
||||
static volatile int prefix##_i_1 = 1; \
|
||||
static volatile int2 prefix##_i_2 = 1; \
|
||||
static volatile int3 prefix##_i_3 = 1; \
|
||||
static volatile int4 prefix##_i_4 = 1; \
|
||||
static volatile uint prefix##_ui_1 = 1; \
|
||||
static volatile uint2 prefix##_ui_2 = 1; \
|
||||
static volatile uint3 prefix##_ui_3 = 1; \
|
||||
static volatile uint4 prefix##_ui_4 = 1; \
|
||||
static volatile long prefix##_l_1 = 1; \
|
||||
static volatile long2 prefix##_l_2 = 1; \
|
||||
static volatile long3 prefix##_l_3 = 1; \
|
||||
static volatile long4 prefix##_l_4 = 1; \
|
||||
static volatile ulong prefix##_ul_1 = 1; \
|
||||
static volatile ulong2 prefix##_ul_2 = 1; \
|
||||
static volatile ulong3 prefix##_ul_3 = 1; \
|
||||
static volatile ulong4 prefix##_ul_4 = 1; \
|
||||
|
||||
DECL_VAR_SET(res)
|
||||
DECL_VAR_SET(src1)
|
||||
DECL_VAR_SET(src2)
|
||||
DECL_VAR_SET(src3)
|
||||
|
||||
|
||||
// Testing macros
|
||||
|
||||
#define RUN_BENCH(line, op) \
|
||||
for (int i = priming_runs - 1; i >= 0; --i) { \
|
||||
line; \
|
||||
} \
|
||||
bench_time = rsUptimeMillis(); \
|
||||
for (int i = timing_runs - 1; i >= 0; --i) { \
|
||||
line; \
|
||||
} \
|
||||
bench_time = rsUptimeMillis() - bench_time; \
|
||||
rsDebug(" " op " took ns", (float)bench_time * inv_timing_runs);
|
||||
|
||||
#define BENCH_BASIC_OP_TYPE(op, type) \
|
||||
RUN_BENCH(res_##type##_1 = src1_##type##_1 op src2_##type##_1, #type "1 " #op " " #type "1") \
|
||||
RUN_BENCH(res_##type##_2 = src1_##type##_2 op src2_##type##_2, #type "2 " #op " " #type "2") \
|
||||
RUN_BENCH(res_##type##_3 = src1_##type##_3 op src2_##type##_3, #type "3 " #op " " #type "3") \
|
||||
RUN_BENCH(res_##type##_4 = src1_##type##_4 op src2_##type##_4, #type "4 " #op " " #type "4") \
|
||||
|
||||
#define BENCH_BASIC_INT_OP(op) \
|
||||
rsDebug("Testing basic operation " #op, 0); \
|
||||
BENCH_BASIC_OP_TYPE(op, c) \
|
||||
BENCH_BASIC_OP_TYPE(op, uc) \
|
||||
BENCH_BASIC_OP_TYPE(op, s) \
|
||||
BENCH_BASIC_OP_TYPE(op, us) \
|
||||
BENCH_BASIC_OP_TYPE(op, i) \
|
||||
BENCH_BASIC_OP_TYPE(op, ui) \
|
||||
RUN_BENCH(res_l_1 = src1_l_1 op src2_l_1, "l1 " #op " l1") \
|
||||
RUN_BENCH(res_ul_1 = src1_ul_1 op src2_ul_1, "ul1 " #op " ul1")
|
||||
|
||||
#define BENCH_BASIC_OP(op) \
|
||||
BENCH_BASIC_INT_OP(op) \
|
||||
BENCH_BASIC_OP_TYPE(op, f)
|
||||
|
||||
#define BENCH_CVT(to, from, type) \
|
||||
rsDebug("Testing convert from " #from " to " #to, 0); \
|
||||
RUN_BENCH(res_##to##_1 = (type)src1_##from##_1, "(" #to ")" #from) \
|
||||
RUN_BENCH(res_##to##_2 = convert_##type##2(src1_##from##_2), #to "2 convert_" #type "2(" #from "2)") \
|
||||
RUN_BENCH(res_##to##_3 = convert_##type##3(src1_##from##_3), #to "3 convert_" #type "3(" #from "3)") \
|
||||
RUN_BENCH(res_##to##_4 = convert_##type##4(src1_##from##_4), #to "4 convert_" #type "4(" #from "4)")
|
||||
|
||||
#define BENCH_CVT_MATRIX(to, type) \
|
||||
BENCH_CVT(to, c, type); \
|
||||
BENCH_CVT(to, uc, type); \
|
||||
BENCH_CVT(to, s, type); \
|
||||
BENCH_CVT(to, us, type); \
|
||||
BENCH_CVT(to, i, type); \
|
||||
BENCH_CVT(to, ui, type); \
|
||||
BENCH_CVT(to, f, type); \
|
||||
|
||||
#define BENCH_XN_FUNC_YN(typeout, fnc, typein) \
|
||||
RUN_BENCH(res_##typeout##_1 = fnc(src1_##typein##_1);, #typeout "1 " #fnc "(" #typein "1)") \
|
||||
RUN_BENCH(res_##typeout##_2 = fnc(src1_##typein##_2);, #typeout "2 " #fnc "(" #typein "2)") \
|
||||
RUN_BENCH(res_##typeout##_3 = fnc(src1_##typein##_3);, #typeout "3 " #fnc "(" #typein "3)") \
|
||||
RUN_BENCH(res_##typeout##_4 = fnc(src1_##typein##_4);, #typeout "4 " #fnc "(" #typein "4)")
|
||||
|
||||
#define BENCH_XN_FUNC_XN_XN(type, fnc) \
|
||||
RUN_BENCH(res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1), #type "1 " #fnc "(" #type "1, " #type "1)") \
|
||||
RUN_BENCH(res_##type##_2 = fnc(src1_##type##_2, src2_##type##_2), #type "2 " #fnc "(" #type "2, " #type "2)") \
|
||||
RUN_BENCH(res_##type##_3 = fnc(src1_##type##_3, src2_##type##_3), #type "3 " #fnc "(" #type "3, " #type "3)") \
|
||||
RUN_BENCH(res_##type##_4 = fnc(src1_##type##_4, src2_##type##_4), #type "4 " #fnc "(" #type "4, " #type "4)") \
|
||||
|
||||
#define BENCH_X_FUNC_X_X_X(type, fnc) \
|
||||
RUN_BENCH(res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1, src3_##type##_1), #type "1 " #fnc "(" #type "1, " #type "1, " #type "1)")
|
||||
|
||||
#define BENCH_IN_FUNC_IN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
BENCH_XN_FUNC_YN(uc, fnc, uc) \
|
||||
BENCH_XN_FUNC_YN(c, fnc, c) \
|
||||
BENCH_XN_FUNC_YN(us, fnc, us) \
|
||||
BENCH_XN_FUNC_YN(s, fnc, s) \
|
||||
BENCH_XN_FUNC_YN(ui, fnc, ui) \
|
||||
BENCH_XN_FUNC_YN(i, fnc, i)
|
||||
|
||||
#define BENCH_UIN_FUNC_IN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
BENCH_XN_FUNC_YN(uc, fnc, c) \
|
||||
BENCH_XN_FUNC_YN(us, fnc, s) \
|
||||
BENCH_XN_FUNC_YN(ui, fnc, i) \
|
||||
|
||||
#define BENCH_IN_FUNC_IN_IN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
BENCH_XN_FUNC_XN_XN(uc, fnc) \
|
||||
BENCH_XN_FUNC_XN_XN(c, fnc) \
|
||||
BENCH_XN_FUNC_XN_XN(us, fnc) \
|
||||
BENCH_XN_FUNC_XN_XN(s, fnc) \
|
||||
BENCH_XN_FUNC_XN_XN(ui, fnc) \
|
||||
BENCH_XN_FUNC_XN_XN(i, fnc)
|
||||
|
||||
#define BENCH_I_FUNC_I_I_I(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
BENCH_X_FUNC_X_X_X(uc, fnc) \
|
||||
BENCH_X_FUNC_X_X_X(c, fnc) \
|
||||
BENCH_X_FUNC_X_X_X(us, fnc) \
|
||||
BENCH_X_FUNC_X_X_X(s, fnc) \
|
||||
BENCH_X_FUNC_X_X_X(ui, fnc) \
|
||||
BENCH_X_FUNC_X_X_X(i, fnc)
|
||||
|
||||
#define BENCH_FN_FUNC_FN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1), "f1 " #fnc "(f1)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2), "f2 " #fnc "(f2)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3), "f3 " #fnc "(f3)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4), "f4 " #fnc "(f4)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_PFN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, (float*) &src2_f_1), "f1 " #fnc "(f1, f1*)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, (float2*) &src2_f_2), "f2 " #fnc "(f2, f2*)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, (float3*) &src2_f_3), "f3 " #fnc "(f3, f3*)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, (float4*) &src2_f_4), "f4 " #fnc "(f4, f4*)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_FN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1), "f1 " #fnc "(f1, f1)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2), "f2 " #fnc "(f2, f2)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3), "f3 " #fnc "(f3, f3)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4), "f4 " #fnc "(f4, f4)")
|
||||
|
||||
#define BENCH_F34_FUNC_F34_F34(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3), "f3 " #fnc "(f3, f3)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4), "f4 " #fnc "(f4, f4)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_F(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1), "f1 " #fnc "(f1, f1)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_1), "f2 " #fnc "(f2, f1)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_1), "f3 " #fnc "(f3, f1)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_1), "f4 " #fnc "(f4, f1)")
|
||||
|
||||
#define BENCH_F_FUNC_FN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1), "f1 " #fnc "(f1)") \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_2), "f1 " #fnc "(f2)") \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_3), "f1 " #fnc "(f3)") \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_4), "f1 " #fnc "(f4)")
|
||||
|
||||
#define BENCH_F_FUNC_FN_FN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1), "f1 " #fnc "(f1, f1)") \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_2, src2_f_2), "f1 " #fnc "(f2, f2)") \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_3, src2_f_3), "f1 " #fnc "(f3, f3)") \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_4, src2_f_4), "f1 " #fnc "(f4, f4)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_IN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src1_i_1), "f1 " #fnc "(f1, i1)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, src1_i_2), "f2 " #fnc "(f2, i2)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src1_i_3), "f3 " #fnc "(f3, i3)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src1_i_4), "f4 " #fnc "(f4, i4)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_I(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src1_i_1), "f1 " #fnc "(f1, i1)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, src1_i_1), "f2 " #fnc "(f2, i1)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src1_i_1), "f3 " #fnc "(f3, i1)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src1_i_1), "f4 " #fnc "(f4, i1)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_FN_FN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1, src3_f_1), "f1 " #fnc "(f1, f1, f1)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2, src3_f_2), "f2 " #fnc "(f2, f2, f2)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3, src3_f_3), "f3 " #fnc "(f3, f3, f3)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4, src3_f_4), "f4 " #fnc "(f4, f4, f4)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_FN_F(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1, src3_f_1), "f1 " #fnc "(f1, f1, f1)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2, src3_f_1), "f2 " #fnc "(f2, f2, f1)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3, src3_f_1), "f3 " #fnc "(f3, f3, f1)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4, src3_f_1), "f4 " #fnc "(f4, f4, f1)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_PIN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, (int*) &src1_i_1), "f1 " #fnc "(f1, i1*)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, (int2*) &src1_i_2), "f2 " #fnc "(f2, i2*)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, (int3*) &src1_i_3), "f3 " #fnc "(f3, i3*)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, (int4*) &src1_i_4), "f4 " #fnc "(f4, i4*)")
|
||||
|
||||
#define BENCH_FN_FUNC_FN_FN_PIN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1, (int*) &src1_i_1), "f1 " #fnc "(f1, f1, i1*)") \
|
||||
RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2, (int2*) &src1_i_2), "f2 " #fnc "(f2, f2, i2*)") \
|
||||
RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3, (int3*) &src1_i_3), "f3 " #fnc "(f3, f3, i3*)") \
|
||||
RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4, (int4*) &src1_i_4), "f4 " #fnc "(f4, f4, i4*)")
|
||||
|
||||
#define BENCH_IN_FUNC_FN(fnc) \
|
||||
rsDebug("Testing " #fnc, 0); \
|
||||
RUN_BENCH(res_i_1 = fnc(src1_f_1), "i1 " #fnc "(f1)") \
|
||||
RUN_BENCH(res_i_2 = fnc(src1_f_2), "i2 " #fnc "(f2)") \
|
||||
RUN_BENCH(res_i_3 = fnc(src1_f_3), "i3 " #fnc "(f3)") \
|
||||
RUN_BENCH(res_i_4 = fnc(src1_f_4), "i4 " #fnc "(f4)")
|
||||
|
||||
|
||||
// Testing functions
|
||||
|
||||
static void bench_basic_operators() {
|
||||
int i = 0;
|
||||
BENCH_BASIC_OP(+);
|
||||
BENCH_BASIC_OP(-);
|
||||
BENCH_BASIC_OP(*);
|
||||
BENCH_BASIC_OP(/);
|
||||
BENCH_BASIC_INT_OP(%);
|
||||
BENCH_BASIC_INT_OP(<<);
|
||||
BENCH_BASIC_INT_OP(>>);
|
||||
}
|
||||
|
||||
static void bench_convert() {
|
||||
BENCH_CVT_MATRIX(c, char);
|
||||
BENCH_CVT_MATRIX(uc, uchar);
|
||||
BENCH_CVT_MATRIX(s, short);
|
||||
BENCH_CVT_MATRIX(us, ushort);
|
||||
BENCH_CVT_MATRIX(i, int);
|
||||
BENCH_CVT_MATRIX(ui, uint);
|
||||
BENCH_CVT_MATRIX(f, float);
|
||||
}
|
||||
|
||||
static void bench_int_math() {
|
||||
BENCH_UIN_FUNC_IN(abs);
|
||||
BENCH_IN_FUNC_IN(clz);
|
||||
BENCH_IN_FUNC_IN_IN(min);
|
||||
BENCH_IN_FUNC_IN_IN(max);
|
||||
BENCH_I_FUNC_I_I_I(rsClamp);
|
||||
}
|
||||
|
||||
static void bench_fp_math() {
|
||||
BENCH_FN_FUNC_FN(acos);
|
||||
BENCH_FN_FUNC_FN(acosh);
|
||||
BENCH_FN_FUNC_FN(acospi);
|
||||
BENCH_FN_FUNC_FN(asin);
|
||||
BENCH_FN_FUNC_FN(asinh);
|
||||
BENCH_FN_FUNC_FN(asinpi);
|
||||
BENCH_FN_FUNC_FN(atan);
|
||||
BENCH_FN_FUNC_FN_FN(atan2);
|
||||
BENCH_FN_FUNC_FN(atanh);
|
||||
BENCH_FN_FUNC_FN(atanpi);
|
||||
BENCH_FN_FUNC_FN_FN(atan2pi);
|
||||
BENCH_FN_FUNC_FN(cbrt);
|
||||
BENCH_FN_FUNC_FN(ceil);
|
||||
BENCH_FN_FUNC_FN_FN_FN(clamp);
|
||||
BENCH_FN_FUNC_FN_FN_F(clamp);
|
||||
BENCH_FN_FUNC_FN_FN(copysign);
|
||||
BENCH_FN_FUNC_FN(cos);
|
||||
BENCH_FN_FUNC_FN(cosh);
|
||||
BENCH_FN_FUNC_FN(cospi);
|
||||
BENCH_F34_FUNC_F34_F34(cross);
|
||||
BENCH_FN_FUNC_FN(degrees);
|
||||
BENCH_F_FUNC_FN_FN(distance);
|
||||
BENCH_F_FUNC_FN_FN(dot);
|
||||
BENCH_FN_FUNC_FN(erfc);
|
||||
BENCH_FN_FUNC_FN(erf);
|
||||
BENCH_FN_FUNC_FN(exp);
|
||||
BENCH_FN_FUNC_FN(exp2);
|
||||
BENCH_FN_FUNC_FN(exp10);
|
||||
BENCH_FN_FUNC_FN(expm1);
|
||||
BENCH_FN_FUNC_FN(fabs);
|
||||
BENCH_FN_FUNC_FN_FN(fdim);
|
||||
BENCH_FN_FUNC_FN(floor);
|
||||
BENCH_FN_FUNC_FN_FN_FN(fma);
|
||||
BENCH_FN_FUNC_FN_FN(fmax);
|
||||
BENCH_FN_FUNC_FN_F(fmax);
|
||||
BENCH_FN_FUNC_FN_FN(fmin);
|
||||
BENCH_FN_FUNC_FN_F(fmin);
|
||||
BENCH_FN_FUNC_FN_FN(fmod);
|
||||
BENCH_FN_FUNC_FN_PFN(fract);
|
||||
BENCH_FN_FUNC_FN_PIN(frexp);
|
||||
BENCH_FN_FUNC_FN_FN(hypot);
|
||||
BENCH_IN_FUNC_FN(ilogb);
|
||||
BENCH_FN_FUNC_FN_IN(ldexp);
|
||||
BENCH_FN_FUNC_FN_I(ldexp);
|
||||
BENCH_F_FUNC_FN(length);
|
||||
BENCH_FN_FUNC_FN(lgamma);
|
||||
BENCH_FN_FUNC_FN_PIN(lgamma);
|
||||
BENCH_FN_FUNC_FN(log);
|
||||
BENCH_FN_FUNC_FN(log2);
|
||||
BENCH_FN_FUNC_FN(log10);
|
||||
BENCH_FN_FUNC_FN(log1p);
|
||||
BENCH_FN_FUNC_FN(logb);
|
||||
BENCH_FN_FUNC_FN_FN_FN(mad);
|
||||
BENCH_FN_FUNC_FN_FN(max);
|
||||
BENCH_FN_FUNC_FN_F(max);
|
||||
BENCH_FN_FUNC_FN_FN(min);
|
||||
BENCH_FN_FUNC_FN_F(min);
|
||||
BENCH_FN_FUNC_FN_FN_FN(mix);
|
||||
BENCH_FN_FUNC_FN_FN_F(mix);
|
||||
BENCH_FN_FUNC_FN_PFN(modf);
|
||||
BENCH_FN_FUNC_FN_FN(nextafter);
|
||||
BENCH_FN_FUNC_FN(normalize);
|
||||
BENCH_FN_FUNC_FN_FN(pow);
|
||||
BENCH_FN_FUNC_FN_IN(pown);
|
||||
BENCH_FN_FUNC_FN_FN(powr);
|
||||
BENCH_FN_FUNC_FN(radians);
|
||||
BENCH_FN_FUNC_FN_FN(remainder);
|
||||
BENCH_FN_FUNC_FN_FN_PIN(remquo);
|
||||
BENCH_FN_FUNC_FN(rint);
|
||||
BENCH_FN_FUNC_FN_IN(rootn);
|
||||
BENCH_FN_FUNC_FN(round);
|
||||
BENCH_FN_FUNC_FN(rsqrt);
|
||||
BENCH_FN_FUNC_FN(sign);
|
||||
BENCH_FN_FUNC_FN(sin);
|
||||
BENCH_FN_FUNC_FN_PFN(sincos);
|
||||
BENCH_FN_FUNC_FN(sinh);
|
||||
BENCH_FN_FUNC_FN(sinpi);
|
||||
BENCH_FN_FUNC_FN(sqrt);
|
||||
BENCH_FN_FUNC_FN_FN(step);
|
||||
BENCH_FN_FUNC_FN_F(step);
|
||||
BENCH_FN_FUNC_FN(tan);
|
||||
BENCH_FN_FUNC_FN(tanh);
|
||||
BENCH_FN_FUNC_FN(tanpi);
|
||||
BENCH_FN_FUNC_FN(tgamma);
|
||||
BENCH_FN_FUNC_FN(trunc);
|
||||
}
|
||||
|
||||
static void bench_approx_math() {
|
||||
BENCH_FN_FUNC_FN(half_recip);
|
||||
BENCH_FN_FUNC_FN(half_sqrt);
|
||||
BENCH_FN_FUNC_FN(half_rsqrt);
|
||||
BENCH_FN_FUNC_FN(fast_length);
|
||||
BENCH_FN_FUNC_FN_FN(fast_distance);
|
||||
BENCH_FN_FUNC_FN(fast_normalize);
|
||||
}
|
||||
|
||||
void bench() {
|
||||
rsDebug("RS Compute Benchmark", 0);
|
||||
rsDebug("Current configuration:", 0);
|
||||
rsDebug("Priming runs", priming_runs);
|
||||
rsDebug("Timing runs", timing_runs);
|
||||
rsDebug("Beginning test", 0);
|
||||
inv_timing_runs = 1000000.f / (float)timing_runs;
|
||||
bench_basic_operators();
|
||||
bench_convert();
|
||||
bench_int_math();
|
||||
bench_fp_math();
|
||||
bench_approx_math();
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2011 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
|
||||
$(call all-renderscript-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := RsComputePerf
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2011 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.android.rs.computeperf">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-sdk android:minSdkVersion="14" />
|
||||
<application android:label="Compute Perf">
|
||||
<activity android:name="ComputePerf">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2011 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/displayin"
|
||||
android:layout_width="320dip"
|
||||
android:layout_height="266dip" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/displayout"
|
||||
android:layout_width="320dip"
|
||||
android:layout_height="266dip" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-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.example.android.rs.computeperf;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Bitmap;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Allocation;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class ComputePerf extends Activity {
|
||||
private LaunchTest mLT;
|
||||
private Mandelbrot mMandel;
|
||||
private RenderScript mRS;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
final int numTries = 100;
|
||||
|
||||
long timesXLW = 0;
|
||||
long timesXYW = 0;
|
||||
|
||||
mRS = RenderScript.create(this);
|
||||
mLT = new LaunchTest(mRS, getResources());
|
||||
mLT.XLW();
|
||||
mLT.XYW();
|
||||
for (int i = 0; i < numTries; i++) {
|
||||
timesXLW += mLT.XLW();
|
||||
timesXYW += mLT.XYW();
|
||||
}
|
||||
|
||||
timesXLW /= numTries;
|
||||
timesXYW /= numTries;
|
||||
|
||||
// XLW and XYW running times should match pretty closely
|
||||
Log.v("ComputePerf", "xlw launch test " + timesXLW + "ms");
|
||||
Log.v("ComputePerf", "xyw launch test " + timesXYW + "ms");
|
||||
|
||||
mMandel = new Mandelbrot(mRS, getResources());
|
||||
mMandel.run();
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-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.example.android.rs.computeperf;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
|
||||
public class LaunchTest {
|
||||
private RenderScript mRS;
|
||||
private Allocation mAllocationX;
|
||||
private Allocation mAllocationXY;
|
||||
private ScriptC_launchtestxlw mScript_xlw;
|
||||
private ScriptC_launchtestxyw mScript_xyw;
|
||||
|
||||
LaunchTest(RenderScript rs, Resources res) {
|
||||
mRS = rs;
|
||||
mScript_xlw = new ScriptC_launchtestxlw(mRS, res, R.raw.launchtestxlw);
|
||||
mScript_xyw = new ScriptC_launchtestxyw(mRS, res, R.raw.launchtestxyw);
|
||||
final int dim = mScript_xlw.get_dim();
|
||||
|
||||
mAllocationX = Allocation.createSized(rs, Element.U8(rs), dim);
|
||||
Type.Builder tb = new Type.Builder(rs, Element.U8(rs));
|
||||
tb.setX(dim);
|
||||
tb.setY(dim);
|
||||
mAllocationXY = Allocation.createTyped(rs, tb.create());
|
||||
mScript_xlw.bind_buf(mAllocationXY);
|
||||
}
|
||||
|
||||
public long XLW() {
|
||||
long t = java.lang.System.currentTimeMillis();
|
||||
mScript_xlw.forEach_root(mAllocationX);
|
||||
mRS.finish();
|
||||
t = java.lang.System.currentTimeMillis() - t;
|
||||
return t;
|
||||
}
|
||||
|
||||
public long XYW() {
|
||||
long t = java.lang.System.currentTimeMillis();
|
||||
mScript_xyw.forEach_root(mAllocationXY);
|
||||
mRS.finish();
|
||||
t = java.lang.System.currentTimeMillis() - t;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.example.android.rs.computeperf;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
|
||||
public class Mandelbrot implements Runnable {
|
||||
private RenderScript mRS;
|
||||
private Allocation mAllocationXY;
|
||||
private ScriptC_mandelbrot mScript;
|
||||
|
||||
Mandelbrot(RenderScript rs, Resources res) {
|
||||
mRS = rs;
|
||||
mScript = new ScriptC_mandelbrot(mRS, res, R.raw.mandelbrot);
|
||||
|
||||
Type.Builder tb = new Type.Builder(rs, Element.U8_4(rs));
|
||||
tb.setX(mScript.get_gDimX());
|
||||
tb.setY(mScript.get_gDimY());
|
||||
mAllocationXY = Allocation.createTyped(rs, tb.create());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
long t = java.lang.System.currentTimeMillis();
|
||||
mScript.forEach_root(mAllocationXY);
|
||||
mRS.finish();
|
||||
t = java.lang.System.currentTimeMillis() - t;
|
||||
android.util.Log.v("ComputePerf", "mandelbrot ms " + t);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.
|
||||
*/
|
||||
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.example.android.rs.computeperf)
|
||||
|
||||
const int dim = 2048;
|
||||
uint8_t *buf;
|
||||
|
||||
void root(uchar *v_out, uint32_t x) {
|
||||
uint8_t *p = buf;
|
||||
p += x * dim;
|
||||
for (int i=0; i<dim; i++) {
|
||||
p[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.
|
||||
*/
|
||||
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.example.android.rs.computeperf)
|
||||
|
||||
void root(uchar *v_out, uint32_t x, uint32_t y) {
|
||||
*v_out = 0;
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright (C) 2011 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.
|
||||
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.example.android.rs.computeperf)
|
||||
|
||||
const int gMaxIteration = 500;
|
||||
const int gDimX = 1024;
|
||||
const int gDimY = 1024;
|
||||
|
||||
void root(uchar4 *v_out, uint32_t x, uint32_t y) {
|
||||
float2 p;
|
||||
p.x = -2.5f + ((float)x / gDimX) * 3.5f;
|
||||
p.y = -1.f + ((float)y / gDimY) * 2.f;
|
||||
|
||||
float2 t = 0;
|
||||
float2 t2 = t * t;
|
||||
int iteration = 0;
|
||||
while((t2.x + t2.y < 4.f) && (iteration < gMaxIteration)) {
|
||||
float xtemp = t2.x - t2.y + p.x;
|
||||
t.y = 2 * t.x * t.y + p.y;
|
||||
t.x = xtemp;
|
||||
iteration++;
|
||||
t2 = t * t;
|
||||
}
|
||||
|
||||
if(iteration >= gMaxIteration) {
|
||||
*v_out = 0;
|
||||
} else {
|
||||
*v_out = (uchar4){iteration & 0xff, (iteration >> 6) & 0xff, 0x8f, 0xff};
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2009 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
|
||||
$(call all-renderscript-files-under, src)
|
||||
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
|
||||
|
||||
LOCAL_PACKAGE_NAME := ImageProcessing
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.rs.image">
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-sdk android:minSdkVersion="17" />
|
||||
<application android:label="Image Processing"
|
||||
android:hardwareAccelerated="true">
|
||||
<uses-library android:name="android.test.runner" />
|
||||
<activity android:name="ImageProcessingActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<instrumentation android:name=".ImageProcessingTestRunner"
|
||||
android:targetPackage="com.android.rs.image"
|
||||
android:label="Test runner for Image Processing Benchmark Test"
|
||||
/>
|
||||
</manifest>
|
||||
|
Before Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 1.1 MiB |
@@ -1,139 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/toplevel">
|
||||
<SurfaceView
|
||||
android:id="@+id/surface"
|
||||
android:layout_width="1dip"
|
||||
android:layout_height="1dip" />
|
||||
<ScrollView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ImageView
|
||||
android:id="@+id/display"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/benchmark"
|
||||
android:onClick="benchmark"/>
|
||||
<TextView
|
||||
android:id="@+id/benchmarkText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:text="@string/saturation"/>
|
||||
</LinearLayout>
|
||||
<Spinner
|
||||
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"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/saturation"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider1"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider2Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/gamma"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider2"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider3Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:textSize="8pt"
|
||||
android:text="@string/out_white"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider3"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider4Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/in_white"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider4"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider5Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/in_white"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider5"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/benchmark_all"
|
||||
android:onClick="benchmark_all"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="10dp"
|
||||
android:textSize="16sp"
|
||||
/>
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright (C) 2008 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<!-- General -->
|
||||
<skip />
|
||||
<!--slider label -->
|
||||
<string name="blur_description">Blur Radius</string>
|
||||
<string name="in_white">In White</string>
|
||||
<string name="out_white">Out White</string>
|
||||
<string name="in_black">In Black</string>
|
||||
<string name="out_black">Out Black</string>
|
||||
<string name="gamma">Gamma</string>
|
||||
<string name="saturation">Saturation</string>
|
||||
<string name="benchmark">Benchmark</string>
|
||||
<string name="benchmark_all">Benchmark All</string>
|
||||
|
||||
</resources>
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
public class BWFilter extends TestBase {
|
||||
private ScriptC_bwfilter mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_bwfilter(mRS);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.invoke_prepareBwFilter(50, 50, 50);
|
||||
mScript.forEach_bwFilterKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
if (mRS != null) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicBlur;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Blur25 extends TestBase {
|
||||
private boolean mUseIntrinsic = false;
|
||||
private ScriptIntrinsicBlur mIntrinsic;
|
||||
|
||||
private int MAX_RADIUS = 25;
|
||||
private ScriptC_threshold mScript;
|
||||
private float mRadius = MAX_RADIUS;
|
||||
private float mSaturation = 1.0f;
|
||||
private Allocation mScratchPixelsAllocation1;
|
||||
private Allocation mScratchPixelsAllocation2;
|
||||
|
||||
|
||||
public Blur25(boolean useIntrinsic) {
|
||||
mUseIntrinsic = useIntrinsic;
|
||||
}
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
t.setText("Radius");
|
||||
b.setProgress(100);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
mRadius = ((float)progress) / 100.0f * MAX_RADIUS;
|
||||
if (mRadius <= 0.10f) {
|
||||
mRadius = 0.10f;
|
||||
}
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.setRadius(mRadius);
|
||||
} else {
|
||||
mScript.invoke_setRadius((int)mRadius);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
int width = mInPixelsAllocation.getType().getX();
|
||||
int height = mInPixelsAllocation.getType().getY();
|
||||
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
|
||||
mIntrinsic.setRadius(MAX_RADIUS);
|
||||
mIntrinsic.setInput(mInPixelsAllocation);
|
||||
} else {
|
||||
|
||||
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
|
||||
tb.setX(width);
|
||||
tb.setY(height);
|
||||
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
|
||||
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
|
||||
|
||||
mScript = new ScriptC_threshold(mRS, res, R.raw.threshold);
|
||||
mScript.set_width(width);
|
||||
mScript.set_height(height);
|
||||
mScript.invoke_setRadius(MAX_RADIUS);
|
||||
|
||||
mScript.set_InPixel(mInPixelsAllocation);
|
||||
mScript.set_ScratchPixel1(mScratchPixelsAllocation1);
|
||||
mScript.set_ScratchPixel2(mScratchPixelsAllocation2);
|
||||
}
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.forEach(mOutPixelsAllocation);
|
||||
} else {
|
||||
mScript.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1);
|
||||
mScript.forEach_horz(mScratchPixelsAllocation2);
|
||||
mScript.forEach_vert(mOutPixelsAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
public void setupBenchmark() {
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.setRadius(MAX_RADIUS);
|
||||
} else {
|
||||
mScript.invoke_setRadius(MAX_RADIUS);
|
||||
}
|
||||
}
|
||||
|
||||
public void exitBenchmark() {
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.setRadius(mRadius);
|
||||
} else {
|
||||
mScript.invoke_setRadius((int)mRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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 android.graphics.Bitmap;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicBlur;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Blur25G extends TestBase {
|
||||
private final int MAX_RADIUS = 25;
|
||||
private float mRadius = MAX_RADIUS;
|
||||
|
||||
private ScriptIntrinsicBlur mIntrinsic;
|
||||
|
||||
private ScriptC_greyscale mScript;
|
||||
private Allocation mScratchPixelsAllocation1;
|
||||
private Allocation mScratchPixelsAllocation2;
|
||||
|
||||
|
||||
public Blur25G() {
|
||||
}
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
t.setText("Radius");
|
||||
b.setProgress(100);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
mRadius = ((float)progress) / 100.0f * MAX_RADIUS;
|
||||
if (mRadius <= 0.10f) {
|
||||
mRadius = 0.10f;
|
||||
}
|
||||
mIntrinsic.setRadius(mRadius);
|
||||
}
|
||||
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
int width = mInPixelsAllocation.getType().getX();
|
||||
int height = mInPixelsAllocation.getType().getY();
|
||||
|
||||
Type.Builder tb = new Type.Builder(mRS, Element.U8(mRS));
|
||||
tb.setX(width);
|
||||
tb.setY(height);
|
||||
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
|
||||
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
|
||||
|
||||
mScript = new ScriptC_greyscale(mRS);
|
||||
mScript.forEach_toU8(mInPixelsAllocation, mScratchPixelsAllocation1);
|
||||
|
||||
mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8(mRS));
|
||||
mIntrinsic.setRadius(MAX_RADIUS);
|
||||
mIntrinsic.setInput(mScratchPixelsAllocation1);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mIntrinsic.forEach(mScratchPixelsAllocation2);
|
||||
}
|
||||
|
||||
public void setupBenchmark() {
|
||||
mIntrinsic.setRadius(MAX_RADIUS);
|
||||
}
|
||||
|
||||
public void exitBenchmark() {
|
||||
mIntrinsic.setRadius(mRadius);
|
||||
}
|
||||
|
||||
public void updateBitmap(Bitmap b) {
|
||||
mScript.forEach_toU8_4(mScratchPixelsAllocation2, mOutPixelsAllocation);
|
||||
mOutPixelsAllocation.copyTo(b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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 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.ScriptIntrinsic3DLUT;
|
||||
import android.renderscript.ScriptIntrinsicColorMatrix;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
|
||||
public class ColorCube extends TestBase {
|
||||
private Allocation mCube;
|
||||
private ScriptC_colorcube mScript;
|
||||
private ScriptIntrinsic3DLUT mIntrinsic;
|
||||
private boolean mUseIntrinsic;
|
||||
|
||||
public ColorCube(boolean useIntrinsic) {
|
||||
mUseIntrinsic = useIntrinsic;
|
||||
}
|
||||
|
||||
private void initCube() {
|
||||
final int sx = 32;
|
||||
final int sy = 32;
|
||||
final int sz = 16;
|
||||
|
||||
Type.Builder tb = new Type.Builder(mRS, Element.U8_4(mRS));
|
||||
tb.setX(sx);
|
||||
tb.setY(sy);
|
||||
tb.setZ(sz);
|
||||
Type t = tb.create();
|
||||
mCube = Allocation.createTyped(mRS, t);
|
||||
|
||||
int dat[] = new int[sx * sy * sz];
|
||||
for (int z = 0; z < sz; z++) {
|
||||
for (int y = 0; y < sy; y++) {
|
||||
for (int x = 0; x < sx; x++ ) {
|
||||
int v = 0xff000000;
|
||||
v |= (0xff * x / (sx - 1));
|
||||
v |= (0xff * y / (sy - 1)) << 8;
|
||||
v |= (0xff * z / (sz - 1)) << 16;
|
||||
dat[z*sy*sx + y*sx + x] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mCube.copyFromUnchecked(dat);
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_colorcube(mRS, res, R.raw.colorcube);
|
||||
mIntrinsic = ScriptIntrinsic3DLUT.create(mRS, Element.U8_4(mRS));
|
||||
|
||||
initCube();
|
||||
mScript.invoke_setCube(mCube);
|
||||
mIntrinsic.setLUT(mCube);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
} else {
|
||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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 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.ScriptIntrinsicColorMatrix;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
|
||||
public class ColorMatrix extends TestBase {
|
||||
private ScriptC_colormatrix mScript;
|
||||
private ScriptIntrinsicColorMatrix mIntrinsic;
|
||||
private boolean mUseIntrinsic;
|
||||
private boolean mUseGrey;
|
||||
|
||||
public ColorMatrix(boolean useIntrinsic, boolean useGrey) {
|
||||
mUseIntrinsic = useIntrinsic;
|
||||
mUseGrey = useGrey;
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
Matrix4f m = new Matrix4f();
|
||||
m.set(1, 0, 0.2f);
|
||||
m.set(1, 1, 0.9f);
|
||||
m.set(1, 2, 0.2f);
|
||||
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
|
||||
if (mUseGrey) {
|
||||
mIntrinsic.setGreyscale();
|
||||
} else {
|
||||
mIntrinsic.setColorMatrix(m);
|
||||
}
|
||||
} else {
|
||||
mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
|
||||
mScript.invoke_setMatrix(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
} else {
|
||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
|
||||
public class Contrast extends TestBase {
|
||||
private ScriptC_contrast mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_contrast(mRS);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.invoke_setBright(50.f);
|
||||
mScript.forEach_contrast(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* 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 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.ScriptIntrinsicConvolve3x3;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
|
||||
public class Convolve3x3 extends TestBase {
|
||||
private ScriptC_convolve3x3 mScript;
|
||||
private ScriptIntrinsicConvolve3x3 mIntrinsic;
|
||||
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private boolean mUseIntrinsic;
|
||||
|
||||
public Convolve3x3(boolean useIntrinsic) {
|
||||
mUseIntrinsic = useIntrinsic;
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mWidth = mInPixelsAllocation.getType().getX();
|
||||
mHeight = mInPixelsAllocation.getType().getY();
|
||||
|
||||
float f[] = new float[9];
|
||||
f[0] = 0.f; f[1] = -1.f; f[2] = 0.f;
|
||||
f[3] = -1.f; f[4] = 5.f; f[5] = -1.f;
|
||||
f[6] = 0.f; f[7] = -1.f; f[8] = 0.f;
|
||||
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS));
|
||||
mIntrinsic.setCoefficients(f);
|
||||
mIntrinsic.setInput(mInPixelsAllocation);
|
||||
} else {
|
||||
mScript = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3);
|
||||
mScript.set_gCoeffs(f);
|
||||
mScript.set_gIn(mInPixelsAllocation);
|
||||
mScript.set_gWidth(mWidth);
|
||||
mScript.set_gHeight(mHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.forEach(mOutPixelsAllocation);
|
||||
} else {
|
||||
mScript.forEach_root(mOutPixelsAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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 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.ScriptIntrinsicConvolve5x5;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
|
||||
public class Convolve5x5 extends TestBase {
|
||||
private ScriptC_convolve5x5 mScript;
|
||||
private ScriptIntrinsicConvolve5x5 mIntrinsic;
|
||||
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private boolean mUseIntrinsic;
|
||||
|
||||
public Convolve5x5(boolean useIntrinsic) {
|
||||
mUseIntrinsic = useIntrinsic;
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mWidth = mInPixelsAllocation.getType().getX();
|
||||
mHeight = mInPixelsAllocation.getType().getY();
|
||||
|
||||
float f[] = new float[25];
|
||||
//f[0] = 0.012f; f[1] = 0.025f; f[2] = 0.031f; f[3] = 0.025f; f[4] = 0.012f;
|
||||
//f[5] = 0.025f; f[6] = 0.057f; f[7] = 0.075f; f[8] = 0.057f; f[9] = 0.025f;
|
||||
//f[10]= 0.031f; f[11]= 0.075f; f[12]= 0.095f; f[13]= 0.075f; f[14]= 0.031f;
|
||||
//f[15]= 0.025f; f[16]= 0.057f; f[17]= 0.075f; f[18]= 0.057f; f[19]= 0.025f;
|
||||
//f[20]= 0.012f; f[21]= 0.025f; f[22]= 0.031f; f[23]= 0.025f; f[24]= 0.012f;
|
||||
|
||||
//f[0] = 1.f; f[1] = 2.f; f[2] = 0.f; f[3] = -2.f; f[4] = -1.f;
|
||||
//f[5] = 4.f; f[6] = 8.f; f[7] = 0.f; f[8] = -8.f; f[9] = -4.f;
|
||||
//f[10]= 6.f; f[11]=12.f; f[12]= 0.f; f[13]=-12.f; f[14]= -6.f;
|
||||
//f[15]= 4.f; f[16]= 8.f; f[17]= 0.f; f[18]= -8.f; f[19]= -4.f;
|
||||
//f[20]= 1.f; f[21]= 2.f; f[22]= 0.f; f[23]= -2.f; f[24]= -1.f;
|
||||
|
||||
f[0] = -1.f; f[1] = -3.f; f[2] = -4.f; f[3] = -3.f; f[4] = -1.f;
|
||||
f[5] = -3.f; f[6] = 0.f; f[7] = 6.f; f[8] = 0.f; f[9] = -3.f;
|
||||
f[10]= -4.f; f[11]= 6.f; f[12]= 20.f; f[13]= 6.f; f[14]= -4.f;
|
||||
f[15]= -3.f; f[16]= 0.f; f[17]= 6.f; f[18]= 0.f; f[19]= -3.f;
|
||||
f[20]= -1.f; f[21]= -3.f; f[22]= -4.f; f[23]= -3.f; f[24]= -1.f;
|
||||
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic = ScriptIntrinsicConvolve5x5.create(mRS, Element.U8_4(mRS));
|
||||
mIntrinsic.setCoefficients(f);
|
||||
mIntrinsic.setInput(mInPixelsAllocation);
|
||||
} else {
|
||||
mScript = new ScriptC_convolve5x5(mRS, res, R.raw.convolve5x5);
|
||||
mScript.set_gCoeffs(f);
|
||||
mScript.set_gIn(mInPixelsAllocation);
|
||||
mScript.set_gWidth(mWidth);
|
||||
mScript.set_gHeight(mHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (mUseIntrinsic) {
|
||||
mIntrinsic.forEach(mOutPixelsAllocation);
|
||||
} else {
|
||||
mScript.forEach_root(mOutPixelsAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
|
||||
public class Copy extends TestBase {
|
||||
private ScriptC_copy mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_copy(mRS, res, R.raw.copy);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicLUT;
|
||||
import android.util.Log;
|
||||
|
||||
public class CrossProcess extends TestBase {
|
||||
private ScriptIntrinsicLUT mIntrinsic;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mIntrinsic = ScriptIntrinsicLUT.create(mRS, Element.U8_4(mRS));
|
||||
for (int ct=0; ct < 256; ct++) {
|
||||
float f = ((float)ct) / 255.f;
|
||||
|
||||
float r = f;
|
||||
if (r < 0.5f) {
|
||||
r = 4.0f * r * r * r;
|
||||
} else {
|
||||
r = 1.0f - r;
|
||||
r = 1.0f - (4.0f * r * r * r);
|
||||
}
|
||||
mIntrinsic.setRed(ct, (int)(r * 255.f + 0.5f));
|
||||
|
||||
float g = f;
|
||||
if (g < 0.5f) {
|
||||
g = 2.0f * g * g;
|
||||
} else {
|
||||
g = 1.0f - g;
|
||||
g = 1.0f - (2.0f * g * g);
|
||||
}
|
||||
mIntrinsic.setGreen(ct, (int)(g * 255.f + 0.5f));
|
||||
|
||||
float b = f * 0.5f + 0.25f;
|
||||
mIntrinsic.setBlue(ct, (int)(b * 255.f + 0.5f));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
|
||||
public class Exposure extends TestBase {
|
||||
private ScriptC_exposure mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_exposure(mRS);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.invoke_setBright(50.f);
|
||||
mScript.forEach_exposure(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.Sampler;
|
||||
import android.renderscript.Type;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Fisheye extends TestBase {
|
||||
private ScriptC_fisheye_full mScript_full = null;
|
||||
private ScriptC_fisheye_relaxed mScript_relaxed = null;
|
||||
private ScriptC_fisheye_approx_full mScript_approx_full = null;
|
||||
private ScriptC_fisheye_approx_relaxed mScript_approx_relaxed = null;
|
||||
private final boolean approx;
|
||||
private final boolean relaxed;
|
||||
private float center_x = 0.5f;
|
||||
private float center_y = 0.5f;
|
||||
private float scale = 0.5f;
|
||||
|
||||
public Fisheye(boolean approx, boolean relaxed) {
|
||||
this.approx = approx;
|
||||
this.relaxed = relaxed;
|
||||
}
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
t.setText("Scale");
|
||||
b.setMax(100);
|
||||
b.setProgress(25);
|
||||
return true;
|
||||
}
|
||||
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||
t.setText("Shift center X");
|
||||
b.setMax(100);
|
||||
b.setProgress(50);
|
||||
return true;
|
||||
}
|
||||
public boolean onBar3Setup(SeekBar b, TextView t) {
|
||||
t.setText("Shift center Y");
|
||||
b.setMax(100);
|
||||
b.setProgress(50);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
scale = progress / 50.0f;
|
||||
do_init();
|
||||
}
|
||||
public void onBar2Changed(int progress) {
|
||||
center_x = progress / 100.0f;
|
||||
do_init();
|
||||
}
|
||||
public void onBar3Changed(int progress) {
|
||||
center_y = progress / 100.0f;
|
||||
do_init();
|
||||
}
|
||||
|
||||
private void do_init() {
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed.invoke_init_filter(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x,
|
||||
center_y, scale);
|
||||
else
|
||||
mScript_approx_full.invoke_init_filter(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x,
|
||||
center_y, scale);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed.invoke_init_filter(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||
scale);
|
||||
else
|
||||
mScript_full.invoke_init_filter(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||
scale);
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
if (approx) {
|
||||
if (relaxed) {
|
||||
mScript_approx_relaxed = new ScriptC_fisheye_approx_relaxed(mRS,
|
||||
res, R.raw.fisheye_approx_relaxed);
|
||||
mScript_approx_relaxed.set_in_alloc(mInPixelsAllocation);
|
||||
mScript_approx_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||
} else {
|
||||
mScript_approx_full = new ScriptC_fisheye_approx_full(mRS, res,
|
||||
R.raw.fisheye_approx_full);
|
||||
mScript_approx_full.set_in_alloc(mInPixelsAllocation);
|
||||
mScript_approx_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||
}
|
||||
} else if (relaxed) {
|
||||
mScript_relaxed = new ScriptC_fisheye_relaxed(mRS, res,
|
||||
R.raw.fisheye_relaxed);
|
||||
mScript_relaxed.set_in_alloc(mInPixelsAllocation);
|
||||
mScript_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||
} else {
|
||||
mScript_full = new ScriptC_fisheye_full(mRS, res,
|
||||
R.raw.fisheye_full);
|
||||
mScript_full.set_in_alloc(mInPixelsAllocation);
|
||||
mScript_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||
}
|
||||
do_init();
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed.forEach_root(mOutPixelsAllocation);
|
||||
else
|
||||
mScript_approx_full.forEach_root(mOutPixelsAllocation);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed.forEach_root(mOutPixelsAllocation);
|
||||
else
|
||||
mScript_full.forEach_root(mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Grain extends TestBase {
|
||||
private ScriptC_grain mScript;
|
||||
private Allocation mNoise;
|
||||
private Allocation mNoise2;
|
||||
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
t.setText("Strength");
|
||||
b.setProgress(50);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
float s = progress / 100.0f;
|
||||
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) {
|
||||
int width = mInPixelsAllocation.getType().getX();
|
||||
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));
|
||||
tb.setX(noiseW);
|
||||
tb.setY(noiseH);
|
||||
mNoise = Allocation.createTyped(mRS, tb.create());
|
||||
mNoise2 = Allocation.createTyped(mRS, tb.create());
|
||||
|
||||
mScript = new ScriptC_grain(mRS, res, R.raw.grain);
|
||||
mScript.set_gWMask(noiseW - 1);
|
||||
mScript.set_gHMask(noiseH - 1);
|
||||
mScript.set_gNoiseStrength(0.5f);
|
||||
mScript.set_gBlendSource(mNoise);
|
||||
mScript.set_gNoise(mNoise2);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.forEach_genRand(mNoise);
|
||||
mScript.forEach_blend9(mNoise2);
|
||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
|
||||
public class Greyscale extends TestBase {
|
||||
private ScriptC_greyscale mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_greyscale(mRS, res, R.raw.greyscale);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicConvolve3x3;
|
||||
import android.renderscript.ScriptIntrinsicColorMatrix;
|
||||
import android.renderscript.Type;
|
||||
import android.renderscript.Matrix4f;
|
||||
import android.renderscript.ScriptGroup;
|
||||
import android.util.Log;
|
||||
|
||||
public class GroupTest extends TestBase {
|
||||
private ScriptIntrinsicConvolve3x3 mConvolve;
|
||||
private ScriptIntrinsicColorMatrix mMatrix;
|
||||
|
||||
private Allocation mScratchPixelsAllocation1;
|
||||
private ScriptGroup mGroup;
|
||||
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private boolean mUseNative;
|
||||
|
||||
|
||||
public GroupTest(boolean useNative) {
|
||||
mUseNative = useNative;
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mWidth = mInPixelsAllocation.getType().getX();
|
||||
mHeight = mInPixelsAllocation.getType().getY();
|
||||
|
||||
mConvolve = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS));
|
||||
mMatrix = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
|
||||
|
||||
float f[] = new float[9];
|
||||
f[0] = 0.f; f[1] = -1.f; f[2] = 0.f;
|
||||
f[3] = -1.f; f[4] = 5.f; f[5] = -1.f;
|
||||
f[6] = 0.f; f[7] = -1.f; f[8] = 0.f;
|
||||
mConvolve.setCoefficients(f);
|
||||
|
||||
Matrix4f m = new Matrix4f();
|
||||
m.set(1, 0, 0.2f);
|
||||
m.set(1, 1, 0.9f);
|
||||
m.set(1, 2, 0.2f);
|
||||
mMatrix.setColorMatrix(m);
|
||||
|
||||
Type.Builder tb = new Type.Builder(mRS, Element.U8_4(mRS));
|
||||
tb.setX(mWidth);
|
||||
tb.setY(mHeight);
|
||||
Type connect = tb.create();
|
||||
|
||||
if (mUseNative) {
|
||||
ScriptGroup.Builder b = new ScriptGroup.Builder(mRS);
|
||||
b.addKernel(mConvolve.getKernelID());
|
||||
b.addKernel(mMatrix.getKernelID());
|
||||
b.addConnection(connect, mConvolve.getKernelID(), mMatrix.getKernelID());
|
||||
mGroup = b.create();
|
||||
} else {
|
||||
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, connect);
|
||||
}
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mConvolve.setInput(mInPixelsAllocation);
|
||||
if (mUseNative) {
|
||||
mGroup.setOutput(mMatrix.getKernelID(), mOutPixelsAllocation);
|
||||
mGroup.execute();
|
||||
} else {
|
||||
mConvolve.forEach(mScratchPixelsAllocation1);
|
||||
mMatrix.forEach(mScratchPixelsAllocation1, mOutPixelsAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,557 +0,0 @@
|
||||
/*
|
||||
* 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 android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.view.SurfaceView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.view.View;
|
||||
import android.util.Log;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Type;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.Script;
|
||||
|
||||
import android.os.Environment;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImageProcessingActivity extends Activity
|
||||
implements SeekBar.OnSeekBarChangeListener {
|
||||
private final String TAG = "Img";
|
||||
public final String RESULT_FILE = "image_processing_result.csv";
|
||||
|
||||
RenderScript mRS;
|
||||
Allocation mInPixelsAllocation;
|
||||
Allocation mInPixelsAllocation2;
|
||||
Allocation mOutPixelsAllocation;
|
||||
|
||||
/**
|
||||
* Define enum type for test names
|
||||
*/
|
||||
public enum TestName {
|
||||
// totally there are 38 test cases
|
||||
LEVELS_VEC3_RELAXED ("Levels Vec3 Relaxed"),
|
||||
LEVELS_VEC4_RELAXED ("Levels Vec4 Relaxed"),
|
||||
LEVELS_VEC3_FULL ("Levels Vec3 Full"),
|
||||
LEVELS_VEC4_FULL ("Levels Vec4 Full"),
|
||||
BLUR_RADIUS_25 ("Blur radius 25"),
|
||||
INTRINSIC_BLUE_RADIUS_25 ("Intrinsic Blur radius 25"),
|
||||
GREYSCALE ("Greyscale"),
|
||||
GRAIN ("Grain"),
|
||||
FISHEYE_FULL ("Fisheye Full"),
|
||||
FISHEYE_RELAXED ("Fisheye Relaxed"),
|
||||
FISHEYE_APPROXIMATE_FULL ("Fisheye Approximate Full"),
|
||||
FISHEYE_APPROXIMATE_RELAXED ("Fisheye Approximate Relaxed"),
|
||||
VIGNETTE_FULL ("Vignette Full"),
|
||||
VIGNETTE_RELAXED ("Vignette Relaxed"),
|
||||
VIGNETTE_APPROXIMATE_FULL ("Vignette Approximate Full"),
|
||||
VIGNETTE_APPROXIMATE_RELAXED ("Vignette Approximate Relaxed"),
|
||||
GROUP_TEST_EMULATED ("Group Test (emulated)"),
|
||||
GROUP_TEST_NATIVE ("Group Test (native)"),
|
||||
CONVOLVE_3X3 ("Convolve 3x3"),
|
||||
INTRINSICS_CONVOLVE_3X3 ("Intrinsics Convolve 3x3"),
|
||||
COLOR_MATRIX ("ColorMatrix"),
|
||||
INTRINSICS_COLOR_MATRIX ("Intrinsics ColorMatrix"),
|
||||
INTRINSICS_COLOR_MATRIX_GREY ("Intrinsics ColorMatrix Grey"),
|
||||
COPY ("Copy"),
|
||||
CROSS_PROCESS_USING_LUT ("CrossProcess (using LUT)"),
|
||||
CONVOLVE_5X5 ("Convolve 5x5"),
|
||||
INTRINSICS_CONVOLVE_5X5 ("Intrinsics Convolve 5x5"),
|
||||
MANDELBROT ("Mandelbrot"),
|
||||
INTRINSICS_BLEND ("Intrinsics Blend"),
|
||||
INTRINSICS_BLUR_25G ("Intrinsics Blur 25 uchar"),
|
||||
VIBRANCE ("Vibrance"),
|
||||
BW_FILTER ("BW Filter"),
|
||||
SHADOWS ("Shadows"),
|
||||
CONTRAST ("Contrast"),
|
||||
EXPOSURE ("Exposure"),
|
||||
WHITE_BALANCE ("White Balance"),
|
||||
COLOR_CUBE ("Color Cube"),
|
||||
COLOR_CUBE_3D_INTRINSIC ("Color Cube (3D LUT intrinsic)"),
|
||||
USAGE_IO ("Usage io)");
|
||||
|
||||
|
||||
private final String name;
|
||||
|
||||
private TestName(String s) {
|
||||
name = s;
|
||||
}
|
||||
|
||||
// return quoted string as displayed test name
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap mBitmapIn;
|
||||
Bitmap mBitmapIn2;
|
||||
Bitmap mBitmapOut;
|
||||
|
||||
private Spinner mSpinner;
|
||||
private SeekBar mBar1;
|
||||
private SeekBar mBar2;
|
||||
private SeekBar mBar3;
|
||||
private SeekBar mBar4;
|
||||
private SeekBar mBar5;
|
||||
private TextView mText1;
|
||||
private TextView mText2;
|
||||
private TextView mText3;
|
||||
private TextView mText4;
|
||||
private TextView mText5;
|
||||
|
||||
private float mSaturation = 1.0f;
|
||||
|
||||
private TextView mBenchmarkResult;
|
||||
private Spinner mTestSpinner;
|
||||
|
||||
private SurfaceView mSurfaceView;
|
||||
private ImageView mDisplayView;
|
||||
|
||||
private boolean mDoingBenchmark;
|
||||
|
||||
private TestBase mTest;
|
||||
private int mRunCount;
|
||||
|
||||
public void updateDisplay() {
|
||||
mHandler.sendMessage(Message.obtain());
|
||||
}
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
// Allow the filter to complete without blocking the UI
|
||||
// thread. When the message arrives that the op is complete
|
||||
// we will either mark completion or start a new filter if
|
||||
// more work is ready. Either way, display the result.
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
boolean doTest = false;
|
||||
synchronized(this) {
|
||||
if (mRS == null) {
|
||||
return;
|
||||
}
|
||||
mTest.updateBitmap(mBitmapOut);
|
||||
mDisplayView.invalidate();
|
||||
if (mRunCount > 0) {
|
||||
mRunCount--;
|
||||
if (mRunCount > 0) {
|
||||
doTest = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doTest) {
|
||||
mTest.runTestSendMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (fromUser) {
|
||||
|
||||
if (seekBar == mBar1) {
|
||||
mTest.onBar1Changed(progress);
|
||||
} else if (seekBar == mBar2) {
|
||||
mTest.onBar2Changed(progress);
|
||||
} else if (seekBar == mBar3) {
|
||||
mTest.onBar3Changed(progress);
|
||||
} else if (seekBar == mBar4) {
|
||||
mTest.onBar4Changed(progress);
|
||||
} else if (seekBar == mBar5) {
|
||||
mTest.onBar5Changed(progress);
|
||||
}
|
||||
|
||||
boolean doTest = false;
|
||||
synchronized(this) {
|
||||
if (mRunCount == 0) {
|
||||
doTest = true;
|
||||
mRunCount = 1;
|
||||
} else {
|
||||
mRunCount = 2;
|
||||
}
|
||||
}
|
||||
if (doTest) {
|
||||
mTest.runTestSendMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
void setupBars() {
|
||||
mSpinner.setVisibility(View.VISIBLE);
|
||||
mTest.onSpinner1Setup(mSpinner);
|
||||
|
||||
mBar1.setVisibility(View.VISIBLE);
|
||||
mText1.setVisibility(View.VISIBLE);
|
||||
mTest.onBar1Setup(mBar1, mText1);
|
||||
|
||||
mBar2.setVisibility(View.VISIBLE);
|
||||
mText2.setVisibility(View.VISIBLE);
|
||||
mTest.onBar2Setup(mBar2, mText2);
|
||||
|
||||
mBar3.setVisibility(View.VISIBLE);
|
||||
mText3.setVisibility(View.VISIBLE);
|
||||
mTest.onBar3Setup(mBar3, mText3);
|
||||
|
||||
mBar4.setVisibility(View.VISIBLE);
|
||||
mText4.setVisibility(View.VISIBLE);
|
||||
mTest.onBar4Setup(mBar4, mText4);
|
||||
|
||||
mBar5.setVisibility(View.VISIBLE);
|
||||
mText5.setVisibility(View.VISIBLE);
|
||||
mTest.onBar5Setup(mBar5, mText5);
|
||||
}
|
||||
|
||||
|
||||
void changeTest(TestName testName) {
|
||||
if (mTest != null) {
|
||||
mTest.destroy();
|
||||
}
|
||||
switch(testName) {
|
||||
case LEVELS_VEC3_RELAXED:
|
||||
mTest = new LevelsV4(false, false);
|
||||
break;
|
||||
case LEVELS_VEC4_RELAXED:
|
||||
mTest = new LevelsV4(false, true);
|
||||
break;
|
||||
case LEVELS_VEC3_FULL:
|
||||
mTest = new LevelsV4(true, false);
|
||||
break;
|
||||
case LEVELS_VEC4_FULL:
|
||||
mTest = new LevelsV4(true, true);
|
||||
break;
|
||||
case BLUR_RADIUS_25:
|
||||
mTest = new Blur25(false);
|
||||
break;
|
||||
case INTRINSIC_BLUE_RADIUS_25:
|
||||
mTest = new Blur25(true);
|
||||
break;
|
||||
case GREYSCALE:
|
||||
mTest = new Greyscale();
|
||||
break;
|
||||
case GRAIN:
|
||||
mTest = new Grain();
|
||||
break;
|
||||
case FISHEYE_FULL:
|
||||
mTest = new Fisheye(false, false);
|
||||
break;
|
||||
case FISHEYE_RELAXED:
|
||||
mTest = new Fisheye(false, true);
|
||||
break;
|
||||
case FISHEYE_APPROXIMATE_FULL:
|
||||
mTest = new Fisheye(true, false);
|
||||
break;
|
||||
case FISHEYE_APPROXIMATE_RELAXED:
|
||||
mTest = new Fisheye(true, true);
|
||||
break;
|
||||
case VIGNETTE_FULL:
|
||||
mTest = new Vignette(false, false);
|
||||
break;
|
||||
case VIGNETTE_RELAXED:
|
||||
mTest = new Vignette(false, true);
|
||||
break;
|
||||
case VIGNETTE_APPROXIMATE_FULL:
|
||||
mTest = new Vignette(true, false);
|
||||
break;
|
||||
case VIGNETTE_APPROXIMATE_RELAXED:
|
||||
mTest = new Vignette(true, true);
|
||||
break;
|
||||
case GROUP_TEST_EMULATED:
|
||||
mTest = new GroupTest(false);
|
||||
break;
|
||||
case GROUP_TEST_NATIVE:
|
||||
mTest = new GroupTest(true);
|
||||
break;
|
||||
case CONVOLVE_3X3:
|
||||
mTest = new Convolve3x3(false);
|
||||
break;
|
||||
case INTRINSICS_CONVOLVE_3X3:
|
||||
mTest = new Convolve3x3(true);
|
||||
break;
|
||||
case COLOR_MATRIX:
|
||||
mTest = new ColorMatrix(false, false);
|
||||
break;
|
||||
case INTRINSICS_COLOR_MATRIX:
|
||||
mTest = new ColorMatrix(true, false);
|
||||
break;
|
||||
case INTRINSICS_COLOR_MATRIX_GREY:
|
||||
mTest = new ColorMatrix(true, true);
|
||||
break;
|
||||
case COPY:
|
||||
mTest = new Copy();
|
||||
break;
|
||||
case CROSS_PROCESS_USING_LUT:
|
||||
mTest = new CrossProcess();
|
||||
break;
|
||||
case CONVOLVE_5X5:
|
||||
mTest = new Convolve5x5(false);
|
||||
break;
|
||||
case INTRINSICS_CONVOLVE_5X5:
|
||||
mTest = new Convolve5x5(true);
|
||||
break;
|
||||
case MANDELBROT:
|
||||
mTest = new Mandelbrot();
|
||||
break;
|
||||
case INTRINSICS_BLEND:
|
||||
mTest = new Blend();
|
||||
break;
|
||||
case INTRINSICS_BLUR_25G:
|
||||
mTest = new Blur25G();
|
||||
break;
|
||||
case VIBRANCE:
|
||||
mTest = new Vibrance();
|
||||
break;
|
||||
case BW_FILTER:
|
||||
mTest = new BWFilter();
|
||||
break;
|
||||
case SHADOWS:
|
||||
mTest = new Shadows();
|
||||
break;
|
||||
case CONTRAST:
|
||||
mTest = new Contrast();
|
||||
break;
|
||||
case EXPOSURE:
|
||||
mTest = new Exposure();
|
||||
break;
|
||||
case WHITE_BALANCE:
|
||||
mTest = new WhiteBalance();
|
||||
break;
|
||||
case COLOR_CUBE:
|
||||
mTest = new ColorCube(false);
|
||||
break;
|
||||
case COLOR_CUBE_3D_INTRINSIC:
|
||||
mTest = new ColorCube(true);
|
||||
break;
|
||||
case USAGE_IO:
|
||||
mTest = new UsageIO();
|
||||
break;
|
||||
}
|
||||
|
||||
mTest.createBaseTest(this, mBitmapIn, mBitmapIn2, mBitmapOut);
|
||||
setupBars();
|
||||
|
||||
mTest.runTest();
|
||||
updateDisplay();
|
||||
mBenchmarkResult.setText("Result: not run");
|
||||
}
|
||||
|
||||
void setupTests() {
|
||||
mTestSpinner.setAdapter(new ArrayAdapter<TestName>(
|
||||
this, R.layout.spinner_layout, TestName.values()));
|
||||
}
|
||||
|
||||
private AdapterView.OnItemSelectedListener mTestSpinnerListener =
|
||||
new AdapterView.OnItemSelectedListener() {
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||
changeTest(TestName.values()[pos]);
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView parent) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void init() {
|
||||
mBitmapIn = loadBitmap(R.drawable.img1600x1067);
|
||||
mBitmapIn2 = loadBitmap(R.drawable.img1600x1067b);
|
||||
mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(),
|
||||
mBitmapIn.getConfig());
|
||||
|
||||
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
|
||||
|
||||
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);
|
||||
mBar4 = (SeekBar) findViewById(R.id.slider4);
|
||||
mBar5 = (SeekBar) findViewById(R.id.slider5);
|
||||
|
||||
mBar1.setOnSeekBarChangeListener(this);
|
||||
mBar2.setOnSeekBarChangeListener(this);
|
||||
mBar3.setOnSeekBarChangeListener(this);
|
||||
mBar4.setOnSeekBarChangeListener(this);
|
||||
mBar5.setOnSeekBarChangeListener(this);
|
||||
|
||||
mText1 = (TextView) findViewById(R.id.slider1Text);
|
||||
mText2 = (TextView) findViewById(R.id.slider2Text);
|
||||
mText3 = (TextView) findViewById(R.id.slider3Text);
|
||||
mText4 = (TextView) findViewById(R.id.slider4Text);
|
||||
mText5 = (TextView) findViewById(R.id.slider5Text);
|
||||
|
||||
mTestSpinner = (Spinner) findViewById(R.id.filterselection);
|
||||
mTestSpinner.setOnItemSelectedListener(mTestSpinnerListener);
|
||||
|
||||
mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
|
||||
mBenchmarkResult.setText("Result: not run");
|
||||
|
||||
|
||||
mRS = RenderScript.create(this);
|
||||
mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn);
|
||||
mInPixelsAllocation2 = Allocation.createFromBitmap(mRS, mBitmapIn2);
|
||||
mOutPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapOut);
|
||||
|
||||
|
||||
setupTests();
|
||||
changeTest(TestName.LEVELS_VEC3_RELAXED);
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
synchronized(this) {
|
||||
RenderScript rs = mRS;
|
||||
mRS = null;
|
||||
while(mDoingBenchmark) {
|
||||
try {
|
||||
Thread.sleep(1, 0);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
|
||||
}
|
||||
rs.destroy();
|
||||
}
|
||||
|
||||
mInPixelsAllocation = null;
|
||||
mInPixelsAllocation2 = null;
|
||||
mOutPixelsAllocation = null;
|
||||
mBitmapIn = null;
|
||||
mBitmapIn2 = null;
|
||||
mBitmapOut = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private Bitmap loadBitmap(int resource) {
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
return BitmapFactory.decodeResource(getResources(), resource, options);
|
||||
}
|
||||
|
||||
// button hook
|
||||
public void benchmark(View v) {
|
||||
float t = getBenchmark();
|
||||
//long javaTime = javaFilter();
|
||||
//mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
|
||||
mBenchmarkResult.setText("Result: " + t + " ms");
|
||||
Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + t);
|
||||
}
|
||||
|
||||
public void benchmark_all(View v) {
|
||||
// write result into a file
|
||||
File externalStorage = Environment.getExternalStorageDirectory();
|
||||
if (!externalStorage.canWrite()) {
|
||||
Log.v(TAG, "sdcard is not writable");
|
||||
return;
|
||||
}
|
||||
File resultFile = new File(externalStorage, RESULT_FILE);
|
||||
resultFile.setWritable(true, false);
|
||||
try {
|
||||
BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
|
||||
Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
|
||||
for (TestName tn: TestName.values()) {
|
||||
changeTest(tn);
|
||||
float t = getBenchmark();
|
||||
String s = new String("" + tn.toString() + ", " + t);
|
||||
rsWriter.write(s + "\n");
|
||||
Log.v(TAG, "Test " + s + "ms\n");
|
||||
}
|
||||
rsWriter.close();
|
||||
} catch (IOException e) {
|
||||
Log.v(TAG, "Unable to write result file " + e.getMessage());
|
||||
}
|
||||
changeTest(TestName.LEVELS_VEC3_RELAXED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// For benchmark test
|
||||
public float getBenchmark() {
|
||||
if (mRS == null) {
|
||||
return 0;
|
||||
}
|
||||
mDoingBenchmark = true;
|
||||
|
||||
mTest.setupBenchmark();
|
||||
long result = 0;
|
||||
|
||||
//Log.v(TAG, "Warming");
|
||||
long t = java.lang.System.currentTimeMillis() + 250;
|
||||
do {
|
||||
mTest.runTest();
|
||||
mTest.finish();
|
||||
} while (t > java.lang.System.currentTimeMillis());
|
||||
|
||||
//Log.v(TAG, "Benchmarking");
|
||||
int ct = 0;
|
||||
t = java.lang.System.currentTimeMillis();
|
||||
do {
|
||||
mTest.runTest();
|
||||
mTest.finish();
|
||||
ct++;
|
||||
} while ((t+1000) > java.lang.System.currentTimeMillis());
|
||||
t = java.lang.System.currentTimeMillis() - t;
|
||||
float ft = (float)t;
|
||||
ft /= ct;
|
||||
|
||||
mTest.exitBenchmark();
|
||||
mDoingBenchmark = false;
|
||||
return ft;
|
||||
}
|
||||
}
|
||||
@@ -1,379 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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 com.android.rs.image.ImageProcessingTestRunner;
|
||||
|
||||
import android.os.Bundle;
|
||||
import com.android.rs.image.ImageProcessingActivity.TestName;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* ImageProcessing benchmark test.
|
||||
* To run the test, please use command
|
||||
*
|
||||
* adb shell am instrument -e iteration <n> -w com.android.rs.image/.ImageProcessingTestRunner
|
||||
*
|
||||
*/
|
||||
public class ImageProcessingTest extends ActivityInstrumentationTestCase2<ImageProcessingActivity> {
|
||||
private final String TAG = "ImageProcessingTest";
|
||||
private final String TEST_NAME = "Testname";
|
||||
private final String ITERATIONS = "Iterations";
|
||||
private final String BENCHMARK = "Benchmark";
|
||||
private static int INSTRUMENTATION_IN_PROGRESS = 2;
|
||||
private int mIteration;
|
||||
private ImageProcessingActivity mActivity;
|
||||
|
||||
public ImageProcessingTest() {
|
||||
super(ImageProcessingActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
ImageProcessingTestRunner mRunner = (ImageProcessingTestRunner) getInstrumentation();
|
||||
mIteration = mRunner.mIteration;
|
||||
assertTrue("please enter a valid iteration value", mIteration > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
class TestAction implements Runnable {
|
||||
TestName mTestName;
|
||||
float mResult;
|
||||
public TestAction(TestName testName) {
|
||||
mTestName = testName;
|
||||
}
|
||||
public void run() {
|
||||
mActivity.changeTest(mTestName);
|
||||
mResult = mActivity.getBenchmark();
|
||||
Log.v(TAG, "Benchmark for test \"" + mTestName.toString() + "\" is: " + mResult);
|
||||
synchronized(this) {
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
public float getBenchmark() {
|
||||
return mResult;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the benchmark thread to run on ui thread
|
||||
// Synchronized the thread such that the test will wait for the benchmark thread to finish
|
||||
public void runOnUiThread(Runnable action) {
|
||||
synchronized(action) {
|
||||
mActivity.runOnUiThread(action);
|
||||
try {
|
||||
action.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Log.v(TAG, "waiting for action running on UI thread is interrupted: " +
|
||||
e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void runTest(TestAction ta, String testName) {
|
||||
float sum = 0;
|
||||
for (int i = 0; i < mIteration; i++) {
|
||||
runOnUiThread(ta);
|
||||
float bmValue = ta.getBenchmark();
|
||||
Log.v(TAG, "results for iteration " + i + " is " + bmValue);
|
||||
sum += bmValue;
|
||||
}
|
||||
float avgResult = sum/mIteration;
|
||||
|
||||
// post result to INSTRUMENTATION_STATUS
|
||||
Bundle results = new Bundle();
|
||||
results.putString(TEST_NAME, testName);
|
||||
results.putInt(ITERATIONS, mIteration);
|
||||
results.putFloat(BENCHMARK, avgResult);
|
||||
getInstrumentation().sendStatus(INSTRUMENTATION_IN_PROGRESS, results);
|
||||
}
|
||||
|
||||
// Test case 0: Levels Vec3 Relaxed
|
||||
@LargeTest
|
||||
public void testLevelsVec3Relaxed() {
|
||||
TestAction ta = new TestAction(TestName.LEVELS_VEC3_RELAXED);
|
||||
runTest(ta, TestName.LEVELS_VEC3_RELAXED.name());
|
||||
}
|
||||
|
||||
// Test case 1: Levels Vec4 Relaxed
|
||||
@LargeTest
|
||||
public void testLevelsVec4Relaxed() {
|
||||
TestAction ta = new TestAction(TestName.LEVELS_VEC4_RELAXED);
|
||||
runTest(ta, TestName.LEVELS_VEC4_RELAXED.name());
|
||||
}
|
||||
|
||||
// Test case 2: Levels Vec3 Full
|
||||
@LargeTest
|
||||
public void testLevelsVec3Full() {
|
||||
TestAction ta = new TestAction(TestName.LEVELS_VEC3_FULL);
|
||||
runTest(ta, TestName.LEVELS_VEC3_FULL.name());
|
||||
}
|
||||
|
||||
// Test case 3: Levels Vec4 Full
|
||||
@LargeTest
|
||||
public void testLevelsVec4Full() {
|
||||
TestAction ta = new TestAction(TestName.LEVELS_VEC4_FULL);
|
||||
runTest(ta, TestName.LEVELS_VEC4_FULL.name());
|
||||
}
|
||||
|
||||
// Test case 4: Blur Radius 25
|
||||
@LargeTest
|
||||
public void testBlurRadius25() {
|
||||
TestAction ta = new TestAction(TestName.BLUR_RADIUS_25);
|
||||
runTest(ta, TestName.BLUR_RADIUS_25.name());
|
||||
}
|
||||
|
||||
// Test case 5: Intrinsic Blur Radius 25
|
||||
@LargeTest
|
||||
public void testIntrinsicBlurRadius25() {
|
||||
TestAction ta = new TestAction(TestName.INTRINSIC_BLUE_RADIUS_25);
|
||||
runTest(ta, TestName.INTRINSIC_BLUE_RADIUS_25.name());
|
||||
}
|
||||
|
||||
// Test case 6: Greyscale
|
||||
@LargeTest
|
||||
public void testGreyscale() {
|
||||
TestAction ta = new TestAction(TestName.GREYSCALE);
|
||||
runTest(ta, TestName.GREYSCALE.name());
|
||||
}
|
||||
|
||||
// Test case 7: Grain
|
||||
@LargeTest
|
||||
public void testGrain() {
|
||||
TestAction ta = new TestAction(TestName.GRAIN);
|
||||
runTest(ta, TestName.GRAIN.name());
|
||||
}
|
||||
|
||||
// Test case 8: Fisheye Full
|
||||
@LargeTest
|
||||
public void testFisheyeFull() {
|
||||
TestAction ta = new TestAction(TestName.FISHEYE_FULL);
|
||||
runTest(ta, TestName.FISHEYE_FULL.name());
|
||||
}
|
||||
|
||||
// Test case 9: Fisheye Relaxed
|
||||
@LargeTest
|
||||
public void testFishEyeRelaxed() {
|
||||
TestAction ta = new TestAction(TestName.FISHEYE_RELAXED);
|
||||
runTest(ta, TestName.FISHEYE_RELAXED.name());
|
||||
}
|
||||
|
||||
// Test case 10: Fisheye Approximate Full
|
||||
@LargeTest
|
||||
public void testFisheyeApproximateFull() {
|
||||
TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_FULL);
|
||||
runTest(ta, TestName.FISHEYE_APPROXIMATE_FULL.name());
|
||||
}
|
||||
|
||||
// Test case 11: Fisheye Approximate Relaxed
|
||||
@LargeTest
|
||||
public void testFisheyeApproximateRelaxed() {
|
||||
TestAction ta = new TestAction(TestName.FISHEYE_APPROXIMATE_RELAXED);
|
||||
runTest(ta, TestName.FISHEYE_APPROXIMATE_RELAXED.name());
|
||||
}
|
||||
|
||||
// Test case 12: Vignette Full
|
||||
@LargeTest
|
||||
public void testVignetteFull() {
|
||||
TestAction ta = new TestAction(TestName.VIGNETTE_FULL);
|
||||
runTest(ta, TestName.VIGNETTE_FULL.name());
|
||||
}
|
||||
|
||||
// Test case 13: Vignette Relaxed
|
||||
@LargeTest
|
||||
public void testVignetteRelaxed() {
|
||||
TestAction ta = new TestAction(TestName.VIGNETTE_RELAXED);
|
||||
runTest(ta, TestName.VIGNETTE_RELAXED.name());
|
||||
}
|
||||
|
||||
// Test case 14: Vignette Approximate Full
|
||||
@LargeTest
|
||||
public void testVignetteApproximateFull() {
|
||||
TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_FULL);
|
||||
runTest(ta, TestName.VIGNETTE_APPROXIMATE_FULL.name());
|
||||
}
|
||||
|
||||
// Test case 15: Vignette Approximate Relaxed
|
||||
@LargeTest
|
||||
public void testVignetteApproximateRelaxed() {
|
||||
TestAction ta = new TestAction(TestName.VIGNETTE_APPROXIMATE_RELAXED);
|
||||
runTest(ta, TestName.VIGNETTE_APPROXIMATE_RELAXED.name());
|
||||
}
|
||||
|
||||
// Test case 16: Group Test (emulated)
|
||||
@LargeTest
|
||||
public void testGroupTestEmulated() {
|
||||
TestAction ta = new TestAction(TestName.GROUP_TEST_EMULATED);
|
||||
runTest(ta, TestName.GROUP_TEST_EMULATED.name());
|
||||
}
|
||||
|
||||
// Test case 17: Group Test (native)
|
||||
@LargeTest
|
||||
public void testGroupTestNative() {
|
||||
TestAction ta = new TestAction(TestName.GROUP_TEST_NATIVE);
|
||||
runTest(ta, TestName.GROUP_TEST_NATIVE.name());
|
||||
}
|
||||
|
||||
// Test case 18: Convolve 3x3
|
||||
@LargeTest
|
||||
public void testConvolve3x3() {
|
||||
TestAction ta = new TestAction(TestName.CONVOLVE_3X3);
|
||||
runTest(ta, TestName.CONVOLVE_3X3.name());
|
||||
}
|
||||
|
||||
// Test case 19: Intrinsics Convolve 3x3
|
||||
@LargeTest
|
||||
public void testIntrinsicsConvolve3x3() {
|
||||
TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_3X3);
|
||||
runTest(ta, TestName.INTRINSICS_CONVOLVE_3X3.name());
|
||||
}
|
||||
|
||||
// Test case 20: ColorMatrix
|
||||
@LargeTest
|
||||
public void testColorMatrix() {
|
||||
TestAction ta = new TestAction(TestName.COLOR_MATRIX);
|
||||
runTest(ta, TestName.COLOR_MATRIX.name());
|
||||
}
|
||||
|
||||
// Test case 21: Intrinsics ColorMatrix
|
||||
@LargeTest
|
||||
public void testIntrinsicsColorMatrix() {
|
||||
TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX);
|
||||
runTest(ta, TestName.INTRINSICS_COLOR_MATRIX.name());
|
||||
}
|
||||
|
||||
// Test case 22: Intrinsics ColorMatrix Grey
|
||||
@LargeTest
|
||||
public void testIntrinsicsColorMatrixGrey() {
|
||||
TestAction ta = new TestAction(TestName.INTRINSICS_COLOR_MATRIX_GREY);
|
||||
runTest(ta, TestName.INTRINSICS_COLOR_MATRIX_GREY.name());
|
||||
}
|
||||
|
||||
// Test case 23: Copy
|
||||
@LargeTest
|
||||
public void testCopy() {
|
||||
TestAction ta = new TestAction(TestName.COPY);
|
||||
runTest(ta, TestName.COPY.name());
|
||||
}
|
||||
|
||||
// Test case 24: CrossProcess (using LUT)
|
||||
@LargeTest
|
||||
public void testCrossProcessUsingLUT() {
|
||||
TestAction ta = new TestAction(TestName.CROSS_PROCESS_USING_LUT);
|
||||
runTest(ta, TestName.CROSS_PROCESS_USING_LUT.name());
|
||||
}
|
||||
|
||||
// Test case 25: Convolve 5x5
|
||||
@LargeTest
|
||||
public void testConvolve5x5() {
|
||||
TestAction ta = new TestAction(TestName.CONVOLVE_5X5);
|
||||
runTest(ta, TestName.CONVOLVE_5X5.name());
|
||||
}
|
||||
|
||||
// Test case 26: Intrinsics Convolve 5x5
|
||||
@LargeTest
|
||||
public void testIntrinsicsConvolve5x5() {
|
||||
TestAction ta = new TestAction(TestName.INTRINSICS_CONVOLVE_5X5);
|
||||
runTest(ta, TestName.INTRINSICS_CONVOLVE_5X5.name());
|
||||
}
|
||||
|
||||
// Test case 27: Mandelbrot
|
||||
@LargeTest
|
||||
public void testMandelbrot() {
|
||||
TestAction ta = new TestAction(TestName.MANDELBROT);
|
||||
runTest(ta, TestName.MANDELBROT.name());
|
||||
}
|
||||
|
||||
// Test case 28: Intrinsics Blend
|
||||
@LargeTest
|
||||
public void testIntrinsicsBlend() {
|
||||
TestAction ta = new TestAction(TestName.INTRINSICS_BLEND);
|
||||
runTest(ta, TestName.INTRINSICS_BLEND.name());
|
||||
}
|
||||
|
||||
// Test case 29: Intrinsics Blur 25 uchar
|
||||
@LargeTest
|
||||
public void testIntrinsicsBlur25G() {
|
||||
TestAction ta = new TestAction(TestName.INTRINSICS_BLUR_25G);
|
||||
runTest(ta, TestName.INTRINSICS_BLUR_25G.name());
|
||||
}
|
||||
|
||||
// Test case 30: Vibrance
|
||||
@LargeTest
|
||||
public void testVibrance() {
|
||||
TestAction ta = new TestAction(TestName.VIBRANCE);
|
||||
runTest(ta, TestName.VIBRANCE.name());
|
||||
}
|
||||
|
||||
// Test case 31: BWFilter
|
||||
@LargeTest
|
||||
public void testBWFilter() {
|
||||
TestAction ta = new TestAction(TestName.BW_FILTER);
|
||||
runTest(ta, TestName.BW_FILTER.name());
|
||||
}
|
||||
|
||||
// Test case 32: Shadows
|
||||
@LargeTest
|
||||
public void testShadows() {
|
||||
TestAction ta = new TestAction(TestName.SHADOWS);
|
||||
runTest(ta, TestName.SHADOWS.name());
|
||||
}
|
||||
|
||||
// Test case 33: Contrast
|
||||
@LargeTest
|
||||
public void testContrast() {
|
||||
TestAction ta = new TestAction(TestName.CONTRAST);
|
||||
runTest(ta, TestName.CONTRAST.name());
|
||||
}
|
||||
|
||||
// Test case 34: Exposure
|
||||
@LargeTest
|
||||
public void testExposure(){
|
||||
TestAction ta = new TestAction(TestName.EXPOSURE);
|
||||
runTest(ta, TestName.EXPOSURE.name());
|
||||
}
|
||||
|
||||
// Test case 35: White Balance
|
||||
@LargeTest
|
||||
public void testWhiteBalance() {
|
||||
TestAction ta = new TestAction(TestName.WHITE_BALANCE);
|
||||
runTest(ta, TestName.WHITE_BALANCE.name());
|
||||
}
|
||||
|
||||
// Test case 36: Color Cube
|
||||
@LargeTest
|
||||
public void testColorCube() {
|
||||
TestAction ta = new TestAction(TestName.COLOR_CUBE);
|
||||
runTest(ta, TestName.COLOR_CUBE.name());
|
||||
}
|
||||
|
||||
// Test case 37: Color Cube (3D Intrinsic)
|
||||
@LargeTest
|
||||
public void testColorCube3DIntrinsic() {
|
||||
TestAction ta = new TestAction(TestName.COLOR_CUBE_3D_INTRINSIC);
|
||||
runTest(ta, TestName.COLOR_CUBE_3D_INTRINSIC.name());
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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 com.android.rs.image.ImageProcessingTest;
|
||||
import android.os.Bundle;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
import android.test.InstrumentationTestSuite;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Run the ImageProcessing benchmark test
|
||||
* adb shell am instrument -e iteration <n> -w com.android.rs.image/.ImageProcessingTestRunner
|
||||
*
|
||||
*/
|
||||
public class ImageProcessingTestRunner extends InstrumentationTestRunner {
|
||||
public int mIteration = 5;
|
||||
|
||||
@Override
|
||||
public TestSuite getAllTests() {
|
||||
TestSuite suite = new InstrumentationTestSuite(this);
|
||||
suite.addTestSuite(ImageProcessingTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
String strIteration = (String) icicle.get("iteration");
|
||||
if (strIteration != null) {
|
||||
mIteration = Integer.parseInt(strIteration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Matrix3f;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class LevelsV4 extends TestBase {
|
||||
private ScriptC_levels_relaxed mScriptR;
|
||||
private ScriptC_levels_full mScriptF;
|
||||
private float mInBlack = 0.0f;
|
||||
private float mOutBlack = 0.0f;
|
||||
private float mInWhite = 255.0f;
|
||||
private float mOutWhite = 255.0f;
|
||||
private float mSaturation = 1.0f;
|
||||
|
||||
Matrix3f satMatrix = new Matrix3f();
|
||||
float mInWMinInB;
|
||||
float mOutWMinOutB;
|
||||
float mOverInWMinInB;
|
||||
|
||||
boolean mUseFull;
|
||||
boolean mUseV4;
|
||||
|
||||
LevelsV4(boolean useFull, boolean useV4) {
|
||||
mUseFull = useFull;
|
||||
mUseV4 = useV4;
|
||||
}
|
||||
|
||||
|
||||
private void setLevels() {
|
||||
mInWMinInB = mInWhite - mInBlack;
|
||||
mOutWMinOutB = mOutWhite - mOutBlack;
|
||||
mOverInWMinInB = 1.f / mInWMinInB;
|
||||
|
||||
mScriptR.set_inBlack(mInBlack);
|
||||
mScriptR.set_outBlack(mOutBlack);
|
||||
mScriptR.set_inWMinInB(mInWMinInB);
|
||||
mScriptR.set_outWMinOutB(mOutWMinOutB);
|
||||
mScriptR.set_overInWMinInB(mOverInWMinInB);
|
||||
mScriptF.set_inBlack(mInBlack);
|
||||
mScriptF.set_outBlack(mOutBlack);
|
||||
mScriptF.set_inWMinInB(mInWMinInB);
|
||||
mScriptF.set_outWMinOutB(mOutWMinOutB);
|
||||
mScriptF.set_overInWMinInB(mOverInWMinInB);
|
||||
}
|
||||
|
||||
private void setSaturation() {
|
||||
float rWeight = 0.299f;
|
||||
float gWeight = 0.587f;
|
||||
float bWeight = 0.114f;
|
||||
float oneMinusS = 1.0f - mSaturation;
|
||||
|
||||
satMatrix.set(0, 0, oneMinusS * rWeight + mSaturation);
|
||||
satMatrix.set(0, 1, oneMinusS * rWeight);
|
||||
satMatrix.set(0, 2, oneMinusS * rWeight);
|
||||
satMatrix.set(1, 0, oneMinusS * gWeight);
|
||||
satMatrix.set(1, 1, oneMinusS * gWeight + mSaturation);
|
||||
satMatrix.set(1, 2, oneMinusS * gWeight);
|
||||
satMatrix.set(2, 0, oneMinusS * bWeight);
|
||||
satMatrix.set(2, 1, oneMinusS * bWeight);
|
||||
satMatrix.set(2, 2, oneMinusS * bWeight + mSaturation);
|
||||
mScriptR.set_colorMat(satMatrix);
|
||||
mScriptF.set_colorMat(satMatrix);
|
||||
}
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
b.setProgress(50);
|
||||
t.setText("Saturation");
|
||||
return true;
|
||||
}
|
||||
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||
b.setMax(128);
|
||||
b.setProgress(0);
|
||||
t.setText("In Black");
|
||||
return true;
|
||||
}
|
||||
public boolean onBar3Setup(SeekBar b, TextView t) {
|
||||
b.setMax(128);
|
||||
b.setProgress(0);
|
||||
t.setText("Out Black");
|
||||
return true;
|
||||
}
|
||||
public boolean onBar4Setup(SeekBar b, TextView t) {
|
||||
b.setMax(128);
|
||||
b.setProgress(128);
|
||||
t.setText("Out White");
|
||||
return true;
|
||||
}
|
||||
public boolean onBar5Setup(SeekBar b, TextView t) {
|
||||
b.setMax(128);
|
||||
b.setProgress(128);
|
||||
t.setText("Out White");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
mSaturation = (float)progress / 50.0f;
|
||||
setSaturation();
|
||||
}
|
||||
public void onBar2Changed(int progress) {
|
||||
mInBlack = (float)progress;
|
||||
setLevels();
|
||||
}
|
||||
public void onBar3Changed(int progress) {
|
||||
mOutBlack = (float)progress;
|
||||
setLevels();
|
||||
}
|
||||
public void onBar4Changed(int progress) {
|
||||
mInWhite = (float)progress + 127.0f;
|
||||
setLevels();
|
||||
}
|
||||
public void onBar5Changed(int progress) {
|
||||
mOutWhite = (float)progress + 127.0f;
|
||||
setLevels();
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScriptR = new ScriptC_levels_relaxed(mRS, res, R.raw.levels_relaxed);
|
||||
mScriptF = new ScriptC_levels_full(mRS, res, R.raw.levels_full);
|
||||
setSaturation();
|
||||
setLevels();
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (mUseFull) {
|
||||
if (mUseV4) {
|
||||
mScriptF.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
} else {
|
||||
mScriptF.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
} else {
|
||||
if (mUseV4) {
|
||||
mScriptR.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
} else {
|
||||
mScriptR.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.Type;
|
||||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Mandelbrot extends TestBase {
|
||||
private ScriptC_mandelbrot mScript;
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
t.setText("Iterations");
|
||||
b.setProgress(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
int iters = progress * 3 + 50;
|
||||
mScript.set_gMaxIteration(iters);
|
||||
}
|
||||
|
||||
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||
t.setText("Lower Bound: X");
|
||||
b.setProgress(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar2Changed(int progress) {
|
||||
float scaleFactor = mScript.get_scaleFactor();
|
||||
// allow viewport to be moved by 2x scale factor
|
||||
float lowerBoundX = -2.f + ((progress / scaleFactor) / 50.f);
|
||||
mScript.set_lowerBoundX(lowerBoundX);
|
||||
}
|
||||
|
||||
public boolean onBar3Setup(SeekBar b, TextView t) {
|
||||
t.setText("Lower Bound: Y");
|
||||
b.setProgress(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar3Changed(int progress) {
|
||||
float scaleFactor = mScript.get_scaleFactor();
|
||||
// allow viewport to be moved by 2x scale factor
|
||||
float lowerBoundY = -2.f + ((progress / scaleFactor) / 50.f);
|
||||
mScript.set_lowerBoundY(lowerBoundY);
|
||||
}
|
||||
|
||||
public boolean onBar4Setup(SeekBar b, TextView t) {
|
||||
t.setText("Scale Factor");
|
||||
b.setProgress(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar4Changed(int progress) {
|
||||
float scaleFactor = 4.f - (3.96f * (progress / 100.f));
|
||||
mScript.set_scaleFactor(scaleFactor);
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
int width = mOutPixelsAllocation.getType().getX();
|
||||
int height = mOutPixelsAllocation.getType().getY();
|
||||
|
||||
mScript = new ScriptC_mandelbrot(mRS, res, R.raw.mandelbrot);
|
||||
mScript.set_gDimX(width);
|
||||
mScript.set_gDimY(height);
|
||||
mScript.set_gMaxIteration(50);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.forEach_root(mOutPixelsAllocation);
|
||||
mRS.finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
|
||||
public class Shadows extends TestBase {
|
||||
private ScriptC_shadows mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_shadows(mRS);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.invoke_prepareShadows(50.f);
|
||||
mScript.forEach_shadowsKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* 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 android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Type;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.Script;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
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;
|
||||
|
||||
private class MessageProcessor extends RenderScript.RSMessageHandler {
|
||||
ImageProcessingActivity mAct;
|
||||
|
||||
MessageProcessor(ImageProcessingActivity act) {
|
||||
mAct = act;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
mAct.updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
// Override to use UI elements
|
||||
public void onBar1Changed(int progress) {
|
||||
}
|
||||
public void onBar2Changed(int progress) {
|
||||
}
|
||||
public void onBar3Changed(int progress) {
|
||||
}
|
||||
public void onBar4Changed(int progress) {
|
||||
}
|
||||
public void onBar5Changed(int progress) {
|
||||
}
|
||||
|
||||
// Override to use UI elements
|
||||
// Unused bars will be hidden.
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
b.setVisibility(View.INVISIBLE);
|
||||
t.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||
b.setVisibility(View.INVISIBLE);
|
||||
t.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
public boolean onBar3Setup(SeekBar b, TextView t) {
|
||||
b.setVisibility(View.INVISIBLE);
|
||||
t.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
public boolean onBar4Setup(SeekBar b, TextView t) {
|
||||
b.setVisibility(View.INVISIBLE);
|
||||
t.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
public boolean onBar5Setup(SeekBar b, TextView t) {
|
||||
b.setVisibility(View.INVISIBLE);
|
||||
t.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onSpinner1Setup(Spinner s) {
|
||||
s.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void createBaseTest(ImageProcessingActivity ipact, Bitmap b, Bitmap b2, Bitmap outb) {
|
||||
act = ipact;
|
||||
mRS = ipact.mRS;
|
||||
mRS.setMessageHandler(new MessageProcessor(act));
|
||||
|
||||
mInPixelsAllocation = ipact.mInPixelsAllocation;
|
||||
mInPixelsAllocation2 = ipact.mInPixelsAllocation2;
|
||||
mOutPixelsAllocation = ipact.mOutPixelsAllocation;
|
||||
|
||||
createTest(act.getResources());
|
||||
}
|
||||
|
||||
// Must override
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
}
|
||||
|
||||
// Must override
|
||||
public void runTest() {
|
||||
}
|
||||
|
||||
final public void runTestSendMessage() {
|
||||
runTest();
|
||||
mRS.sendMessage(0, null);
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
mRS.finish();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
mRS.setMessageHandler(null);
|
||||
}
|
||||
|
||||
public void updateBitmap(Bitmap b) {
|
||||
mOutPixelsAllocation.copyTo(b);
|
||||
}
|
||||
|
||||
// Override to configure specific benchmark config.
|
||||
public void setupBenchmark() {
|
||||
}
|
||||
|
||||
// Override to reset after benchmark.
|
||||
public void exitBenchmark() {
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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 android.view.Surface;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicConvolve3x3;
|
||||
import android.renderscript.ScriptIntrinsicColorMatrix;
|
||||
import android.renderscript.Type;
|
||||
import android.renderscript.Matrix4f;
|
||||
import android.renderscript.ScriptGroup;
|
||||
import android.util.Log;
|
||||
|
||||
public class UsageIO extends TestBase {
|
||||
private ScriptIntrinsicColorMatrix mMatrix;
|
||||
|
||||
private Allocation mScratchPixelsAllocation1;
|
||||
private Allocation mScratchPixelsAllocation2;
|
||||
|
||||
public UsageIO() {
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mMatrix = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
|
||||
|
||||
Matrix4f m = new Matrix4f();
|
||||
m.set(1, 0, 0.2f);
|
||||
m.set(1, 1, 0.9f);
|
||||
m.set(1, 2, 0.2f);
|
||||
mMatrix.setColorMatrix(m);
|
||||
|
||||
Type connect = mInPixelsAllocation.getType();
|
||||
|
||||
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, connect, Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT);
|
||||
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, connect, Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
|
||||
|
||||
Surface s = mScratchPixelsAllocation2.getSurface();
|
||||
mScratchPixelsAllocation1.setSurface(s);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScratchPixelsAllocation1.copyFrom(mInPixelsAllocation);
|
||||
mScratchPixelsAllocation1.ioSend();
|
||||
mScratchPixelsAllocation2.ioReceive();
|
||||
mMatrix.forEach(mScratchPixelsAllocation2, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
|
||||
public class Vibrance extends TestBase {
|
||||
private ScriptC_vibrance mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_vibrance(mRS);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.set_vibrance(50.f);
|
||||
mScript.invoke_prepareVibrance();
|
||||
mScript.forEach_vibranceKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.Sampler;
|
||||
import android.renderscript.Type;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Vignette extends TestBase {
|
||||
private ScriptC_vignette_full mScript_full = null;
|
||||
private ScriptC_vignette_relaxed mScript_relaxed = null;
|
||||
private ScriptC_vignette_approx_full mScript_approx_full = null;
|
||||
private ScriptC_vignette_approx_relaxed mScript_approx_relaxed = null;
|
||||
private final boolean approx;
|
||||
private final boolean relaxed;
|
||||
private float center_x = 0.5f;
|
||||
private float center_y = 0.5f;
|
||||
private float scale = 0.5f;
|
||||
private float shade = 0.5f;
|
||||
private float slope = 20.0f;
|
||||
|
||||
public Vignette(boolean approx, boolean relaxed) {
|
||||
this.approx = approx;
|
||||
this.relaxed = relaxed;
|
||||
}
|
||||
|
||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||
t.setText("Scale");
|
||||
b.setMax(100);
|
||||
b.setProgress(25);
|
||||
return true;
|
||||
}
|
||||
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||
t.setText("Shade");
|
||||
b.setMax(100);
|
||||
b.setProgress(50);
|
||||
return true;
|
||||
}
|
||||
public boolean onBar3Setup(SeekBar b, TextView t) {
|
||||
t.setText("Slope");
|
||||
b.setMax(100);
|
||||
b.setProgress(20);
|
||||
return true;
|
||||
}
|
||||
public boolean onBar4Setup(SeekBar b, TextView t) {
|
||||
t.setText("Shift center X");
|
||||
b.setMax(100);
|
||||
b.setProgress(50);
|
||||
return true;
|
||||
}
|
||||
public boolean onBar5Setup(SeekBar b, TextView t) {
|
||||
t.setText("Shift center Y");
|
||||
b.setMax(100);
|
||||
b.setProgress(50);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBar1Changed(int progress) {
|
||||
scale = progress / 50.0f;
|
||||
do_init();
|
||||
}
|
||||
public void onBar2Changed(int progress) {
|
||||
shade = progress / 100.0f;
|
||||
do_init();
|
||||
}
|
||||
public void onBar3Changed(int progress) {
|
||||
slope = (float)progress;
|
||||
do_init();
|
||||
}
|
||||
public void onBar4Changed(int progress) {
|
||||
center_x = progress / 100.0f;
|
||||
do_init();
|
||||
}
|
||||
public void onBar5Changed(int progress) {
|
||||
center_y = progress / 100.0f;
|
||||
do_init();
|
||||
}
|
||||
|
||||
private void do_init() {
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed.invoke_init_vignette(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x,
|
||||
center_y, scale, shade, slope);
|
||||
else
|
||||
mScript_approx_full.invoke_init_vignette(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x,
|
||||
center_y, scale, shade, slope);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed.invoke_init_vignette(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||
scale, shade, slope);
|
||||
else
|
||||
mScript_full.invoke_init_vignette(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||
scale, shade, slope);
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed = new ScriptC_vignette_approx_relaxed(
|
||||
mRS, res, R.raw.vignette_approx_relaxed);
|
||||
else
|
||||
mScript_approx_full = new ScriptC_vignette_approx_full(
|
||||
mRS, res, R.raw.vignette_approx_full);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed = new ScriptC_vignette_relaxed(mRS, res,
|
||||
R.raw.vignette_relaxed);
|
||||
else
|
||||
mScript_full = new ScriptC_vignette_full(mRS, res,
|
||||
R.raw.vignette_full);
|
||||
do_init();
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
else
|
||||
mScript_approx_full.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
else
|
||||
mScript_full.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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 android.renderscript.Allocation;
|
||||
|
||||
public class WhiteBalance extends TestBase {
|
||||
private ScriptC_wbalance mScript;
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
mScript = new ScriptC_wbalance(mRS);
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
mScript.set_histogramSource(mInPixelsAllocation);
|
||||
mScript.set_histogramWidth(mInPixelsAllocation.getType().getX());
|
||||
mScript.set_histogramHeight(mInPixelsAllocation.getType().getY());
|
||||
mScript.invoke_prepareWhiteBalance();
|
||||
mScript.forEach_whiteBalanceKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2011 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.
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
uchar alpha = 0x0;
|
||||
|
||||
void setImageAlpha(uchar4 *v_out, uint32_t x, uint32_t y) {
|
||||
v_out->rgba = convert_uchar4((convert_uint4(v_out->rgba) * alpha) >> (uint4)8);
|
||||
v_out->a = alpha;
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
//#pragma rs_fp_relaxed
|
||||
|
||||
static float sr = 0.f;
|
||||
static float sg = 0.f;
|
||||
static float sb = 0.f;
|
||||
|
||||
void prepareBwFilter(uint32_t rw, uint32_t gw, uint32_t bw) {
|
||||
|
||||
sr = rw;
|
||||
sg = gw;
|
||||
sb = bw;
|
||||
|
||||
float imageMin = min(sg,sb);
|
||||
imageMin = fmin(sr,imageMin);
|
||||
float imageMax = max(sg,sb);
|
||||
imageMax = fmax(sr,imageMax);
|
||||
float avg = (imageMin + imageMax)/2;
|
||||
sb /= avg;
|
||||
sg /= avg;
|
||||
sr /= avg;
|
||||
|
||||
}
|
||||
|
||||
void bwFilterKernel(const uchar4 *in, uchar4 *out) {
|
||||
float r = in->r * sr;
|
||||
float g = in->g * sg;
|
||||
float b = in->b * sb;
|
||||
float localMin, localMax, avg;
|
||||
localMin = fmin(g,b);
|
||||
localMin = fmin(r,localMin);
|
||||
localMax = fmax(g,b);
|
||||
localMax = fmax(r,localMax);
|
||||
avg = (localMin+localMax) * 0.5f;
|
||||
out->r = out->g = out->b = rsClamp(avg, 0, 255);
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
|
||||
static rs_allocation gCube;
|
||||
static int4 gDims;
|
||||
static int4 gCoordMul;
|
||||
|
||||
|
||||
void setCube(rs_allocation c) {
|
||||
gCube = c;
|
||||
gDims.x = rsAllocationGetDimX(gCube);
|
||||
gDims.y = rsAllocationGetDimY(gCube);
|
||||
gDims.z = rsAllocationGetDimZ(gCube);
|
||||
gDims.w = 0;
|
||||
|
||||
float4 m = (float4)(1.f / 255.f) * convert_float4(gDims - 1);
|
||||
gCoordMul = convert_int4(m * (float4)0x10000);
|
||||
|
||||
rsDebug("dims", gDims);
|
||||
rsDebug("gCoordMul", gCoordMul);
|
||||
}
|
||||
|
||||
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
||||
//rsDebug("root", in);
|
||||
|
||||
int4 baseCoord = convert_int4(*in) * gCoordMul;
|
||||
int4 coord1 = baseCoord >> (int4)16;
|
||||
int4 coord2 = min(coord1 + 1, gDims - 1);
|
||||
|
||||
int4 weight2 = baseCoord & 0xffff;
|
||||
int4 weight1 = (int4)0x10000 - weight2;
|
||||
|
||||
uint4 v000 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord1.y, coord1.z));
|
||||
uint4 v100 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord1.y, coord1.z));
|
||||
uint4 v010 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord2.y, coord1.z));
|
||||
uint4 v110 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord2.y, coord1.z));
|
||||
uint4 v001 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord1.y, coord2.z));
|
||||
uint4 v101 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord1.y, coord2.z));
|
||||
uint4 v011 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord2.y, coord2.z));
|
||||
uint4 v111 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord2.y, coord2.z));
|
||||
|
||||
uint4 yz00 = ((v000 * weight1.x) + (v100 * weight2.x)) >> (int4)8;
|
||||
uint4 yz10 = ((v010 * weight1.x) + (v110 * weight2.x)) >> (int4)8;
|
||||
uint4 yz01 = ((v001 * weight1.x) + (v101 * weight2.x)) >> (int4)8;
|
||||
uint4 yz11 = ((v011 * weight1.x) + (v111 * weight2.x)) >> (int4)8;
|
||||
|
||||
uint4 z0 = ((yz00 * weight1.y) + (yz10 * weight2.y)) >> (int4)16;
|
||||
uint4 z1 = ((yz01 * weight1.y) + (yz11 * weight2.y)) >> (int4)16;
|
||||
|
||||
uint4 v = ((z0 * weight1.z) + (z1 * weight2.z)) >> (int4)16;
|
||||
uint4 v2 = (v + 0x7f) >> (int4)8;
|
||||
|
||||
*out = convert_uchar4(v2);
|
||||
out->a = 0xff;
|
||||
|
||||
#if 0
|
||||
if (in->r != out->r) {
|
||||
rsDebug("dr", in->r - out->r);
|
||||
//rsDebug("in", convert_int4(*in));
|
||||
//rsDebug("coord1", coord1);
|
||||
//rsDebug("coord2", coord2);
|
||||
//rsDebug("weight1", weight1);
|
||||
//rsDebug("weight2", weight2);
|
||||
//rsDebug("yz00", yz00);
|
||||
//rsDebug("z0", z0);
|
||||
//rsDebug("v", v);
|
||||
//rsDebug("v2", v2);
|
||||
//rsDebug("out", convert_int4(*out));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
static rs_matrix4x4 Mat;
|
||||
|
||||
void init() {
|
||||
rsMatrixLoadIdentity(&Mat);
|
||||
}
|
||||
|
||||
void setMatrix(rs_matrix4x4 m) {
|
||||
Mat = m;
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uchar4 in) {
|
||||
float4 f = convert_float4(in);
|
||||
f = rsMatrixMultiply(&Mat, f);
|
||||
f = clamp(f, 0.f, 255.f);
|
||||
return convert_uchar4(f);
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
static float brightM = 0.f;
|
||||
static float brightC = 0.f;
|
||||
|
||||
void setBright(float v) {
|
||||
brightM = pow(2.f, v / 100.f);
|
||||
brightC = 127.f - brightM * 127.f;
|
||||
}
|
||||
|
||||
void contrast(const uchar4 *in, uchar4 *out)
|
||||
{
|
||||
#if 0
|
||||
out->r = rsClamp((int)(brightM * in->r + brightC), 0, 255);
|
||||
out->g = rsClamp((int)(brightM * in->g + brightC), 0, 255);
|
||||
out->b = rsClamp((int)(brightM * in->b + brightC), 0, 255);
|
||||
#else
|
||||
float3 v = convert_float3(in->rgb) * brightM + brightC;
|
||||
out->rgb = convert_uchar3(clamp(v, 0.f, 255.f));
|
||||
#endif
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
int32_t gWidth;
|
||||
int32_t gHeight;
|
||||
rs_allocation gIn;
|
||||
|
||||
float gCoeffs[9];
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||
uint32_t x1 = min((int32_t)x+1, gWidth-1);
|
||||
uint32_t x2 = max((int32_t)x-1, 0);
|
||||
uint32_t y1 = min((int32_t)y+1, gHeight-1);
|
||||
uint32_t y2 = max((int32_t)y-1, 0);
|
||||
|
||||
float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1));
|
||||
float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, x, y1));
|
||||
float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y1));
|
||||
float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y));
|
||||
float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, x, y));
|
||||
float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y));
|
||||
float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y2));
|
||||
float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, x, y2));
|
||||
float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y2));
|
||||
p00 *= gCoeffs[0];
|
||||
p01 *= gCoeffs[1];
|
||||
p02 *= gCoeffs[2];
|
||||
p10 *= gCoeffs[3];
|
||||
p11 *= gCoeffs[4];
|
||||
p12 *= gCoeffs[5];
|
||||
p20 *= gCoeffs[6];
|
||||
p21 *= gCoeffs[7];
|
||||
p22 *= gCoeffs[8];
|
||||
|
||||
p00 += p01;
|
||||
p02 += p10;
|
||||
p11 += p12;
|
||||
p20 += p21;
|
||||
|
||||
p22 += p00;
|
||||
p02 += p11;
|
||||
|
||||
p20 += p22;
|
||||
p20 += p02;
|
||||
|
||||
p20 = clamp(p20, 0.f, 255.f);
|
||||
return convert_uchar4(p20);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
int32_t gWidth;
|
||||
int32_t gHeight;
|
||||
rs_allocation gIn;
|
||||
|
||||
float gCoeffs[25];
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||
uint32_t x0 = max((int32_t)x-2, 0);
|
||||
uint32_t x1 = max((int32_t)x-1, 0);
|
||||
uint32_t x2 = x;
|
||||
uint32_t x3 = min((int32_t)x+1, gWidth-1);
|
||||
uint32_t x4 = min((int32_t)x+2, gWidth-1);
|
||||
|
||||
uint32_t y0 = max((int32_t)y-2, 0);
|
||||
uint32_t y1 = max((int32_t)y-1, 0);
|
||||
uint32_t y2 = y;
|
||||
uint32_t y3 = min((int32_t)y+1, gHeight-1);
|
||||
uint32_t y4 = min((int32_t)y+2, gHeight-1);
|
||||
|
||||
float4 p0 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4];
|
||||
|
||||
float4 p1 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9];
|
||||
|
||||
float4 p2 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14];
|
||||
|
||||
float4 p3 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19];
|
||||
|
||||
float4 p4 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23]
|
||||
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24];
|
||||
|
||||
p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f);
|
||||
return convert_uchar4(p0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uchar4 v_in) {
|
||||
return v_in;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
static float bright = 0.f;
|
||||
|
||||
void setBright(float v) {
|
||||
bright = 255.f / (255.f - v);
|
||||
}
|
||||
|
||||
void exposure(const uchar4 *in, uchar4 *out)
|
||||
{
|
||||
out->r = rsClamp((int)(bright * in->r), 0, 255);
|
||||
out->g = rsClamp((int)(bright * in->g), 0, 255);
|
||||
out->b = rsClamp((int)(bright * in->b), 0, 255);
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
rs_allocation in_alloc;
|
||||
rs_sampler sampler;
|
||||
|
||||
static float2 center, neg_center, inv_dimensions, axis_scale;
|
||||
static float alpha, radius2, factor;
|
||||
|
||||
void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, float k) {
|
||||
center.x = center_x;
|
||||
center.y = center_y;
|
||||
neg_center = -center;
|
||||
inv_dimensions.x = 1.f / (float)dim_x;
|
||||
inv_dimensions.y = 1.f / (float)dim_y;
|
||||
alpha = k * 2.0f + 0.75f;
|
||||
|
||||
axis_scale = (float2)1.f;
|
||||
if (dim_x > dim_y)
|
||||
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||
else
|
||||
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||
|
||||
const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
|
||||
const float bound = sqrt(bound2);
|
||||
const float radius = 1.15f * bound;
|
||||
radius2 = radius*radius;
|
||||
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
|
||||
factor = bound / max_radian;
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||
// Convert x and y to floating point coordinates with center as origin
|
||||
const float2 inCoord = {(float)x, (float)y};
|
||||
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||
const float2 scaledCoord = axis_scale * coord;
|
||||
const float dist2 = scaledCoord.x*scaledCoord.x + scaledCoord.y*scaledCoord.y;
|
||||
const float inv_dist = rsqrt(dist2);
|
||||
const float radian = M_PI_2 - atan((alpha * sqrt(radius2 - dist2)) * inv_dist);
|
||||
const float scalar = radian * factor * inv_dist;
|
||||
const float2 new_coord = mad(coord, scalar, center);
|
||||
const float4 fout = rsSample(in_alloc, sampler, new_coord);
|
||||
return rsPackColorTo8888(fout);
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
rs_allocation in_alloc;
|
||||
rs_sampler sampler;
|
||||
|
||||
static float2 center, neg_center, inv_dimensions, axis_scale;
|
||||
static float alpha, radius2, factor;
|
||||
|
||||
void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, float k) {
|
||||
center.x = center_x;
|
||||
center.y = center_y;
|
||||
neg_center = -center;
|
||||
inv_dimensions.x = 1.f / (float)dim_x;
|
||||
inv_dimensions.y = 1.f / (float)dim_y;
|
||||
alpha = k * 2.0f + 0.75f;
|
||||
|
||||
axis_scale = (float2)1.f;
|
||||
if (dim_x > dim_y)
|
||||
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||
else
|
||||
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||
|
||||
const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
|
||||
const float bound = sqrt(bound2);
|
||||
const float radius = 1.15f * bound;
|
||||
radius2 = radius*radius;
|
||||
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
|
||||
factor = bound / max_radian;
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||
// Convert x and y to floating point coordinates with center as origin
|
||||
const float2 inCoord = {(float)x, (float)y};
|
||||
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||
const float2 scaledCoord = axis_scale * coord;
|
||||
const float dist2 = scaledCoord.x*scaledCoord.x + scaledCoord.y*scaledCoord.y;
|
||||
const float inv_dist = half_rsqrt(dist2);
|
||||
const float radian = M_PI_2 - atan((alpha * half_sqrt(radius2 - dist2)) * inv_dist);
|
||||
const float scalar = radian * factor * inv_dist;
|
||||
const float2 new_coord = mad(coord, scalar, center);
|
||||
const float4 fout = rsSample(in_alloc, sampler, new_coord);
|
||||
return rsPackColorTo8888(fout);
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "fisheye_approx.rsh"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "fisheye_approx.rsh"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "fisheye.rsh"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "fisheye.rsh"
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
uchar __attribute__((kernel)) genRand() {
|
||||
return (uchar)rsRand(0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convolution matrix of distance 2 with fixed point of 'kShiftBits' bits
|
||||
* shifted. Thus the sum of this matrix should be 'kShiftValue'. Entries of
|
||||
* small values are not calculated to gain efficiency.
|
||||
* The order ot pixels represented in this matrix is:
|
||||
* 1 2 3
|
||||
* 4 0 5
|
||||
* 6 7 8
|
||||
* and the matrix should be: {230, 56, 114, 56, 114, 114, 56, 114, 56}.
|
||||
* However, since most of the valus are identical, we only use the first three
|
||||
* entries and the entries corresponding to the pixels is:
|
||||
* 1 2 1
|
||||
* 2 0 2
|
||||
* 1 2 1
|
||||
*/
|
||||
|
||||
int32_t gWMask;
|
||||
int32_t gHMask;
|
||||
|
||||
rs_allocation gBlendSource;
|
||||
uchar __attribute__((kernel)) blend9(uint32_t x, uint32_t y) {
|
||||
uint32_t x1 = (x-1) & gWMask;
|
||||
uint32_t x2 = (x+1) & gWMask;
|
||||
uint32_t y1 = (y-1) & gHMask;
|
||||
uint32_t y2 = (y+1) & gHMask;
|
||||
|
||||
uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1);
|
||||
uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1);
|
||||
uint p02 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y1);
|
||||
uint p10 = 114 * rsGetElementAt_uchar(gBlendSource, x1, y);
|
||||
uint p11 = 230 * rsGetElementAt_uchar(gBlendSource, x, y);
|
||||
uint p12 = 114 * rsGetElementAt_uchar(gBlendSource, x2, y);
|
||||
uint p20 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y2);
|
||||
uint p21 = 114 * rsGetElementAt_uchar(gBlendSource, x, y2);
|
||||
uint p22 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y2);
|
||||
|
||||
p00 += p01;
|
||||
p02 += p10;
|
||||
p11 += p12;
|
||||
p20 += p21;
|
||||
|
||||
p22 += p00;
|
||||
p02 += p11;
|
||||
|
||||
p20 += p22;
|
||||
p20 += p02;
|
||||
|
||||
p20 = min(p20 >> 10, (uint)255);
|
||||
return (uchar)p20;
|
||||
}
|
||||
|
||||
float gNoiseStrength;
|
||||
|
||||
rs_allocation gNoise;
|
||||
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||
float4 ip = convert_float4(in);
|
||||
float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask);
|
||||
|
||||
float energy_level = ip.r + ip.g + ip.b;
|
||||
float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f;
|
||||
pnoise = (pnoise - 128.f) * energy_mask;
|
||||
|
||||
ip += pnoise * gNoiseStrength;
|
||||
ip = clamp(ip, 0.f, 255.f);
|
||||
|
||||
uchar4 p = convert_uchar4(ip);
|
||||
p.a = 0xff;
|
||||
return p;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uchar4 v_in) {
|
||||
float4 f4 = rsUnpackColor8888(v_in);
|
||||
|
||||
float3 mono = dot(f4.rgb, gMonoMult);
|
||||
return rsPackColorTo8888(mono);
|
||||
}
|
||||
|
||||
uchar __attribute__((kernel)) toU8(uchar4 v_in) {
|
||||
float4 f4 = convert_float4(v_in);
|
||||
return (uchar)dot(f4.rgb, gMonoMult);
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) toU8_4(uchar v_in) {
|
||||
return (uchar4)v_in;
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.android.rs.image)
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
float inBlack;
|
||||
float outBlack;
|
||||
float inWMinInB;
|
||||
float outWMinOutB;
|
||||
float overInWMinInB;
|
||||
rs_matrix3x3 colorMat;
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||
uchar4 out;
|
||||
float3 pixel = convert_float4(in).rgb;
|
||||
pixel = rsMatrixMultiply(&colorMat, pixel);
|
||||
pixel = clamp(pixel, 0.f, 255.f);
|
||||
pixel = (pixel - inBlack) * overInWMinInB;
|
||||
pixel = pixel * outWMinOutB + outBlack;
|
||||
pixel = clamp(pixel, 0.f, 255.f);
|
||||
out.xyz = convert_uchar3(pixel);
|
||||
out.w = 0xff;
|
||||
return out;
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) root4(uchar4 in, uint32_t x, uint32_t y) {
|
||||
float4 pixel = convert_float4(in);
|
||||
pixel.rgb = rsMatrixMultiply(&colorMat, pixel.rgb);
|
||||
pixel = clamp(pixel, 0.f, 255.f);
|
||||
pixel = (pixel - inBlack) * overInWMinInB;
|
||||
pixel = pixel * outWMinOutB + outBlack;
|
||||
pixel = clamp(pixel, 0.f, 255.f);
|
||||
return convert_uchar4(pixel);
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "levels.rsh"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "levels.rsh"
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright (C) 2011 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.
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
uint32_t gMaxIteration = 500;
|
||||
uint32_t gDimX = 1024;
|
||||
uint32_t gDimY = 1024;
|
||||
|
||||
float lowerBoundX = -2.f;
|
||||
float lowerBoundY = -2.f;
|
||||
float scaleFactor = 4.f;
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||
float2 p;
|
||||
p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor;
|
||||
p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor;
|
||||
|
||||
float2 t = 0;
|
||||
float2 t2 = t * t;
|
||||
int iter = 0;
|
||||
while((t2.x + t2.y < 4.f) && (iter < gMaxIteration)) {
|
||||
float xtemp = t2.x - t2.y + p.x;
|
||||
t.y = 2 * t.x * t.y + p.y;
|
||||
t.x = xtemp;
|
||||
iter++;
|
||||
t2 = t * t;
|
||||
}
|
||||
|
||||
if(iter >= gMaxIteration) {
|
||||
// write a non-transparent black pixel
|
||||
return (uchar4){0, 0, 0, 0xff};
|
||||
} else {
|
||||
float mi3 = gMaxIteration / 3.f;
|
||||
if (iter <= (gMaxIteration / 3))
|
||||
return (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
|
||||
else if (iter <= (((gMaxIteration / 3) * 2)))
|
||||
return (uchar4){0xff - (0xff * ((iter - mi3) / mi3)),
|
||||
(0xff * ((iter - mi3) / mi3)), 0, 0xff};
|
||||
else
|
||||
return (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)),
|
||||
(0xff * ((iter - (mi3 * 2)) / mi3)), 0xff};
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
//#pragma rs_fp_relaxed
|
||||
|
||||
static double shadowFilterMap[] = {
|
||||
-0.00591, 0.0001,
|
||||
1.16488, 0.01668,
|
||||
-0.18027, -0.06791,
|
||||
-0.12625, 0.09001,
|
||||
0.15065, -0.03897
|
||||
};
|
||||
|
||||
static double poly[] = {
|
||||
0., 0.,
|
||||
0., 0.,
|
||||
0.
|
||||
};
|
||||
|
||||
static const int ABITS = 4;
|
||||
static const int HSCALE = 256;
|
||||
static const int k1=255 << ABITS;
|
||||
static const int k2=HSCALE << ABITS;
|
||||
|
||||
static double fastevalPoly(double *poly,int n, double x){
|
||||
|
||||
double f =x;
|
||||
double sum = poly[0]+poly[1]*f;
|
||||
int i;
|
||||
for (i = 2; i < n; i++) {
|
||||
f*=x;
|
||||
sum += poly[i]*f;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
static ushort3 rgb2hsv( uchar4 rgb)
|
||||
{
|
||||
int iMin,iMax,chroma;
|
||||
|
||||
int ri = rgb.r;
|
||||
int gi = rgb.g;
|
||||
int bi = rgb.b;
|
||||
short rv,rs,rh;
|
||||
|
||||
if (ri > gi) {
|
||||
iMax = max (ri, bi);
|
||||
iMin = min (gi, bi);
|
||||
} else {
|
||||
iMax = max (gi, bi);
|
||||
iMin = min (ri, bi);
|
||||
}
|
||||
|
||||
chroma = iMax - iMin;
|
||||
// set value
|
||||
rv = (short)( iMax << ABITS);
|
||||
|
||||
// set saturation
|
||||
if (rv == 0)
|
||||
rs = 0;
|
||||
else
|
||||
rs = (short)((k1*chroma)/iMax);
|
||||
|
||||
// set hue
|
||||
if (rs == 0)
|
||||
rh = 0;
|
||||
else {
|
||||
if ( ri == iMax ) {
|
||||
rh = (short)( (k2*(6*chroma+gi - bi))/(6*chroma));
|
||||
if (rh >= k2) rh -= k2;
|
||||
} else if (gi == iMax)
|
||||
rh = (short)( (k2*(2*chroma+bi - ri ))/(6*chroma));
|
||||
else // (bi == iMax )
|
||||
rh = (short)( (k2*(4*chroma+ri - gi ))/(6*chroma));
|
||||
}
|
||||
|
||||
ushort3 out;
|
||||
out.x = rv;
|
||||
out.y = rs;
|
||||
out.z = rh;
|
||||
return out;
|
||||
}
|
||||
|
||||
static uchar4 hsv2rgb(ushort3 hsv)
|
||||
{
|
||||
int ABITS = 4;
|
||||
int HSCALE = 256;
|
||||
int m;
|
||||
int H,X,ih,is,iv;
|
||||
int k1=255<<ABITS;
|
||||
int k2=HSCALE<<ABITS;
|
||||
int k3=1<<(ABITS-1);
|
||||
int rr=0;
|
||||
int rg=0;
|
||||
int rb=0;
|
||||
short cv = hsv.x;
|
||||
short cs = hsv.y;
|
||||
short ch = hsv.z;
|
||||
|
||||
// set chroma and min component value m
|
||||
//chroma = ( cv * cs )/k1;
|
||||
//m = cv - chroma;
|
||||
m = ((int)cv*(k1 - (int)cs ))/k1;
|
||||
|
||||
// chroma == 0 <-> cs == 0 --> m=cv
|
||||
if (cs == 0) {
|
||||
rb = ( rg = ( rr =( cv >> ABITS) ));
|
||||
} else {
|
||||
ih=(int)ch;
|
||||
is=(int)cs;
|
||||
iv=(int)cv;
|
||||
|
||||
H = (6*ih)/k2;
|
||||
X = ((iv*is)/k2)*(k2- abs(6*ih- 2*(H>>1)*k2 - k2)) ;
|
||||
|
||||
// removing additional bits --> unit8
|
||||
X=( (X+iv*(k1 - is ))/k1 + k3 ) >> ABITS;
|
||||
m=m >> ABITS;
|
||||
|
||||
// ( chroma + m ) --> cv ;
|
||||
cv=(short) (cv >> ABITS);
|
||||
switch (H) {
|
||||
case 0:
|
||||
rr = cv;
|
||||
rg = X;
|
||||
rb = m;
|
||||
break;
|
||||
case 1:
|
||||
rr = X;
|
||||
rg = cv;
|
||||
rb = m;
|
||||
break;
|
||||
case 2:
|
||||
rr = m;
|
||||
rg = cv;
|
||||
rb = X;
|
||||
break;
|
||||
case 3:
|
||||
rr = m;
|
||||
rg = X;
|
||||
rb = cv;
|
||||
break;
|
||||
case 4:
|
||||
rr = X;
|
||||
rg = m;
|
||||
rb = cv;
|
||||
break;
|
||||
case 5:
|
||||
rr = cv;
|
||||
rg = m ;
|
||||
rb = X;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uchar4 rgb;
|
||||
|
||||
rgb.r = rr;
|
||||
rgb.g = rg;
|
||||
rgb.b = rb;
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
void prepareShadows(float scale) {
|
||||
double s = (scale>=0)?scale:scale/5;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
poly[i] = fastevalPoly(shadowFilterMap+i*2,2 , s);
|
||||
}
|
||||
}
|
||||
|
||||
void shadowsKernel(const uchar4 *in, uchar4 *out) {
|
||||
ushort3 hsv = rgb2hsv(*in);
|
||||
double v = (fastevalPoly(poly,5,hsv.x/4080.)*4080);
|
||||
if (v>4080) v = 4080;
|
||||
hsv.x = (unsigned short) ((v>0)?v:0);
|
||||
*out = hsv2rgb(hsv);
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
|
||||
int height;
|
||||
int width;
|
||||
static int radius;
|
||||
|
||||
rs_allocation InPixel;
|
||||
rs_allocation ScratchPixel1;
|
||||
rs_allocation ScratchPixel2;
|
||||
|
||||
const int MAX_RADIUS = 25;
|
||||
|
||||
// Store our coefficients here
|
||||
static float gaussian[MAX_RADIUS * 2 + 1];
|
||||
|
||||
void setRadius(int rad) {
|
||||
radius = rad;
|
||||
// Compute gaussian weights for the blur
|
||||
// e is the euler's number
|
||||
float e = 2.718281828459045f;
|
||||
float pi = 3.1415926535897932f;
|
||||
// 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.
|
||||
// Based on some experimental radius values and sigma's
|
||||
// we approximately fit sigma = f(radius) as
|
||||
// sigma = radius * 0.4 + 0.6
|
||||
// The larger the radius gets, the more our gaussian blur
|
||||
// will resemble a box blur since with large sigma
|
||||
// the gaussian curve begins to lose its shape
|
||||
float sigma = 0.4f * (float)radius + 0.6f;
|
||||
|
||||
// Now compute the coefficints
|
||||
// We will store some redundant values to save some math during
|
||||
// the blur calculations
|
||||
// precompute some values
|
||||
float coeff1 = 1.0f / (sqrt( 2.0f * pi ) * sigma);
|
||||
float coeff2 = - 1.0f / (2.0f * sigma * sigma);
|
||||
|
||||
float normalizeFactor = 0.0f;
|
||||
float floatR = 0.0f;
|
||||
for (int r = -radius; r <= radius; r ++) {
|
||||
floatR = (float)r;
|
||||
gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2);
|
||||
normalizeFactor += gaussian[r + radius];
|
||||
}
|
||||
|
||||
//Now we need to normalize the weights because all our coefficients need to add up to one
|
||||
normalizeFactor = 1.0f / normalizeFactor;
|
||||
for (int r = -radius; r <= radius; r ++) {
|
||||
floatR = (float)r;
|
||||
gaussian[r + radius] *= normalizeFactor;
|
||||
}
|
||||
}
|
||||
|
||||
float4 __attribute__((kernel)) copyIn(uchar4 in) {
|
||||
return convert_float4(in);
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) vert(uint32_t x, uint32_t y) {
|
||||
float3 blurredPixel = 0;
|
||||
int gi = 0;
|
||||
uchar4 out;
|
||||
if ((y > radius) && (y < (height - radius))) {
|
||||
for (int r = -radius; r <= radius; r ++) {
|
||||
float4 i = rsGetElementAt_float4(ScratchPixel2, x, y + r);
|
||||
blurredPixel += i.xyz * gaussian[gi++];
|
||||
}
|
||||
} else {
|
||||
for (int r = -radius; r <= radius; r ++) {
|
||||
int validH = rsClamp((int)y + r, (int)0, (int)(height - 1));
|
||||
float4 i = rsGetElementAt_float4(ScratchPixel2, x, validH);
|
||||
blurredPixel += i.xyz * gaussian[gi++];
|
||||
}
|
||||
}
|
||||
|
||||
out.xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f));
|
||||
out.w = 0xff;
|
||||
return out;
|
||||
}
|
||||
|
||||
float4 __attribute__((kernel)) horz(uint32_t x, uint32_t y) {
|
||||
float4 blurredPixel = 0;
|
||||
int gi = 0;
|
||||
if ((x > radius) && (x < (width - radius))) {
|
||||
for (int r = -radius; r <= radius; r ++) {
|
||||
float4 i = rsGetElementAt_float4(ScratchPixel1, x + r, y);
|
||||
blurredPixel += i * gaussian[gi++];
|
||||
}
|
||||
} else {
|
||||
for (int r = -radius; r <= radius; r ++) {
|
||||
// Stepping left and right away from the pixel
|
||||
int validX = rsClamp((int)x + r, (int)0, (int)(width - 1));
|
||||
float4 i = rsGetElementAt_float4(ScratchPixel1, validX, y);
|
||||
blurredPixel += i * gaussian[gi++];
|
||||
}
|
||||
}
|
||||
|
||||
return blurredPixel;
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
float vibrance = 0.f;
|
||||
|
||||
static const float Rf = 0.2999f;
|
||||
static const float Gf = 0.587f;
|
||||
static const float Bf = 0.114f;
|
||||
|
||||
static float S = 0.f;
|
||||
static float MS = 0.f;
|
||||
static float Rt = 0.f;
|
||||
static float Gt = 0.f;
|
||||
static float Bt = 0.f;
|
||||
static float Vib = 0.f;
|
||||
|
||||
void vibranceKernel(const uchar4 *in, uchar4 *out) {
|
||||
|
||||
float R, G, B;
|
||||
|
||||
int r = in->r;
|
||||
int g = in->g;
|
||||
int b = in->b;
|
||||
float red = (r-max(g, b))/256.f;
|
||||
float sx = (float)(Vib/(1+native_exp(-red*3)));
|
||||
S = sx+1;
|
||||
MS = 1.0f - S;
|
||||
Rt = Rf * MS;
|
||||
Gt = Gf * MS;
|
||||
Bt = Bf * MS;
|
||||
int t = (r + g) / 2;
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
|
||||
float Rc = R * (Rt + S) + G * Gt + B * Bt;
|
||||
float Gc = R * Rt + G * (Gt + S) + B * Bt;
|
||||
float Bc = R * Rt + G * Gt + B * (Bt + S);
|
||||
|
||||
out->r = rsClamp(Rc, 0, 255);
|
||||
out->g = rsClamp(Gc, 0, 255);
|
||||
out->b = rsClamp(Bc, 0, 255);
|
||||
|
||||
}
|
||||
|
||||
void prepareVibrance() {
|
||||
|
||||
Vib = vibrance/100.f;
|
||||
S = Vib + 1;
|
||||
MS = 1.0f - S;
|
||||
Rt = Rf * MS;
|
||||
Gt = Gf * MS;
|
||||
Bt = Bf * MS;
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
static float2 neg_center, axis_scale, inv_dimensions;
|
||||
static float sloped_neg_range, sloped_inv_max_dist, shade, opp_shade;
|
||||
|
||||
void init_vignette(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
|
||||
float desired_scale, float desired_shade, float desired_slope) {
|
||||
|
||||
neg_center.x = -center_x;
|
||||
neg_center.y = -center_y;
|
||||
inv_dimensions.x = 1.f / (float)dim_x;
|
||||
inv_dimensions.y = 1.f / (float)dim_y;
|
||||
|
||||
axis_scale = (float2)1.f;
|
||||
if (dim_x > dim_y)
|
||||
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||
else
|
||||
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||
|
||||
const float max_dist = 0.5f * length(axis_scale);
|
||||
sloped_inv_max_dist = desired_slope * 1.f/max_dist;
|
||||
|
||||
// Range needs to be between 1.3 to 0.6. When scale is zero then range is
|
||||
// 1.3 which means no vignette at all because the luminousity difference is
|
||||
// less than 1/256. Expect input scale to be between 0.0 and 1.0.
|
||||
const float neg_range = 0.7f*sqrt(desired_scale) - 1.3f;
|
||||
sloped_neg_range = exp(neg_range * desired_slope);
|
||||
|
||||
shade = desired_shade;
|
||||
opp_shade = 1.f - desired_shade;
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||
// Convert x and y to floating point coordinates with center as origin
|
||||
const float4 fin = convert_float4(in);
|
||||
const float2 inCoord = {(float)x, (float)y};
|
||||
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||
const float sloped_dist_ratio = length(axis_scale * coord) * sloped_inv_max_dist;
|
||||
const float lumen = opp_shade + shade / ( 1.0f + sloped_neg_range * exp(sloped_dist_ratio) );
|
||||
float4 fout;
|
||||
fout.rgb = fin.rgb * lumen;
|
||||
fout.w = fin.w;
|
||||
return convert_uchar4(fout);
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
static float2 neg_center, axis_scale, inv_dimensions;
|
||||
static float sloped_neg_range, sloped_inv_max_dist, shade, opp_shade;
|
||||
|
||||
void init_vignette(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
|
||||
float desired_scale, float desired_shade, float desired_slope) {
|
||||
|
||||
neg_center.x = -center_x;
|
||||
neg_center.y = -center_y;
|
||||
inv_dimensions.x = 1.f / (float)dim_x;
|
||||
inv_dimensions.y = 1.f / (float)dim_y;
|
||||
|
||||
axis_scale = (float2)1.f;
|
||||
if (dim_x > dim_y)
|
||||
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||
else
|
||||
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||
|
||||
const float max_dist = 0.5f * length(axis_scale);
|
||||
sloped_inv_max_dist = desired_slope * 1.f/max_dist;
|
||||
|
||||
// Range needs to be between 1.3 to 0.6. When scale is zero then range is
|
||||
// 1.3 which means no vignette at all because the luminousity difference is
|
||||
// less than 1/256. Expect input scale to be between 0.0 and 1.0.
|
||||
const float neg_range = 0.7f*sqrt(desired_scale) - 1.3f;
|
||||
sloped_neg_range = exp(neg_range * desired_slope);
|
||||
|
||||
shade = desired_shade;
|
||||
opp_shade = 1.f - desired_shade;
|
||||
}
|
||||
|
||||
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||
// Convert x and y to floating point coordinates with center as origin
|
||||
const float4 fin = convert_float4(in);
|
||||
const float2 inCoord = {(float)x, (float)y};
|
||||
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||
const float sloped_dist_ratio = fast_length(axis_scale * coord) * sloped_inv_max_dist;
|
||||
const float lumen = opp_shade + shade * half_recip(1.f + sloped_neg_range * native_exp(sloped_dist_ratio));
|
||||
float4 fout;
|
||||
fout.rgb = fin.rgb * lumen;
|
||||
fout.w = fin.w;
|
||||
return convert_uchar4(fout);
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "vignette_approx.rsh"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "vignette_approx.rsh"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "vignette.rsh"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
|
||||
#include "vignette.rsh"
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ip.rsh"
|
||||
//#pragma rs_fp_relaxed
|
||||
|
||||
static int histR[256] = {0}, histG[256] = {0}, histB[256] = {0};
|
||||
|
||||
rs_allocation histogramSource;
|
||||
uint32_t histogramHeight;
|
||||
uint32_t histogramWidth;
|
||||
|
||||
static float scaleR;
|
||||
static float scaleG;
|
||||
static float scaleB;
|
||||
|
||||
static uchar4 estimateWhite() {
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
histR[i] = 0; histG[i] = 0; histB[i] = 0;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < histogramHeight; i++) {
|
||||
for (uint32_t j = 0; j < histogramWidth; j++) {
|
||||
uchar4 in = rsGetElementAt_uchar4(histogramSource, j, i);
|
||||
histR[in.r]++;
|
||||
histG[in.g]++;
|
||||
histB[in.b]++;
|
||||
}
|
||||
}
|
||||
|
||||
int min_r = -1, min_g = -1, min_b = -1;
|
||||
int max_r = 0, max_g = 0, max_b = 0;
|
||||
int sum_r = 0, sum_g = 0, sum_b = 0;
|
||||
|
||||
for (int i = 1; i < 255; i++) {
|
||||
int r = histR[i];
|
||||
int g = histG[i];
|
||||
int b = histB[i];
|
||||
sum_r += r;
|
||||
sum_g += g;
|
||||
sum_b += b;
|
||||
|
||||
if (r>0){
|
||||
if (min_r < 0) min_r = i;
|
||||
max_r = i;
|
||||
}
|
||||
if (g>0){
|
||||
if (min_g < 0) min_g = i;
|
||||
max_g = i;
|
||||
}
|
||||
if (b>0){
|
||||
if (min_b < 0) min_b = i;
|
||||
max_b = i;
|
||||
}
|
||||
}
|
||||
|
||||
int sum15r = 0, sum15g = 0, sum15b = 0;
|
||||
int count15r = 0, count15g = 0, count15b = 0;
|
||||
int tmp_r = 0, tmp_g = 0, tmp_b = 0;
|
||||
|
||||
for (int i = 254; i >0; i--) {
|
||||
int r = histR[i];
|
||||
int g = histG[i];
|
||||
int b = histB[i];
|
||||
tmp_r += r;
|
||||
tmp_g += g;
|
||||
tmp_b += b;
|
||||
|
||||
if ((tmp_r > sum_r/20) && (tmp_r < sum_r/5)) {
|
||||
sum15r += r*i;
|
||||
count15r += r;
|
||||
}
|
||||
if ((tmp_g > sum_g/20) && (tmp_g < sum_g/5)) {
|
||||
sum15g += g*i;
|
||||
count15g += g;
|
||||
}
|
||||
if ((tmp_b > sum_b/20) && (tmp_b < sum_b/5)) {
|
||||
sum15b += b*i;
|
||||
count15b += b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uchar4 out;
|
||||
|
||||
if ((count15r>0) && (count15g>0) && (count15b>0) ){
|
||||
out.r = sum15r/count15r;
|
||||
out.g = sum15g/count15g;
|
||||
out.b = sum15b/count15b;
|
||||
}else {
|
||||
out.r = out.g = out.b = 255;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
void prepareWhiteBalance() {
|
||||
uchar4 estimation = estimateWhite();
|
||||
int minimum = min(estimation.r, min(estimation.g, estimation.b));
|
||||
int maximum = max(estimation.r, max(estimation.g, estimation.b));
|
||||
float avg = (minimum + maximum) / 2.f;
|
||||
|
||||
scaleR = avg/estimation.r;
|
||||
scaleG = avg/estimation.g;
|
||||
scaleB = avg/estimation.b;
|
||||
|
||||
}
|
||||
|
||||
static unsigned char contrastClamp(int c)
|
||||
{
|
||||
int N = 255;
|
||||
c &= ~(c >> 31);
|
||||
c -= N;
|
||||
c &= (c >> 31);
|
||||
c += N;
|
||||
return (unsigned char) c;
|
||||
}
|
||||
|
||||
void whiteBalanceKernel(const uchar4 *in, uchar4 *out) {
|
||||
float Rc = in->r*scaleR;
|
||||
float Gc = in->g*scaleG;
|
||||
float Bc = in->b*scaleB;
|
||||
|
||||
out->r = contrastClamp(Rc);
|
||||
out->g = contrastClamp(Gc);
|
||||
out->b = contrastClamp(Bc);
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2009 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
|
||||
$(call all-renderscript-files-under, src)
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := android.support.v8.renderscript
|
||||
|
||||
LOCAL_PACKAGE_NAME := ImageProcessing2
|
||||
LOCAL_SDK_VERSION := 8
|
||||
LOCAL_RENDERSCRIPT_TARGET_API := 18
|
||||
LOCAL_RENDERSCRIPT_COMPATIBILITY := 18
|
||||
LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE := $(TOPDIR)external/clang/lib/Headers \
|
||||
$(TOPDIR)frameworks/rs/scriptc
|
||||
|
||||
LOCAL_RENDERSCRIPT_FLAGS := -rs-package-name=android.support.v8.renderscript
|
||||
LOCAL_REQUIRED_MODULES := librsjni
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
#include $(call all-makefiles-under, $(LOCAL_PATH))
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.rs.image2">
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
<application android:label="IP GB">
|
||||
<activity android:name="ImageProcessingActivity2">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
|
Before Width: | Height: | Size: 597 KiB |
|
Before Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 1.1 MiB |
@@ -1,139 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/toplevel">
|
||||
<SurfaceView
|
||||
android:id="@+id/surface"
|
||||
android:layout_width="1dip"
|
||||
android:layout_height="1dip" />
|
||||
<ScrollView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ImageView
|
||||
android:id="@+id/display"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/benchmark"
|
||||
android:onClick="benchmark"/>
|
||||
<TextView
|
||||
android:id="@+id/benchmarkText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:text="@string/saturation"/>
|
||||
</LinearLayout>
|
||||
<Spinner
|
||||
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"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/saturation"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider1"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider2Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/gamma"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider2"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider3Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:textSize="8pt"
|
||||
android:text="@string/out_white"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider3"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider4Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/in_white"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider4"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/slider5Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/in_white"/>
|
||||
<SeekBar
|
||||
android:id="@+id/slider5"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/benchmark_all"
|
||||
android:onClick="benchmark_all"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="10dp"
|
||||
android:textSize="16sp"
|
||||
/>
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright (C) 2008 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<!-- General -->
|
||||
<skip />
|
||||
<!--slider label -->
|
||||
<string name="blur_description">Blur Radius</string>
|
||||
<string name="in_white">In White</string>
|
||||
<string name="out_white">Out White</string>
|
||||
<string name="in_black">In Black</string>
|
||||
<string name="out_black">Out Black</string>
|
||||
<string name="gamma">Gamma</string>
|
||||
<string name="saturation">Saturation</string>
|
||||
<string name="benchmark">Benchmark</string>
|
||||
<string name="benchmark_all">Benchmark All</string>
|
||||
|
||||
</resources>
|
||||