App
GammaLUTLayer.java
Go to the documentation of this file.
1 package mhr.appcore.image.layers.lut;
2 
3 import org.w3c.dom.Document;
4 import org.w3c.dom.Element;
5 
6 import mhr.appcore.bitmap.NBitmap;
7 import mhr.appcore.bitmap.exceptions.BitmapAllocationException;
8 import mhr.appcore.bitmap.exceptions.UnsupportedBitmapException;
9 import mhr.appcore.exceptions.AlreadyDisposedException;
10 import mhr.appcore.image.Image;
11 import mhr.appcore.image.exceptions.InvalidLayerSpecificPresentationSuppliedException;
12 import mhr.appcore.image.exceptions.LayerCreationException;
13 import mhr.appcore.image.layers.Layer;
14 import mhr.appcore.image.layers.LayerPDInfo;
15 import mhr.appcore.image.layers.LayerType;
16 import mhr.appcore.interfaces.ImageFile;
17 import mhr.appcore.pointops.LUT;
18 import mhr.appcore.pointops.LUTAllocationException;
19 import mhr.appcore.utils.Rect;
20 
24 public class GammaLUTLayer extends LUTLayer {
25 
26  //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
27  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
28  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
29 
30  //===== FIELDS ==============================================================================================================================//
31  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
32  protected double gamma = 1;
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 GammaLUTLayer(GammaLUTLayer l, int newId) {
44  super(l, newId);
45  lut = LUT.getGammaLut(l.gamma);
46  }
47 
48  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
58  super(owner, id);
60  }
61 
62  public GammaLUTLayer(Image owner, Element i, ImageFile f) {
63  super(owner, i, f);
64  try {
65  gamma = Double.parseDouble(i.getElementsByTagName("Gamma").item(0).getTextContent());
66  } catch (Exception e) {
67  throw new LayerCreationException(e);
68  }
69 
71  }
72 
73  @Override
74  public synchronized int dispose() {
75  super.dispose();
76  return 0;
77  }
78 
79  //===== METHODS =============================================================================================================================//
80  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
81  protected void fillSpecificElement(Document d, ImageFile f, Element e) {
82  appendLeafElement(d, e, "Gamma", Double.toString(gamma));
83  }
84 
85  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
86  @Override
87  public LayerType getType() {
88  return LayerType.LAYER_GAMMA;
89  }
90 
91 
92 //----- Pole --------------------------------------------------------------------------------------------------------------------------------//
93 
94 //----- Accessory a primitivní metody -------------------------------------------------------------------------------------------------------//
95 
96 //----- Pomocné metody ----------------------------------------------------------------------------------------------------------------------//
97 //----- Konstruktory ------------------------------------------------------------------------------------------------------------------------//
98 
99 //----- Destruktory -------------------------------------------------------------------------------------------------------------------------//
100 
101 //----- Metody ------------------------------------------------------------------------------------------------------------------------------//
102 
103  @Override
104  public Layer duplicate(int newId) {
105  return new GammaLUTLayer(this, newId);
106  }
107 
108  @Override
109  protected void updateSpecificData(LayerPDInfo info) {
111  p.gamma = gamma;
112  info.extra = p;
113  }
114 
115  @Override
116  public void updateFromSpecificPresentation(LayerPDInfo presentation) {
117  if (!(presentation.extra instanceof GammaLUTLayerSpecificPresentation)) {
118  throw new InvalidLayerSpecificPresentationSuppliedException("Invalid specific data supplied");
119  }
120  GammaLUTLayerSpecificPresentation p = (GammaLUTLayerSpecificPresentation) presentation.extra;
121  gamma = p.gamma;
122  if (lut != null) {
123  lut.dispose();
124  }
126 
127  presentation.isChanged = true;
128  }
129 }