Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / band / ColorBalanceCMYByteFilter.java @ 2443

History | View | Annotate | Download (2.59 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.impl.grid.filter.band;
23

    
24

    
25
/**
26
 * Filtro de balance de colores para tipo de datos byte.
27
 *
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class ColorBalanceCMYByteFilter extends ColorBalanceCMYFilter {
31

    
32
        public void process(int col, int line) {
33
                byte[] value = new byte[4];
34
                value[0] = raster.getElemByte(line, col, redBandNumber);
35
                value[1] = raster.getElemByte(line, col, greenBandNumber);
36
                value[2] = raster.getElemByte(line, col, blueBandNumber);
37
                value[3] = (byte)255;
38
                
39
                double[] cmyk = colorConversion.RGBtoCMYK(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff, 1);
40
                double lum = colorConversion.getLuminosity(value[0] & 0xff, value[1] & 0xff, value[2] & 0xff);
41
                cmyk[0] = Math.min(cmyk[0] + (cyan / 300.0), 1D);
42
                cmyk[1] = Math.min(cmyk[1] + (magenta / 300.0), 1D);
43
                cmyk[2] = Math.min(cmyk[2] + (yellow / 300.0), 1D);
44
                double[] rgb = colorConversion.CMYKtoRGB(cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
45
                for (int band = 0; band < 3; band++)
46
                        value[band] = (byte)(rgb[band] * 255);
47
                
48
                if(luminosity) {
49
                        double[] hsl = colorConversion.RGBtoHSL(value[0] & 0xff, 
50
                                                                                                        value[1] & 0xff, 
51
                                                                                                        value[2] & 0xff);
52
                        hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5);
53
                        hsl[1] = (int) (hsl[1] * 255. + 0.5);
54
                        hsl[2] = (int) (lum * 255. + 0.5);
55
                        int[] v1 = colorConversion.HSLtoRGB((int)(((int)hsl[0]) & 0xffffffff), 
56
                                                                                                (int)(((int)hsl[1]) & 0xffffffff), 
57
                                                                                                (int)(((int)hsl[2]) & 0xffffffff));
58
                        byte[] v = new byte[4];
59
                        for (int band = 0; band < 3; band++)
60
                                v[band] = (byte)v1[band];
61
                        v[3] = value[3];
62
                        getOutputBuffer().setElemByte(line, col, v);
63
                } else
64
                        getOutputBuffer().setElemByte(line, col, value);
65
                
66
                writeAlphaBand(line, col);
67
        }
68
}