gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / FilterLoaderImpl.java @ 2308
History | View | Annotate | Download (2.53 KB)
1 |
package org.gvsig.raster.impl.grid.filter; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
4 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
5 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
6 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
7 |
import org.gvsig.fmap.dal.coverage.filter.FilterLoader; |
8 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
9 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
10 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
11 |
import org.slf4j.LoggerFactory; |
12 |
|
13 |
/**
|
14 |
* <P>
|
15 |
* Applies the stack of filters to a buffer. With the same <code>FilterLoader</code>
|
16 |
* you can process different buffers. Each buffer can use a different environment
|
17 |
* </P>
|
18 |
*
|
19 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
20 |
*/
|
21 |
public class FilterLoaderImpl implements FilterLoader { |
22 |
private RasterFilterList filterList = null; |
23 |
|
24 |
/**
|
25 |
* Creates a filter loader with a default filter list
|
26 |
* @param dataType
|
27 |
*/
|
28 |
public FilterLoaderImpl(int dataType) { |
29 |
this.filterList = RasterLocator.getManager().createEmptyFilterList(dataType);
|
30 |
} |
31 |
|
32 |
/**
|
33 |
* Creates a filter loader with the list of filters passed by parameter
|
34 |
* @param filterList
|
35 |
*/
|
36 |
public FilterLoaderImpl(RasterFilterList filterList) {
|
37 |
this.filterList = filterList;
|
38 |
} |
39 |
|
40 |
public void addTransparency(Transparency transparency) { |
41 |
filterList.addEnvParam("Transparency", transparency.cloneTransparency());
|
42 |
} |
43 |
|
44 |
public void addSrcDataType(int datatype) { |
45 |
filterList.addEnvParam("SrcDataType", datatype);
|
46 |
} |
47 |
|
48 |
public void addSrcBandCount(int bandcount) { |
49 |
filterList.addEnvParam("SrcBandCount", bandcount);
|
50 |
} |
51 |
|
52 |
public void addSrcStatistics(Statistics statistics) { |
53 |
filterList.addEnvParam("SrcStatistics", statistics);
|
54 |
} |
55 |
|
56 |
public Buffer applyFilters(Buffer buffer) { |
57 |
//Checks if the transparency is inside the buffer
|
58 |
Transparency transparency = (Transparency)filterList.getEnvParam("Transparency"); |
59 |
if(transparency.existAlphaBand() && transparency.getAlphaBandNumber() >= buffer.getBandCount()) {
|
60 |
transparency.setTransparencyBand(-1);
|
61 |
transparency.activeTransparency(); |
62 |
} |
63 |
filterList.setInitRasterBuf(buffer); |
64 |
try {
|
65 |
filterList.execute(); |
66 |
} catch (ProcessInterruptedException e) {
|
67 |
return buffer;
|
68 |
} catch (FilterAddException e) {
|
69 |
LoggerFactory.getLogger(this.getClass()).debug("Filters cannot be applied", e); |
70 |
return buffer;
|
71 |
} |
72 |
if(filterList.getResult() != null) |
73 |
return (Buffer) filterList.getResult(); |
74 |
return buffer;
|
75 |
} |
76 |
|
77 |
public Transparency getTransparency() { |
78 |
return filterList.getTransparency();
|
79 |
} |
80 |
} |