Skip to content
Browse files

histogram coloring working, but unstable and slow

  • Loading branch information...
1 parent b55b1c5 commit 5c987caccddc47cf22451b721c9deb57adf606eb @dbyrne committed Mar 21, 2010
Showing with 30 additions and 1 deletion.
  1. +11 −0 src/byrne/fractal/FractalView.java
  2. +19 −1 src/byrne/fractal/GenerateFractalTask.java
View
11 src/byrne/fractal/FractalView.java
@@ -31,6 +31,7 @@
import android.content.res.Configuration;
import android.util.AttributeSet;
import byrne.fractal.MultiTouchController.*;
+import java.util.ArrayList;
public class FractalView extends View implements MultiTouchObjectCanvas<FractalView.Img> {
@@ -52,6 +53,8 @@
private int[] colorIntegers;
private final NativeLib mNativeLib = new NativeLib();
+ ArrayList<Integer> histogram;
+
public FractalView(Context context){
super(context);
res = context.getResources();
@@ -181,6 +184,13 @@ private void calculateColors(int numberOfColors) {
}
}
+ public void setHistogram(ArrayList<Integer> a) {
+ histogram = a;
+ }
+
+ public ArrayList<Integer> getHistogram() {
+ return histogram;
+ }
public void setColorSet(ColorSet cs) {
colorSet = cs;
@@ -310,6 +320,7 @@ public void startFractalTask(boolean reset) {
stopFractalTask();
if (reset) {
+ histogram = new ArrayList();
mNativeLib.resetValues();
relative = false;
}
View
20 src/byrne/fractal/GenerateFractalTask.java
@@ -21,6 +21,9 @@
import android.os.AsyncTask;
import android.graphics.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
public class GenerateFractalTask extends AsyncTask<Void, Bitmap, Bitmap> {
@@ -31,6 +34,7 @@
int[] colors;
int prog = 0;
boolean relative;
+ ArrayList<Integer> histogram;
public GenerateFractalTask(FractalView fv, boolean rel) {
fractalView = fv;
@@ -43,6 +47,16 @@ public GenerateFractalTask(FractalView fv, boolean rel) {
private Bitmap createBitmap() {
+ histogram = fractalView.getHistogram();
+ HashMap<Integer,Integer> map = new HashMap();
+ if (relative) {
+ int count = 0;
+ for (int i : histogram) {
+ map.put(i,count);
+ count++;
+ }
+ }
+
double realmin = mNativeLib.getRealMin();
double realmax = mNativeLib.getRealMax();
double imagmin = mNativeLib.getImagMin();
@@ -100,8 +114,10 @@ private Bitmap createBitmap() {
if (rowColors[col] >= 0) {
if (relative) {
- paint.setColor(colors[Math.round(((float)(rowColors[col]-minimum)/range)*1020)]);
+ int cindex = Math.round(((float)map.get(rowColors[col])/histogram.size())*1020);
+ paint.setColor(colors[cindex]);
} else {
+ histogram.add(rowColors[col]);
paint.setColor(colors[(rowColors[col]%10200)/10]);
}
} else {
@@ -127,6 +143,8 @@ private Bitmap createBitmap() {
fractalView.invalidate();
}
@Override protected void onPostExecute(Bitmap b) {
+ Collections.sort(histogram);
+ fractalView.setHistogram(histogram);
fractalView.setFractal(b);
fractalView.clearBackground();
fractalView.setTime(System.currentTimeMillis()-startTime);

0 comments on commit 5c987ca

Please sign in to comment.
Something went wrong with that request. Please try again.