Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / ContrastShortFilter.java @ 10740

History | View | Annotate | Download (2.45 KB)

1
package org.gvsig.raster.grid.filter.enhancement;
2

    
3
import org.cresques.filter.RasterBuf;
4
import org.gvsig.raster.dataaccess.buffer.RasterBuffer;
5

    
6
/**
7
 * Filtro de contraste para im?genes de 16 bits.
8
 * @author Miguel ?ngel Querol Carratal? <querol_mig@gva.es>
9
 *
10
 */
11
public class ContrastShortFilter extends ContrastFilter {
12
        private short[]                 px = new short[4];
13
        /**
14
         * Variable que contendra el incremento del contraste.
15
         */
16
        private short incrContraste = 0;
17
        
18
        private short diferencia = 0;
19
        
20
        public ContrastShortFilter(){
21
                super();
22
        }
23
                
24
        public void pre(){
25
                exec = true;
26
                this.raster = (RasterBuffer) params.get("raster");
27
                height = raster.getHeight();
28
        width = raster.getWidth();
29
        this.incrContraste = ((Integer)this.params.get("incrContraste")).shortValue();
30

    
31
                super.pre();
32
        }
33

    
34
        /**
35
         * Algoritmo de contraste
36
         * @param px3 valores ARGB
37
         * @return valores ARGB con el algoritmo aplicado
38
         */
39
        private short[] calcContrast(short[] px){
40
                short result = 0;
41
                for (int i = 0 ; i < 3 ; i++){                        
42
                        if(incrContraste >= 0){
43
                                if (px[i] < 127){
44
                                        diferencia = (short)(127 - px[i]);
45
                                        result = (short)(px[i] - (short)((diferencia * 5) * (incrContraste * 0.1) / 25));
46
                                        if(result < 0)        result = 0;
47
                                        
48
                                }
49
                                if (px[i] > 127){
50
                                        diferencia = (short)(px[i] - 127);
51
                                        result = (short)(px[i] + (short)((diferencia * 5) * (incrContraste * 0.1) / 25));
52
                                        if(result > 255)        result = 255;
53
                                }
54
                        }else{ //incrContraste < 0        
55
                                if(px[i] < 127){
56
                                        diferencia = (short)(127 - px[i]);
57
                                        result = (short)(px[i] + (diferencia * (short)(-incrContraste * 0.1) / 25));
58
                                        if(result > 127)        result = 127;
59
                                        if(px[i] == 0 || px[i] == 0)
60
                                                if(incrContraste > -255)
61
                                                        result = 0;
62
                                }
63
                                if(px[i] > 127){
64
                                        diferencia = (short)(px[i] - 127);
65
                                        result = (short)(px[i] - (diferencia * (short)(-incrContraste * 0.1) / 25));
66
                                        if (result < 127)        result = 127;
67
                                        if(px[i] == 255 || px[i] == 254)        
68
                                                if(incrContraste > -255)
69
                                                        result = 255;
70
                                }
71
                        }
72
                        px[i] = result;
73
                }
74
                return px;
75
        }
76
        
77
        public void process(int col, int line) {
78
                raster.getElemShort(line, col, px);
79
                px = calcContrast(px);
80
                raster.setElemShort(line, col, px);
81
        }
82
        
83
        public int getInRasterDataType() {
84
                return RasterBuffer.TYPE_SHORT;
85
        }
86

    
87
        public int getOutRasterDataType() {
88
                return RasterBuffer.TYPE_SHORT;
89
        }
90

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