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 / colorbalancecmy / ColorBalanceCMYOperation.java @ 43862
History | View | Annotate | Download (4.55 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.colorbalancecmy; |
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.impl.ColorManager; |
31 |
import org.gvsig.raster.lib.legend.impl.RasterLegendManagerServices; |
32 |
import org.gvsig.raster.lib.legend.impl.operations.colorbalancergb.AbstractColorBalanceOperation; |
33 |
|
34 |
|
35 |
/**
|
36 |
* @author fdiaz
|
37 |
*
|
38 |
*/
|
39 |
public class ColorBalanceCMYOperation extends AbstractColorBalanceOperation { |
40 |
|
41 |
static public String CYAN_PARAM = "cyan"; |
42 |
static public String MAGENTA_PARAM = "magenta"; |
43 |
static public String YELLOW_PARAM = "yellow"; |
44 |
static public String LUMINOSITY_PARAM = "luminosity"; |
45 |
|
46 |
private int cyan; |
47 |
private int magenta; |
48 |
private int yellow; |
49 |
private boolean luminosity; |
50 |
|
51 |
/**
|
52 |
* @param factory
|
53 |
*
|
54 |
*/
|
55 |
public ColorBalanceCMYOperation(OperationFactory factory) {
|
56 |
super(factory);
|
57 |
} |
58 |
|
59 |
@Override
|
60 |
protected void initialiceParams() { |
61 |
cyan = (Integer) this.getParameter(CYAN_PARAM,0); |
62 |
magenta = (Integer) this.getParameter(MAGENTA_PARAM,0); |
63 |
yellow = (Integer) this.getParameter(YELLOW_PARAM,0); |
64 |
luminosity = (Boolean) this.getParameter(LUMINOSITY_PARAM,0); |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void postProcess() throws BufferOperationException { |
69 |
super.postProcess();
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
protected void processRow(Object[] inputRows, List outputRows) { |
74 |
ColorManager colorManager = ((RasterLegendManagerServices)RasterLegendLocator.getRasterLegendManager()).getColorManager(); |
75 |
byte[][] inputByteRows = new byte[inputRows.length][((byte[]) inputRows[0]).length]; |
76 |
for (int i = 0; i < inputRows.length; i++) { |
77 |
inputByteRows[i] = (byte[]) inputRows[i]; |
78 |
} |
79 |
// byte[][] outputByteRows = (byte[][]) outputRows;
|
80 |
|
81 |
for (int i = 0; i < inputByteRows[0].length; i++) { |
82 |
byte[] value = new byte[4]; |
83 |
value[0] = inputByteRows[0][i]; |
84 |
value[1] = inputByteRows[1][i]; |
85 |
value[2] = inputByteRows[2][i]; |
86 |
|
87 |
double[] cmyk = colorManager.RGBtoCMYK(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff, 1); |
88 |
double lum = colorManager.getLuminosity(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff); |
89 |
cmyk[0] = Math.min(cmyk[0] + (cyan / 300.0), 1D); //FIXME: ?Por qu? 300 y no 255? |
90 |
cmyk[1] = Math.min(cmyk[1] + (magenta / 300.0), 1D); |
91 |
cmyk[2] = Math.min(cmyk[2] + (yellow / 300.0), 1D); |
92 |
double[] rgb = colorManager.CMYKtoRGB(cmyk[0], cmyk[1], cmyk[2], cmyk[3]); |
93 |
for (int band = 0; band < 3; band++) { |
94 |
value[band] = (byte)(rgb[band] * 255); |
95 |
} |
96 |
|
97 |
if(luminosity) {
|
98 |
double[] hsl = colorManager.RGBtoHSL(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff); |
99 |
hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5); |
100 |
hsl[1] = (int) (hsl[1] * 255. + 0.5); |
101 |
hsl[2] = (int) (lum * 255. + 0.5); |
102 |
int[] v1 = colorManager.HSLtoRGB( |
103 |
(int)(((int)hsl[0]) & 0xffffffff), |
104 |
(int)(((int)hsl[1]) & 0xffffffff), |
105 |
(int)(((int)hsl[2]) & 0xffffffff)); |
106 |
for (int band = 0; band < 3; band++) { |
107 |
value[band] = new Integer(v1[band]).byteValue(); |
108 |
} |
109 |
} |
110 |
|
111 |
for (int band = 0; band < inputRows.length; band++) { |
112 |
((byte[])(outputRows.get(band)))[i] = value[band]; |
113 |
} |
114 |
} |
115 |
} |
116 |
} |