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 / buffer / DefaultDataServerWriter.java @ 1073
History | View | Annotate | Download (8.79 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.buffer; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
25 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
26 |
/**
|
27 |
* <code>WriterBufferServer</code> sirve los datos desde un IBuffer para el
|
28 |
* driver de escritura. El driver de escritura que va a volcar un
|
29 |
* <code>IBuffer</code> a imagen en disco va solicitando los datos por bloques
|
30 |
* a medida que va salvando los anteriores. Esta clase es la encargada de hacer
|
31 |
* la divisi?n en bloques del buffer a volcar e ir sirviendolos a medida que el
|
32 |
* driver pide m?s datos.
|
33 |
* </P>
|
34 |
* <P>
|
35 |
* Implementa el interfaz <code>DataServerWriter</code> que es el que define
|
36 |
* m?todos necesarios para el driver. Adem?s es una tarea incrementable por lo
|
37 |
* que deber? implementar el interfaz <code>IIncrementable</code> para poder
|
38 |
* mostrar el dialogo de incremento de tarea.
|
39 |
* </P>
|
40 |
*
|
41 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
42 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
43 |
* @version 27/04/2007
|
44 |
*/
|
45 |
public class DefaultDataServerWriter implements DataServerWriter { |
46 |
private Buffer buffer = null; |
47 |
private Buffer alphaBuffer = null; |
48 |
private int row = 0; |
49 |
/**
|
50 |
* Tama?o de bloque. Este se asignar? en la primera petici?n
|
51 |
*/
|
52 |
private int block = 0; |
53 |
|
54 |
private double percent = 0; |
55 |
private double increment = 0; |
56 |
private int nBand = 0; |
57 |
|
58 |
/**
|
59 |
* Crea un nuevo <code>WriterBufferServer</code>
|
60 |
*/
|
61 |
public DefaultDataServerWriter() {
|
62 |
} |
63 |
|
64 |
/**
|
65 |
* Crea un nuevo <code>WriterBufferServer</code> con el buffer de datos.
|
66 |
* @param buffer
|
67 |
*/
|
68 |
public DefaultDataServerWriter(Buffer buffer) { |
69 |
setBuffer(buffer, -1);
|
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#setBuffer(org.gvsig.fmap.dal.coverage.dataset.Buffer, int)
|
75 |
*/
|
76 |
public void setBuffer(Buffer buffer, int nband) { |
77 |
this.buffer = buffer;
|
78 |
nBand = nband; |
79 |
row = 0;
|
80 |
block = 0;
|
81 |
percent = 0;
|
82 |
increment = 0;
|
83 |
} |
84 |
|
85 |
/*
|
86 |
* (non-Javadoc)
|
87 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#setBand(int)
|
88 |
*/
|
89 |
public void setBand(int nband) { |
90 |
this.nBand = nband;
|
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#readARGBData(int, int, int)
|
96 |
*/
|
97 |
public int[] readARGBData(int sizeX, int sizeY, int nBand) { |
98 |
return null; |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Acciones de inicializaci?n para la lectura de de un bloque
|
103 |
* @param sizeY Tama?o en Y del bloque
|
104 |
*/
|
105 |
private void initRead(int sizeY) { |
106 |
//Si es la primera linea se asigna el tama?o de bloque y el incremento
|
107 |
if (row == 0) { |
108 |
block = sizeY; |
109 |
//nblocks = (int)Math.ceil(((double) buffer.getHeight() / (double) sizeY));
|
110 |
increment = 100D / ((double) buffer.getHeight() / (double) sizeY); |
111 |
} |
112 |
} |
113 |
|
114 |
/*
|
115 |
* (non-Javadoc)
|
116 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#readByteData(int, int)
|
117 |
*/
|
118 |
public byte[][] readByteData(int sizeX, int sizeY) { |
119 |
initRead(sizeY); |
120 |
percent += increment; |
121 |
int len = buffer.getWidth() * sizeY;
|
122 |
int nbands = (nBand < 0) ? buffer.getBandCount() : 1; |
123 |
byte[][] b; |
124 |
if (alphaBuffer != null) |
125 |
b = new byte[nbands + 1][len]; |
126 |
else
|
127 |
b = new byte[nbands][len]; |
128 |
if(nBand < 0) { |
129 |
for (int iBand = 0; iBand < nbands; iBand++) |
130 |
for (int j = row; j < (row + sizeY); j++) |
131 |
for (int i = 0; i < buffer.getWidth(); i++) |
132 |
b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemByte(j, i, iBand); |
133 |
} else {
|
134 |
for (int j = row; j < (row + sizeY); j++) |
135 |
for (int i = 0; i < buffer.getWidth(); i++) |
136 |
b[0][(j % block) * buffer.getWidth() + i] = buffer.getElemByte(j, i, nBand);
|
137 |
} |
138 |
if (alphaBuffer != null) { |
139 |
for (int j = row; j < (row + sizeY); j++) |
140 |
for (int i = 0; i < alphaBuffer.getWidth(); i++) { |
141 |
b[nbands][(j % block) * alphaBuffer.getWidth() + i] = alphaBuffer.getElemByte(j, i, 0);
|
142 |
} |
143 |
} |
144 |
row += sizeY; |
145 |
return b;
|
146 |
} |
147 |
|
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#readShortData(int, int)
|
151 |
*/
|
152 |
public short[][] readShortData(int sizeX, int sizeY) { |
153 |
initRead(sizeY); |
154 |
percent += increment; |
155 |
int len = buffer.getWidth() * sizeY;
|
156 |
int nbands = (nBand < 0) ? buffer.getBandCount() : 1; |
157 |
short[][] b = new short[nbands][len]; |
158 |
if(nBand < 0) { |
159 |
for (int iBand = 0; iBand < nbands; iBand++) |
160 |
for (int j = row; j < (row + sizeY); j++) |
161 |
for (int i = 0; i < buffer.getWidth(); i++) |
162 |
b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemShort(j, i, iBand); |
163 |
} else {
|
164 |
for (int j = row; j < (row + sizeY); j++) |
165 |
for (int i = 0; i < buffer.getWidth(); i++) |
166 |
b[0][(j % block) * buffer.getWidth() + i] = buffer.getElemShort(j, i, nBand);
|
167 |
} |
168 |
row += sizeY; |
169 |
return b;
|
170 |
} |
171 |
|
172 |
/*
|
173 |
* (non-Javadoc)
|
174 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#readIntData(int, int)
|
175 |
*/
|
176 |
public int[][] readIntData(int sizeX, int sizeY) { |
177 |
initRead(sizeY); |
178 |
percent += increment; |
179 |
int len = buffer.getWidth() * sizeY;
|
180 |
int nbands = (nBand < 0) ? buffer.getBandCount() : 1; |
181 |
int[][] b = new int[nbands][len]; |
182 |
if(nBand < 0) { |
183 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) |
184 |
for (int j = row; j < (row + sizeY); j++) |
185 |
for (int i = 0; i < buffer.getWidth(); i++) |
186 |
b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemInt(j, i, iBand); |
187 |
} else {
|
188 |
for (int j = row; j < (row + sizeY); j++) |
189 |
for (int i = 0; i < buffer.getWidth(); i++) |
190 |
b[0][(j % block) * buffer.getWidth() + i] = buffer.getElemInt(j, i, nBand);
|
191 |
} |
192 |
row += sizeY; |
193 |
return b;
|
194 |
} |
195 |
|
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#readFloatData(int, int)
|
199 |
*/
|
200 |
public float[][] readFloatData(int sizeX, int sizeY) { |
201 |
initRead(sizeY); |
202 |
percent += increment; |
203 |
int len = buffer.getWidth() * sizeY;
|
204 |
int nbands = (nBand < 0) ? buffer.getBandCount() : 1; |
205 |
float[][] b = null; |
206 |
if (alphaBuffer != null) |
207 |
b = new float[nbands + 1][len]; |
208 |
else
|
209 |
b = new float[nbands][len]; |
210 |
if(nBand < 0) { |
211 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) |
212 |
for (int j = row; j < (row + sizeY); j++) |
213 |
for (int i = 0; i < buffer.getWidth(); i++) |
214 |
b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemFloat(j, i, iBand); |
215 |
} else {
|
216 |
for (int j = row; j < (row + sizeY); j++) |
217 |
for (int i = 0; i < buffer.getWidth(); i++) |
218 |
b[0][(j % block) * buffer.getWidth() + i] = buffer.getElemFloat(j, i, nBand);
|
219 |
} |
220 |
|
221 |
if (alphaBuffer != null) { |
222 |
for (int j = row; j < (row + sizeY); j++) |
223 |
for (int i = 0; i < alphaBuffer.getWidth(); i++) { |
224 |
b[nbands][(j % block) * alphaBuffer.getWidth() + i] = alphaBuffer.getElemByte(j, i, 0);
|
225 |
} |
226 |
} |
227 |
|
228 |
row += sizeY; |
229 |
return b;
|
230 |
} |
231 |
|
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#readDoubleData(int, int)
|
235 |
*/
|
236 |
public double[][] readDoubleData(int sizeX, int sizeY) { |
237 |
initRead(sizeY); |
238 |
percent += increment; |
239 |
int len = buffer.getWidth() * sizeY;
|
240 |
int nbands = (nBand < 0) ? buffer.getBandCount() : 1; |
241 |
double[][] b = new double[nbands][len]; |
242 |
if(nBand < 0) { |
243 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) |
244 |
for (int j = row; j < (row + sizeY); j++) |
245 |
for (int i = 0; i < buffer.getWidth(); i++) |
246 |
b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemDouble(j, i, iBand); |
247 |
} else {
|
248 |
for (int j = row; j < (row + sizeY); j++) |
249 |
for (int i = 0; i < buffer.getWidth(); i++) |
250 |
b[0][(j % block) * buffer.getWidth() + i] = buffer.getElemDouble(j, i, nBand);
|
251 |
} |
252 |
row += sizeY; |
253 |
return b;
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* Obtiene el porcentaje de incremento de la lectura de datos
|
258 |
* @return
|
259 |
*/
|
260 |
public int getPercent() { |
261 |
return Math.min((int)percent, 100); |
262 |
} |
263 |
|
264 |
/**
|
265 |
* @param alphaBuffer the alphaBuffer to set
|
266 |
*/
|
267 |
public void setAlphaBuffer(Buffer alphaBuffer) { |
268 |
this.alphaBuffer = alphaBuffer;
|
269 |
} |
270 |
|
271 |
/*
|
272 |
* (non-Javadoc)
|
273 |
* @see org.gvsig.fmap.dal.coverage.store.DataServerWriter#getSource()
|
274 |
*/
|
275 |
public Buffer getSource() { |
276 |
return buffer;
|
277 |
} |
278 |
|
279 |
public void dispose() { |
280 |
if(buffer != null) |
281 |
buffer.dispose(); |
282 |
if(alphaBuffer != null) |
283 |
alphaBuffer.dispose(); |
284 |
} |
285 |
} |