Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / bands / PaletteShortFilter.java @ 8026

History | View | Annotate | Download (3.15 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.bands;
21

    
22
import java.awt.image.BufferedImage;
23

    
24
import org.cresques.io.data.RasterBuf;
25

    
26
/**
27
 * Filtro de paleta a aplicar sobre una imagen con tipo de dato short. Para cada elemento
28
 * del RasterBuf se realiza la conversi?n de dato a trav?s de la clase palette que se pasa
29
 * como par?metro al filtro en la inicializaci?n.
30
 * 
31
 * @author Nacho Brodin (brodin_ign@gva.es)
32
 *
33
 */
34
public class PaletteShortFilter extends PaletteFilter {
35
        private short[]                 px = new short[4];
36
        
37
        
38
        /**
39
         * Constructor
40
         *
41
         */
42
        public PaletteShortFilter(){
43
                super();
44
        }
45
        
46
        
47
        public void pre(){
48
                this.raster = (RasterBuf) params.get("raster");
49
                height = raster.getHeight();
50
        width = raster.getWidth();
51
        rasterResult = new RasterBuf(raster.getDataType(),width,height,3,true);
52
                super.pre();
53
        }
54
        
55
        public void process(int col, int line) {
56
                raster.getElemShort(line, col, px);
57
        int rgb;
58
        if(interpolate)
59
                rgb = palette.getInterpolateRGB2(px[0]);
60
        else
61
                rgb = palette.getRGB(px[0]);
62
                
63
        short pxOut[] = {(short)((rgb & 0x00ff0000) >> 16),
64
                        (short)((rgb & 0x0000ff00) >> 8), 
65
                        (short)((rgb & 0x000000ff))};
66
        rasterResult.setElemShort(line, col,pxOut);
67
        }
68

    
69
         /* (non-Javadoc)
70
     * @see org.cresques.io.raster.IRasterFilter#processSuperSampling(int, int)
71
     */
72
        public void processSuperSampling(int col, int line) {
73
                raster.getElemShort(line, col, px);
74
                int rgb;
75
        if(interpolate)
76
                rgb = palette.getInterpolateRGB2(px[0]);
77
        else
78
                rgb = palette.getRGB(px[0]);
79
                
80
        short pxOut[] = {(short)((rgb & 0x00ff0000) >> 16),
81
                        (short)((rgb & 0x0000ff00) >> 8), 
82
                        (short)((rgb & 0x000000ff))};
83
        for(int j = col; j < width && j < (col + stepX[contX + 1]); j++)
84
                        for(int i = line; i < height && i < (line + stepY[contY + 1]); i++)
85
                                rasterResult.setElemShort(i, j,pxOut);                
86
        }
87
        
88
        public void processLine(int y) {
89
                // TODO Auto-generated method stub
90

    
91
        }
92

    
93
        public int getInRasterDataType() {
94
                return RasterBuf.TYPE_SHORT;
95
        }
96

    
97
        public int getOutRasterDataType() {
98
                return RasterBuf.TYPE_SHORT;
99
        }
100

    
101
        public Object getResult(String name) {
102
                if (name.equals("raster")) {
103
                        if(isExec())
104
                                return (Object) this.rasterResult;
105
                        else
106
                                return (Object) this.raster;
107
        } else {
108
            return null;
109
        }
110
        }
111

    
112
}