App
LUTLayer.java
Go to the documentation of this file.
1 package mhr.appcore.image.layers.lut;
2 
3 import org.w3c.dom.Element;
4 
5 import mhr.appcore.bitmap.BitmapInfo;
6 import mhr.appcore.bitmap.ChannelCount;
7 import mhr.appcore.bitmap.ColorMode;
8 import mhr.appcore.bitmap.NBitmap;
9 import mhr.appcore.bitmap.exceptions.BitmapAllocationException;
10 import mhr.appcore.bitmap.exceptions.UnsupportedBitmapException;
11 import mhr.appcore.blending.BlendMode;
12 import mhr.appcore.exceptions.AlreadyDisposedException;
13 import mhr.appcore.image.Image;
14 import mhr.appcore.image.layers.Layer;
15 import mhr.appcore.interfaces.ImageFile;
16 import mhr.appcore.interfaces.PDBitmap;
17 import mhr.appcore.pointops.LUT;
18 import mhr.appcore.utils.Rect;
19 
23 public abstract class LUTLayer extends Layer {
24 
25  //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
26  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
27  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
28 
29  //===== FIELDS ==============================================================================================================================//
30  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
31  protected LUT lut = null;
32 
33  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
34 
35  //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
36  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
37  @Override
38  protected void finalize() throws Throwable {
39  dispose();
40  super.finalize();
41  }
42 
43  protected LUTLayer(Layer l, int newId) {
44  super(l, newId);
45  }
46 
47  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
48 
49 
56  super(owner, id);
57  }
58 
59  public LUTLayer(Image owner, Element i, ImageFile f) {
60  super(owner, i, f);
61  }
62 
63  @Override
64  public synchronized int dispose() {
65  super.dispose();
66  if (lut != null) {
67  lut.dispose();
68  lut = null;
69  }
70  return 0;
71  }
72 
73  //===== METHODS =============================================================================================================================//
74  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
75  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
76 
81  public LUT getLut() {
82  return lut;
83  }
84 
85 //----- Pole --------------------------------------------------------------------------------------------------------------------------------//
86 
87 //----- Accessory a primitivní metody -------------------------------------------------------------------------------------------------------//
88 
89 //----- Pomocné metody ----------------------------------------------------------------------------------------------------------------------//
90 //----- Konstruktory ------------------------------------------------------------------------------------------------------------------------//
91 
92 //----- Destruktory -------------------------------------------------------------------------------------------------------------------------//
93 
94 //----- Metody ------------------------------------------------------------------------------------------------------------------------------//
95 
96  @Override
97  public int applyTo(NBitmap dst) {
98  if (!visible) {
99  return 0;
100  }
101  if (lut == null) {
102  throw new AlreadyDisposedException("Layer is already disposed");
103  }
104  if (isMaskActive()) {
105  return lut.applyTo(dst, mask, mask.getRect(), 0, 0, opacity);
106  } else {
107  return lut.applyTo(dst, dst.getRect(), opacity);
108  }
109  }
110 
111  @Override
112  public int applyTo(NBitmap dst, Rect srcRect, int srcOrigX, int srcOrigY) {
113  if (!visible) {
114  return 0;
115  }
116  if (lut == null) {
117  throw new AlreadyDisposedException("Layer is already disposed");
118  }
119  if (isMaskActive()) {
120  return lut.applyTo(dst, mask, srcRect, srcOrigX, srcOrigY, opacity);
121  } else {
122  return lut.applyTo(dst, srcRect, opacity);
123  }
124  }
125 
126  @Override
127  public int applyTo(NBitmap dst, Rect srcRect, int srcOrigX, int srcOrigY, NBitmap forcedMask) {
128  if (!visible) {
129  return 0;
130  }
131  if (lut == null) {
132  throw new AlreadyDisposedException("Layer is already disposed");
133  }
134  if (isMaskActive()) {
135  return lut.applyTo(dst, forcedMask, srcRect, srcOrigX, srcOrigY, opacity);
136  } else {
137  return lut.applyTo(dst, srcRect, opacity);
138  }
139  }
140 }