svn-gvsig-desktop / tags / v1_0_RELEASE / libraries / libCq CMS for java.old / src / org / cresques / filter / RasterToImageFilter.java @ 9167
History | View | Annotate | Download (3.27 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.filter; |
25 |
|
26 |
import java.awt.image.BufferedImage; |
27 |
|
28 |
|
29 |
/**
|
30 |
* Renderiza el raster.
|
31 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
32 |
*/
|
33 |
public class RasterToImageFilter extends RasterFilter { |
34 |
private BufferedImage image; |
35 |
private int alpha; |
36 |
private int rgb; |
37 |
|
38 |
/**
|
39 |
* Constructor
|
40 |
*
|
41 |
*/
|
42 |
public RasterToImageFilter() {
|
43 |
} |
44 |
|
45 |
/* (non-Javadoc)
|
46 |
* @see org.cresques.io.raster.IRasterFilter#pre()
|
47 |
*/
|
48 |
public void pre() { |
49 |
//Obtenemos par?metros
|
50 |
this.raster = (RasterBuf) params.get("raster"); |
51 |
this.alpha = ((Integer) params.get("alpha")).intValue(); |
52 |
this.height = raster.getHeight();
|
53 |
this.width = raster.getWidth();
|
54 |
this.alpha = (alpha & 0xff) << 24; |
55 |
image = new BufferedImage(raster.getWidth(), raster.getHeight(), |
56 |
BufferedImage.TYPE_INT_ARGB);
|
57 |
} |
58 |
|
59 |
/* (non-Javadoc)
|
60 |
* @see org.cresques.px.PxRaster.RasterFilter#process(int, int)
|
61 |
*/
|
62 |
public void process(int x, int y) { |
63 |
raster.getElemInt(x, y, px); |
64 |
rgb = (alpha & ((px[3] & 0xff) << 24)) | ((px[0] & 0xff) << 16) | |
65 |
((px[1] & 0xff) << 8) | (px[2] & 0xff); |
66 |
|
67 |
image.setRGB(x, y, rgb); |
68 |
} |
69 |
|
70 |
/* (non-Javadoc)
|
71 |
* @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
|
72 |
*/
|
73 |
public Object getResult(String name) { |
74 |
if (name.equals("raster")) { |
75 |
return (Object) image; |
76 |
} else {
|
77 |
return null; |
78 |
} |
79 |
} |
80 |
|
81 |
/* (non-Javadoc)
|
82 |
* @see org.cresques.px.PxRaster.RasterFilter#processLines(int)
|
83 |
*/
|
84 |
public void processLine(int y) { |
85 |
for (int x = 0; x < width; x++) { |
86 |
int[][] line = raster.getLineInt(y); |
87 |
rgb = (alpha & ((px[3] & 0xff) << 24)) | |
88 |
((line[x][0] & 0xff) << 16) | ((line[x][1] & 0xff) << 8) | |
89 |
(line[x][2] & 0xff); |
90 |
|
91 |
image.setRGB(x, y, rgb); |
92 |
} |
93 |
} |
94 |
|
95 |
/* (non-Javadoc)
|
96 |
* @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
|
97 |
*/
|
98 |
public int getInRasterDataType() { |
99 |
return raster.getDataType();
|
100 |
} |
101 |
|
102 |
/* (non-Javadoc)
|
103 |
* @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
|
104 |
*/
|
105 |
public int getOutRasterDataType() { |
106 |
return RasterBuf.TYPE_IMAGE;
|
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see org.cresques.io.raster.IRasterFilter#post()
|
111 |
*/
|
112 |
public void post() { |
113 |
} |
114 |
} |