Revision 12097

View differences:

trunk/libraries/libRaster/src/org/gvsig/raster/grid/GridTransparency.java
18 18
 */
19 19
package org.gvsig.raster.grid;
20 20

  
21
import org.gvsig.raster.dataset.IBuffer;
22
import org.gvsig.raster.dataset.properties.DatasetListTransparency;
23 21
import org.gvsig.raster.shared.Transparency;
24 22
import org.gvsig.raster.util.TransparencyRange;
25 23

  
26 24
//TODO: FUNCIONALIDAD: Convertir la transparencia a String y viceversa para salvar proyecto
27 25
/**
28 26
 * <P>
29
 * Representa el estado de transparencia de un grid. Esta estar? formada por la transparencia
30
 * asociada al fichero/s (FileTransparencyStatus) y la transparencia asignada por el usuario
31
 * a la capa. 
27
 * Representa el estado de transparencia de un grid. 
32 28
 * </P>
33 29
 * <P>
34 30
 * El estado de transparencia de un raster puede verse modificado desde los siguientes sitios:
......
44 40
 * asignar valores o rangos de valores como transparentes.</LI>
45 41
 * </UL> 
46 42
 * </P>
43
 * <P>
44
 * Estas transparencias quedan representadas por cinco tipo b?sicos:
45
 * <UL>
46
 * <LI><b>Transparencia por rangos. </b>Esta se aplicar? antes que ninguna y siempre sobre los valores
47
 * base del raster.</LI>
48
 * <LI><b>Banda de transparencia en un raster. </b></LI>
49
 * <LI>M?scara de transparencia</LI>
50
 * <LI>Opacidad</LI>
51
 * <LI>Zona de recorte</LI>
52
 * </UL>
53
 * </P>
47 54
 * @author Nacho Brodin (nachobrodin@gmail.com)
48 55
 *
49 56
 */
......
109 116
	public int processRGB(int rgb, int line, int col) {
110 117
		int[] px = {(rgb & 0xff000000) >> 24, (rgb & 0xff0000) >> 16,
111 118
                	(rgb & 0x00ff00) >> 8, (rgb & 0x0000ff)};
112
		
113
		if(!processRange(px)){
114
			if(existAlphaBand() && getMask() != null)
115
				px[0] = getMask().getElemByte(line, col, 0);
119
			
120
		if(!processRange(px)) {
121
			if(existAlphaBand() && getAlphaBand() != null)
122
				px[0] = getAlphaBand().getElemByte(line, col, 0);
116 123
		}
117 124
			
118
		px[0] &= opacity;
125
		px[0] &= (opacity & 0x000000ff);
119 126
		
120
		return  (((px[0] << 24) & 0xff000000) |
121
                ((px[1] << 16) & 0x00ff0000) |
122
                ((px[2] << 8) & 0x0000ff00) |
123
                (px[3] & 0x0000ff));
127
		return (((px[0] << 24) & 0xff000000) | (rgb & 0x00ffffff));
124 128
	}
125 129
	
126 130
	/**     
......
186 190
	public void setTransparencyActive(boolean transparencyActive) {
187 191
		this.transparencyActive = transparencyActive;
188 192
	}
189
	
190
	/**
191
	 * Obtiene la banda con la transparencia a aplicar en el process
192
	 * @return banda de transparencia a aplicar en el siguiente process
193
	 */
194
	public IBuffer getBand() {
195
		return getMask();
196
	}
197
		
198
	/**
199
	 * Mezcla las bandas de transparencia contenidas en el array IBuffer[] sobre
200
	 * una sola. Para obtener esta mezcla se hace una operaci?n OR dato a dato. La
201
	 * banda resultante tendr? el mayor valor de transparencia de las bandas
202
	 * individuales.
203
	 * 
204
	 * Antes de hacer la mezcla se har?n comprobaciones en las bandas de entrada.
205
	 * Todas deben tener el mismo n?mero de bandas, tipo de datos, ancho y alto. El
206
	 * buffer de salida (out) debe tener memoria reservado con el tama?o de los
207
	 * datos de entrada.
208
	 * 
209
	 * @param bands buffers con las bandas a mezclas
210
	 * @param out buffer de salida
211
	 */
212
	public void mergeTransparencyBands(IBuffer[] bands, IBuffer out) {
213
		if(bands == null || out == null)
214
			return;
215
		int dataType = out.getDataType();
216
		int w = out.getWidth();
217
		int h = out.getHeight();
218
		
219
		//Comprobaci?n de que todas tengan el mismo n?mero de bandas, tipo de datos, ancho y alto 
220
		for(int i = 0; i < bands.length; i++) {
221
			if(	bands[i] == null ||
222
				bands[i].getBandCount() != 1 || 
223
				bands[i].getDataType() != dataType ||
224
				bands[i].getWidth() != w ||
225
				bands[i].getHeight() != h)
226
				return;
227
		}
228
		
229
		for(int line = 0; line < h; line++) {
230
			for(int col = 0; col < w; col++) {
231
				byte value = 0; 
232
				for(int i = 0; i < bands.length; i++)
233
					value |= bands[i].getElemByte(line, col, 0);
234
				out.setElem(line, col, 0, value);
235
			}
236
		}
237
	}
193
			
238 194
}
trunk/libraries/libRaster/src/org/gvsig/raster/grid/render/Rendering.java
242 242
				 int[] step = null;
243 243

  
244 244
				 if (bufferFactory != null) {
245
					 if(lastTransparency == null)
246
						 lastTransparency = new GridTransparency(bufferFactory.getMultiRasterDataset().getTransparencyFilesStatus());
247
					 //Asignamos la banda de transparencia si existe esta
248
					 if(bufferFactory.getMultiRasterDataset().getTransparencyFilesStatus().existAlphaBand()) {
249
						 //BufferFactory bufferFactoryAlphaBand = new BufferFactory(bufferFactory.getMultiRasterDataset());
250
						 bufferFactory.setSupersamplingLoadingBuffer(false);	//Desactivamos el supersampleo en la carga del buffer.
251
						 bufferFactory.clearDrawableBand();
252
						 bufferFactory.addDrawableBands(new int[]{lastTransparency.getAlphaBandNumber(), -1, -1});
253
						 bufferFactory.setAreaOfInterest(adjustedExtent[0], adjustedExtent[1], adjustedExtent[2], adjustedExtent[3], wImg, hImg, true);
254
						 bufferFactory.setSupersamplingLoadingBuffer(true);
255
						 lastTransparency.setAlphaBand(bufferFactory.getRasterBuf());
256
						 lastTransparency.activeTransparency();
257
					 }
245 258
					bufferFactory.clearDrawableBand();
246 259
					bufferFactory.setSupersamplingLoadingBuffer(false);	//Desactivamos el supersampleo en la carga del buffer.
247 260
																		//En el renderizado ser? ImageDrawer el que se encargue de esta funci?n
248 261
					bufferFactory.addDrawableBands(getRenderBands());
249 262
					step = bufferFactory.setAreaOfInterest(adjustedExtent[0], adjustedExtent[1], adjustedExtent[2], adjustedExtent[3], wImg, hImg, true);
250 263
					bufferFactory.setSupersamplingLoadingBuffer(true);
264
					
251 265
				 } else
252 266
					 return;
253 267

  
254 268

  
255 269
				 grid = new Grid(bufferFactory, true);
256
				 if(this.lastTransparency != null) {
257
					 //Asignamos la banda de transparencia si existe esta
258
					 if(bufferFactory.getMultiRasterDataset().getTransparencyFilesStatus().existAlphaBand()) {
259
							BufferFactory bufferFactoryAlphaBand = new BufferFactory(bufferFactory.getMultiRasterDataset());
260
							bufferFactoryAlphaBand.setSupersamplingLoadingBuffer(false);	//Desactivamos el supersampleo en la carga del buffer.
261
							bufferFactoryAlphaBand.addDrawableBands(new int[]{lastTransparency.getAlphaBand(), -1, -1});
262
							bufferFactoryAlphaBand.setAreaOfInterest(adjustedExtent[0], adjustedExtent[1], adjustedExtent[2], adjustedExtent[3], wImg, hImg, true);
263
							lastTransparency.setMask(bufferFactoryAlphaBand.getRasterBuf());
264
							lastTransparency.activeTransparency();
265
					 }
266
					 grid.setTransparency(lastTransparency);
267
				 }
270
				 grid.setTransparency(lastTransparency);
268 271
				 if(filterList == null)
269 272
					 filterList = grid.getFilterList();
270 273
				 else
trunk/libraries/libRaster/src/org/gvsig/raster/grid/render/ImageDrawer.java
151 151
				for(int col = 0; col < width; col ++) {
152 152
					try{
153 153
						rasterBuf.getElemByte(r[row], c[col], data);
154
						value = transparency.processRGB(0xff000000 + ((data[0] & 0xff) << 16) + ((data[1] & 0xff) << 8) + (data[2] & 0xff), row, col);
154
						value = transparency.processRGB(0xff000000 + ((data[0] & 0xff) << 16) + ((data[1] & 0xff) << 8) + (data[2] & 0xff), r[row], c[col]);
155 155
						image.setRGB(col, row, value);
156 156
					} catch(ArrayIndexOutOfBoundsException e){}
157 157
				}
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/bands/ColorTableIntegerFilter.java
45 45
	 */
46 46
	public void process(int col, int line) {
47 47
		int value = raster.getElemInt(line, col, 0);
48
		byte[] rgb = colorTable.getRGBByBand(value);
48
		byte[] rgb = colorTable.getRGBByBand(value & 0x000000ff);
49 49
		rasterResult.setElemByte(line, col, rgb);
50 50
	}
51 51
	
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/bands/ColorTableShortFilter.java
45 45
	 */
46 46
	public void process(int col, int line) {
47 47
		short value = raster.getElemShort(line, col, 0);
48
		byte[] rgb = colorTable.getRGBByBand((int)value);
48
		byte[] rgb = colorTable.getRGBByBand((int)(int)(value & 0x000000ff));
49 49
		rasterResult.setElemByte(line, col, rgb);
50 50
	}
51 51
	
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/bands/ColorTableByteFilter.java
52 52
	 */
53 53
	public void process(int col, int line) {
54 54
		byte value = raster.getElemByte(line, col, 0);
55
		byte[] rgb = colorTable.getRGBByBand((int)value);
55
		byte[] rgb = colorTable.getRGBByBand((int)(value & 0x000000ff));
56 56
		rasterResult.setElemByte(line, col, rgb);
57 57
	}
58 58
	
trunk/libraries/libRaster/src/org/gvsig/raster/shared/Transparency.java
36 36
	public class Transparency{
37 37
		public static int	MAX_OPACITY = 255;
38 38
		
39
		protected int alphaBand = -1;
40
		private IBuffer mask = null;
39
		protected int alphaBandNumber = -1;
40
		private IBuffer alphaBand = null;
41 41
		/**
42 42
		 * Rangos de transparencia aplicados. Lista de TransparencyRange
43 43
		 */
......
61 61
		public Transparency(Transparency t) {
62 62
			//TODO: FUNCIONALIDAD: Falta asignar lo necesario para la transparencia por selecci?n
63 63
			this.transparencyRanges = (ArrayList)t.getTransparencyRange().clone();
64
			this.mask = t.getMask();
64
			this.alphaBand = t.getAlphaBand();
65 65
			this.opacity = t.getOpacity();
66
			this.alphaBand = t.alphaBand;
66
			this.alphaBandNumber = t.alphaBandNumber;
67 67
		}
68 68
		
69 69
		/**
70 70
		 * Obtiene la m?scara asociada
71 71
		 * @return M?scara de transparencia
72 72
		 */
73
		public IBuffer getMask() {
74
			return mask;
73
		public IBuffer getAlphaBand() {
74
			return alphaBand;
75 75
		}
76 76
		
77 77
		/**
78 78
		 * Asigna el buffer con la m?scara
79 79
		 * @param b
80 80
		 */
81
		public void setMask(IBuffer b) {
82
			mask = b;
81
		public void setAlphaBand(IBuffer b) {
82
			alphaBand = b;
83 83
		}
84 84
			    		
85 85
		/**
......
173 173
					getTransparencyRange().add(noDataValue);
174 174
			}
175 175
		}
176
		
176
				
177 177
		/**
178
		 * Simplifica los rangos introducidos si es posible.
179
		 */
180
		/*public void simplify() {
181
			//ArrayList newRangeList = new ArrayList();
182
			for (int i = 0; i < transparencyRanges.size(); i++) {
183
				TransparencyRange tr1 = (TransparencyRange)transparencyRanges.get(i);
184
				if((i + 1) < transparencyRanges.size()) {
185
					for (int j = i + 1; j < transparencyRanges.size(); j++) {
186
						TransparencyRange tr2 = (TransparencyRange)transparencyRanges.get(j);
187
						if(tr2.getAlpha() == tr1.getAlpha() && tr2.isAnd() == tr1.isAnd()) {
188
							int[] r = tr1.union(tr2.getRed(), RasterDataset.RED_BAND);
189
							if(r != null) {
190
								int[] g = tr1.union(tr2.getGreen(), RasterDataset.GREEN_BAND);
191
								int[] b = tr1.union(tr2.getBlue(), RasterDataset.BLUE_BAND);
192
								TransparencyRange rangeToAdd = new TransparencyRange();
193
								rangeToAdd.setRGB(r, g, b);
194
								rangeToAdd.setAnd(tr1.isAnd());
195
								rangeToAdd.loadStrEntryFromValues();
196
								transparencyRanges.remove(i);
197
								transparencyRanges.remove(j);
198
								transparencyRanges.add(i, rangeToAdd);
199
							}
200
						}
201
					}
202
				}
203
			}
204
		}*/
205
		
206
		/**
207 178
		 * Mezcla un objeto Transparency con el actual
208 179
		 * @param ts objeto TransparencyStatus
209 180
		 */
......
220 191
				transparencyRanges.add(tr.get(i));
221 192
			
222 193
			//TODO: FUNCIONALIDAD Mezclamos la m?scara
223
			if(mask != null && transp.getMask() != null) {
224
				IBuffer newMask = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, mask.getWidth(), mask.getHeight(), 1, true);
225
				for (int y = 0; y < mask.getHeight(); y++) {
226
					for (int x = 0; x < mask.getWidth(); x++) {
227
						double v = (mask.getElemByte(y, x, 0) / 255D) * (transp.getMask().getElemByte(y, x, 0) / 255D); 
194
			if(alphaBand != null && transp.getAlphaBand() != null) {
195
				IBuffer newMask = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, alphaBand.getWidth(), alphaBand.getHeight(), 1, true);
196
				for (int y = 0; y < alphaBand.getHeight(); y++) {
197
					for (int x = 0; x < alphaBand.getWidth(); x++) {
198
						double v = (alphaBand.getElemByte(y, x, 0) / 255D) * (transp.getAlphaBand().getElemByte(y, x, 0) / 255D); 
228 199
						newMask.setElem(y, x, 0, (byte)(v * 255));
229 200
					}
230 201
				}
231 202
				t.alphaBand = alphaBand;
232
			} else if(mask != null) {
233
				t.setMask(mask);
234
				t.alphaBand = alphaBand;
203
			} else if(alphaBand != null) {
204
				t.setAlphaBand(alphaBand);
205
				t.alphaBandNumber = alphaBandNumber;
235 206
			} else {
236
				t.setMask(transp.getMask());
237
				t.alphaBand = transp.alphaBand;
207
				t.setAlphaBand(transp.getAlphaBand());
208
				t.alphaBandNumber = transp.alphaBandNumber;
238 209
			}
239 210
			
240
			//TODO: FUNCIONALIDAD Mezclamos las ?reas 
211
			//TODO: FUNCIONALIDAD Mezclamos las ?reas
212
			
213
			//TODO: FUNCIONALIDAD Mezclamos las mascaras 
241 214
			return t;
242 215
		}
243 216

  
......
249 222
		 * @return true si existe banda de transparencia y false si no lo es.
250 223
		 */
251 224
		public boolean existAlphaBand() {
252
			return (alphaBand != -1);
225
			return (alphaBandNumber != -1);
253 226
		}
254 227

  
255 228
		/**
256
		 * Obtiene el flag de existencia de banda de transparencia. 
257
		 * @return true existe una banda con informaci?n de transparencia y false no existe.
258
		 */
259
		public boolean existMask() {
260
			return (mask != null);
261
		}
262
		
263
		/**
264 229
		 * Obtiene la banda de transpareci si existe o -1 si no existe.
265 230
		 * @return n?mero de banda de transparencia o -1 si no existe.
266 231
		 */
267
		public int getAlphaBand() {
268
			return alphaBand;
232
		public int getAlphaBandNumber() {
233
			return alphaBandNumber;
269 234
		}
270 235
		
271 236
		/**
......
275 240
		 * variable mask.
276 241
		 * @param true si existe banda de transparencia y false si no lo es.
277 242
		 */
278
		public void setTransparencyBand(int alphaBand) {
279
			this.alphaBand = alphaBand;
243
		public void setTransparencyBand(int alphaBandNumber) {
244
			this.alphaBandNumber = alphaBandNumber;
280 245
		}
281 246
		
282 247
	}

Also available in: Unified diff