Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools / src / org / gvsig / rasterTools / brightnessContrast / filter / BrightnessImageFilter.java @ 5497

History | View | Annotate | Download (2.57 KB)

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

    
20
package org.gvsig.rasterTools.brightnessContrast.filter;
21

    
22
import java.awt.Image;
23
import java.awt.image.BufferedImage;
24

    
25
import org.cresques.io.raster.RasterBuf;
26

    
27
/**
28
 * Filtro de brillo que se aplica en la imagen. Toma como entrada la imagen
29
 * y el incremento de brillo y devuelve la imagen con lo nuevos valores de brillo.
30
 * @author Miguel ?ngel Querol Carratal?  <querol_mig@gva.es>
31
 *
32
 */
33

    
34
public class BrightnessImageFilter extends BrightnessFilter {
35

    
36
        
37
        /**
38
         * Constructor
39
         *
40
         */
41
        
42
        
43
        public BrightnessImageFilter(){
44
                super();
45
        }
46
        
47
        
48
        public void pre(){
49
                exec = true;
50
                this.image = (Image) params.get("raster");
51
                height = image.getHeight(null);
52
        width = image.getWidth(null);
53
                this.incrBrillo = ((Integer) params.get("incrBrillo")).intValue();
54
                
55
                super.pre();
56
        }
57
        
58
        public void process(int x, int y) {
59
                int px = ((BufferedImage) image).getRGB(x, y);
60
                int px3[] = {(px & 0xff000000) >> 24, 
61
                                        (px & 0x00ff0000) >> 16, 
62
                                        (px & 0x0000ff00) >> 8, 
63
                                        (px & 0x000000ff)};
64
                
65
                for (int i = 1 ; i < 4 ; i++){
66
                        if((px3[i] + incrBrillo) > 255)
67
                                px3[i] = 255;
68
                        else if((px3[i] + incrBrillo) < 0)
69
                                px3[i] = 0;
70
                        else
71
                                px3[i] += incrBrillo;
72
                }
73
                
74
                ((BufferedImage) image).setRGB(x, y,         ((px3[0] << 24) & 0xff000000) | 
75
                                                                                                ((px3[1] << 16) & 0x00ff0000) |
76
                                                                                                ((px3[2] << 8) & 0x0000ff00) |
77
                                                                                                (px3[3] & 0x000000ff));
78
        }
79

    
80
        public void processLine(int y) {
81
                // TODO Auto-generated method stub
82

    
83
        }
84

    
85
        public int getInRasterDataType() {
86
                return RasterBuf.TYPE_IMAGE;
87
        }
88

    
89
        public int getOutRasterDataType() {
90
                return RasterBuf.TYPE_IMAGE;
91
        }
92

    
93
        public Object getResult(String name) {
94
                if (name.equals("raster")) {
95
            return (Object) this.image;
96
        } else {
97
            return null;
98
        }
99
        }
100

    
101
}