blob: a7dc7732a0235ac9bc9aa17caff44e155f914952 (
plain)
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
50
51
|
package bjc.imgchain.pipeline.stages;
import javax.swing.JComponent;
import javax.swing.JLabel;
import bjc.imgchain.pipeline.StageType;
/**
* Transforms an image to a greyscale version.
*
* @author Ben Culkin
*
*/
public class GreyscaleStage extends AbstractPixelStage {
/**
* Create a new greyscale stage.
*/
public GreyscaleStage() {
super(StageType.IMGTRANS);
}
@Override
public int[] processPixel(int[] pix) {
int[] ret = new int[4];
int avg = (pix[1] + pix[2] + pix[3]) / 3;
ret[0] = pix[0];
ret[1] = avg;
ret[2] = avg;
ret[3] = avg;
return ret;
}
@Override
public String name() {
return "Greyscale";
}
@Override
public String description() {
return "Convert an image into greyscale color";
}
@Override
public JComponent getEditor() {
return new JLabel("No configuration possible");
}
}
|