Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / enhancement / BrightnessFilter.java @ 2443

History | View | Annotate | Download (3.08 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.impl.grid.filter.enhancement;
23

    
24
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
25
import org.gvsig.fmap.dal.coverage.datastruct.Params;
26
import org.gvsig.fmap.dal.coverage.exception.FilterAddException;
27
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter;
28
import org.gvsig.raster.impl.buffer.RasterBuffer;
29
import org.gvsig.raster.impl.store.ParamsImpl;
30
/**
31
 * Clase base para los filtros de brillo.
32
 *
33
 * @author Miguel ?ngel Querol Carratal?  
34
 */
35
public class BrightnessFilter extends BaseRasterFilter {
36
        public static String[]           names           = new String[] {"brightness"};
37

    
38
        /**
39
         * Variable para guardar el incremento de brillo que se va a aplicar
40
         */
41
        int incrBrillo = 0;
42

    
43
        /**
44
         * Constructor. Llama al constructor de la clase base y asigna el
45
         * nombre del filtro.
46
         */
47
        public BrightnessFilter() {
48
                setName(names[0]);
49
        }
50

    
51
        public void pre() throws FilterAddException {
52
                super.pre();
53
                incrBrillo = ((Integer) params.get("incrBrillo")).intValue();
54
                createBufferResult(Buffer.TYPE_BYTE, raster.getBandCount());
55
        }
56

    
57
        public void post() {
58
                // En caso de que nadie apunte a raster, se liberar? su memoria.
59
                raster = null;
60
        }
61

    
62
        /**
63
         * Obtiene el incremento de brillo que se est? aplicando
64
         * @return entero que representa el incremento de brillo aplicado.
65
         */
66
        public int getBrightnessIncrease() {
67
                return this.incrBrillo;
68
        }
69

    
70
        public String getGroup() {
71
                return "realces";
72
        }
73

    
74
        public Params getUIParams(String nameFilter) {
75
                Params params = new ParamsImpl();
76
                params.setParam("Brightness",
77
                                new Integer(incrBrillo),
78
                                Params.SLIDER,
79
                                new String[]{ "-255", "255", "50", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande;
80
                return params;
81
        }
82

    
83
        public int getInRasterDataType() {
84
                //No parece que tenga sentido para im?genes que no sean RGB
85
                return RasterBuffer.TYPE_BYTE;
86
        }
87

    
88
        public int getOutRasterDataType() {
89
                return RasterBuffer.TYPE_BYTE;
90
        }
91

    
92
        public void process(int x, int y) {
93
        }
94

    
95
        /**
96
         * Calcula el brillo para un pixel
97
         * @param px
98
         * @return
99
         */
100
        protected int calcBrightness(int px) {
101
                px += incrBrillo;
102
                if (px > 255)
103
                        px = 255;
104
                else if (px < 0)
105
                        px = 0;
106
                return px;
107
        }
108

    
109
        public String[] getNames() {
110
                return names;
111
        }
112
}