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 / colorbalancehsl / ColorBalanceHSLOperation.java @ 43862

History | View | Annotate | Download (3.58 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.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 ColorBalanceHSLOperation extends AbstractColorBalanceOperation {
40

    
41
    static public String HUE_PARAM = "hue";
42
    static public String LIGHTNESS_PARAM = "lightness";
43
    static public String SATURATION_PARAM = "saturation";
44

    
45
    private double hue = 0;
46
    private double lightness = 0;
47
    private double saturation = 0;
48

    
49

    
50
    /**
51
     * @param factory
52
     *
53
     */
54
    public ColorBalanceHSLOperation(OperationFactory factory) {
55
        super(factory);
56
    }
57

    
58
    @Override
59
    protected void initialiceParams() {
60
        hue = (Double) this.getParameter(HUE_PARAM,0);
61
        lightness = (Double) this.getParameter(LIGHTNESS_PARAM,0);
62
        saturation = (Double) this.getParameter(SATURATION_PARAM,0);
63
    }
64

    
65
    @Override
66
    public void postProcess() throws BufferOperationException {
67
        super.postProcess();
68
    }
69

    
70
    @Override
71
    protected void processRow(Object[] inputRows, List outputRows) {
72
        ColorManager colorManager = ((RasterLegendManagerServices)RasterLegendLocator.getRasterLegendManager()).getColorManager();
73
        byte[][] inputByteRows = new byte[inputRows.length][((byte[]) inputRows[0]).length];
74
        for (int i = 0; i < inputRows.length; i++) {
75
            inputByteRows[i] = (byte[]) inputRows[i];
76
        }
77

    
78
        for (int i = 0; i < inputByteRows[0].length; i++) {
79
            byte[] value = new byte[4];
80
            value[0] = inputByteRows[0][i];
81
            value[1] = inputByteRows[1][i];
82
            value[2] = inputByteRows[2][i];
83

    
84
            double[] hsl = colorManager.RGBtoHSL(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff);
85

    
86
            hsl[0] = ((hsl[0] + hue) % 360);
87
            hsl[1] = Math.max(Math.min(hsl[1] + (saturation / 100.0), 1D), 0.001);
88
            hsl[2] = Math.max(Math.min(hsl[2] + (lightness / 100.0), 1D), 0);
89
            int[] rgb = colorManager.HSLtoRGB(hsl[0], hsl[1], hsl[2]);
90

    
91
            for (int band = 0; band < 3; band++) {
92
                value[band] = (byte)(rgb[band]);
93
            }
94

    
95
            for (int band = 0; band < inputRows.length; band++) {
96
                ((byte[])(outputRows.get(band)))[i] = value[band];
97
            }
98
        }
99
    }
100
}