svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / raster / LinearEnhancementImageFilter.java @ 4578
History | View | Annotate | Download (3.75 KB)
1 | 2809 | nacho | /*
|
---|---|---|---|
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.io.raster; |
||
25 | |||
26 | import java.awt.Image; |
||
27 | import java.awt.image.BufferedImage; |
||
28 | |||
29 | |||
30 | /**
|
||
31 | * Realzado Lineal (Amplitude Rescaling) para objetos Image.
|
||
32 | * @author Luis W. Sevilla (sevilla_lui@gva.es)
|
||
33 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
34 | */
|
||
35 | public class LinearEnhancementImageFilter extends LinearEnhancementFilter { |
||
36 | /**
|
||
37 | * Constructor
|
||
38 | */
|
||
39 | public LinearEnhancementImageFilter() {
|
||
40 | super();
|
||
41 | } |
||
42 | |||
43 | /* (non-Javadoc)
|
||
44 | * @see org.cresques.io.raster.IRasterFilter#pre()
|
||
45 | */
|
||
46 | public void pre() { |
||
47 | //Obtenci?n de par?metros
|
||
48 | this.image = (Image) params.get("raster"); |
||
49 | this.stats = (RasterStats) params.get("stats"); |
||
50 | this.removeExtrema = ((Boolean) params.get("remove")).booleanValue(); |
||
51 | this.filename = (String) params.get("filename"); |
||
52 | height = image.getHeight(null);
|
||
53 | width = image.getWidth(null);
|
||
54 | super.pre();
|
||
55 | } |
||
56 | |||
57 | /* (non-Javadoc)
|
||
58 | * @see org.cresques.io.raster.IRasterFilter#process(int, int)
|
||
59 | */
|
||
60 | public void process(int x, int y) { |
||
61 | int pt = ((BufferedImage) image).getRGB(x, y); |
||
62 | int[] px4 = { |
||
63 | ((pt & 0xff000000) >> 24) & 0xff, |
||
64 | ((pt & 0xff0000) >> 16) & 0xff, |
||
65 | ((pt & 0xff00) >> 8) & 0xff, pt & 0xff |
||
66 | }; |
||
67 | |||
68 | for (int i = 0; i < 3; i++) { |
||
69 | if (px4[i + 1] > maxBandValue[i]) { |
||
70 | px4[i + 1] = maxBandValue[i];
|
||
71 | } else if (px4[i + 1] < minBandValue[i]) { |
||
72 | px4[i + 1] = minBandValue[i];
|
||
73 | } |
||
74 | |||
75 | px4[i + 1] = (((int) ((((double) px4[i + 1]) * scale[i]) + |
||
76 | offset[i])) & 0xff);
|
||
77 | } |
||
78 | |||
79 | ((BufferedImage) image).setRGB(x, y,
|
||
80 | (((px4[0] << 24) & 0xff000000) | |
||
81 | ((px4[1] << 16) & 0xff0000) | |
||
82 | ((px4[2] << 8) & 0xff00) | |
||
83 | (px4[3] & 0xff))); |
||
84 | } |
||
85 | |||
86 | /* (non-Javadoc)
|
||
87 | * @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
|
||
88 | */
|
||
89 | public Object getResult(String name) { |
||
90 | if (name.equals("raster")) { |
||
91 | return (Object) this.image; |
||
92 | } else {
|
||
93 | return null; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | /* (non-Javadoc)
|
||
98 | * @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
|
||
99 | */
|
||
100 | public int getInRasterDataType() { |
||
101 | return RasterBuf.TYPE_IMAGE;
|
||
102 | } |
||
103 | |||
104 | /* (non-Javadoc)
|
||
105 | * @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
|
||
106 | */
|
||
107 | public int getOutRasterDataType() { |
||
108 | return RasterBuf.TYPE_IMAGE;
|
||
109 | } |
||
110 | |||
111 | /* (non-Javadoc)
|
||
112 | * @see org.cresques.io.raster.IRasterFilter#post()
|
||
113 | */
|
||
114 | public void post() { |
||
115 | } |
||
116 | |||
117 | /* (non-Javadoc)
|
||
118 | * @see org.cresques.io.raster.RasterFilter#processLine(int)
|
||
119 | */
|
||
120 | public void processLine(int y) { |
||
121 | } |
||
122 | } |