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