Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/raster/TransparencyImageFilter.java
TransparencyImageFilter.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; |
... | ... | |
26 | 26 |
import java.awt.Image; |
27 | 27 |
import java.awt.image.BufferedImage; |
28 | 28 |
|
29 |
|
|
29 | 30 |
/** |
30 | 31 |
* Filtro de transparencia aplicada a un rango de valores de un pixel sobre un objeto image |
31 | 32 |
* @author Nacho Brodin (brodin_ign@gva.es) |
32 |
*
|
|
33 |
* |
|
33 | 34 |
*/ |
34 |
public class TransparencyImageFilter extends TransparencyFilter { |
|
35 |
public class TransparencyImageFilter extends TransparencyFilter { |
|
36 |
/** |
|
37 |
* Constructor |
|
38 |
* |
|
39 |
*/ |
|
40 |
public TransparencyImageFilter() { |
|
41 |
super(); |
|
42 |
} |
|
35 | 43 |
|
36 |
/** |
|
37 |
* Constructor |
|
38 |
* |
|
39 |
*/ |
|
40 |
public TransparencyImageFilter(){ |
|
41 |
super(); |
|
42 |
} |
|
43 |
|
|
44 |
/* (non-Javadoc) |
|
45 |
* @see org.cresques.io.raster.IRasterFilter#pre() |
|
46 |
*/ |
|
47 |
public void pre(){ |
|
48 |
//Obtenci?n de par?metros |
|
49 |
this.image = (Image)params.get("raster"); |
|
50 |
height = image.getHeight(null); |
|
51 |
width = image.getWidth(null); |
|
52 |
super.pre(); |
|
53 |
} |
|
54 |
|
|
44 |
/* (non-Javadoc) |
|
45 |
* @see org.cresques.io.raster.IRasterFilter#pre() |
|
46 |
*/ |
|
47 |
public void pre() { |
|
48 |
//Obtenci?n de par?metros |
|
49 |
this.image = (Image) params.get("raster"); |
|
50 |
height = image.getHeight(null); |
|
51 |
width = image.getWidth(null); |
|
52 |
super.pre(); |
|
53 |
} |
|
55 | 54 |
|
56 |
/** |
|
57 |
* Dado un pixel y un rango, asigna ese pixel al color de transparencia por |
|
58 |
* defecto si el pixel en una banda determinada est? en el rango definido. |
|
59 |
* @param range rango |
|
60 |
* @param banda banda |
|
61 |
* @param px pixel |
|
62 |
*/ |
|
63 |
private void processRange(int[][] range, int banda, int[] px){ |
|
64 |
for(int i=0;i<range.length;i++){ |
|
65 |
if( (px[banda] >= range[i][0] && px[banda] <= range[i][1]) ){ |
|
66 |
px[0] = this.alpha; |
|
67 |
px[1] = this.transparencyColorRed; |
|
68 |
px[2] = this.transparencyColorGreen; |
|
69 |
px[3] = this.transparencyColorBlue; |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
/* (non-Javadoc) |
|
75 |
* @see org.cresques.io.raster.IRasterFilter#process(int, int) |
|
76 |
*/ |
|
77 |
public void process(int x, int y) { |
|
78 |
int pt = ((BufferedImage) image).getRGB(x,y); |
|
79 |
int []px4 = {(pt & 0xff000000) >> 24,(pt & 0xff0000) >> 16, (pt & 0x00ff00) >> 8, (pt & 0x0000ff)}; |
|
80 |
if(rangesR!=null) |
|
81 |
processRange(rangesR, 1, px4); |
|
82 |
if(rangesG!=null) |
|
83 |
processRange(rangesG, 2, px4); |
|
84 |
if(rangesB!=null) |
|
85 |
processRange(rangesB, 3, px4); |
|
86 |
((BufferedImage) image).setRGB(x,y, ( |
|
87 |
(px4[0] << 24) & 0xff000000 | (px4[1] << 16) & 0x00ff0000 | |
|
88 |
(px4[2] << 8) & 0x0000ff00 | (px4[3] & 0x0000ff) )); |
|
89 |
} |
|
90 |
|
|
91 |
/* (non-Javadoc) |
|
92 |
* @see org.cresques.io.raster.IRasterFilter#getInRasterDataType() |
|
93 |
*/ |
|
94 |
public int getInRasterDataType(){ |
|
95 |
return RasterBuf.TYPE_IMAGE; |
|
96 |
} |
|
97 |
|
|
98 |
/* (non-Javadoc) |
|
99 |
* @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType() |
|
100 |
*/ |
|
101 |
public int getOutRasterDataType(){ |
|
102 |
return RasterBuf.TYPE_IMAGE; |
|
103 |
} |
|
104 |
|
|
105 |
/* (non-Javadoc) |
|
106 |
* @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String) |
|
107 |
*/ |
|
108 |
public Object getResult(String name){ |
|
109 |
if(name.equals("raster")) |
|
110 |
return (Object)this.image; |
|
111 |
else |
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
115 |
/* (non-Javadoc) |
|
116 |
* @see org.cresques.io.raster.RasterFilter#processLine(int) |
|
117 |
*/ |
|
118 |
public void processLine(int y){}; |
|
119 |
|
|
120 |
/* (non-Javadoc) |
|
121 |
* @see org.cresques.io.raster.IRasterFilter#post() |
|
122 |
*/ |
|
123 |
public void post(){} |
|
124 |
} |
|
55 |
/** |
|
56 |
* Dado un pixel y un rango, asigna ese pixel al color de transparencia por |
|
57 |
* defecto si el pixel en una banda determinada est? en el rango definido. |
|
58 |
* @param range rango |
|
59 |
* @param banda banda |
|
60 |
* @param px pixel |
|
61 |
*/ |
|
62 |
private void processRange(int[][] range, int banda, int[] px) { |
|
63 |
for (int i = 0; i < range.length; i++) { |
|
64 |
if (((px[banda] >= range[i][0]) && (px[banda] <= range[i][1]))) { |
|
65 |
px[0] = this.alpha; |
|
66 |
px[1] = this.transparencyColorRed; |
|
67 |
px[2] = this.transparencyColorGreen; |
|
68 |
px[3] = this.transparencyColorBlue; |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
125 | 72 |
|
73 |
/* (non-Javadoc) |
|
74 |
* @see org.cresques.io.raster.IRasterFilter#process(int, int) |
|
75 |
*/ |
|
76 |
public void process(int x, int y) { |
|
77 |
int pt = ((BufferedImage) image).getRGB(x, y); |
|
78 |
int[] px4 = { |
|
79 |
(pt & 0xff000000) >> 24, (pt & 0xff0000) >> 16, |
|
80 |
(pt & 0x00ff00) >> 8, (pt & 0x0000ff) |
|
81 |
}; |
|
126 | 82 |
|
83 |
if (rangesR != null) { |
|
84 |
processRange(rangesR, 1, px4); |
|
85 |
} |
|
86 |
|
|
87 |
if (rangesG != null) { |
|
88 |
processRange(rangesG, 2, px4); |
|
89 |
} |
|
90 |
|
|
91 |
if (rangesB != null) { |
|
92 |
processRange(rangesB, 3, px4); |
|
93 |
} |
|
94 |
|
|
95 |
((BufferedImage) image).setRGB(x, y, |
|
96 |
(((px4[0] << 24) & 0xff000000) | |
|
97 |
((px4[1] << 16) & 0x00ff0000) | |
|
98 |
((px4[2] << 8) & 0x0000ff00) | |
|
99 |
(px4[3] & 0x0000ff))); |
|
100 |
} |
|
101 |
|
|
102 |
/* (non-Javadoc) |
|
103 |
* @see org.cresques.io.raster.IRasterFilter#getInRasterDataType() |
|
104 |
*/ |
|
105 |
public int getInRasterDataType() { |
|
106 |
return RasterBuf.TYPE_IMAGE; |
|
107 |
} |
|
108 |
|
|
109 |
/* (non-Javadoc) |
|
110 |
* @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType() |
|
111 |
*/ |
|
112 |
public int getOutRasterDataType() { |
|
113 |
return RasterBuf.TYPE_IMAGE; |
|
114 |
} |
|
115 |
|
|
116 |
/* (non-Javadoc) |
|
117 |
* @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String) |
|
118 |
*/ |
|
119 |
public Object getResult(String name) { |
|
120 |
if (name.equals("raster")) { |
|
121 |
return (Object) this.image; |
|
122 |
} else { |
|
123 |
return null; |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
/* (non-Javadoc) |
|
128 |
* @see org.cresques.io.raster.RasterFilter#processLine(int) |
|
129 |
*/ |
|
130 |
public void processLine(int y) { |
|
131 |
} |
|
132 |
|
|
133 |
/* (non-Javadoc) |
|
134 |
* @see org.cresques.io.raster.IRasterFilter#post() |
|
135 |
*/ |
|
136 |
public void post() { |
|
137 |
} |
|
138 |
} |
Also available in: Unified diff