Revision 1708 org.gvsig.raster/tags/2.0.0/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/buffer/cache/RasterReadOnlyBuffer.java

View differences:

RasterReadOnlyBuffer.java
97 97
	private int            offset = 1;
98 98
	
99 99
	private int            bufWidth, bufHeight;
100
	private int            blockHeight  = RasterLibrary.blockHeight;
100 101
	
101 102
	/**
102 103
	 * Constructor. Asigna las variables de inicializaci?n y crea la estructura de 
......
112 113
	 */
113 114
	public RasterReadOnlyBuffer(int dataType, int width, int height, int nBand) {
114 115
		this.dataType = dataType;
115
				this.width = width;
116
				this.height = height;
117
				this.nBands = nBand;	
116
		this.width = width;
117
		this.height = height;
118
		this.nBands = nBand;	
118 119
	}
119 120
	
120 121
	/**
......
174 175
		this.maxX = maxX;
175 176
		this.maxY = maxY;
176 177
		
177
		if(Math.abs(maxX - minX) != width)
178
		if(Math.abs(maxX - minX) != width || Math.abs(maxY - minY) != height) {
178 179
			bufWidth = width;
179
		if(Math.abs(maxY - minY) != height) 
180 180
			bufHeight = height;
181
		}
181 182
					
182 183
		init();
183 184
	}
......
190 191
	 */
191 192
	private void init() {
192 193
		//Calculo de los bits por p?gina
193
		int h = RasterLibrary.blockHeight; 
194
		int h = blockHeight; 
194 195
		while(h > 1) {
195 196
			h >>= 1;
196 197
			bitsPag ++;
197 198
		}
198 199
		
199 200
		//Calculo del desplazamiento
200
		offset = RasterLibrary.blockHeight - 1;    
201
		offset = blockHeight - 1;    
201 202
		
202 203
		//Creamos el bufferFactory asociado a la carga de p?ginas. Cada p?gina se fuerza
203 204
		//a que sea cargada en memoria.
......
205 206
		query.setMemoryBuffer(true);
206 207
		query.setDrawableBands(bandList.getDrawableBands());
207 208
		
208
		nPages = (int)Math.ceil((double)height / (double)RasterLibrary.blockHeight);
209
		nPages = (int)Math.ceil((double)height / (double)blockHeight);
209 210
		//double aux = ((double)height / (double)RasterLibrary.blockHeight);
210 211
		//heightLastPage = (int)((aux - (int)aux) * RasterLibrary.blockHeight);
211
		if(height % RasterLibrary.blockHeight == 0)
212
			heightLastPage = RasterLibrary.blockHeight;
212
		if(height % blockHeight == 0)
213
			heightLastPage = blockHeight;
213 214
		else {
214
			double aux = ((double)height / (double)RasterLibrary.blockHeight);
215
			heightLastPage = (int)((aux - (int)aux) * RasterLibrary.blockHeight);
215
			double aux = ((double)height / (double)blockHeight);
216
			heightLastPage = (int)((aux - (int)aux) * blockHeight);
216 217
		}
217 218
		
218 219
		drawableBands = new int[datasource.getBandCount()];
219
			for (int i = 0; i < drawableBands.length; i++) 
220
		for (int i = 0; i < drawableBands.length; i++) 
220 221
			drawableBands[i] = i;
221 222
	}
222 223
	
......
251 252
	 */
252 253
	public Extent[] calcExtentPages(DefaultRasterProvider dataset, int nPages) {
253 254
		Extent datasetExtent = dataset.getExtent();
254
		double h = (RasterLibrary.blockHeight * dataset.getExtent().height()) / dataset.getHeight();
255
		double h = (blockHeight * dataset.getExtent().height()) / dataset.getHeight();
255 256
		Extent[] ext = new Extent[nPages];
256 257
		
257 258
		double minX = datasetExtent.getMin().getX();
......
282 283
	private Buffer queryPage(int pag) throws RasterDriverException, ProcessInterruptedException, InvalidSetViewException {
283 284
		int w = maxX - minX + 1;
284 285
		int h = maxY - minY + 1;
286
		
287
		if((minX + w) > datasource.getWidth())
288
			w = (int)(datasource.getWidth() - minX);
289
		
285 290
		if(bufWidth == 0 && bufHeight == 0) {
286 291
			if(pag == nPages - 1)
287
				query.setAreaOfInterest(minX, (RasterLibrary.blockHeight * pag) + minY, w, heightLastPage);
292
				query.setAreaOfInterest(minX, (blockHeight * pag) + minY, w, heightLastPage);
288 293
			else 
289
				query.setAreaOfInterest(minX, (RasterLibrary.blockHeight * pag) + minY, w, RasterLibrary.blockHeight);
294
				query.setAreaOfInterest(minX, (blockHeight * pag) + minY, w, blockHeight);
290 295
		} else {
291
			int hPage = (int)Math.round((RasterLibrary.blockHeight * h) / (double)bufHeight);
296
			int hPage = (int)Math.round((blockHeight * h) / (double)bufHeight);
292 297
			if(pag == nPages - 1) {
293
				int hLastPage = (int)Math.round((heightLastPage * bufHeight) / (double)h);
294
				query.setAreaOfInterest(minX, (hPage * pag) + minY, w, hLastPage, bufWidth, heightLastPage);
298
				int hLastPage = 0;
299
				if(heightLastPage == bufHeight) {
300
					hLastPage = h;
301
					hPage = 0;
302
				} else
303
					hLastPage = (int)Math.round((heightLastPage * h) / (double)bufHeight);
304
				int newMiY = (hPage * pag) + minY;
305
				if((newMiY + hLastPage) > datasource.getHeight())
306
					hLastPage = (int)(datasource.getHeight() - newMiY);
307
				query.setAreaOfInterest(minX, newMiY, w, hLastPage, bufWidth, heightLastPage);
295 308
			} else 
296
				query.setAreaOfInterest(minX, (hPage * pag) + minY, w, hPage, bufWidth, RasterLibrary.blockHeight);
309
				query.setAreaOfInterest(minX, (hPage * pag) + minY, w, hPage, bufWidth, blockHeight);
297 310
		}
298 311
		return datasource.query(query);
299 312
	}

Also available in: Unified diff