Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / LinearStretchEnhancementByteFilter.java @ 27361

History | View | Annotate | Download (3.27 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.grid.filter.enhancement;
20

    
21
import org.gvsig.raster.dataset.IBuffer;
22
import org.gvsig.raster.grid.filter.enhancement.LinearStretchParams.Stretch;
23
/**
24
 * Filtro de realce lineal para tipos de datos byte. El realce es aplicado por intervalos.
25
 * Para cada pixel se obtiene en que intervalo se encuentra y se aplica la scala y offset
26
 * calculados para ese intervalo.
27
 *
28
 * @version 11/05/2007
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public class LinearStretchEnhancementByteFilter extends LinearStretchEnhancementFilter {
32
                
33
        /*
34
         * (non-Javadoc)
35
         * @see org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter#process(int, int)
36
         */
37
        public void process(int col, int line) throws InterruptedException {
38
                for (int iBand = 0; iBand < raster.getBandCount(); iBand++) {
39
                        if (renderBands[iBand] < 0) {
40
                                rasterResult.setElem(line, col, iBand, (byte) 0);
41
                                continue;
42
                        }
43

    
44
                        int p;
45
                        if (stretchs.rgb)
46
                                p = (int) (raster.getElemByte(line, col, iBand) & 0xff);
47
                        else
48
                                p = (int) raster.getElemByte(line, col, iBand);
49

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

    
85
        /*
86
         * (non-Javadoc)
87
         * @see org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter#getInRasterDataType()
88
         */
89
        public int getInRasterDataType() {
90
                return IBuffer.TYPE_BYTE;
91
        }
92
}