diff options
author | Jason Sams <rjsams@android.com> | 2010-06-21 17:42:41 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2010-06-21 17:42:41 -0700 |
commit | f110d4b787b91dabe968a812e76e5c1f8d953487 (patch) | |
tree | 65d71a0acb1441510240bec336535898a27d59e7 /libs/rs/java/ImageProcessing | |
parent | 3ac8da87bba83de254e612ff8387db23e6434119 (diff) | |
download | frameworks_base-f110d4b787b91dabe968a812e76e5c1f8d953487.zip frameworks_base-f110d4b787b91dabe968a812e76e5c1f8d953487.tar.gz frameworks_base-f110d4b787b91dabe968a812e76e5c1f8d953487.tar.bz2 |
Move ImageProcessing and ModelViewer to reflected files.
Implement boolean support.
Change-Id: Iac2dc28067ac430b3e413fc651dfaa0b96214e2e
Diffstat (limited to 'libs/rs/java/ImageProcessing')
-rw-r--r-- | libs/rs/java/ImageProcessing/res/raw/threshold.rs | 80 | ||||
-rw-r--r-- | libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc | bin | 8524 -> 8372 bytes | |||
-rw-r--r-- | libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java | 10 | ||||
-rw-r--r-- | libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java | 216 |
4 files changed, 182 insertions, 124 deletions
diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold.rs b/libs/rs/java/ImageProcessing/res/raw/threshold.rs index 93a1a36..a8eb164 100644 --- a/libs/rs/java/ImageProcessing/res/raw/threshold.rs +++ b/libs/rs/java/ImageProcessing/res/raw/threshold.rs @@ -10,13 +10,9 @@ int height; int width; int radius; -typedef struct c4u_s { - uint8_t r, g, b, a; -} c4u_t; - -c4u_t * InPixel; -c4u_t * OutPixel; -c4u_t * ScratchPixel; +uchar4 * InPixel; +uchar4 * OutPixel; +uchar4 * ScratchPixel; float inBlack; float outBlack; @@ -31,7 +27,7 @@ static float outWMinOutB; static float overInWMinInB; //static float3 gammaV; -#pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation) +#pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation, InPixel, OutPixel, ScratchPixel) #pragma rs export_func(filter, filterBenchmark); // Store our coefficients here @@ -166,19 +162,21 @@ static void processNoBlur() { for(h = 0; h < height; h ++) { for(w = 0; w < width; w ++) { - c4u_t *input = InPixel + h*width + w; + uchar4 *input = InPixel + h*width + w; - currentPixel.x = (float)(input->r); - currentPixel.y = (float)(input->g); - currentPixel.z = (float)(input->b); + //currentPixel.xyz = convert_float3(input.xyz); + currentPixel.x = (float)(input->x); + currentPixel.y = (float)(input->y); + currentPixel.z = (float)(input->z); currentPixel = levelsSaturation(currentPixel); - c4u_t *output = OutPixel + h*width + w; - output->r = (uint8_t)currentPixel.x; - output->g = (uint8_t)currentPixel.y; - output->b = (uint8_t)currentPixel.z; - output->a = input->a; + uchar4 *output = OutPixel + h*width + w; + //output.xyz = convert_uchar3(currentPixel.xyz); + output->x = (uint8_t)currentPixel.x; + output->y = (uint8_t)currentPixel.y; + output->z = (uint8_t)currentPixel.z; + output->w = input->w; } } rsSendToClient(&count, 1, 4, 0); @@ -205,21 +203,21 @@ static void horizontalBlur() { validW = width - 1; } - c4u_t *input = InPixel + h*width + validW; + uchar4 *input = InPixel + h*width + validW; float weight = gaussian[r + radius]; - currentPixel.x = (float)(input->r); - currentPixel.y = (float)(input->g); - currentPixel.z = (float)(input->b); + currentPixel.x = (float)(input->x); + currentPixel.y = (float)(input->y); + currentPixel.z = (float)(input->z); //currentPixel.w = (float)(input->a); blurredPixel += currentPixel*weight; } - c4u_t *output = ScratchPixel + h*width + w; - output->r = (uint8_t)blurredPixel.x; - output->g = (uint8_t)blurredPixel.y; - output->b = (uint8_t)blurredPixel.z; + uchar4 *output = ScratchPixel + h*width + w; + output->x = (uint8_t)blurredPixel.x; + output->y = (uint8_t)blurredPixel.y; + output->z = (uint8_t)blurredPixel.z; //output->a = (uint8_t)blurredPixel.w; } } @@ -246,12 +244,12 @@ static void horizontalBlurLevels() { validW = width - 1; } - c4u_t *input = InPixel + h*width + validW; + uchar4 *input = InPixel + h*width + validW; float weight = gaussian[r + radius]; - currentPixel.x = (float)(input->r); - currentPixel.y = (float)(input->g); - currentPixel.z = (float)(input->b); + currentPixel.x = (float)(input->x); + currentPixel.y = (float)(input->y); + currentPixel.z = (float)(input->z); //currentPixel.w = (float)(input->a); blurredPixel += currentPixel*weight; @@ -259,10 +257,10 @@ static void horizontalBlurLevels() { blurredPixel = levelsSaturation(blurredPixel); - c4u_t *output = ScratchPixel + h*width + w; - output->r = (uint8_t)blurredPixel.x; - output->g = (uint8_t)blurredPixel.y; - output->b = (uint8_t)blurredPixel.z; + uchar4 *output = ScratchPixel + h*width + w; + output->x = (uint8_t)blurredPixel.x; + output->y = (uint8_t)blurredPixel.y; + output->z = (uint8_t)blurredPixel.z; //output->a = (uint8_t)blurredPixel.w; } } @@ -287,23 +285,23 @@ static void verticalBlur() { validH = height - 1; } - c4u_t *input = ScratchPixel + validH*width + w; + uchar4 *input = ScratchPixel + validH*width + w; float weight = gaussian[r + radius]; - currentPixel.x = (float)(input->r); - currentPixel.y = (float)(input->g); - currentPixel.z = (float)(input->b); + currentPixel.x = (float)(input->x); + currentPixel.y = (float)(input->y); + currentPixel.z = (float)(input->z); //currentPixel.w = (float)(input->a); blurredPixel += currentPixel*weight; } - c4u_t *output = OutPixel + h*width + w; + uchar4 *output = OutPixel + h*width + w; - output->r = (uint8_t)blurredPixel.x; - output->g = (uint8_t)blurredPixel.y; - output->b = (uint8_t)blurredPixel.z; + output->x = (uint8_t)blurredPixel.x; + output->y = (uint8_t)blurredPixel.y; + output->z = (uint8_t)blurredPixel.z; //output->a = (uint8_t)blurredPixel.w; } } diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc b/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc Binary files differindex 4cf0629..fd60f76 100644 --- a/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc +++ b/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index b39d141..7bf6596 100644 --- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -285,7 +285,7 @@ public class ImageProcessingActivity extends Activity long t = java.lang.System.currentTimeMillis(); if (true) { - mScript.invokable_Filter(); + mScript.invoke_filter(); mRS.finish(); } else { javaFilter(); @@ -355,7 +355,7 @@ public class ImageProcessingActivity extends Activity public void surfaceCreated(SurfaceHolder holder) { createScript(); - mScript.invokable_Filter(); + mScript.invoke_filter(); mRS.finish(); } @@ -373,7 +373,7 @@ public class ImageProcessingActivity extends Activity mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut); mScratchPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapScratch); - mScript = new ScriptC_Threshold(mRS, getResources(), false); + mScript = new ScriptC_Threshold(mRS, getResources(), R.raw.threshold_bc, false); mScript.set_width(mBitmapIn.getWidth()); mScript.set_height(mBitmapIn.getHeight()); mScript.set_radius(mRadius); @@ -413,7 +413,7 @@ public class ImageProcessingActivity extends Activity long t = java.lang.System.currentTimeMillis(); - mScript.invokable_FilterBenchmark(); + mScript.invoke_filterBenchmark(); mRS.finish(); t = java.lang.System.currentTimeMillis() - t; @@ -426,7 +426,7 @@ public class ImageProcessingActivity extends Activity mRadius = oldRadius; mScript.set_radius(mRadius); - mScript.invokable_Filter(); + mScript.invoke_filter(); mRS.finish(); } } diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java index 42adb27..ea363d3 100644 --- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java @@ -1,115 +1,175 @@ +/* + * Copyright (C) 2010 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.content.res.Resources; import android.renderscript.*; +import android.content.res.Resources; import android.util.Log; -public class ScriptC_Threshold - extends android.renderscript.ScriptC -{ - private final static int mFieldIndex_height = 0; - private final static int mFieldIndex_width = 1; - private final static int mFieldIndex_radius = 2; - private final static int mFieldIndex_InPixel = 3; - private final static int mFieldIndex_OutPixel = 4; - private final static int mFieldIndex_ScratchPixel = 5; - - private final static int mFieldIndex_inBlack = 6; - private final static int mFieldIndex_outBlack = 7; - private final static int mFieldIndex_inWhite = 8; - private final static int mFieldIndex_outWhite = 9; - private final static int mFieldIndex_gamma = 10; - - private final static int mFieldIndex_saturation = 11; - private final static int mFieldIndex_hue = 12; - - private Allocation mField_InPixel; - private Allocation mField_OutPixel; - private Allocation mField_ScratchPixel; - - public ScriptC_Threshold(RenderScript rs, Resources resources, boolean isRoot) { - super(rs, resources, R.raw.threshold_bc, isRoot); - } - - public void bind_InPixel(Allocation f) { - if (f != null) { - //if (f.getType().getElement() != Element.ATTRIB_COLOR_U8_4(mRS)) { - //throw new IllegalArgumentException("Element type mismatch."); - //} - } - bindAllocation(f, mFieldIndex_InPixel); - mField_InPixel = f; - } - public Allocation get_InPixel() { - return mField_InPixel; - } - - public void bind_OutPixel(Allocation f) { - if (f != null) { - //if (f.getType().getElement() != Element.ATTRIB_COLOR_U8_4(mRS)) { - //throw new IllegalArgumentException("Element type mismatch."); - //} - } - bindAllocation(f, mFieldIndex_OutPixel); - mField_OutPixel = f; - } - public void bind_ScratchPixel(Allocation f) { - if (f != null) { - //if (f.getType().getElement() != Element.ATTRIB_COLOR_U8_4(mRS)) { - //throw new IllegalArgumentException("Element type mismatch."); - //} - } - bindAllocation(f, mFieldIndex_ScratchPixel); - mField_ScratchPixel = f; - } - public Allocation get_OutPixel() { - return mField_OutPixel; +public class ScriptC_Threshold extends ScriptC { + // Constructor + public ScriptC_Threshold(RenderScript rs, Resources resources, int id, boolean isRoot) { + super(rs, resources, id, isRoot); } + private final static int mExportVarIdx_height = 0; + private int mExportVar_height; public void set_height(int v) { - setVar(mFieldIndex_height, v); + mExportVar_height = v; + setVar(mExportVarIdx_height, v); } + public int get_height() { + return mExportVar_height; + } + + private final static int mExportVarIdx_width = 1; + private int mExportVar_width; public void set_width(int v) { - setVar(mFieldIndex_width, v); + mExportVar_width = v; + setVar(mExportVarIdx_width, v); } + public int get_width() { + return mExportVar_width; + } + + private final static int mExportVarIdx_radius = 2; + private int mExportVar_radius; public void set_radius(int v) { - setVar(mFieldIndex_radius, v); + mExportVar_radius = v; + setVar(mExportVarIdx_radius, v); + } + + public int get_radius() { + return mExportVar_radius; + } + + private final static int mExportVarIdx_InPixel = 3; + private Allocation mExportVar_InPixel; + public void bind_InPixel(Allocation v) { + mExportVar_InPixel = v; + if(v == null) bindAllocation(null, mExportVarIdx_InPixel); + else bindAllocation(v, mExportVarIdx_InPixel); + } + + public Allocation get_InPixel() { + return mExportVar_InPixel; + } + + private final static int mExportVarIdx_OutPixel = 4; + private Allocation mExportVar_OutPixel; + public void bind_OutPixel(Allocation v) { + mExportVar_OutPixel = v; + if(v == null) bindAllocation(null, mExportVarIdx_OutPixel); + else bindAllocation(v, mExportVarIdx_OutPixel); + } + + public Allocation get_OutPixel() { + return mExportVar_OutPixel; + } + + private final static int mExportVarIdx_ScratchPixel = 5; + private Allocation mExportVar_ScratchPixel; + public void bind_ScratchPixel(Allocation v) { + mExportVar_ScratchPixel = v; + if(v == null) bindAllocation(null, mExportVarIdx_ScratchPixel); + else bindAllocation(v, mExportVarIdx_ScratchPixel); } + public Allocation get_ScratchPixel() { + return mExportVar_ScratchPixel; + } + + private final static int mExportVarIdx_inBlack = 6; + private float mExportVar_inBlack; public void set_inBlack(float v) { - setVar(mFieldIndex_inBlack, v); + mExportVar_inBlack = v; + setVar(mExportVarIdx_inBlack, v); } + + public float get_inBlack() { + return mExportVar_inBlack; + } + + private final static int mExportVarIdx_outBlack = 7; + private float mExportVar_outBlack; public void set_outBlack(float v) { - setVar(mFieldIndex_outBlack, v); + mExportVar_outBlack = v; + setVar(mExportVarIdx_outBlack, v); } + + public float get_outBlack() { + return mExportVar_outBlack; + } + + private final static int mExportVarIdx_inWhite = 8; + private float mExportVar_inWhite; public void set_inWhite(float v) { - setVar(mFieldIndex_inWhite, v); + mExportVar_inWhite = v; + setVar(mExportVarIdx_inWhite, v); } + + public float get_inWhite() { + return mExportVar_inWhite; + } + + private final static int mExportVarIdx_outWhite = 9; + private float mExportVar_outWhite; public void set_outWhite(float v) { - setVar(mFieldIndex_outWhite, v); + mExportVar_outWhite = v; + setVar(mExportVarIdx_outWhite, v); + } + + public float get_outWhite() { + return mExportVar_outWhite; } + + private final static int mExportVarIdx_gamma = 10; + private float mExportVar_gamma; public void set_gamma(float v) { - setVar(mFieldIndex_gamma, v); + mExportVar_gamma = v; + setVar(mExportVarIdx_gamma, v); + } + + public float get_gamma() { + return mExportVar_gamma; } + private final static int mExportVarIdx_saturation = 11; + private float mExportVar_saturation; public void set_saturation(float v) { - setVar(mFieldIndex_saturation, v); + mExportVar_saturation = v; + setVar(mExportVarIdx_saturation, v); } - public void set_hue(float v) { - setVar(mFieldIndex_hue, v); + + public float get_saturation() { + return mExportVar_saturation; } - private final static int mInvokableIndex_Filter = 4; - public void invokable_Filter() { - invoke(mInvokableIndex_Filter); + private final static int mExportFuncIdx_filter = 0; + public void invoke_filter() { + invoke(mExportFuncIdx_filter); } - private final static int mInvokableIndex_FilterBenchmark = 5; - public void invokable_FilterBenchmark() { - invoke(mInvokableIndex_FilterBenchmark); + private final static int mExportFuncIdx_filterBenchmark = 1; + public void invoke_filterBenchmark() { + invoke(mExportFuncIdx_filterBenchmark); } + } |