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 / enhancement / LinearStretchEnhancementIntegerFilter.java @ 2311
History | View | Annotate | Download (2.79 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.grid.filter.enhancement; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
25 |
import org.gvsig.raster.impl.datastruct.DefaultStretch; |
26 |
/**
|
27 |
* Filtro de realce lineal para tipos de datos int. El realce es aplicado por intervalos.
|
28 |
* Para cada pixel se obtiene en que intervalo se encuentra y se aplica la scala y offset
|
29 |
* calculados para ese intervalo.
|
30 |
*
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
32 |
*/
|
33 |
public class LinearStretchEnhancementIntegerFilter extends LinearStretchEnhancementFilter { |
34 |
|
35 |
public void process(int col, int line) { |
36 |
for (int iBand = 0; iBand < numberOfBandsToProcess(); iBand++) { |
37 |
int p = raster.getElemInt(line, col, iBand);
|
38 |
if (iBand < scaleOffsetList.length)
|
39 |
processValue(p, scaleOffsetList[iBand], col, line, iBand); |
40 |
else
|
41 |
rasterResult.setElem(line, col, iBand, (byte) p);
|
42 |
} |
43 |
} |
44 |
|
45 |
/**
|
46 |
* Procesa un dato del raster aplicandole el factor de escala y desplazamiento que
|
47 |
* necesita.
|
48 |
* @param p Valor del punto
|
49 |
* @param data Estructura de datos con los valores de escala y desplazamiento
|
50 |
* @param col Columna del valor dentro del raster
|
51 |
* @param line L?nea del valor dentro del raster
|
52 |
* @param iBand N?mero de banda del valor dentro del raster
|
53 |
* @return true si ha podido ser procesado y false si no lo hace
|
54 |
*/
|
55 |
private void processValue(int p, DefaultStretch data, int col, int line, int iBand) { |
56 |
if(data.scale != null) { |
57 |
if (p > data.maxValue)
|
58 |
p = (int) data.maxValue;
|
59 |
else if (p < data.minValue) |
60 |
p = (int) data.minValue;
|
61 |
|
62 |
for (int i = 0; i < data.scale.length; i++) { |
63 |
if((p > data.stretchIn[i] && p <= data.stretchIn[i + 1]) || (i == 0 && p == data.stretchIn[i])) { |
64 |
p = (int)( (((double)p) - data.stretchIn[i]) * data.scale[i] + data.offset[i]); |
65 |
break;
|
66 |
} |
67 |
} |
68 |
rasterResult.setElem(line, col, iBand, (byte)(((byte) p) & 0xff)); |
69 |
} |
70 |
} |
71 |
|
72 |
public int getInRasterDataType() { |
73 |
return Buffer.TYPE_INT; |
74 |
} |
75 |
} |