root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / statistics / ComputeMinMaxImageFilter.java @ 8026
History | View | Annotate | Download (4.14 KB)
1 | 8026 | 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.filter.statistics; |
||
25 | |||
26 | import java.awt.Image; |
||
27 | import java.awt.image.BufferedImage; |
||
28 | |||
29 | import org.cresques.io.data.RasterBuf; |
||
30 | |||
31 | |||
32 | /**
|
||
33 | * Clase base para los filtros de calculo de m?ximo y m?nimo en sus diferentes
|
||
34 | * tipos de datos.
|
||
35 | */
|
||
36 | public class ComputeMinMaxImageFilter extends ComputeMinMaxFilter { |
||
37 | |||
38 | /**
|
||
39 | * Constructor
|
||
40 | *
|
||
41 | */
|
||
42 | public ComputeMinMaxImageFilter() {
|
||
43 | super();
|
||
44 | } |
||
45 | |||
46 | /* (non-Javadoc)
|
||
47 | * @see org.cresques.io.raster.IRasterFilter#pre()
|
||
48 | */
|
||
49 | public void pre() { |
||
50 | //Obtenci?n de par?metros
|
||
51 | this.image = (Image) params.get("raster"); |
||
52 | |||
53 | height = image.getHeight(null);
|
||
54 | width = image.getWidth(null);
|
||
55 | super.pre();
|
||
56 | } |
||
57 | |||
58 | /**
|
||
59 | * Calcula el m?nimo y el m?ximo y lo salva sobre las variables de instancia min, max,
|
||
60 | * @param px
|
||
61 | */
|
||
62 | private void calcMinMax(int px){ |
||
63 | int pxBand = ((px & 0xff0000) >> 16); |
||
64 | |||
65 | if (pxBand < min[0]) { |
||
66 | secondMin[0] = min[0]; |
||
67 | min[0] = pxBand;
|
||
68 | } else if ((pxBand < secondMin[0]) && (pxBand != min[0])) { |
||
69 | secondMin[0] = pxBand;
|
||
70 | } |
||
71 | |||
72 | if (pxBand > max[0]) { |
||
73 | secondMax[0] = max[0]; |
||
74 | max[0] = pxBand;
|
||
75 | } else if ((pxBand > secondMax[0]) && (pxBand != max[0])) { |
||
76 | secondMax[0] = pxBand;
|
||
77 | } |
||
78 | |||
79 | pxBand = ((px & 0x00ff00) >> 8); |
||
80 | |||
81 | if (pxBand < min[1]) { |
||
82 | secondMin[1] = min[1]; |
||
83 | min[1] = pxBand;
|
||
84 | } else if ((pxBand < secondMin[1]) && (pxBand != min[1])) { |
||
85 | secondMin[1] = pxBand;
|
||
86 | } |
||
87 | |||
88 | if (pxBand > max[1]) { |
||
89 | secondMax[1] = max[1]; |
||
90 | max[1] = pxBand;
|
||
91 | } else if ((pxBand > secondMax[1]) && (pxBand != max[1])) { |
||
92 | secondMax[1] = pxBand;
|
||
93 | } |
||
94 | |||
95 | pxBand = (px & 0x0000ff);
|
||
96 | |||
97 | if (pxBand < min[2]) { |
||
98 | secondMin[2] = min[2]; |
||
99 | min[2] = pxBand;
|
||
100 | } else if ((pxBand < secondMin[2]) && (pxBand != min[2])) { |
||
101 | secondMin[2] = pxBand;
|
||
102 | } |
||
103 | |||
104 | if (pxBand > max[2]) { |
||
105 | secondMax[2] = max[2]; |
||
106 | max[2] = pxBand;
|
||
107 | } else if ((pxBand > secondMax[2]) && (pxBand != max[2])) { |
||
108 | secondMax[2] = pxBand;
|
||
109 | } |
||
110 | |||
111 | } |
||
112 | |||
113 | /* (non-Javadoc)
|
||
114 | * @see org.cresques.io.raster.IRasterFilter#process(int, int)
|
||
115 | */
|
||
116 | public void process(int col, int line) { |
||
117 | int px = ((BufferedImage) image).getRGB(col, line); |
||
118 | calcMinMax(px); |
||
119 | } |
||
120 | |||
121 | /* (non-Javadoc)
|
||
122 | * @see org.cresques.io.raster.IRasterFilter#processSuperSampling(int, int)
|
||
123 | */
|
||
124 | public void processSuperSampling(int col, int line) { |
||
125 | process(col, line); |
||
126 | } |
||
127 | |||
128 | /* (non-Javadoc)
|
||
129 | * @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
|
||
130 | */
|
||
131 | public int getInRasterDataType() { |
||
132 | return RasterBuf.TYPE_IMAGE;
|
||
133 | } |
||
134 | |||
135 | /* (non-Javadoc)
|
||
136 | * @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
|
||
137 | */
|
||
138 | public int getOutRasterDataType() { |
||
139 | return RasterBuf.TYPE_IMAGE;
|
||
140 | } |
||
141 | |||
142 | /* (non-Javadoc)
|
||
143 | * @see org.cresques.io.raster.IRasterFilter#post()
|
||
144 | */
|
||
145 | public void post() { |
||
146 | super.post();
|
||
147 | } |
||
148 | |||
149 | /* (non-Javadoc)
|
||
150 | * @see org.cresques.io.raster.RasterFilter#processLine(int)
|
||
151 | */
|
||
152 | public void processLine(int y) { |
||
153 | } |
||
154 | } |