Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / filter / BrightnessContrast / ContrastImageFilter.java @ 6195

History | View | Annotate | Download (3.53 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.cresques.filter.BrightnessContrast;
21

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

    
25
import org.cresques.filter.RasterBuf;
26
import org.cresques.filter.RasterFilter;
27
import org.cresques.filter.RasterFilterStack;
28

    
29
/**
30
 * Filtro de contraste para im?genes raster. Toma como entrada la imagen
31
 * raster y el incremento de contraste introducido por el usuario y devuelve
32
 * la imagen con el filtro aplicado.
33
 * @author Miguel ?ngel Querol Carratal?  <querol_mig@gva.es>
34
 *
35
 */
36
public class ContrastImageFilter extends ContrastFilter {
37

    
38
        public ContrastImageFilter(){
39
                super();
40
        }
41

    
42
        int diferencia = 0;
43
        
44
        public void pre(){
45
                exec = true;
46
                this.image = (Image) params.get("raster");
47
                height = image.getHeight(null);
48
        width = image.getWidth(null);
49
        this.incrContraste = ((Integer)this.params.get("incrContraste")).intValue();
50

    
51
                
52
                super.pre();
53
        }
54
        
55
        public void process(int x, int y) {
56
                int px = ((BufferedImage) image).getRGB(x, y);
57
                int px3[] = {(px & 0xff000000) >> 24, 
58
                                        (px & 0x00ff0000) >> 16, 
59
                                        (px & 0x0000ff00) >> 8, 
60
                                        (px & 0x000000ff)};
61
                
62
                for (int i = 1 ; i < 4 ; i++){                        
63
                        //************ALGORITMO DE CONTRASTE*************
64
                        if(incrContraste >= 0){
65
                                if (px3[i] < 127){
66
                                        diferencia = 127 - px3[i];
67
                                        result = px3[i] - (int)((diferencia * 5) * (incrContraste*0.1)/25);
68
                                        if(result < 0)        result = 0;
69
                                }
70
                                if (px3[i] > 127){
71
                                        diferencia = px3[i] - 127;
72
                                        result = px3[i] + (int)((diferencia * 5) * (incrContraste*0.1)/25);
73
                                        if(result > 255)        result = 255;
74
                                }
75
                        }
76
                        
77
                        if(incrContraste < 0){
78
                                if(px3[i] < 127){
79
                                        diferencia = 127 - px3[i];
80
                                        result = px3[i] + ((int)(diferencia * 1) * (int)(-incrContraste * 0.1)/25);
81
                                        if(result > 127)        result = 127;
82
                                        if(px3[i] == 0 || px3[i] == 1)
83
                                                if(incrContraste > -255)
84
                                                        result = 0;
85
                                }
86
                                if(px3[i] > 127){
87
                                        diferencia = px3[i] - 127;
88
                                        result = px3[i] - ((int)(diferencia * 1) * (int)(-incrContraste * 0.1)/25);
89
                                        if (result < 127)        result = 127;
90
                                        if(px3[i] == 255 || px3[i] == 254)        
91
                                                if(incrContraste > -255)
92
                                                        result = 255;
93
                                }
94
                        }
95
                        px3[i] = result;
96
                }
97
                
98
                ((BufferedImage) this.image).setRGB(x, y,         ((px3[0] << 24) & 0xff000000) | 
99
                                                                                                ((px3[1] << 16) & 0x00ff0000) |
100
                                                                                                ((px3[2] << 8) & 0x0000ff00) |
101
                                                                                                (px3[3] & 0x000000ff));
102
        }
103
        
104
        public int getInRasterDataType() {
105
                return RasterBuf.TYPE_IMAGE;
106
        }
107

    
108
        public int getOutRasterDataType() {
109
                return RasterBuf.TYPE_IMAGE;
110
        }
111

    
112
        public Object getResult(String name) {
113
                if (name.equals("raster")) {
114
            return (Object) this.image;
115
        } else {
116
            return null;
117
        }
118
        }
119

    
120
        public void processLine(int y) {
121
                // TODO Auto-generated method stub
122
                
123
        }
124

    
125
}