Revision 4377 trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/TransparencyImageFilter.java

View differences:

TransparencyImageFilter.java
53 53
    }
54 54

  
55 55
    /**
56
     * Dado un pixel y un rango, asigna ese pixel al color de transparencia por
57
     * defecto si el pixel en una banda determinada est? en el rango definido.
58
     * @param range        rango
56
     * Asigna al pixel pasado como par?metro como transparente con 
57
     * el color de transparencia que est? seleccionado
58
     * @param px Pixel a asignarle transparencia
59
     */
60
    private void setPixelTransparent(int[] px){
61
		px[0] = this.alpha;
62
        px[1] = this.transparencyColorRed;
63
        px[2] = this.transparencyColorGreen;
64
        px[3] = this.transparencyColorBlue;	
65
    }
66
    
67
    /**     
68
     * @param range rango
59 69
     * @param banda banda
60
     * @param px        pixel
70
     * @param px    pixel
61 71
     */
62
    private void processRange(int[][] range, int banda, int[] px) {
63
        for (int i = 0; i < range.length; i++) {
64
            if (((px[banda] >= range[i][0]) && (px[banda] <= range[i][1]))) {
65
                px[0] = this.alpha;
66
                px[1] = this.transparencyColorRed;
67
                px[2] = this.transparencyColorGreen;
68
                px[3] = this.transparencyColorBlue;
69
            }
70
        }
72
    private void processRange(int[] px) {
73
    	for (int i = 0; i < rangesList.size(); i++) {
74
    		TransparencyRange tr = ((TransparencyRange)rangesList.get(i));
75

  
76
    		if(tr.isAnd()){
77
    			if(tr.getRed() != null)
78
    				if (px[1] < tr.getRed()[0] || px[1] > tr.getRed()[1])
79
    					continue;
80
    			if(tr.getGreen() != null)
81
    				if (px[2] < tr.getGreen()[0] || px[2] > tr.getGreen()[1])
82
    					continue;
83
    			if(tr.getBlue() != null)
84
    				if (px[3] < tr.getBlue()[0] || px[3] > tr.getBlue()[1])
85
    					continue;
86
    			if(tr.getRed() != null || tr.getGreen() != null || tr.getBlue() != null)
87
    				setPixelTransparent(px);
88
    			
89
    		}else{
90
    			if(tr.getRed() != null){
91
    				if (px[1] >= tr.getRed()[0] && px[1] <= tr.getRed()[1]){
92
    					setPixelTransparent(px);
93
    					continue;
94
    				}
95
    			}
96
    			if(tr.getGreen() != null){
97
    				if (px[2] >= tr.getGreen()[0] && px[2] <= tr.getGreen()[1]){
98
    					setPixelTransparent(px);
99
    					continue;
100
    				}
101
    			}
102
    			if(tr.getBlue() != null){
103
    				if (px[3] >= tr.getBlue()[0] && px[3] <= tr.getBlue()[1]){
104
    					setPixelTransparent(px);
105
    					continue;
106
    				}
107
    			}
108
    		}
109
    	}
110
    	
71 111
    }
72

  
112
    
73 113
    /* (non-Javadoc)
74 114
     * @see org.cresques.io.raster.IRasterFilter#process(int, int)
75 115
     */
......
80 120
                        (pt & 0x00ff00) >> 8, (pt & 0x0000ff)
81 121
                    };
82 122

  
83
        if (rangesR != null) {
84
            processRange(rangesR, 1, px4);
85
        }
86

  
87
        if (rangesG != null) {
88
            processRange(rangesG, 2, px4);
89
        }
90

  
91
        if (rangesB != null) {
92
            processRange(rangesB, 3, px4);
93
        }
94

  
123
        processRange(px4);
124
       
95 125
        ((BufferedImage) image).setRGB(x, y,
96 126
                                       (((px4[0] << 24) & 0xff000000) |
97 127
                                       ((px4[1] << 16) & 0x00ff0000) |

Also available in: Unified diff