Statistics
| Revision:

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 @ 43803

History | View | Annotate | Download (4.77 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.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 ColorBalanceCMYOperation extends AbstractColorBalanceOperation {
41

    
42
    static public String CYAN_PARAM = "cyan";
43
    static public String MAGENTA_PARAM = "magenta";
44
    static public String YELLOW_PARAM = "yellow";
45
    static public String LUMINOSITY_PARAM = "luminosity";
46
    static public String COPY_UNPROCESSED_BANDS_PARAM = "copy_unprocessed_bands";
47

    
48
    private int cyan;
49
    private int magenta;
50
    private int yellow;
51
    private boolean luminosity;
52
    private boolean copyUnprocessedBands;
53

    
54
    /**
55
     * @param factory
56
     *
57
     */
58
    public ColorBalanceCMYOperation(OperationFactory factory) {
59
        this.factory = factory;
60
    }
61

    
62
    @Override
63
    protected void initialiceParams() {
64
        cyan = (Integer) this.parameters.getDynValue(CYAN_PARAM);
65
        magenta = (Integer) this.parameters.getDynValue(MAGENTA_PARAM);
66
        yellow = (Integer) this.parameters.getDynValue(YELLOW_PARAM);
67
        luminosity = (Boolean) this.parameters.getDynValue(LUMINOSITY_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
//        byte[][] outputByteRows = (byte[][]) outputRows;
82

    
83
        for (int i = 0; i < inputByteRows[0].length; i++) {
84
            byte[] value = new byte[4];
85
            value[0] = inputByteRows[0][i];
86
            value[1] = inputByteRows[1][i];
87
            value[2] = inputByteRows[2][i];
88

    
89
            double[] cmyk = colorManager.RGBtoCMYK(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff, 1);
90
            double lum = colorManager.getLuminosity(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff);
91
            cmyk[0] = Math.min(cmyk[0] + (cyan / 300.0), 1D); //FIXME: ?Por qu? 300 y no 255?
92
            cmyk[1] = Math.min(cmyk[1] + (magenta / 300.0), 1D);
93
            cmyk[2] = Math.min(cmyk[2] + (yellow / 300.0), 1D);
94
            double[] rgb = colorManager.CMYKtoRGB(cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
95
            for (int band = 0; band < 3; band++) {
96
                value[band] = (byte)(rgb[band] * 255);
97
            }
98

    
99
            if(luminosity) {
100
                double[] hsl = colorManager.RGBtoHSL(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff);
101
                hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5);
102
                hsl[1] = (int) (hsl[1] * 255. + 0.5);
103
                hsl[2] = (int) (lum * 255. + 0.5);
104
                int[] v1 = colorManager.HSLtoRGB(
105
                    (int)(((int)hsl[0]) & 0xffffffff),
106
                    (int)(((int)hsl[1]) & 0xffffffff),
107
                    (int)(((int)hsl[2]) & 0xffffffff));
108
                for (int band = 0; band < 3; band++) {
109
                    value[band] = new Integer(v1[band]).byteValue();
110
                }
111
            }
112

    
113
            for (int band = 0; band < inputRows.length; band++) {
114
                ((byte[])(outputRows.get(band)))[i] = value[band];
115
            }
116
        }
117
    }
118
}