Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / branches / org.gvsig.raster.tools_dataaccess_refactoring / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / filter / grayscale / GrayScaleByteFilter.java @ 2308

History | View | Annotate | Download (1.83 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.tools.app.basic.tool.filter.grayscale;
23

    
24

    
25
/**
26
 * Filtro para la conversi?n a escala de grises de tipo byte
27
 * @author Nacho Brodin nachobrodin@gmail.com
28
 */
29
public class GrayScaleByteFilter extends GrayScaleFilter {
30
        public void process(int col, int line) {
31
                byte value = 0;
32
                switch (type) {
33
                case 0:
34
                case 4:        value = raster.getElemByte(line, col, 0);
35
                                break;
36
                case 1:        value = raster.getElemByte(line, col, 1);
37
                                break;
38
                case 2:        value = raster.getElemByte(line, col, 2);
39
                                break;
40
                case 3:        int r = (raster.getElemByte(line, col, 0) & 0xff);
41
                                int g = (raster.getElemByte(line, col, 1) & 0xff);
42
                                int b = (raster.getElemByte(line, col, 2) & 0xff);
43
                                value = (byte)((r + g + b) / 3);
44
                                break;
45
                }
46
                
47
                rasterResult.setElem(line, col, 0, value);
48
                rasterResult.setElem(line, col, 1, value);
49
                rasterResult.setElem(line, col, 2, value);
50
                rasterResult.setElem(line, col, 3, (byte)255);
51
                
52
                writeAlphaBand(line, col);
53
        }
54
}