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

History | View | Annotate | Download (2.9 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 byte. 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 LinearStretchEnhancementByteFilter extends LinearStretchEnhancementFilter {
34
                
35
        public void process(int col, int line) {
36
                for (int iBand = 0; iBand < numberOfBandsToProcess(); iBand++) {
37
                        int p;
38
                        if (stretchs.rgb)
39
                                p = (int) (raster.getElemByte(line, col, iBand) & 0xff);
40
                        else
41
                                p = (int) raster.getElemByte(line, col, iBand);
42

    
43
                        if (iBand < scaleOffsetList.length)
44
                                processValue(p, scaleOffsetList[iBand], col, line, iBand);
45
                        else
46
                                rasterResult.setElem(line, col, iBand, (byte) p);
47
                }
48
                writeAlphaBand(line, col);
49
        }
50
        
51
        /**
52
         * Procesa un dato del raster aplicandole el factor de escala y desplazamiento que
53
         * necesita.
54
         * @param p Valor del punto
55
         * @param data Estructura de datos con los valores de escala y desplazamiento
56
         * @param col Columna del valor dentro del raster
57
         * @param line L?nea del valor dentro del raster
58
         * @param iBand N?mero de banda del valor dentro del raster
59
         * @return true si ha podido ser procesado y false si no lo hace
60
         */
61
        private void processValue(int p, DefaultStretch data, int col, int line, int iBand) {
62
                if(data.scale != null) {
63
                        if (p > data.maxValue)
64
                                p = (int) data.maxValue;
65
                        else if (p < data.minValue)
66
                                p = (int) data.minValue;
67
                        
68
                        for (int i = 0; i < data.scale.length; i++) {
69
                                if((p > data.stretchIn[i] && p <= data.stretchIn[i + 1]) || (i == 0 && p == data.stretchIn[i])) {
70
                                        p =  (int)( (((double)p) - data.stretchIn[i]) * data.scale[i] + data.offset[i]);
71
                                        break;
72
                                }
73
                        }
74
                        rasterResult.setElem(line, col, iBand, (byte)p);
75
                }
76
        }
77

    
78
        public int getInRasterDataType() {
79
                return Buffer.TYPE_BYTE;
80
        }
81
}