Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / filter / grayscale / GrayScaleByteFilter.java @ 27361

History | View | Annotate | Download (1.79 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.filter.grayscale;
20

    
21
/**
22
 * Filtro para la conversi?n a escala de grises de tipo byte
23
 * 26/06/2008
24
 * @author Nacho Brodin nachobrodin@gmail.com
25
 */
26
public class GrayScaleByteFilter extends GrayScaleFilter {
27
        /*
28
         * (non-Javadoc)
29
         * @see org.gvsig.raster.grid.filter.bands.ColorTableFilter#process(int, int)
30
         */
31
        public void process(int col, int line) throws InterruptedException {
32
                byte value = 0;
33
                switch (type) {
34
                case 0:
35
                case 4:        value = raster.getElemByte(line, col, 0);
36
                                break;
37
                case 1:        value = raster.getElemByte(line, col, 1);
38
                                break;
39
                case 2:        value = raster.getElemByte(line, col, 2);
40
                                break;
41
                case 3:        int r = (raster.getElemByte(line, col, 0) & 0xff);
42
                                int g = (raster.getElemByte(line, col, 1) & 0xff);
43
                                int b = (raster.getElemByte(line, col, 2) & 0xff);
44
                                value = (byte)((r + g + b) / 3);
45
                                break;
46
                }
47
                
48
                for (int i = 0; i < rasterResult.getBandCount(); i++) 
49
                        rasterResult.setElem(line, col, i, value);
50
        }
51
}