M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@ -0,0 +1 @@
include $(call all-subdir-makefiles)

View File

@ -0,0 +1,27 @@
#
# 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 := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
LOCAL_PACKAGE_NAME := Film
include $(BUILD_PACKAGE)

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.film">
<application android:label="Film">
<activity android:name="Film"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 KiB

View File

@ -0,0 +1,110 @@
// Fountain test script
#pragma version(1)
#pragma stateVertex(orthoWindow)
#pragma stateRaster(flat)
#pragma stateFragment(PgmFragBackground)
#pragma stateStore(MyBlend)
int main(void* con, int ft, int launchID) {
int count, touch, x, y, rate, maxLife, lifeShift;
int life;
int ct, ct2;
int newPart;
int drawCount;
int dx, dy, idx;
int posx,posy;
int c;
int srcIdx;
int dstIdx;
count = loadI32(con, 0, 1);
touch = loadI32(con, 0, 2);
x = loadI32(con, 0, 3);
y = loadI32(con, 0, 4);
rate = 4;
maxLife = (count / rate) - 1;
lifeShift = 0;
{
life = maxLife;
while (life > 255) {
life = life >> 1;
lifeShift ++;
}
}
drawRect(con, 0, 256, 0, 512);
contextBindProgramFragment(con, NAMED_PgmFragParts);
if (touch) {
newPart = loadI32(con, 2, 0);
for (ct2=0; ct2<rate; ct2++) {
dx = scriptRand(con, 0x10000) - 0x8000;
dy = scriptRand(con, 0x10000) - 0x8000;
idx = newPart * 5 + 1;
storeI32(con, 2, idx, dx);
storeI32(con, 2, idx + 1, dy);
storeI32(con, 2, idx + 2, maxLife);
storeI32(con, 2, idx + 3, x << 16);
storeI32(con, 2, idx + 4, y << 16);
newPart++;
if (newPart >= count) {
newPart = 0;
}
}
storeI32(con, 2, 0, newPart);
}
drawCount = 0;
for (ct=0; ct < count; ct++) {
srcIdx = ct * 5 + 1;
dx = loadI32(con, 2, srcIdx);
dy = loadI32(con, 2, srcIdx + 1);
life = loadI32(con, 2, srcIdx + 2);
posx = loadI32(con, 2, srcIdx + 3);
posy = loadI32(con, 2, srcIdx + 4);
if (life) {
if (posy < (480 << 16)) {
dstIdx = drawCount * 9;
c = 0xffafcf | ((life >> lifeShift) << 24);
storeU32(con, 1, dstIdx, c);
storeI32(con, 1, dstIdx + 1, posx);
storeI32(con, 1, dstIdx + 2, posy);
storeU32(con, 1, dstIdx + 3, c);
storeI32(con, 1, dstIdx + 4, posx + 0x10000);
storeI32(con, 1, dstIdx + 5, posy + dy * 4);
storeU32(con, 1, dstIdx + 6, c);
storeI32(con, 1, dstIdx + 7, posx - 0x10000);
storeI32(con, 1, dstIdx + 8, posy + dy * 4);
drawCount ++;
} else {
if (dy > 0) {
dy = (-dy) >> 1;
}
}
posx = posx + dx;
posy = posy + dy;
dy = dy + 0x400;
life --;
//storeI32(con, 2, srcIdx, dx);
storeI32(con, 2, srcIdx + 1, dy);
storeI32(con, 2, srcIdx + 2, life);
storeI32(con, 2, srcIdx + 3, posx);
storeI32(con, 2, srcIdx + 4, posy);
}
}
drawTriangleArray(con, NAMED_PartBuffer, drawCount);
return 1;
}

View File

@ -0,0 +1,94 @@
// Fountain test script
#pragma version(1)
#pragma stateVertex(PVBackground)
#pragma stateFragment(PFBackground)
#pragma stateStore(PSBackground)
#define STATE_TRIANGLE_OFFSET_COUNT 0
#define STATE_LAST_FOCUS 1
// The script enviroment has 3 env allocations.
// bank0: (r) The enviroment structure
// bank1: (r) The position information
// bank2: (rw) The temporary texture state
int lastFocus;
int main(int index)
{
float mat1[16];
float trans = Pos->translate;
float rot = Pos->rotate;
matrixLoadScale(mat1, 2.f, 2.f, 2.f);
matrixTranslate(mat1, 0.f, 0.f, trans);
matrixRotate(mat1, 90.f, 0.f, 0.f, 1.f);
matrixRotate(mat1, rot, 1.f, 0.f, 0.f);
vpLoadModelMatrix(mat1);
// Draw the lighting effect in the strip and fill the Z buffer.
drawSimpleMesh(NAMED_mesh);
// Start of images.
bindProgramStore(NAMED_PSImages);
bindProgramFragment(NAMED_PFImages);
bindProgramVertex(NAMED_PVImages);
float focusPos = Pos->focus;
int focusID = 0;
int lastFocusID = loadI32(2, STATE_LAST_FOCUS);
int imgCount = 13;
if (trans > (-.3f)) {
focusID = -1.0f - focusPos;
if (focusID >= imgCount) {
focusID = -1;
}
} else {
focusID = -1;
}
/*
if (focusID != lastFocusID) {
if (lastFocusID >= 0) {
uploadToTexture(con, env->tex[lastFocusID], 1);
}
if (focusID >= 0) {
uploadToTexture(con, env->tex[focusID], 0);
}
}
*/
lastFocus = focusID;
int triangleOffsetsCount = Pos->triangleOffsetCount;
int imgId = 0;
for (imgId=1; imgId <= imgCount; imgId++) {
float pos = focusPos + imgId + 0.4f;
int offset = (int)floorf(pos * 2.f);
pos = pos - 0.75f;
offset = offset + triangleOffsetsCount / 2;
if (!((offset < 0) || (offset >= triangleOffsetsCount))) {
int start = offset -2;
int end = offset + 2;
if (start < 0) {
start = 0;
}
if (end >= triangleOffsetsCount) {
end = triangleOffsetsCount-1;
}
bindTexture(NAMED_PFImages, 0, loadI32(0, imgId - 1));
matrixLoadTranslate(mat1, -pos - loadF(5, triangleOffsetsCount / 2), 0, 0);
vpLoadTextureMatrix(mat1);
drawSimpleMeshRange(NAMED_mesh, loadI32(4, start), (loadI32(4, end) - loadI32(4, start)));
}
}
return 0;
}

View File

@ -0,0 +1,90 @@
/*
* 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.android.film;
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.Config;
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 java.lang.Runtime;
public class Film extends Activity {
//EventListener mListener = new EventListener();
private static final String LOG_TAG = "libRS_jni";
private static final boolean DEBUG = false;
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
private FilmView mView;
// get the current looper (from your Activity UI thread for instance
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create our Preview view and set it as the content of our
// Activity
mView = new FilmView(this);
setContentView(mView);
}
@Override
protected void onResume() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
}
@Override
protected void onPause() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
Runtime.getRuntime().exit(0);
}
static void log(String message) {
if (LOG_ENABLED) {
Log.v(LOG_TAG, message);
}
}
}

View File

@ -0,0 +1,258 @@
/*
* 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.android.film;
import java.io.Writer;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.util.Log;
import android.renderscript.*;
public class FilmRS {
class StripPosition {
public float translate;
public float rotate;
public float focus;
public int triangleOffsetCount;
}
StripPosition mPos = new StripPosition();
private final int STATE_LAST_FOCUS = 1;
public FilmRS() {
}
public void init(RenderScriptGL rs, Resources res, int width, int height) {
mRS = rs;
mRes = res;
initRS();
}
public void setFilmStripPosition(int x, int y)
{
if (x < 50) {
x = 50;
}
if (x > 270) {
x = 270;
}
float anim = ((float)x-50) / 270.f;
mPos.translate = 2f * anim + 0.5f; // translation
mPos.rotate = (anim * 40); // rotation
mPos.focus = ((float)y) / 16.f - 10.f; // focusPos
mPos.triangleOffsetCount = mFSM.mTriangleOffsetsCount;
mAllocPos.data(mPos);
}
private Resources mRes;
private RenderScriptGL mRS;
private Script mScriptStrip;
private Script mScriptImage;
private Sampler mSampler;
private ProgramStore mPSBackground;
private ProgramStore mPSImages;
private ProgramFragment mPFBackground;
private ProgramFragment mPFImages;
private ProgramVertex mPVBackground;
private ProgramVertex mPVImages;
private ProgramVertex.MatrixAllocation mPVA;
private Type mStripPositionType;
private Allocation mImages[];
private Allocation mAllocIDs;
private Allocation mAllocPos;
private Allocation mAllocState;
private Allocation mAllocPV;
private Allocation mAllocOffsetsTex;
private Allocation mAllocOffsets;
private SimpleMesh mMesh;
private Light mLight;
private FilmStripMesh mFSM;
private int[] mBufferIDs;
private float[] mBufferPos = new float[3];
private int[] mBufferState;
private void initPFS() {
ProgramStore.Builder b = new ProgramStore.Builder(mRS, null, null);
b.setDepthFunc(ProgramStore.DepthFunc.LESS);
b.setDitherEnable(true);
b.setDepthMask(true);
mPSBackground = b.create();
mPSBackground.setName("PSBackground");
b.setDepthFunc(ProgramStore.DepthFunc.EQUAL);
b.setDitherEnable(false);
b.setDepthMask(false);
b.setBlendFunc(ProgramStore.BlendSrcFunc.ONE,
ProgramStore.BlendDstFunc.ONE);
mPSImages = b.create();
mPSImages.setName("PSImages");
}
private void initPF() {
Sampler.Builder bs = new Sampler.Builder(mRS);
bs.setMin(Sampler.Value.LINEAR);//_MIP_LINEAR);
bs.setMag(Sampler.Value.LINEAR);
bs.setWrapS(Sampler.Value.CLAMP);
bs.setWrapT(Sampler.Value.WRAP);
mSampler = bs.create();
ProgramFragment.Builder b = new ProgramFragment.Builder(mRS);
mPFBackground = b.create();
mPFBackground.setName("PFBackground");
b = new ProgramFragment.Builder(mRS);
b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
ProgramFragment.Builder.Format.RGBA, 0);
mPFImages = b.create();
mPFImages.bindSampler(mSampler, 0);
mPFImages.setName("PFImages");
}
private void initPV() {
mLight = (new Light.Builder(mRS)).create();
mLight.setPosition(0, -0.5f, -1.0f);
ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
//pvb.addLight(mLight);
mPVBackground = pvb.create();
mPVBackground.setName("PVBackground");
pvb = new ProgramVertex.Builder(mRS, null, null);
pvb.setTextureMatrixEnable(true);
mPVImages = pvb.create();
mPVImages.setName("PVImages");
}
private void loadImages() {
mBufferIDs = new int[13];
mImages = new Allocation[13];
mAllocIDs = Allocation.createSized(mRS,
Element.createUser(mRS, Element.DataType.FLOAT_32),
mBufferIDs.length);
Element ie = Element.createPixel(mRS, Element.DataType.UNSIGNED_5_6_5, Element.DataKind.PIXEL_RGB);
mImages[0] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p01, ie, true);
mImages[1] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p02, ie, true);
mImages[2] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p03, ie, true);
mImages[3] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p04, ie, true);
mImages[4] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p05, ie, true);
mImages[5] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p06, ie, true);
mImages[6] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p07, ie, true);
mImages[7] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p08, ie, true);
mImages[8] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p09, ie, true);
mImages[9] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p10, ie, true);
mImages[10] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p11, ie, true);
mImages[11] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p12, ie, true);
mImages[12] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p13, ie, true);
int black[] = new int[1024];
for(int ct=0; ct < mImages.length; ct++) {
Allocation.Adapter2D a = mImages[ct].createAdapter2D();
int size = 512;
int mip = 0;
while(size >= 2) {
a.subData(0, 0, 2, size, black);
a.subData(size-2, 0, 2, size, black);
a.subData(0, 0, size, 2, black);
a.subData(0, size-2, size, 2, black);
size >>= 1;
mip++;
a.setConstraint(Dimension.LOD, mip);
}
mImages[ct].uploadToTexture(1);
mBufferIDs[ct] = mImages[ct].getID();
}
mAllocIDs.data(mBufferIDs);
}
private void initState()
{
mBufferState = new int[10];
mAllocState = Allocation.createSized(mRS,
Element.createUser(mRS, Element.DataType.FLOAT_32),
mBufferState.length);
mBufferState[STATE_LAST_FOCUS] = -1;
mAllocState.data(mBufferState);
}
private void initRS() {
mFSM = new FilmStripMesh();
mMesh = mFSM.init(mRS);
mMesh.setName("mesh");
initPFS();
initPF();
initPV();
Log.e("rs", "Done loading named");
mStripPositionType = Type.createFromClass(mRS, StripPosition.class, 1);
ScriptC.Builder sb = new ScriptC.Builder(mRS);
sb.setScript(mRes, R.raw.filmstrip);
sb.setRoot(true);
sb.setType(mStripPositionType, "Pos", 1);
mScriptStrip = sb.create();
mScriptStrip.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
mAllocPos = Allocation.createTyped(mRS, mStripPositionType);
loadImages();
initState();
mPVA = new ProgramVertex.MatrixAllocation(mRS);
mPVBackground.bindAllocation(mPVA);
mPVImages.bindAllocation(mPVA);
mPVA.setupProjectionNormalized(320, 480);
mScriptStrip.bindAllocation(mAllocIDs, 0);
mScriptStrip.bindAllocation(mAllocPos, 1);
mScriptStrip.bindAllocation(mAllocState, 2);
mScriptStrip.bindAllocation(mPVA.mAlloc, 3);
mAllocOffsets = Allocation.createSized(mRS,
Element.createUser(mRS, Element.DataType.SIGNED_32), mFSM.mTriangleOffsets.length);
mAllocOffsets.data(mFSM.mTriangleOffsets);
mScriptStrip.bindAllocation(mAllocOffsets, 4);
mAllocOffsetsTex = Allocation.createSized(mRS,
Element.createUser(mRS, Element.DataType.FLOAT_32), mFSM.mTriangleOffsetsTex.length);
mAllocOffsetsTex.data(mFSM.mTriangleOffsetsTex);
mScriptStrip.bindAllocation(mAllocOffsetsTex, 5);
setFilmStripPosition(0, 0);
mRS.contextBindRootScript(mScriptStrip);
}
}

View File

@ -0,0 +1,259 @@
/*
* 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.
*/
package com.android.film;
import java.io.Writer;
import java.lang.Math;
import android.util.Log;
import android.renderscript.RenderScript;
import android.renderscript.SimpleMesh;
class FilmStripMesh {
class Vertex {
float nx;
float ny;
float nz;
float s;
float t;
float x;
float y;
float z;
Vertex() {
nx = 0;
ny = 0;
nz = 0;
s = 0;
t = 0;
x = 0;
y = 0;
z = 0;
}
void xyz(float _x, float _y, float _z) {
x = _x;
y = _y;
z = _z;
}
void nxyz(float _x, float _y, float _z) {
nx = _x;
ny = _y;
nz = _z;
}
void st(float _s, float _t) {
s = _s;
t = _t;
}
void computeNorm(Vertex v1, Vertex v2) {
float dx = v1.x - v2.x;
float dy = v1.y - v2.y;
float dz = v1.z - v2.z;
float len = (float)java.lang.Math.sqrt(dx*dx + dy*dy + dz*dz);
dx /= len;
dy /= len;
dz /= len;
nx = dx * dz;
ny = dy * dz;
nz = (float)java.lang.Math.sqrt(dx*dx + dy*dy);
len = (float)java.lang.Math.sqrt(nx*nx + ny*ny + nz*nz);
nx /= len;
ny /= len;
nz /= len;
}
}
int[] mTriangleOffsets;
float[] mTriangleOffsetsTex;
int mTriangleOffsetsCount;
SimpleMesh init(RenderScript rs)
{
float vtx[] = new float[] {
60.431003f, 124.482050f,
60.862074f, 120.872604f,
61.705303f, 117.336662f,
62.949505f, 113.921127f,
64.578177f, 110.671304f,
66.569716f, 107.630302f,
68.897703f, 104.838457f,
71.531259f, 102.332803f,
74.435452f, 100.146577f,
77.571757f, 98.308777f,
80.898574f, 96.843781f,
84.371773f, 95.771023f,
87.945283f, 95.104731f,
98.958994f, 95.267098f,
109.489523f, 98.497596f,
118.699582f, 104.539366f,
125.856872f, 112.912022f,
130.392311f, 122.949849f,
131.945283f, 133.854731f,
130.392311f, 144.759613f,
125.856872f, 154.797439f,
118.699582f, 163.170096f,
109.489523f, 169.211866f,
98.958994f, 172.442364f,
87.945283f, 172.604731f,
72.507313f, 172.672927f,
57.678920f, 168.377071f,
44.668135f, 160.067134f,
34.534908f, 148.420104f,
28.104767f, 134.384831f,
25.901557f, 119.104731f,
28.104767f, 103.824631f,
34.534908f, 89.789358f,
44.668135f, 78.142327f,
57.678920f, 69.832390f,
72.507313f, 65.536534f,
87.945283f, 65.604731f,
106.918117f, 65.688542f,
125.141795f, 60.409056f,
141.131686f, 50.196376f,
153.585137f, 35.882502f,
161.487600f, 18.633545f,
164.195283f, -0.145269f,
161.487600f, -18.924084f,
153.585137f, -36.173040f,
141.131686f, -50.486914f,
125.141795f, -60.699594f,
106.918117f, -65.979081f,
87.945283f, -65.895269f,
80f, -65.895269f,
60f, -65.895269f,
40f, -65.895269f,
20f, -65.895269f,
0f, -65.895269f,
-20f, -65.895269f,
-40f, -65.895269f,
-60f, -65.895269f,
-80f, -65.895269f,
-87.945283f, -65.895269f,
-106.918117f, -65.979081f,
-125.141795f, -60.699594f,
-141.131686f, -50.486914f,
-153.585137f, -36.173040f,
-161.487600f, -18.924084f,
-164.195283f, -0.145269f,
-161.487600f, 18.633545f,
-153.585137f, 35.882502f,
-141.131686f, 50.196376f,
-125.141795f, 60.409056f,
-106.918117f, 65.688542f,
-87.945283f, 65.604731f,
-72.507313f, 65.536534f,
-57.678920f, 69.832390f,
-44.668135f, 78.142327f,
-34.534908f, 89.789358f,
-28.104767f, 103.824631f,
-25.901557f, 119.104731f,
-28.104767f, 134.384831f,
-34.534908f, 148.420104f,
-44.668135f, 160.067134f,
-57.678920f, 168.377071f,
-72.507313f, 172.672927f,
-87.945283f, 172.604731f,
-98.958994f, 172.442364f,
-109.489523f, 169.211866f,
-118.699582f, 163.170096f,
-125.856872f, 154.797439f,
-130.392311f, 144.759613f,
-131.945283f, 133.854731f,
-130.392311f, 122.949849f,
-125.856872f, 112.912022f,
-118.699582f, 104.539366f,
-109.489523f, 98.497596f,
-98.958994f, 95.267098f,
-87.945283f, 95.104731f,
-84.371773f, 95.771023f,
-80.898574f, 96.843781f,
-77.571757f, 98.308777f,
-74.435452f, 100.146577f,
-71.531259f, 102.332803f,
-68.897703f, 104.838457f,
-66.569716f, 107.630302f,
-64.578177f, 110.671304f,
-62.949505f, 113.921127f,
-61.705303f, 117.336662f,
-60.862074f, 120.872604f,
-60.431003f, 124.482050f
};
mTriangleOffsets = new int[64];
mTriangleOffsetsTex = new float[64];
mTriangleOffsets[0] = 0;
mTriangleOffsetsCount = 1;
Vertex t = new Vertex();
t.nxyz(1, 0, 0);
int count = vtx.length / 2;
SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(
rs, 3,
SimpleMesh.TriangleMeshBuilder.NORMAL | SimpleMesh.TriangleMeshBuilder.TEXTURE_0);
float runningS = 0;
for (int ct=0; ct < (count-1); ct++) {
t.x = -vtx[ct*2] / 100.f;
t.z = vtx[ct*2+1] / 100.f;
t.s = runningS;
t.nx = (vtx[ct*2+3] - vtx[ct*2 +1]);
t.ny = (vtx[ct*2+2] - vtx[ct*2 ]);
float len = (float)java.lang.Math.sqrt(t.nx * t.nx + t.ny * t.ny);
runningS += len / 100;
t.nx /= len;
t.ny /= len;
t.y = -0.5f;
t.t = 0;
tm.setNormal(t.nx, t.ny, t.nz);
tm.setTexture(t.s, t.t);
tm.addVertex(t.x, t.y, t.z);
//android.util.Log.e("rs", "vtx x="+t.x+" y="+t.y+" z="+t.z+" s="+t.s+" t="+t.t);
t.y = .5f;
t.t = 1;
tm.setTexture(t.s, t.t);
tm.addVertex(t.x, t.y, t.z);
//android.util.Log.e("rs", "vtx x="+t.x+" y="+t.y+" z="+t.z+" s="+t.s+" t="+t.t);
if((runningS*2) > mTriangleOffsetsCount) {
mTriangleOffsets[mTriangleOffsetsCount] = ct*2 * 3;
mTriangleOffsetsTex[mTriangleOffsetsCount] = t.s;
mTriangleOffsetsCount ++;
}
}
count = (count * 2 - 2);
for (int ct=0; ct < (count-2); ct+= 2) {
tm.addTriangle(ct, ct+1, ct+2);
tm.addTriangle(ct+1, ct+3, ct+2);
}
return tm.create();
}
}

View File

@ -0,0 +1,93 @@
/*
* 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.android.film;
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 FilmView extends RSSurfaceView {
public FilmView(Context context) {
super(context);
//setFocusable(true);
}
private RenderScriptGL mRS;
private FilmRS mRender;
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
if (mRS == null) {
mRS = createRenderScript(true);
mRS.contextSetSurface(w, h, holder.getSurface());
mRender = new FilmRS();
mRender.init(mRS, getResources(), w, h);
}
}
@Override
protected void onDetachedFromWindow() {
if(mRS != null) {
mRS = null;
destroyRenderScript();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
// break point at here
// this method doesn't work when 'extends View' include 'extends ScrollView'.
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onTouchEvent(MotionEvent ev)
{
boolean ret = true;
int act = ev.getAction();
if (act == ev.ACTION_UP) {
ret = false;
}
mRender.setFilmStripPosition((int)ev.getX(), (int)ev.getY() / 5);
return ret;
}
}

View File

@ -0,0 +1,27 @@
#
# 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 := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
LOCAL_PACKAGE_NAME := Fountain
include $(BUILD_PACKAGE)

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.fountain">
<application
android:label="Fountain"
android:icon="@drawable/test_pattern">
<activity android:name="Fountain">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

View File

@ -0,0 +1,52 @@
// Fountain test script
#pragma version(1)
int newPart = 0;
int main(int launchID) {
int ct;
int count = Control->count;
int rate = Control->rate;
float height = getHeight();
struct point_s * p = (struct point_s *)point;
if (rate) {
float rMax = ((float)rate) * 0.005f;
int x = Control->x;
int y = Control->y;
int color = ((int)(Control->r * 255.f)) |
((int)(Control->g * 255.f)) << 8 |
((int)(Control->b * 255.f)) << 16 |
(0xf0 << 24);
struct point_s * np = &p[newPart];
while (rate--) {
vec2Rand((float *)&np->delta.x, rMax);
np->position.x = x;
np->position.y = y;
np->color = color;
newPart++;
np++;
if (newPart >= count) {
newPart = 0;
np = &p[newPart];
}
}
}
for (ct=0; ct < count; ct++) {
float dy = p->delta.y + 0.15f;
float posy = p->position.y + dy;
if ((posy > height) && (dy > 0)) {
dy *= -0.3f;
}
p->delta.y = dy;
p->position.x += p->delta.x;
p->position.y = posy;
p++;
}
uploadToBufferObject(NAMED_PartBuffer);
drawSimpleMesh(NAMED_PartMesh);
return 1;
}

View File

@ -0,0 +1,73 @@
// Fountain test script
#pragma version(1)
#include "rs_types.rsh"
#include "rs_math.rsh"
#include "rs_graphics.rsh"
static int newPart = 0;
typedef struct Control_s {
int x, y;
int rate;
int count;
float r, g, b;
rs_allocation partBuffer;
rs_mesh partMesh;
} Control_t;
Control_t *Control;
typedef struct Point_s{
float2 delta;
float2 position;
unsigned int color;
} Point_t;
Point_t *point;
int main(int launchID) {
int ct;
int count = Control->count;
int rate = Control->rate;
float height = getHeight();
Point_t * p = point;
if (rate) {
float rMax = ((float)rate) * 0.005f;
int x = Control->x;
int y = Control->y;
int color = ((int)(Control->r * 255.f)) |
((int)(Control->g * 255.f)) << 8 |
((int)(Control->b * 255.f)) << 16 |
(0xf0 << 24);
Point_t * np = &p[newPart];
while (rate--) {
np->delta = vec2Rand(rMax);
np->position.x = x;
np->position.y = y;
np->color = color;
newPart++;
np++;
if (newPart >= count) {
newPart = 0;
np = &p[newPart];
}
}
}
for (ct=0; ct < count; ct++) {
float dy = p->delta.y + 0.15f;
float posy = p->position.y + dy;
if ((posy > height) && (dy > 0)) {
dy *= -0.3f;
}
p->delta.y = dy;
p->position.x += p->delta.x;
p->position.y = posy;
p++;
}
uploadToBufferObject(Control->partBuffer);
drawSimpleMesh(Control->partMesh);
return 1;
}

View File

@ -0,0 +1,96 @@
/*
* 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.android.fountain;
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.Config;
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 java.lang.Runtime;
public class Fountain extends Activity {
//EventListener mListener = new EventListener();
private static final String LOG_TAG = "libRS_jni";
private static final boolean DEBUG = false;
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
private FountainView mView;
// get the current looper (from your Activity UI thread for instance
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create our Preview view and set it as the content of our
// Activity
mView = new FountainView(this);
setContentView(mView);
}
@Override
protected void onResume() {
Log.e("rs", "onResume");
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
}
@Override
protected void onPause() {
Log.e("rs", "onPause");
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
//Runtime.getRuntime().exit(0);
}
static void log(String message) {
if (LOG_ENABLED) {
Log.v(LOG_TAG, message);
}
}
}

View File

@ -0,0 +1,115 @@
/*
* 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.android.fountain;
import android.content.res.Resources;
import android.renderscript.*;
import android.util.Log;
public class FountainRS {
public static final int PART_COUNT = 20000;
static class SomeData {
public int x;
public int y;
public int rate;
public int count;
public float r;
public float g;
public float b;
}
public FountainRS() {
}
public void init(RenderScriptGL rs, Resources res, int width, int height) {
mRS = rs;
mRes = res;
initRS();
}
public void newTouchPosition(int x, int y, int rate) {
if (mSD.rate == 0) {
mSD.r = ((x & 0x1) != 0) ? 0.f : 1.f;
mSD.g = ((x & 0x2) != 0) ? 0.f : 1.f;
mSD.b = ((x & 0x4) != 0) ? 0.f : 1.f;
if ((mSD.r + mSD.g + mSD.b) < 0.9f) {
mSD.r = 0.8f;
mSD.g = 0.5f;
mSD.b = 1.f;
}
}
mSD.rate = rate;
mSD.x = x;
mSD.y = y;
mIntAlloc.data(mSD);
}
/////////////////////////////////////////
private Resources mRes;
private RenderScriptGL mRS;
private Allocation mIntAlloc;
private SimpleMesh mSM;
private SomeData mSD;
private Type mSDType;
private void initRS() {
mSD = new SomeData();
mSDType = Type.createFromClass(mRS, SomeData.class, 1, "SomeData");
mIntAlloc = Allocation.createTyped(mRS, mSDType);
mSD.count = PART_COUNT;
mIntAlloc.data(mSD);
Element.Builder eb = new Element.Builder(mRS);
eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 2), "delta");
eb.add(Element.createAttrib(mRS, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "position");
eb.add(Element.createAttrib(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color");
Element primElement = eb.create();
SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
int vtxSlot = smb.addVertexType(primElement, PART_COUNT);
smb.setPrimitive(Primitive.POINT);
mSM = smb.create();
mSM.setName("PartMesh");
Allocation partAlloc = mSM.createVertexAllocation(vtxSlot);
partAlloc.setName("PartBuffer");
mSM.bindVertexAllocation(partAlloc, 0);
// All setup of named objects should be done by this point
// because we are about to compile the script.
ScriptC.Builder sb = new ScriptC.Builder(mRS);
sb.setScript(mRes, R.raw.fountain);
sb.setRoot(true);
sb.setType(mSDType, "Control", 0);
sb.setType(mSM.getVertexType(0), "point", 1);
Script script = sb.create();
script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
script.bindAllocation(mIntAlloc, 0);
script.bindAllocation(partAlloc, 1);
mRS.contextBindRootScript(script);
}
}

View File

@ -0,0 +1,89 @@
/*
* 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.android.fountain;
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 FountainView extends RSSurfaceView {
public FountainView(Context context) {
super(context);
//setFocusable(true);
}
private RenderScriptGL mRS;
private FountainRS mRender;
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
if (mRS == null) {
mRS = createRenderScript(false);
mRS.contextSetSurface(w, h, holder.getSurface());
mRender = new FountainRS();
mRender.init(mRS, getResources(), w, h);
}
}
@Override
protected void onDetachedFromWindow() {
if(mRS != null) {
mRS = null;
destroyRenderScript();
}
}
@Override
public boolean onTouchEvent(MotionEvent ev)
{
int act = ev.getAction();
if (act == ev.ACTION_UP) {
mRender.newTouchPosition(0, 0, 0);
return false;
}
float rate = (ev.getPressure() * 50.f);
rate *= rate;
if(rate > 2000.f) {
rate = 2000.f;
}
mRender.newTouchPosition((int)ev.getX(), (int)ev.getY(), (int)rate);
return true;
}
}

View File

@ -0,0 +1,27 @@
#
# 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 := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
LOCAL_PACKAGE_NAME := ImageProcessing
include $(BUILD_PACKAGE)

View File

@ -0,0 +1,16 @@
<?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" />
<application android:label="Image Processing">
<activity android:name="ImageProcessingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@ -0,0 +1,38 @@
<?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.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<SurfaceView
android:id="@+id/surface"
android:layout_width="1dip"
android:layout_height="1dip" />
<ImageView
android:id="@+id/display"
android:layout_width="320dip"
android:layout_height="266dip" />
<SeekBar
android:id="@+id/threshold"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</merge>

View File

@ -0,0 +1,62 @@
/*
// block of defines matching what RS will insert at runtime.
struct Params_s{
int inHeight;
int inWidth;
int outHeight;
int outWidth;
float threshold;
};
struct Params_s * Params;
struct InPixel_s{
char a;
char b;
char g;
char r;
};
struct InPixel_s * InPixel;
struct OutPixel_s{
char a;
char b;
char g;
char r;
};
struct OutPixel_s * OutPixel;
*/
struct color_s {
char b;
char g;
char r;
char a;
};
void main() {
int t = uptimeMillis();
struct color_s *in = (struct color_s *) InPixel;
struct color_s *out = (struct color_s *) OutPixel;
int count = Params->inWidth * Params->inHeight;
int i;
float threshold = (Params->threshold * 255.f);
for (i = 0; i < count; i++) {
float luminance = 0.2125f * in->r +
0.7154f * in->g +
0.0721f * in->b;
if (luminance > threshold) {
*out = *in;
} else {
*((int *)out) = *((int *)in) & 0xff000000;
}
in++;
out++;
}
t= uptimeMillis() - t;
debugI32("Filter time", t);
sendToClient(&count, 1, 4, 0);
}

View File

@ -0,0 +1,232 @@
/*
* 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.
*/
package com.android.rs.image;
import android.app.Activity;
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 java.lang.Math;
public class ImageProcessingActivity extends Activity implements SurfaceHolder.Callback {
private Bitmap mBitmap;
private Params mParams;
private Script.Invokable mInvokable;
private int[] mInData;
private int[] mOutData;
@SuppressWarnings({"FieldCanBeLocal"})
private RenderScript mRS;
@SuppressWarnings({"FieldCanBeLocal"})
private Type mParamsType;
@SuppressWarnings({"FieldCanBeLocal"})
private Allocation mParamsAllocation;
@SuppressWarnings({"FieldCanBeLocal"})
private Type mPixelType;
@SuppressWarnings({"FieldCanBeLocal"})
private Allocation mInPixelsAllocation;
@SuppressWarnings({"FieldCanBeLocal"})
private Allocation mOutPixelsAllocation;
private SurfaceView mSurfaceView;
private ImageView mDisplayView;
static class Params {
public int inWidth;
public int outWidth;
public int inHeight;
public int outHeight;
public float threshold;
}
static class Pixel {
public byte a;
public byte r;
public byte g;
public byte b;
}
class FilterCallback extends RenderScript.RSMessage {
private Runnable mAction = new Runnable() {
public void run() {
mOutPixelsAllocation.readData(mOutData);
mBitmap.setPixels(mOutData, 0, mParams.outWidth, 0, 0,
mParams.outWidth, mParams.outHeight);
mDisplayView.invalidate();
}
};
@Override
public void run() {
mSurfaceView.removeCallbacks(mAction);
mSurfaceView.post(mAction);
}
}
private void javaFilter() {
long t = java.lang.System.currentTimeMillis();
int count = mParams.inWidth * mParams.inHeight;
float threshold = mParams.threshold * 255.f;
for (int i = 0; i < count; i++) {
final float r = (float)((mInData[i] >> 0) & 0xff);
final float g = (float)((mInData[i] >> 8) & 0xff);
final float b = (float)((mInData[i] >> 16) & 0xff);
final float luminance = 0.2125f * r +
0.7154f * g +
0.0721f * b;
if (luminance > threshold) {
mOutData[i] = mInData[i];
} else {
mOutData[i] = mInData[i] & 0xff000000;
}
}
t = java.lang.System.currentTimeMillis() - t;
android.util.Log.v("Img", "frame time ms " + t);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBitmap = loadBitmap(R.drawable.data);
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
mSurfaceView.getHolder().addCallback(this);
mDisplayView = (ImageView) findViewById(R.id.display);
mDisplayView.setImageBitmap(mBitmap);
((SeekBar) findViewById(R.id.threshold)).setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
mParams.threshold = progress / 100.0f;
mParamsAllocation.data(mParams);
if (true) {
mInvokable.execute();
} else {
javaFilter();
mBitmap.setPixels(mOutData, 0, mParams.outWidth, 0, 0,
mParams.outWidth, mParams.outHeight);
mDisplayView.invalidate();
}
}
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
public void surfaceCreated(SurfaceHolder holder) {
mParams = createParams();
mInvokable = createScript();
mInvokable.execute();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
private Script.Invokable createScript() {
mRS = RenderScript.create();
mRS.mMessageCallback = new FilterCallback();
mParamsType = Type.createFromClass(mRS, Params.class, 1, "Parameters");
mParamsAllocation = Allocation.createTyped(mRS, mParamsType);
mParamsAllocation.data(mParams);
final int pixelCount = mParams.inWidth * mParams.inHeight;
mPixelType = Type.createFromClass(mRS, Pixel.class, 1, "Pixel");
mInPixelsAllocation = Allocation.createSized(mRS,
Element.createUser(mRS, Element.DataType.SIGNED_32),
pixelCount);
mOutPixelsAllocation = Allocation.createSized(mRS,
Element.createUser(mRS, Element.DataType.SIGNED_32),
pixelCount);
mInData = new int[pixelCount];
mBitmap.getPixels(mInData, 0, mParams.inWidth, 0, 0, mParams.inWidth, mParams.inHeight);
mInPixelsAllocation.data(mInData);
mOutData = new int[pixelCount];
mOutPixelsAllocation.data(mOutData);
ScriptC.Builder sb = new ScriptC.Builder(mRS);
sb.setType(mParamsType, "Params", 0);
sb.setType(mPixelType, "InPixel", 1);
sb.setType(mPixelType, "OutPixel", 2);
sb.setType(true, 2);
Script.Invokable invokable = sb.addInvokable("main");
sb.setScript(getResources(), R.raw.threshold);
//sb.setRoot(true);
ScriptC script = sb.create();
script.bindAllocation(mParamsAllocation, 0);
script.bindAllocation(mInPixelsAllocation, 1);
script.bindAllocation(mOutPixelsAllocation, 2);
return invokable;
}
private Params createParams() {
final Params params = new Params();
params.inWidth = params.outWidth = mBitmap.getWidth();
params.inHeight = params.outHeight = mBitmap.getHeight();
params.threshold = 0.5f;
return params;
}
private Bitmap loadBitmap(int resource) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
return copyBitmap(BitmapFactory.decodeResource(getResources(), resource, options));
}
private static Bitmap copyBitmap(Bitmap source) {
Bitmap b = Bitmap.createBitmap(source.getWidth(), source.getHeight(), source.getConfig());
Canvas c = new Canvas(b);
c.drawBitmap(source, 0, 0, null);
source.recycle();
return b;
}
}