root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / enhancement / BrightnessImageFilter.java @ 8026
History | View | Annotate | Download (3.67 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.enhancement; |
21 |
|
22 |
import java.awt.Image; |
23 |
import java.awt.image.BufferedImage; |
24 |
|
25 |
import org.cresques.io.data.RasterBuf; |
26 |
|
27 |
/**
|
28 |
* Filtro de brillo que se aplica en la imagen. Toma como entrada la imagen
|
29 |
* y el incremento de brillo y devuelve la imagen con lo nuevos valores de brillo.
|
30 |
* @author Miguel ?ngel Querol Carratal? <querol_mig@gva.es>
|
31 |
*
|
32 |
*/
|
33 |
|
34 |
public class BrightnessImageFilter extends BrightnessFilter { |
35 |
|
36 |
|
37 |
/**
|
38 |
* Constructor
|
39 |
*
|
40 |
*/
|
41 |
|
42 |
|
43 |
public BrightnessImageFilter(){
|
44 |
super();
|
45 |
} |
46 |
|
47 |
|
48 |
public void pre(){ |
49 |
exec = true;
|
50 |
this.image = (Image) params.get("raster"); |
51 |
height = image.getHeight(null);
|
52 |
width = image.getWidth(null);
|
53 |
this.incrBrillo = ((Integer) params.get("incrBrillo")).intValue(); |
54 |
|
55 |
super.pre();
|
56 |
} |
57 |
|
58 |
public void process(int col, int line) { |
59 |
int px = ((BufferedImage) image).getRGB(col, line); |
60 |
int px3[] = {(px & 0xff000000) >> 24, |
61 |
(px & 0x00ff0000) >> 16, |
62 |
(px & 0x0000ff00) >> 8, |
63 |
(px & 0x000000ff)};
|
64 |
|
65 |
for (int i = 1 ; i < 4 ; i++){ |
66 |
if((px3[i] + incrBrillo) > 255) |
67 |
px3[i] = 255;
|
68 |
else if((px3[i] + incrBrillo) < 0) |
69 |
px3[i] = 0;
|
70 |
else
|
71 |
px3[i] += incrBrillo; |
72 |
} |
73 |
|
74 |
((BufferedImage) image).setRGB(col, line, ((px3[0] << 24) & 0xff000000) | |
75 |
((px3[1] << 16) & 0x00ff0000) | |
76 |
((px3[2] << 8) & 0x0000ff00) | |
77 |
(px3[3] & 0x000000ff)); |
78 |
} |
79 |
|
80 |
/* (non-Javadoc)
|
81 |
* @see org.cresques.io.raster.IRasterFilter#processSuperSampling(int, int)
|
82 |
*/
|
83 |
public void processSuperSampling(int col, int line) { |
84 |
int px = ((BufferedImage) image).getRGB(col, line); |
85 |
int px3[] = {(px & 0xff000000) >> 24, |
86 |
(px & 0x00ff0000) >> 16, |
87 |
(px & 0x0000ff00) >> 8, |
88 |
(px & 0x000000ff)};
|
89 |
|
90 |
for (int i = 1 ; i < 4 ; i++){ |
91 |
if((px3[i] + incrBrillo) > 255) |
92 |
px3[i] = 255;
|
93 |
else if((px3[i] + incrBrillo) < 0) |
94 |
px3[i] = 0;
|
95 |
else
|
96 |
px3[i] += incrBrillo; |
97 |
} |
98 |
|
99 |
/*((BufferedImage) image).setRGB(col, line, ((px3[0] << 24) & 0xff000000) |
|
100 |
((px3[1] << 16) & 0x00ff0000) |
|
101 |
((px3[2] << 8) & 0x0000ff00) |
|
102 |
(px3[3] & 0x000000ff));*/
|
103 |
for(int j = col; j < image.getWidth(null) && j < (col + stepX[contX + 1]); j++) |
104 |
for(int i = line; i < image.getHeight(null) && i < (line + stepY[contY + 1]); i++) |
105 |
((BufferedImage) image).setRGB(j, i, ((px3[0] << 24) & 0xff000000) | |
106 |
((px3[1] << 16) & 0x00ff0000) | |
107 |
((px3[2] << 8) & 0x0000ff00) | |
108 |
(px3[3] & 0x000000ff)); |
109 |
|
110 |
|
111 |
} |
112 |
|
113 |
public void processLine(int y) { |
114 |
// TODO Auto-generated method stub
|
115 |
|
116 |
} |
117 |
|
118 |
public int getInRasterDataType() { |
119 |
return RasterBuf.TYPE_IMAGE;
|
120 |
} |
121 |
|
122 |
public int getOutRasterDataType() { |
123 |
return RasterBuf.TYPE_IMAGE;
|
124 |
} |
125 |
|
126 |
public Object getResult(String name) { |
127 |
if (name.equals("raster")) { |
128 |
return (Object) this.image; |
129 |
} else {
|
130 |
return null; |
131 |
} |
132 |
} |
133 |
|
134 |
} |