Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / enhancement / LinearStretchEnhancementFloatFilter.java @ 2443

History | View | Annotate | Download (2.93 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 float. 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 LinearStretchEnhancementFloatFilter extends LinearStretchEnhancementFilter {
34
                
35
        public void process(int col, int line) {
36
                for (int destinationBand = 0; destinationBand < renderBands.length; destinationBand++) {
37
                        if(renderBands[destinationBand] >= 0) {
38
                                float p = raster.getElemFloat(line, col, destinationBand);
39
                                if (destinationBand < scaleOffsetList.length)
40
                                        processValue(p, scaleOffsetList[destinationBand], col, line, destinationBand);
41
                                else
42
                                        rasterResult.setElem(line, col, destinationBand, (byte) p);
43
                        }
44
                }
45
        }
46

    
47
        /**
48
         * Procesa un dato del raster aplicandole el factor de escala y desplazamiento que
49
         * necesita.
50
         * @param p Valor del punto
51
         * @param data Estructura de datos con los valores de escala y desplazamiento
52
         * @param col Columna del valor dentro del raster
53
         * @param line L?nea del valor dentro del raster
54
         * @param iBand N?mero de banda del valor dentro del raster
55
         * @return true si ha podido ser procesado y false si no lo hace
56
         */
57
        private void processValue(float p, DefaultStretch data, int col, int line, int iBand) {
58
                if (data.scale != null) {
59
                        if (p > data.maxValue)
60
                                p = (float) data.maxValue;
61
                        else
62
                                if (p < data.minValue)
63
                                        p = (float) data.minValue;
64

    
65
                        for (int i = 0; i < data.scale.length; i++) {
66
                                if ((p > data.stretchIn[i] && p <= data.stretchIn[i + 1]) || (i == 0 && p == data.stretchIn[i])) {
67
                                        p = (float) ((((double) p) - data.stretchIn[i]) * data.scale[i] + data.offset[i]);
68
                                        break;
69
                                }
70
                        }
71
                        rasterResult.setElem(line, col, iBand, (byte) (((byte) p) & 0xff));
72
                }
73
        }
74
        
75
        public int getInRasterDataType() {
76
                return Buffer.TYPE_FLOAT;
77
        }
78
}