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 / colorbalancergb / ColorBalanceRGBOperation.java @ 43862

History | View | Annotate | Download (3.89 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.colorbalancergb;
24

    
25
import java.util.List;
26

    
27
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
28
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
29
import org.gvsig.raster.lib.legend.impl.ColorManager;
30
import org.gvsig.raster.lib.legend.impl.RasterLegendManagerServices;
31

    
32

    
33
/**
34
 * @author fdiaz
35
 *
36
 */
37
public class ColorBalanceRGBOperation extends AbstractColorBalanceOperation {
38

    
39
    static public String RED_PARAM = "red";
40
    static public String GREEN_PARAM = "green";
41
    static public String BLUE_PARAM = "blue";
42
    static public String LUMINOSITY_PARAM = "luminosity";
43

    
44
    private int red;
45
    private int green;
46
    private int blue;
47
    private boolean luminosity;
48

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

    
57

    
58
    @Override
59
    protected void initialiceParams() {
60
        red = (Integer) this.getParameter(RED_PARAM,0);
61
        green = (Integer) this.getParameter(GREEN_PARAM,0);
62
        blue = (Integer) this.getParameter(BLUE_PARAM,0);
63
        luminosity = (Boolean) this.getParameter(LUMINOSITY_PARAM,true);
64
    }
65

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

    
74
        for (int i = 0; i < inputByteRows[0].length; i++) {
75
            byte[] value = new byte[4];
76
            value[0] = inputByteRows[0][i];
77
            value[1] = inputByteRows[1][i];
78
            value[2] = inputByteRows[2][i];
79

    
80
            double lum = colorManager.getLuminosity(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff);
81

    
82
            value[0] = (byte)Math.min((value[0] & 0xff) + (red >> 1), 255);
83
            value[1] = (byte)Math.min((value[1] & 0xff) + (green >> 1), 255);
84
            value[2] = (byte)Math.min((value[2] & 0xff) + (blue >> 1), 255);
85

    
86
            if(luminosity) {
87
                double[] hsl = colorManager.RGBtoHSL(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff);
88
                hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5);
89
                hsl[1] = (int) (hsl[1] * 255. + 0.5);
90
                hsl[2] = (int) (lum * 255. + 0.5);
91
                int[] v1 = colorManager.HSLtoRGB(
92
                    (int)(((int)hsl[0]) & 0xffffffff),
93
                    (int)(((int)hsl[1]) & 0xffffffff),
94
                    (int)(((int)hsl[2]) & 0xffffffff));
95
                for (int band = 0; band < 3; band++) {
96
                    value[band] = new Integer(v1[band]).byteValue();
97
                }
98
            }
99

    
100
            for (int band = 0; band < inputRows.length; band++) {
101
                ((byte[])(outputRows.get(band)))[i] = value[band];
102
            }
103
        }
104
    }
105

    
106
}