root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / bands / PaletteIntFilter.java @ 8026
History | View | Annotate | Download (3.12 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; |
23 |
import java.awt.image.BufferedImage; |
24 |
|
25 |
import org.cresques.io.data.RasterBuf; |
26 |
import org.cresques.io.datastruct.Palette; |
27 |
|
28 |
/**
|
29 |
* Filtro de paleta a aplicar sobre una imagen con tipo de dato integer. Para cada elemento
|
30 |
* del RasterBuf se realiza la conversi?n de dato a trav?s de la clase palette que se pasa
|
31 |
* como par?metro al filtro en la inicializaci?n.
|
32 |
*
|
33 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
34 |
*
|
35 |
*/
|
36 |
public class PaletteIntFilter extends PaletteFilter { |
37 |
private int[] px = new int[4]; |
38 |
|
39 |
/**
|
40 |
* Constructor
|
41 |
*
|
42 |
*/
|
43 |
public PaletteIntFilter(){
|
44 |
super();
|
45 |
} |
46 |
|
47 |
|
48 |
public void pre(){ |
49 |
this.raster = (RasterBuf) params.get("raster"); |
50 |
height = raster.getHeight(); |
51 |
width = raster.getWidth(); |
52 |
rasterResult = new RasterBuf(raster.getDataType(),width,height,3,true); |
53 |
super.pre();
|
54 |
} |
55 |
|
56 |
public void process(int col, int line) { |
57 |
raster.getElemInt(line, col, px); |
58 |
int rgb;
|
59 |
if(interpolate)
|
60 |
rgb = palette.getInterpolateRGB2(px[0]);
|
61 |
else
|
62 |
rgb = palette.getRGB(px[0]);
|
63 |
|
64 |
int pxOut[] = {(rgb & 0x00ff0000) >> 16, |
65 |
(rgb & 0x0000ff00) >> 8, |
66 |
(rgb & 0x000000ff)};
|
67 |
rasterResult.setElemInt(line, col,pxOut); |
68 |
|
69 |
} |
70 |
|
71 |
/* (non-Javadoc)
|
72 |
* @see org.cresques.io.raster.IRasterFilter#processSuperSampling(int, int)
|
73 |
*/
|
74 |
public void processSuperSampling(int col, int line) { |
75 |
raster.getElemInt(line, col, px); |
76 |
int rgb;
|
77 |
if(interpolate)
|
78 |
rgb = palette.getInterpolateRGB2(px[0]);
|
79 |
else
|
80 |
rgb = palette.getRGB(px[0]);
|
81 |
|
82 |
int pxOut[] = {(rgb & 0x00ff0000) >> 16, |
83 |
(rgb & 0x0000ff00) >> 8, |
84 |
(rgb & 0x000000ff)};
|
85 |
for(int j = col; j < width && j < (col + stepX[contX + 1]); j++) |
86 |
for(int i = line; i < height && i < (line + stepY[contY + 1]); i++) |
87 |
rasterResult.setElemInt(i, j,pxOut); |
88 |
} |
89 |
|
90 |
public void processLine(int y) { |
91 |
// TODO Auto-generated method stub
|
92 |
} |
93 |
|
94 |
public int getInRasterDataType() { |
95 |
return RasterBuf.TYPE_INT;
|
96 |
} |
97 |
|
98 |
public int getOutRasterDataType() { |
99 |
return RasterBuf.TYPE_INT;
|
100 |
} |
101 |
|
102 |
public Object getResult(String name) { |
103 |
if (name.equals("raster")) { |
104 |
if(isExec())
|
105 |
return (Object) this.rasterResult; |
106 |
else
|
107 |
return (Object) this.raster; |
108 |
} else {
|
109 |
return null; |
110 |
} |
111 |
} |
112 |
|
113 |
} |