App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

AlphaBrush.java
Go to the documentation of this file.
1 package mhr.appcore.tools.brushlike;
2
3 import mhr.appcore.bitmap.NBitmap;
4 import mhr.appcore.blending.Blender;
5 import mhr.appcore.image.Image;
6 import mhr.appcore.tools.actiondata.ToolActionData;
7 import mhr.appcore.utils.Rect;
8
14 public class AlphaBrush extends BrushLikeTool {
15
16 protected BrushMode alphaMode;
17
26 public AlphaBrush(NBitmap brush, BrushMode mode, double opacity, double flow, double spacing) {
27 super(brush, BrushMode.MODE_ADD, opacity, flow, spacing);
28 alphaMode = mode;
29 }
30
31 @Override
32 public void applyTo(Image img, ToolActionData data) {
33 super.applyTo(img, data);
34 }
35
36 @Override
37 public void onRender(Image i, NBitmap c, NBitmap l, NBitmap o, NBitmap m, Rect src, int srcOrigX, int srcOrigY) {
38 o.copyTo(l, src, srcOrigX, srcOrigY);
39 switch (l.getInfo().channelCount) {
40 case SINGLE_CHANNEL:
41 switch (alphaMode) {
42 case MODE_ADD:
43 Blender.addTo(l, c, src, srcOrigX, srcOrigY, opacity);
44 break;
45 case MODE_REMOVE:
46 Blender.removeFrom(l, c, src, srcOrigX, srcOrigY, opacity);
47 break;
48 default:
49 break;
50 }
51 break;
52 case FOUR_CHANNEL:
53 switch (alphaMode) {
54 case MODE_ADD:
55 Blender.addTo4ch(l, c, src, srcOrigX, srcOrigY, opacity);
56 break;
57 case MODE_REMOVE:
58 Blender.removeFrom4ch(l, c, src, srcOrigX, srcOrigY, opacity);
59 break;
60 default:
61 break;
62 }
63 break;
64 default:
65 break;
66 }
67 }
68
69 @Override
70 public void onCommit(Image i, NBitmap c, NBitmap l, NBitmap o, NBitmap m, Rect src, int srcOrigX, int srcOrigY) {
71 switch (l.getInfo().channelCount) {
72 case SINGLE_CHANNEL:
73 switch (alphaMode) {
74 case MODE_ADD:
75 Blender.addTo(o, c, src, srcOrigX, srcOrigY, opacity);
76 break;
77 case MODE_REMOVE:
78 Blender.removeFrom(o, c, src, srcOrigX, srcOrigY, opacity);
79 break;
80 default:
81 break;
82 }
83 break;
84 case FOUR_CHANNEL:
85 switch (alphaMode) {
86 case MODE_ADD:
87 Blender.addTo4ch(o, c, src, srcOrigX, srcOrigY, opacity);
88 break;
89 case MODE_REMOVE:
90 Blender.removeFrom4ch(o, c, src, srcOrigX, srcOrigY, opacity);
91 break;
92 default:
93 break;
94 }
95 break;
96 default:
97 break;
98 }
99
100 }
101 }