svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.impl / src / main / java / org / gvsig / raster / lib / legend / impl / operations / colorbalancehsl / ColorBalanceHSLOperation.java @ 43803
History | View | Annotate | Download (3.92 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2017 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.raster.lib.legend.impl.operations.colorbalancehsl; |
24 |
|
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
28 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
29 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
30 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
31 |
import org.gvsig.raster.lib.legend.impl.ColorManager; |
32 |
import org.gvsig.raster.lib.legend.impl.RasterLegendManagerServices; |
33 |
import org.gvsig.raster.lib.legend.impl.operations.colorbalancergb.AbstractColorBalanceOperation; |
34 |
|
35 |
|
36 |
/**
|
37 |
* @author fdiaz
|
38 |
*
|
39 |
*/
|
40 |
public class ColorBalanceHSLOperation extends AbstractColorBalanceOperation { |
41 |
|
42 |
static public String COLOR_INTERPRETATION_PARAM = "color_interpretation"; |
43 |
static public String HUE_PARAM = "hue"; |
44 |
static public String LIGHTNESS_PARAM = "lightness"; |
45 |
static public String SATURATION_PARAM = "saturation"; |
46 |
static public String COPY_UNPROCESSED_BANDS_PARAM = "copy_unprocessed_bands"; |
47 |
|
48 |
private ColorInterpretation colorInterpretation;
|
49 |
private double hue = 0; |
50 |
private double lightness = 0; |
51 |
private double saturation = 0; |
52 |
private boolean copyUnprocessedBands; |
53 |
|
54 |
|
55 |
/**
|
56 |
* @param factory
|
57 |
*
|
58 |
*/
|
59 |
public ColorBalanceHSLOperation(OperationFactory factory) {
|
60 |
this.factory = factory;
|
61 |
} |
62 |
|
63 |
@Override
|
64 |
protected void initialiceParams() { |
65 |
hue = (Double) this.parameters.getDynValue(HUE_PARAM); |
66 |
lightness = (Double) this.parameters.getDynValue(LIGHTNESS_PARAM); |
67 |
saturation = (Double) this.parameters.getDynValue(SATURATION_PARAM); |
68 |
} |
69 |
|
70 |
@Override
|
71 |
public void postProcess() throws BufferOperationException { |
72 |
super.postProcess();
|
73 |
} |
74 |
|
75 |
protected void processRow(Object[] inputRows, List outputRows) { |
76 |
ColorManager colorManager = ((RasterLegendManagerServices)RasterLegendLocator.getRasterLegendManager()).getColorManager(); |
77 |
byte[][] inputByteRows = new byte[inputRows.length][((byte[]) inputRows[0]).length]; |
78 |
for (int i = 0; i < inputRows.length; i++) { |
79 |
inputByteRows[i] = (byte[]) inputRows[i]; |
80 |
} |
81 |
|
82 |
for (int i = 0; i < inputByteRows[0].length; i++) { |
83 |
byte[] value = new byte[4]; |
84 |
value[0] = inputByteRows[0][i]; |
85 |
value[1] = inputByteRows[1][i]; |
86 |
value[2] = inputByteRows[2][i]; |
87 |
|
88 |
double[] hsl = colorManager.RGBtoHSL(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff); |
89 |
|
90 |
hsl[0] = ((hsl[0] + hue) % 360); |
91 |
hsl[1] = Math.max(Math.min(hsl[1] + (saturation / 100.0), 1D), 0.001); |
92 |
hsl[2] = Math.max(Math.min(hsl[2] + (lightness / 100.0), 1D), 0); |
93 |
int[] rgb = colorManager.HSLtoRGB(hsl[0], hsl[1], hsl[2]); |
94 |
|
95 |
for (int band = 0; band < 3; band++) { |
96 |
value[band] = (byte)(rgb[band]);
|
97 |
} |
98 |
|
99 |
for (int band = 0; band < inputRows.length; band++) { |
100 |
((byte[])(outputRows.get(band)))[i] = value[band]; |
101 |
} |
102 |
} |
103 |
} |
104 |
} |