Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/raster/RasterToImageFilter.java
RasterToImageFilter.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.io.raster; |
25 | 25 |
|
26 | 26 |
import java.awt.image.BufferedImage; |
27 | 27 |
|
28 |
|
|
28 | 29 |
/** |
29 | 30 |
* Renderiza el raster. |
30 | 31 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
31 | 32 |
*/ |
32 |
|
|
33 | 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 |
/* (non-Javadoc) |
|
45 |
* @see org.cresques.io.raster.IRasterFilter#pre() |
|
46 |
*/ |
|
47 |
public void pre(){ |
|
48 |
//Obtenemos par?metros |
|
49 |
this.raster = (RasterBuf)params.get("raster"); |
|
50 |
this.alpha = ((Integer)params.get("alpha")).intValue(); |
|
51 |
this.height = raster.getHeight(); |
|
52 |
this.width = raster.getWidth(); |
|
53 |
this.alpha = (alpha & 0xff) << 24; |
|
54 |
image = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_ARGB); |
|
55 |
} |
|
56 |
|
|
57 |
/* (non-Javadoc) |
|
58 |
* @see org.cresques.px.PxRaster.RasterFilter#process(int, int) |
|
59 |
*/ |
|
60 |
public void process(int x, int y) { |
|
61 |
raster.getElemInt(x, y, px); |
|
62 |
rgb = (alpha & ((px[3] & 0xff) << 24)) | |
|
63 |
((px[0] & 0xff) << 16) | |
|
64 |
((px[1] & 0xff) << 8) | |
|
65 |
(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 |
} |
|
34 |
private BufferedImage image; |
|
35 |
private int alpha; |
|
36 |
private int rgb; |
|
79 | 37 |
|
80 |
/* (non-Javadoc) |
|
81 |
* @see org.cresques.px.PxRaster.RasterFilter#processLines(int) |
|
82 |
*/ |
|
83 |
public void processLine(int y) { |
|
84 |
for (int x=0; x<width; x++) { |
|
85 |
int [][] line = raster.getLineInt(y); |
|
86 |
rgb = (alpha & ((px[3] & 0xff) << 24)) | |
|
87 |
((line[x][0] & 0xff) << 16) | |
|
88 |
((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 |
} |
|
38 |
/** |
|
39 |
* Constructor |
|
40 |
* |
|
41 |
*/ |
|
42 |
public RasterToImageFilter() { |
|
43 |
} |
|
115 | 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 |
} |
Also available in: Unified diff