Permalink
Browse files

make the brightness value user selectable via a seekbar

  • Loading branch information...
1 parent bce6ee1 commit 68a134e0ae3635ba1882c393e5ce2b0fff2501c2 @ruckus committed Feb 22, 2012
View
@@ -72,7 +72,16 @@
<file leaf-file-name="ImageActivity.java" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/com/example/ImageActivity.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="30" column="103" selection-start="892" selection-end="892" vertical-scroll-proportion="0.5925926">
+ <state line="49" column="99" selection-start="1520" selection-end="1520" vertical-scroll-proportion="0.66938776">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ </file>
+ <file leaf-file-name="README" pinned="false" current="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/README">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="4" column="135" selection-start="309" selection-end="309" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -81,7 +90,7 @@
<file leaf-file-name="main.xml" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/res/layout/main.xml">
<provider selected="true" editor-type-id="text-editor">
- <state line="6" column="2" selection-start="234" selection-end="234" vertical-scroll-proportion="0.0">
+ <state line="9" column="30" selection-start="340" selection-end="340" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -90,7 +99,7 @@
<file leaf-file-name="imageprocessing.c" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/jni/imageprocessing.c">
<provider selected="true" editor-type-id="text-editor">
- <state line="26" column="25" selection-start="613" selection-end="613" vertical-scroll-proportion="0.0">
+ <state line="40" column="53" selection-start="1134" selection-end="1134" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -112,6 +121,7 @@
<option name="changedFiles">
<list>
<option value="$PROJECT_DIR$/jni/Android.mk" />
+ <option value="$PROJECT_DIR$/README" />
<option value="$PROJECT_DIR$/jni/imageprocessing.c" />
<option value="$PROJECT_DIR$/res/layout/main.xml" />
<option value="$PROJECT_DIR$/src/com/example/ImageActivity.java" />
@@ -383,6 +393,7 @@
<editor active="true" />
<layout>
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
+ <window_info id="Preview" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32959402" sideWeight="0.6703079" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
@@ -395,10 +406,9 @@
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24946581" sideWeight="0.6703079" order="0" side_tool="false" content_ui="tabs" />
- <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32969216" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
+ <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32969216" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Android Logcat" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
- <window_info id="Preview" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32977587" sideWeight="0.6703079" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Android Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32969216" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
@@ -476,23 +486,30 @@
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/res/layout/main.xml">
+ <entry file="file://$PROJECT_DIR$/README">
<provider selected="true" editor-type-id="text-editor">
- <state line="6" column="2" selection-start="234" selection-end="234" vertical-scroll-proportion="0.0">
+ <state line="4" column="135" selection-start="309" selection-end="309" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/jni/imageprocessing.c">
<provider selected="true" editor-type-id="text-editor">
- <state line="26" column="25" selection-start="613" selection-end="613" vertical-scroll-proportion="0.0">
+ <state line="40" column="53" selection-start="1134" selection-end="1134" vertical-scroll-proportion="0.0">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/res/layout/main.xml">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="9" column="30" selection-start="340" selection-end="340" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/example/ImageActivity.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="30" column="103" selection-start="892" selection-end="892" vertical-scroll-proportion="0.5925926">
+ <state line="49" column="99" selection-start="1520" selection-end="1520" vertical-scroll-proportion="0.66938776">
<folding />
</state>
</provider>
View
@@ -0,0 +1,5 @@
+Same Android project on how to implement an image filter in C using the Android NDK.
+
+A basic Activity will adjust the brightness level of a bitmap according to user value.
+
+Use the slider to select a brightness value that will be bounded from 1-10 and then click on the button to apply the brightness filter.
@@ -16,6 +16,8 @@
public static final class id {
public static final int button=0x7f050001;
public static final int imageView=0x7f050000;
+ public static final int label=0x7f050003;
+ public static final int seekBar=0x7f050002;
}
public static final class layout {
public static final int main=0x7f030000;
View
@@ -21,10 +21,10 @@ static int rgb_clamp(int value) {
return value;
}
-static void brightness(AndroidBitmapInfo* info, void* pixels){
+static void brightness(AndroidBitmapInfo* info, void* pixels, float brightnessValue){
int xx, yy, red, green, blue, L;
uint32_t* line;
- float brightness = 1.6;
+ //float brightness = 1.6;
for(yy = 0; yy < info->height; yy++){
line = (uint32_t*)pixels;
@@ -36,9 +36,9 @@ static void brightness(AndroidBitmapInfo* info, void* pixels){
blue = (int) (line[xx] & 0x00000FF );
//manipulate each value
- red = rgb_clamp((int)(red * brightness));
- green = rgb_clamp((int)(green * brightness));
- blue = rgb_clamp((int)(blue * brightness));
+ red = rgb_clamp((int)(red * brightnessValue));
+ green = rgb_clamp((int)(green * brightnessValue));
+ blue = rgb_clamp((int)(blue * brightnessValue));
// set the new pixel back in
line[xx] =
@@ -51,7 +51,7 @@ static void brightness(AndroidBitmapInfo* info, void* pixels){
}
}
-JNIEXPORT void JNICALL Java_com_example_ImageActivity_brightness(JNIEnv * env, jobject obj, jobject bitmap)
+JNIEXPORT void JNICALL Java_com_example_ImageActivity_brightness(JNIEnv * env, jobject obj, jobject bitmap, jfloat brightnessValue)
{
AndroidBitmapInfo info;
@@ -71,7 +71,7 @@ JNIEXPORT void JNICALL Java_com_example_ImageActivity_brightness(JNIEnv * env, j
LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
}
- brightness(&info,pixels);
+ brightness(&info,pixels, brightnessValue);
AndroidBitmap_unlockPixels(env, bitmap);
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -6,16 +6,32 @@
>
<ImageView
android:id="@+id/imageView"
- android:layout_width="600px"
- android:layout_height="400px"
+ android:layout_width="400px"
+ android:layout_height="266px"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Adjust Brightness"
-
/>
+
+ <SeekBar
+ android:id="@+id/seekBar"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:max="100"
+ />
+
+ <TextView
+ android:id="@+id/label"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text=""
+ />
+
+
</LinearLayout>
+
@@ -7,11 +7,17 @@
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
+import android.widget.SeekBar;
+import android.widget.TextView;
public class ImageActivity extends Activity {
private ImageView imageView;
private Bitmap bitmap;
private Button button;
+ private SeekBar seekBar;
+ private float brightness;
+ private TextView label;
+ private Bitmap original;
static {
System.loadLibrary("imageprocessing");
@@ -21,22 +27,36 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.wallace);
+ original = BitmapFactory.decodeResource(getResources(), R.drawable.wallace);
imageView = (ImageView) findViewById(R.id.imageView);
button = (Button) findViewById(R.id.button);
+ seekBar = (SeekBar) findViewById(R.id.seekBar);
+ label = (TextView) findViewById(R.id.label);
+
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
adjustBrightness();
}
});
+
+ seekBar.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() {
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ brightness = (float)(progress / 10.0f);
+ label.setText("Brightness = " + brightness);
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) {}
+ public void onStopTrackingTouch(SeekBar seekBar){}
+ });
}
private void adjustBrightness() {
- brightness(bitmap);
+ Bitmap bitmap = original.copy(Bitmap.Config.ARGB_8888, true);
+ brightness(bitmap, brightness);
imageView.setImageBitmap(bitmap);
}
- public native void brightness(Bitmap bmp);
+ public native void brightness(Bitmap bmp, float brightness);
}

0 comments on commit 68a134e

Please sign in to comment.