Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / enhancement / GrayScaleManager.java @ 2348

History | View | Annotate | Download (3.59 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 java.util.ArrayList;
25
import java.util.List;
26

    
27
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
28
import org.gvsig.fmap.dal.coverage.datastruct.Params;
29
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
30
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager;
31
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
32
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
33
/**
34
 * Gestor del filtro de conversi?n a escala de grises
35
 *
36
 * @author Nacho Brodin nachobrodin@gmail.com
37
 */
38
public class GrayScaleManager extends AbstractRasterFilterManager {
39
        public static String   ID = "GrayScale";
40

    
41
        public String getManagerID() {
42
                return ID;
43
        }
44
        
45
        public static void register() {
46
                AbstractRasterFilterManager.register(ID, GrayScaleManager.class);
47
        }
48
        
49
        public boolean isDataTypeSupported(int dataType) {
50
                if(dataType != Buffer.TYPE_BYTE)
51
                        return false;
52
                return true;
53
        }
54
        
55
        public Class<?> getFilterClassByID(String id) {
56
                if( id.compareTo("grayscale") == 0)
57
                        return GrayScaleFilter.class;
58
                return null;
59
        }
60

    
61
        /**
62
         * Constructor.
63
         * Asigna la lista de filtros y el managener global.
64
         *
65
         * @param filterListManager
66
         */
67
        public GrayScaleManager(RasterFilterList filterList) {
68
                super(filterList);
69
        }
70

    
71
        /**
72
         * A?ade un filtro de conversi?n de balance de color RGB.
73
         * @param type. par?metro para el filtro que indica que banda o combinaci?n de
74
         * estas es usada para la conversi?n a escala de gris. El valor de este par?mtro
75
         * est? definido en las constantes de la clase GrayScaleFilter
76
         * @throws FilterTypeException
77
         */
78
        public void addGrayScaleFilter(int type) throws FilterTypeException {
79
                RasterFilter filter = new GrayScaleByteFilter();
80

    
81
                if (filter != null) {
82
                        filter.addParam("typeBand", new Integer(type));
83
                        getFilterList().add(filter);
84
                }
85
        }
86

    
87
        public List<Class<?>> getRasterFilterList() {
88
                List<Class<?>> filters = new ArrayList<Class<?>>();
89
                filters.add(GrayScaleFilter.class);
90
                return filters;
91
        }
92

    
93
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
94
                if (classFilter.equals(GrayScaleFilter.class)) {
95
                        int type = 0;
96

    
97
                        for (int i = 0; i < params.getNumParams(); i++) {
98
                                if (params.getParam(i).getId().equals("typeBand"))
99
                                        type = ((Integer) params.getParam(i).getDefaultValue()).intValue();
100
                        }
101
                        addGrayScaleFilter(type);
102
                }
103
        }
104
        
105
        public RasterFilter createFilter(Params params) {
106
                Integer type = ((Integer) params.getParamById("typeBand").getDefaultValue());
107
                
108
                RasterFilter filter = new GrayScaleByteFilter();
109
                filter.addParam("typeBand", type);
110
                return filter;
111
        }
112
        
113
        public void addFilter(Params params) throws FilterTypeException {
114
                addFilter(GrayScaleFilter.class, params);
115
        }
116
}