Use IO stream
Change-Id: I668383598a326f32f96685bb8ced3900b004ea82
This commit is contained in:
140
samples/RenderScript/Levels/res/layout/rs.xml
Normal file
140
samples/RenderScript/Levels/res/layout/rs.xml
Normal file
@@ -0,0 +1,140 @@
|
||||
<?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: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">
|
||||
<TextureView
|
||||
android:id="@+id/display"
|
||||
android:layout_width="800sp"
|
||||
android:layout_height="423sp" />
|
||||
<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>
|
||||
<TextView
|
||||
android:id="@+id/inSaturationText"
|
||||
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/inSaturation"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/outWhiteText"
|
||||
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/outWhite"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/inWhiteText"
|
||||
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/inWhite"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/outBlackText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="8pt"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:text="@string/out_black"/>
|
||||
<SeekBar
|
||||
android:id="@+id/outBlack"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/inBlackText"
|
||||
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_black"/>
|
||||
<SeekBar
|
||||
android:id="@+id/inBlack"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/inGammaText"
|
||||
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/inGamma"
|
||||
android:layout_marginLeft="10sp"
|
||||
android:layout_marginRight="10sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -21,20 +21,23 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.Bundle;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Matrix3f;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.util.Log;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.RenderScript;
|
||||
|
||||
public class LevelsRSActivity extends Activity
|
||||
implements SeekBar.OnSeekBarChangeListener {
|
||||
implements SeekBar.OnSeekBarChangeListener,
|
||||
TextureView.SurfaceTextureListener
|
||||
{
|
||||
private final String TAG = "Img";
|
||||
private Bitmap mBitmapIn;
|
||||
private Bitmap mBitmapOut;
|
||||
private float mInBlack = 0.0f;
|
||||
private SeekBar mInBlackSeekBar;
|
||||
private float mOutBlack = 0.0f;
|
||||
@@ -48,7 +51,7 @@ public class LevelsRSActivity extends Activity
|
||||
private float mSaturation = 1.0f;
|
||||
private SeekBar mSaturationSeekBar;
|
||||
private TextView mBenchmarkResult;
|
||||
private ImageView mDisplayView;
|
||||
private TextureView mDisplayView;
|
||||
|
||||
Matrix3f satMatrix = new Matrix3f();
|
||||
float mInWMinInB;
|
||||
@@ -128,13 +131,10 @@ public class LevelsRSActivity extends Activity
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
setContentView(R.layout.rs);
|
||||
|
||||
mBitmapIn = loadBitmap(R.drawable.city);
|
||||
mBitmapOut = loadBitmap(R.drawable.city);
|
||||
|
||||
mDisplayView = (ImageView) findViewById(R.id.display);
|
||||
mDisplayView.setImageBitmap(mBitmapOut);
|
||||
mDisplayView = (TextureView) findViewById(R.id.display);
|
||||
|
||||
mInBlackSeekBar = (SeekBar)findViewById(R.id.inBlack);
|
||||
mInBlackSeekBar.setOnSeekBarChangeListener(this);
|
||||
@@ -170,15 +170,16 @@ public class LevelsRSActivity extends Activity
|
||||
mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
|
||||
Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mOutPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapOut,
|
||||
Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mOutPixelsAllocation = Allocation.createTyped(mRS, mInPixelsAllocation.getType(),
|
||||
Allocation.USAGE_SCRIPT |
|
||||
Allocation.USAGE_IO_OUTPUT);
|
||||
mDisplayView.setSurfaceTextureListener(this);
|
||||
|
||||
mScript = new ScriptC_levels(mRS, getResources(), R.raw.levels);
|
||||
mScript.set_gamma(mGamma);
|
||||
|
||||
setSaturation();
|
||||
setLevels();
|
||||
filter();
|
||||
}
|
||||
|
||||
private Bitmap loadBitmap(int resource) {
|
||||
@@ -194,7 +195,8 @@ public class LevelsRSActivity extends Activity
|
||||
|
||||
private void filter() {
|
||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
mOutPixelsAllocation.copyTo(mBitmapOut);
|
||||
mOutPixelsAllocation.ioSendOutput();
|
||||
mRS.finish();
|
||||
}
|
||||
|
||||
public void benchmark(View v) {
|
||||
@@ -205,4 +207,26 @@ public class LevelsRSActivity extends Activity
|
||||
mDisplayView.invalidate();
|
||||
mBenchmarkResult.setText("Result: " + t + " ms");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
||||
mOutPixelsAllocation.setSurfaceTexture(surface);
|
||||
filter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
||||
mOutPixelsAllocation.setSurfaceTexture(surface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
||||
mOutPixelsAllocation.setSurfaceTexture(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,5 +35,6 @@ void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
||||
pixel = pixel * outWMinOutB + outBlack;
|
||||
pixel = clamp(pixel, 0.f, 255.f);
|
||||
out->xyz = convert_uchar3(pixel);
|
||||
out->w = 0xff;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user