-
Notifications
You must be signed in to change notification settings - Fork 0
/
EndeavorImageManip.java
49 lines (40 loc) · 1.27 KB
/
EndeavorImageManip.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.awt.image.*;
import java.awt.*;
import javax.swing.*;
/**
* High-level image editing abstract class for the Endeavor image editing program.
*
* @author Joseph Daly
* @version 0.0.1
*/
public abstract class EndeavorImageManip
{
public static void apply_effect(Container c, BufferedImage img, EndeavorTool effect)
{
effect.configure(c);
// Traverses every pixel in the image
int y = 0;
while(y < img.getHeight())
{
for(int x = 0; x < img.getWidth(); x++)
{
// Uses bitwise operators to deconstruct RGB from ColorInt
int color = img.getRGB(x, y);
int red = (color & 0x00FF0000) >> 16;
int green = (color & 0x0000FF00) >> 8;
int blue = color & 0x000000FF;
int[] result = effect.act(red, green, blue);
red = result[0];
green = result[1];
blue = result[2];
// Re-applies RGB, converting to ColorInt.
red = (red << 16) & 0x00FF0000;
green = (green << 8) & 0x0000FF00;
blue = blue & 0x000000FF;
// Applies changes to image
img.setRGB(x, y, 0xFF000000 | red | green | blue);
}
y++;
}
}
}