Statistics
| Revision:

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 / LinearStretchEnhancementFloatFilter.java @ 2311

History | View | Annotate | Download (2.8 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 iBand = 0; iBand < numberOfBandsToProcess(); iBand++) {
37
                        float p = raster.getElemFloat(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(float p, DefaultStretch data, int col, int line, int iBand) {
56
                if (data.scale != null) {
57
                        if (p > data.maxValue)
58
                                p = (float) data.maxValue;
59
                        else
60
                                if (p < data.minValue)
61
                                        p = (float) data.minValue;
62

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