App
FilterLayer.java
Go to the documentation of this file.
1 package mhr.appcore.image.layers.filter;
2 
3 import org.w3c.dom.Element;
4 
5 import mhr.appcore.bitmap.NBitmap;
6 import mhr.appcore.bitmap.exceptions.BitmapAllocationException;
7 import mhr.appcore.bitmap.exceptions.UnsupportedBitmapException;
8 import mhr.appcore.exceptions.AlreadyDisposedException;
9 import mhr.appcore.filters.Filter;
10 import mhr.appcore.image.Image;
11 import mhr.appcore.image.layers.Layer;
12 import mhr.appcore.interfaces.ImageFile;
13 import mhr.appcore.pointops.LUT;
14 import mhr.appcore.utils.Rect;
15 
19 public abstract class FilterLayer extends Layer {
20 
21  //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
22  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
23  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
24 
25  //===== FIELDS ==============================================================================================================================//
26  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
27  protected Filter filter = null;
28  protected int extraMargin = 0;
29 
30  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
31 
32  //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
33  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
34  @Override
35  protected void finalize() throws Throwable {
36  dispose();
37  super.finalize();
38  }
39 
40  protected FilterLayer(Layer l, int newId) {
41  super(l, newId);
42  }
43 
44  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
51  super(owner, id);
52  }
53 
54  public FilterLayer(Image owner, Element i, ImageFile f) {
55  super(owner, i, f);
56  }
57 
58  @Override
59  public synchronized int dispose() {
60  super.dispose();
61  if (filter != null) {
62  filter.dispose();
63  filter = null;
64  }
65  return 0;
66  }
67 
68  //===== METHODS =============================================================================================================================//
69  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
70  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
71 
76  public Filter getFilter() {
77  return filter;
78  }
79 
80  @Override
81  public int getExtraMargin() {
82  return extraMargin;
83  }
84 
85 //----- Pole --------------------------------------------------------------------------------------------------------------------------------//
86 
87 //----- Accessory a primitivní metody -------------------------------------------------------------------------------------------------------//
88 
89 //----- Pomocné metody ----------------------------------------------------------------------------------------------------------------------//
90 //----- Konstruktory ------------------------------------------------------------------------------------------------------------------------//
91 
92 //----- Destruktory -------------------------------------------------------------------------------------------------------------------------//
93 
94 //----- Metody ------------------------------------------------------------------------------------------------------------------------------//
95  @Override
96  public int applyTo(NBitmap dst) {
97  if (!visible) {
98  return 0;
99  }
100  if (filter == null) {
101  throw new AlreadyDisposedException("Layer is already disposed");
102  }
103  if (isMaskActive()) {
104  return filter.applyTo(dst, mask, mask.getRect(), 0, 0, opacity);
105  } else {
106  return filter.applyTo(dst, dst.getRect(), opacity);
107  }
108  }
109 
110  @Override
111  public int applyTo(NBitmap dst, Rect srcRect, int srcOrigX, int srcOrigY) {
112  if (!visible) {
113  return 0;
114  }
115  if (filter == null) {
116  throw new AlreadyDisposedException("Layer is already disposed");
117  }
118  if (isMaskActive()) {
119  return filter.applyTo(dst, mask, srcRect, srcOrigX, srcOrigY, opacity);
120 // return lut.applyTo(dst, mask, srcRect, 0, 0, opacity);
121  } else {
122  return filter.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 (filter == null) {
132  throw new AlreadyDisposedException("Layer is already disposed");
133  }
134  if (isMaskActive()) {
135  return filter.applyTo(dst, forcedMask, srcRect, srcOrigX, srcOrigY, opacity);
136 // return lut.applyTo(dst, forcedMask, srcRect, 0, 0, opacity);
137  } else {
138  return filter.applyTo(dst, srcRect, opacity);
139  }
140  }
141 
142 }