Skip to content

Commit

Permalink
fixes reducing color filters
Browse files Browse the repository at this point in the history
adds option “p” to process image, as running each time was too slow and
causing exceptions.
  • Loading branch information
catehstn committed May 31, 2014
1 parent 2158505 commit 9f459d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class ImageFilterApp extends PApplet {
static final String INSTRUCTIONS = "R: increase red filter\nE: reduce red filter\n"
+ "G: increase green filter\nF: reduce green filter\nB: increase blue filter\n"
+ "V: reduce blue filter\nI: increase hue tolerance\nU: reduce hue tolerance\n"
+ "S: show dominant hue\nH: hide dominant hue\nC: choose a new file\n"
+ "W: save file\nSPACE: reset image";
+ "S: show dominant hue\nH: hide dominant hue\nP: process image\n"
+ "C: choose a new file\nW: save file\nSPACE: reset image";

static final int FILTER_HEIGHT = 2;
static final int FILTER_INCREMENT = 5;
Expand All @@ -27,6 +27,8 @@ public class ImageFilterApp extends PApplet {
static final int SIDE_BAR_WIDTH = RGB_COLOR_RANGE + 2 * SIDE_BAR_PADDING + 50;

private ImageState imageState;

boolean redrawImage = true;

public void setup() {
noLoop();
Expand All @@ -40,9 +42,15 @@ public void setup() {
}

public void draw() {
background(0);

// Draw image.
if (imageState.image().image() != null && redrawImage) {
background(0);
drawImage();
}

colorMode(RGB, RGB_COLOR_RANGE);
fill(0);
rect(IMAGE_MAX, 0, SIDE_BAR_WIDTH, IMAGE_MAX);
stroke(RGB_COLOR_RANGE);
line(IMAGE_MAX, 0, IMAGE_MAX, IMAGE_MAX);

Expand Down Expand Up @@ -76,12 +84,9 @@ public void draw() {
x + imageState.hueTolerance(), y + FILTER_HEIGHT);

y += 4 * SIDE_BAR_PADDING;
fill(RGB_COLOR_RANGE);
text(INSTRUCTIONS, x, y);

// Draw image.
if (imageState.image() != null) {
drawImage();
}
updatePixels();
}

Expand All @@ -92,6 +97,7 @@ public void fileSelected(File file) {
} else {
imageState.setFilepath(file.getAbsolutePath());
imageState.setUpImage(this, IMAGE_MAX);
redrawImage = true;
redraw();
}
}
Expand All @@ -101,18 +107,23 @@ private void drawImage() {
imageState.updateImage(this, HUE_RANGE, RGB_COLOR_RANGE);
image(imageState.image().image(), IMAGE_MAX/2, IMAGE_MAX/2, imageState.image().getWidth(),
imageState.image().getHeight());
redrawImage = false;
}

public void keyPressed() {
switch(key) {
case 'c':
chooseFile();
break;
case 'p':
redrawImage = true;
break;
case 'w':
imageState.image().save(imageState.filepath() + "-new.png");
break;
case ' ':
imageState.resetImage(this, IMAGE_MAX);
redrawImage = true;
break;
}
imageState.processKeyPress(key, FILTER_INCREMENT, RGB_COLOR_RANGE, HUE_INCREMENT, HUE_RANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class IFAImage {
private PImage image;

public IFAImage() {
image = new PImage(); // SHOULD NOT USE THIS, change to createImage() as per documentation.
image = null;
}

public PImage image() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ enum ColorMode {
public static final int INITIAL_HUE_TOLERANCE = 5;

ColorMode colorModeState = ColorMode.COLOR_FILTER;
//boolean dominantHueHidden = false;
//boolean dominantHueShowing = false;
int blueFilter = 0;
int greenFilter = 0;
int hueTolerance = 0;
Expand Down Expand Up @@ -65,6 +63,7 @@ public String filepath() {
}

public void updateImage(PApplet applet, int hueRange, int rgbColorRange) {
image.update(applet, filepath);
if (colorModeState == ColorMode.SHOW_DOMINANT_HUE) {
colorHelper.processImageForHue(applet, image, hueRange, hueTolerance, true);
} else if (colorModeState == ColorMode.HIDE_DOMINANT_HUE) {
Expand Down

0 comments on commit 9f459d1

Please sign in to comment.