Skip to content

Commit

Permalink
make the brightness value user selectable via a seekbar
Browse files Browse the repository at this point in the history
  • Loading branch information
ruckus committed Feb 22, 2012
1 parent bce6ee1 commit 68a134e
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 22 deletions.
35 changes: 26 additions & 9 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions README
@@ -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.
2 changes: 2 additions & 0 deletions gen/com/example/R.java
Expand Up @@ -16,6 +16,8 @@ public static final class drawable {
public static final class id { public static final class id {
public static final int button=0x7f050001; public static final int button=0x7f050001;
public static final int imageView=0x7f050000; 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 class layout {
public static final int main=0x7f030000; public static final int main=0x7f030000;
Expand Down
14 changes: 7 additions & 7 deletions jni/imageprocessing.c
Expand Up @@ -21,10 +21,10 @@ static int rgb_clamp(int value) {
return 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; int xx, yy, red, green, blue, L;
uint32_t* line; uint32_t* line;
float brightness = 1.6; //float brightness = 1.6;


for(yy = 0; yy < info->height; yy++){ for(yy = 0; yy < info->height; yy++){
line = (uint32_t*)pixels; line = (uint32_t*)pixels;
Expand All @@ -36,9 +36,9 @@ static void brightness(AndroidBitmapInfo* info, void* pixels){
blue = (int) (line[xx] & 0x00000FF ); blue = (int) (line[xx] & 0x00000FF );


//manipulate each value //manipulate each value
red = rgb_clamp((int)(red * brightness)); red = rgb_clamp((int)(red * brightnessValue));
green = rgb_clamp((int)(green * brightness)); green = rgb_clamp((int)(green * brightnessValue));
blue = rgb_clamp((int)(blue * brightness)); blue = rgb_clamp((int)(blue * brightnessValue));


// set the new pixel back in // set the new pixel back in
line[xx] = line[xx] =
Expand All @@ -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; AndroidBitmapInfo info;
Expand All @@ -71,7 +71,7 @@ JNIEXPORT void JNICALL Java_com_example_ImageActivity_brightness(JNIEnv * env, j
LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret); LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
} }


brightness(&info,pixels); brightness(&info,pixels, brightnessValue);


AndroidBitmap_unlockPixels(env, bitmap); AndroidBitmap_unlockPixels(env, bitmap);
} }
Binary file modified libs/armeabi/libimageprocessing.so
Binary file not shown.
Binary file modified obj/local/armeabi/libimageprocessing.so
Binary file not shown.
Binary file modified obj/local/armeabi/objs/imageprocessing/imageprocessing.o
Binary file not shown.
Binary file modified out/production/ImageProcessingTest/ImageProcessingTest.apk
Binary file not shown.
Binary file modified out/production/ImageProcessingTest/ImageProcessingTest.apk.res
Binary file not shown.
Binary file not shown.
Binary file modified out/production/ImageProcessingTest/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/ImageProcessingTest/com/example/R$id.class
Binary file not shown.
Binary file modified out/production/ImageProcessingTest/com/example/R$layout.class
Binary file not shown.
Binary file modified out/production/ImageProcessingTest/com/example/R$string.class
Binary file not shown.
Binary file modified out/production/ImageProcessingTest/com/example/R.class
Binary file not shown.
Binary file modified res/drawable/wallace.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 19 additions & 3 deletions res/layout/main.xml
Expand Up @@ -6,16 +6,32 @@
> >
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="600px" android:layout_width="400px"
android:layout_height="400px" android:layout_height="266px"
/> />


<Button <Button
android:id="@+id/button" android:id="@+id/button"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Adjust Brightness" 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> </LinearLayout>



26 changes: 23 additions & 3 deletions src/com/example/ImageActivity.java
Expand Up @@ -7,11 +7,17 @@
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;


public class ImageActivity extends Activity { public class ImageActivity extends Activity {
private ImageView imageView; private ImageView imageView;
private Bitmap bitmap; private Bitmap bitmap;
private Button button; private Button button;
private SeekBar seekBar;
private float brightness;
private TextView label;
private Bitmap original;


static { static {
System.loadLibrary("imageprocessing"); System.loadLibrary("imageprocessing");
Expand All @@ -21,22 +27,36 @@ public class ImageActivity extends Activity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.main); setContentView(R.layout.main);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.wallace); original = BitmapFactory.decodeResource(getResources(), R.drawable.wallace);


imageView = (ImageView) findViewById(R.id.imageView); imageView = (ImageView) findViewById(R.id.imageView);
button = (Button) findViewById(R.id.button); button = (Button) findViewById(R.id.button);
seekBar = (SeekBar) findViewById(R.id.seekBar);
label = (TextView) findViewById(R.id.label);

button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
adjustBrightness(); 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() { private void adjustBrightness() {
brightness(bitmap); Bitmap bitmap = original.copy(Bitmap.Config.ARGB_8888, true);
brightness(bitmap, brightness);
imageView.setImageBitmap(bitmap); 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.