App

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

- File List
- File Members

ColorLayer.java
Go to the documentation of this file.
1 package mhr.appcore.image.layers;
2
3 import org.w3c.dom.Document;
4 import org.w3c.dom.Element;
5
6 import mhr.appcore.bitmap.BitmapInfo;
7 import mhr.appcore.bitmap.ChannelCount;
8 import mhr.appcore.bitmap.ColorMode;
9 import mhr.appcore.bitmap.NBitmap;
10 import mhr.appcore.bitmap.exceptions.BitmapAllocationException;
11 import mhr.appcore.bitmap.exceptions.UnsupportedBitmapException;
12 import mhr.appcore.blending.BlendMode;
13 import mhr.appcore.blending.Blender;
14 import mhr.appcore.exceptions.AlreadyDisposedException;
15 import mhr.appcore.image.Image;
16 import mhr.appcore.image.exceptions.InvalidLayerSpecificPresentationSuppliedException;
17 import mhr.appcore.interfaces.ImageFile;
18 import mhr.appcore.interfaces.PDBitmap;
19 import mhr.appcore.interpolators.Interpolator;
20 import mhr.appcore.utils.NotImplementedException;
21 import mhr.appcore.utils.Rect;
22
26 public class ColorLayer extends Layer {
27
28 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
29 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
30 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
31
32 //===== FIELDS ==============================================================================================================================//
33 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
34 protected BlendMode mode;
35 protected int color;
36 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
37
38 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
39
40 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
41 @Override
42 protected void finalize() throws Throwable {
43 dispose();
44 super.finalize();
45 }
46
47 protected ColorLayer(ColorLayer l, int newId) {
48 super(l, newId);
49 this.color = l.color;
50 this.mode = l.mode;
51 }
52
53 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
59 public ColorLayer(Image owner, int id) {
60 super(owner, id);
61 mode = BlendMode.BLEND_MODE_NORMAL;
62 color = 0xFFFFFFFF;
63 opacity = 0;
64 }
65
66 public ColorLayer(Image owner, Element i, ImageFile f) {
67 super(owner, i, f);
68 mode = BlendMode.valueOf(i.getElementsByTagName("BlendMode").item(0).getTextContent());
69 color = Integer.parseInt(i.getElementsByTagName("Color").item(0).getTextContent());
70 }
71
72 @Override
73 public synchronized int dispose() {
74 super.dispose();
75 return 0;
76 }
77
78
79
80 //===== METHODS =============================================================================================================================//
81 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
82 protected void fillSpecificElement(Document d, ImageFile f, Element e) {
83 appendLeafElement(d, e, "BlendMode", mode.toString());
84 appendLeafElement(d, e, "Color", Integer.toString(color));
85 }
86
87
88 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
89 @Override
90 public LayerType getType() {
91 return LayerType.LAYER_COLOR;
92 }
93
98 public BlendMode getMode() {
99 return mode;
100 }
101
106 public void setMode(BlendMode mode) {
107 this.mode = mode;
108 }
109
110 public int getColor() {
111 return color;
112 }
113
114 public void setColor(int color) {
115 this.color = color;
116 }
117
118
119 //----- Pole --------------------------------------------------------------------------------------------------------------------------------//
120
121 //----- Accessory a primitivní metody -------------------------------------------------------------------------------------------------------//
122
123 //----- Pomocné metody ----------------------------------------------------------------------------------------------------------------------//
124 //----- Konstruktory ------------------------------------------------------------------------------------------------------------------------//
125
126 //----- Destruktory -------------------------------------------------------------------------------------------------------------------------//
127
128 //----- Metody ------------------------------------------------------------------------------------------------------------------------------//
129
130 @Override
131 public Layer duplicate(int newId) {
132 return new ColorLayer(this, newId);
133 }
134
135 @Override
136 public int applyTo(NBitmap dst) {
137 if (!visible) {
138 return 0;
139 }
140 if (opacity < opacityAsNone) {
141 return 0;
142 }
143 if (isMaskActive()) {
144 if (opacity > opacityAsFull) {
145 return Blender.drawTo(mode, dst, mask, color, mask.getRect(), 0, 0);
146 } else {
147 return Blender.drawTo(mode, dst, mask, color, mask.getRect(), 0, 0, opacity);
148 }
149 } else {
150 if (opacity > opacityAsFull) {
151 return Blender.blendTo(mode, dst, color, dst.getRect());
152 } else {
153 return Blender.blendTo(mode, dst, color, dst.getRect(), opacity);
154 }
155 }
156 }
157
158 @Override
159 public int applyTo(NBitmap dst, Rect srcRect, int srcOrigX, int srcOrigY) {
160 if (!visible) {
161 return 0;
162 }
163 if (opacity < opacityAsNone) {
164 return 0;
165 }
166 if (isMaskActive()) {
167 if (opacity > opacityAsFull) {
168 return Blender.drawTo(mode, dst, mask, color, srcRect, srcOrigX, srcOrigY);
169 } else {
170 return Blender.drawTo(mode, dst, mask, color, srcRect, srcOrigX, srcOrigY, opacity);
171 }
172 } else {
173 if (opacity > opacityAsFull) {
174 return Blender.blendTo(mode, dst, color, srcRect);
175 } else {
176 return Blender.blendTo(mode, dst, color, srcRect, opacity);
177 }
178 }
179 }
180
181 @Override
182 public int applyTo(NBitmap dst, Rect srcRect, int srcOrigX, int srcOrigY, NBitmap forcedMask) {
183 if (!visible) {
184 return 0;
185 }
186 if (opacity < opacityAsNone) {
187 return 0;
188 }
189 if (isMaskActive()) {
190 if (opacity > opacityAsFull) {
191 return Blender.drawTo(mode, dst, forcedMask, color, srcRect, srcOrigX, srcOrigY);
192 } else {
193 return Blender.drawTo(mode, dst, forcedMask, color, srcRect, srcOrigX, srcOrigY, opacity);
194 }
195 } else {
196 if (opacity > opacityAsFull) {
197 return Blender.blendTo(mode, dst, color, srcRect);
198 } else {
199 return Blender.blendTo(mode, dst, color, srcRect, opacity);
200 }
201 }
202 }
203
204 @Override
205 protected void updateSpecificData(LayerPDInfo info) {
206 ColorLayerSpecificPresentation p = new ColorLayerSpecificPresentation();
207 p.mode = mode;
208 p.color = color;
209 info.extra = p;
210 }
211
212 @Override
213 public void updateFromSpecificPresentation(LayerPDInfo presentation) {
214 if (!(presentation.extra instanceof ColorLayerSpecificPresentation)) {
215 throw new InvalidLayerSpecificPresentationSuppliedException("Invalid specific data supplied");
216 }
217 ColorLayerSpecificPresentation p = (ColorLayerSpecificPresentation) presentation.extra;
218 mode = p.mode;
219 color = p.color;
220 presentation.isChanged = true;
221 }
222
223
224 }