blob: 0a6285623a38f63b82d78fe87c56470204d1ab7b (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package bjc.imgchain.pipeline.stages;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import bjc.imgchain.ImgChain;
import bjc.imgchain.ImgPickerPanel;
import bjc.imgchain.pipeline.StageType;
import bjc.imgchain.utils.Utils;
/**
* Mask an image onto another one.
* @author bjculkin
*
*/
public class AddMaskStage extends AbstractPipelineStage {
private String masqueName;
/**
* Create a masking stage.
*/
public AddMaskStage() {
super(StageType.IMGTRANS);
}
@Override
public Image process(Image inp) {
BufferedImage buf = (BufferedImage) inp;
BufferedImage masque = (BufferedImage) ImgChain.chan.imageRepo.get(masqueName);
for (int y = 0; y < buf.getHeight(); y++) {
for (int x = 0; x < buf.getWidth(); x++) {
int[] pix = Utils.toARGBQuad(buf.getRGB(x, y));
int[] msq = Utils.toARGBQuad(masque.getRGB(x, y));
pix[1] += msq[1];
pix[2] += msq[2];
pix[3] += msq[3];
buf.setRGB(x, y, Utils.fromARGBQuad(pix));
}
}
return buf;
}
@Override
public String name() {
return "Additive Mask";
}
@Override
public String description() {
return "Add two images togethers";
}
@Override
public JComponent getEditor() {
ImgPickerPanel pan = new ImgPickerPanel("Mask name");
pan.imgField.field.addPropertyChangeListener("value", (ev) -> {
masqueName = pan.imgField.field.getText();
});
return pan;
}
}
|