Statistics
| Revision:

svn-gvsig-desktop / tags / Root_v061 / libraries / libjni-gdal / src / rasterband_interfaz.c @ 4812

History | View | Annotate | Download (20.9 KB)

1 716 igbrotru
/**********************************************************************
2
 * $Id$
3
 *
4
 * Name:     rasterband_interfaz.c
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:  Raster band's Basic Funcions.
7
 * Author:   Nacho Brodin, brodin_ign@gva.es
8
 *
9
 **********************************************************************/
10 2210 igbrotru
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
11
*
12
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
13
*
14
* This program is free software; you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License
16
* as published by the Free Software Foundation; either version 2
17
* of the License, or (at your option) any later version.
18
*
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
* GNU General Public License for more details.
23
*
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
27
*
28
* For more information, contact:
29
*
30
*  Generalitat Valenciana
31
*   Conselleria d'Infraestructures i Transport
32
*   Av. Blasco Ib??ez, 50
33
*   46010 VALENCIA
34
*   SPAIN
35
*
36
*      +34 963862235
37
*   gvsig@gva.es
38
*      www.gvsig.gva.es
39
*
40
*    or
41
*
42
*   IVER T.I. S.A
43
*   Salamanca 50
44
*   46005 Valencia
45
*   Spain
46
*
47
*   +34 963163400
48
*   dac@iver.es
49
*/
50 716 igbrotru
51
52
53
#include <jni.h>
54 791 igbrotru
#include "es_gva_cit_jgdal_GdalRasterBand.h"
55
#include "es_gva_cit_jgdal_JNIBase.h"
56 716 igbrotru
#include "gdal.h"
57
#include "cpl_string.h"
58
59
60
61
62
63
/******************************************************************************/
64
//                                                        GetRasterBandXSize
65
/******************************************************************************/
66
67
68 791 igbrotru
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterBandXSizeNat
69 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
70
71
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
72
          int res = -1;
73
74
    rb = *(GDALRasterBandH **)&cPtr;
75
76
    if(rb!=NULL)
77
            res = GDALGetRasterBandXSize(rb);
78
79
80
    return res;
81
  }
82
83
84
/******************************************************************************/
85
//                                                        GetRasterBandYSize
86
/******************************************************************************/
87
88
89 791 igbrotru
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterBandYSizeNat
90 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
91
92
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
93
          int res = -1;
94
95
    rb = *(GDALRasterBandH **)&cPtr;
96
97
    if(rb!=NULL)
98
            res = GDALGetRasterBandYSize(rb);
99
100
    return res;
101
102
  }
103
104
 /****************************************************************************/
105
 //                                                         GetOverviewCount
106
 /******************************************************************************/
107
108
109 791 igbrotru
  JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getOverviewCountNat
110 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
111
112
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
113
          int res = -1;
114
115
    rb = *(GDALRasterBandH **)&cPtr;
116
117
    if(rb!=NULL)
118
                res = GDALGetOverviewCount(rb);
119
120
    return res;
121
122
  }
123
124
/******************************************************************************/
125
//                                                                GetOverview
126
/******************************************************************************/
127
128
129 791 igbrotru
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getOverviewNat
130 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr, jint noverview){
131
132
        GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
133
        GDALRasterBandH *res = NULL;
134
        jlong jresult = 0;
135
136
        rb = *(GDALRasterBandH **)&cPtr;
137
138
    if(rb!=NULL)
139
            res = GDALGetOverview(rb,(int)noverview);
140
141
    *(GDALDatasetH **)&jresult = res;
142
143
    if(res==NULL)return -1;
144
    else return jresult;
145
146
  }
147
148 3540 nacho
/******************************************************************************/
149
//                                                                min
150
/******************************************************************************/
151 716 igbrotru
152 3569 nacho
/*int min(int x, int y){
153 3540 nacho
        if(x < y)
154
                return x;
155
        else
156
                return y;
157 3569 nacho
}*/
158 3540 nacho
159 716 igbrotru
/******************************************************************************/
160
//                                                                ReadRaster
161
/******************************************************************************/
162
163
164 791 igbrotru
JNIEXPORT jobject JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_readRasterNat
165 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jint BufXSize, jint BufYSize, jint eBufType){
166
167
                  jclass class_gdalbuffer;
168
                  jmethodID metodo;
169
                  jobject obj_gdalbuffer = NULL;
170
                  jfieldID id_campo;
171 829 igbrotru
172 716 igbrotru
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
173 829 igbrotru
174 716 igbrotru
                  jbyteArray bytearray;
175 826 igbrotru
                  jshortArray shortarray;
176 829 igbrotru
                  jintArray intarray;
177
                  jfloatArray floatarray;
178
                  jdoubleArray doublearray;
179
180
                  unsigned char *pabyScanLineBuf;
181 828 igbrotru
                  int *buffInt=NULL;
182
                  unsigned int *buffUInt=NULL;
183 829 igbrotru
                  long *buffLong=NULL;
184
                  unsigned long *buffULong=NULL;
185
                  float *buffFloat=NULL;
186
                  double *buffDouble=NULL;
187 830 igbrotru
188 716 igbrotru
            rb = *(GDALRasterBandH **)&cPtr;
189
190
                  if(rb!=NULL){
191
192
                  //Creamos el objeto java que contendr? la l?nea
193
194 791 igbrotru
                          class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
195 826 igbrotru
196
                          if(eBufType==1){
197 1309 igbrotru
198 826 igbrotru
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaByte", "(I)V");
199 3540 nacho
200
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
201
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffByte", "[B");
202
203
                                //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
204
205
                                  pabyScanLineBuf = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
206
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, pabyScanLineBuf, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0);
207
                                bytearray = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
208
                                if(bytearray!=NULL){
209 1309 igbrotru
                                          (*env)->SetByteArrayRegion(env, bytearray, 0, (int)(BufXSize*BufYSize),(jbyte *)pabyScanLineBuf);
210 826 igbrotru
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, bytearray);
211
                                }
212
                                if(pabyScanLineBuf != NULL)CPLFree(pabyScanLineBuf);
213 3540 nacho
214 826 igbrotru
                          }else
215
216 829 igbrotru
                          //------------------------------------------------------------------
217 828 igbrotru
218 826 igbrotru
                          if(eBufType==2 || eBufType==3 || eBufType==8){
219 1309 igbrotru
220 826 igbrotru
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaShort", "(I)V");
221 1309 igbrotru
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
222 826 igbrotru
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffShort", "[S");
223
224
                           //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
225 828 igbrotru
226 829 igbrotru
                                  if(eBufType==2){
227 1309 igbrotru
                                          buffUInt = (unsigned int*) CPLMalloc(sizeof(unsigned int) *(int)BufXSize * (int)BufYSize);
228 829 igbrotru
                                          GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffUInt, (int)BufXSize, (int)BufYSize, GDT_UInt16, 0, 0);
229 1309 igbrotru
                                            shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
230 829 igbrotru
                                    if(shortarray!=NULL){
231 1309 igbrotru
                                                  (*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffUInt);
232 829 igbrotru
                                                  (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray);
233
                                        }
234
                                        if(buffUInt != NULL)CPLFree(buffUInt);
235
                                        return obj_gdalbuffer;
236 828 igbrotru
                                  }
237
238 1309 igbrotru
                                  buffInt = (int*) CPLMalloc(sizeof(int) *(int)BufXSize * (int)BufYSize);
239 829 igbrotru
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffInt, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
240 1309 igbrotru
                                  shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
241 826 igbrotru
                            if(shortarray!=NULL){
242 1309 igbrotru
                                          (*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffInt);
243 828 igbrotru
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray);
244 826 igbrotru
                                }
245 828 igbrotru
246 826 igbrotru
                                if(buffInt != NULL)CPLFree(buffInt);
247 828 igbrotru
248 829 igbrotru
                          }else
249
250
                          //------------------------------------------------------------------
251
252
                          if(eBufType==4 || eBufType==5 || eBufType==9){
253 1309 igbrotru
254 829 igbrotru
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaInt", "(I)V");
255 1309 igbrotru
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
256 829 igbrotru
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffInt", "[I");
257
258
                           //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
259
260
                                  if(eBufType==4){
261 1309 igbrotru
                                          buffULong = (unsigned long*) CPLMalloc(sizeof(unsigned long) *(int)BufXSize * (int)BufYSize);
262 829 igbrotru
                                          GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffULong, (int)BufXSize, (int)BufYSize, GDT_UInt32, 0, 0);
263 1309 igbrotru
                                          intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
264 829 igbrotru
                                    if(intarray!=NULL){
265 1309 igbrotru
                                                  (*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffULong);
266 829 igbrotru
                                                  (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, intarray);
267
                                        }
268
                                        if(buffULong != NULL)CPLFree(buffULong);
269
                                        return obj_gdalbuffer;
270
                                  }
271
272 1309 igbrotru
                                  buffLong = (long*) CPLMalloc(sizeof(long) *(int)BufXSize * (int)BufYSize);
273 829 igbrotru
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffLong, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
274 1309 igbrotru
                                  intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
275 829 igbrotru
                            if(intarray!=NULL){
276 1309 igbrotru
                                          (*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffLong);
277 829 igbrotru
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, intarray);
278
                                }
279
280
                                if(buffLong != NULL)CPLFree(buffLong);
281
282
                          }else
283
284
                          //------------------------------------------------------------------
285
286
                          if(eBufType==6 || eBufType==10){
287 1309 igbrotru
288 829 igbrotru
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaFloat", "(I)V");
289 1309 igbrotru
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
290 829 igbrotru
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffFloat", "[F");
291
292
                                   //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
293
294 1309 igbrotru
                                   buffFloat = (float*) CPLMalloc(sizeof(float) *(int)BufXSize * (int)BufYSize);
295 829 igbrotru
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffFloat, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
296 1309 igbrotru
                                  floatarray = (*env)->NewFloatArray(env,(int)(BufXSize*BufYSize));
297 829 igbrotru
                            if(floatarray!=NULL){
298 1309 igbrotru
                                          (*env)->SetFloatArrayRegion(env, floatarray, 0, (int)(BufXSize*BufYSize),(jfloat *)buffFloat);
299 829 igbrotru
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, floatarray);
300
                                }
301
302
                                if(buffFloat != NULL)CPLFree(buffFloat);
303
                          }else
304
305
                          //------------------------------------------------------------------
306
307
                          if(eBufType==7 || eBufType==11){
308 1309 igbrotru
309 829 igbrotru
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaDouble", "(I)V");
310 1309 igbrotru
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
311 829 igbrotru
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffDouble", "[D");
312
313
                                   //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
314
315 1309 igbrotru
                                   buffDouble = (double*) CPLMalloc(sizeof(double) *(int)BufXSize * (int)BufYSize);
316 829 igbrotru
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffDouble, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
317 1309 igbrotru
                                  doublearray = (*env)->NewDoubleArray(env,(int)(BufXSize*BufYSize));
318 829 igbrotru
                            if(doublearray!=NULL){
319 1309 igbrotru
                                          (*env)->SetDoubleArrayRegion(env, doublearray, 0, (int)(BufXSize*BufYSize),(jdouble *)buffDouble);
320 829 igbrotru
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, doublearray);
321
                                }
322
323
                                if(buffDouble != NULL)CPLFree(buffDouble);
324 826 igbrotru
                          }
325
326 829 igbrotru
                  }//if(rb!=NULL)
327 716 igbrotru
328 826 igbrotru
                  return obj_gdalbuffer;
329 716 igbrotru
330
  }
331
332 3540 nacho
/******************************************************************************/
333
//                                                                ReadRaster
334
/******************************************************************************/
335 716 igbrotru
336 3540 nacho
337
JNIEXPORT jobject JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_readRasterWithPaletteNat
338
  (JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jint BufXSize, jint BufYSize, jint eBufType){
339
340
                  jclass class_gdalbuffer;
341
                  jmethodID metodo;
342
                  jobject obj_gdalbuffer = NULL;
343
                  jfieldID id_campoR, id_campoG, id_campoB, id_campoA;
344 3994 nacho
                  int dfNoData, bGotNodata;
345 3540 nacho
346
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
347
348
                  jbyteArray bytearrayR, bytearrayG, bytearrayB, bytearrayA;
349
350
                  unsigned char *scanLineBufR, *scanLineBufG, *scanLineBufB, *scanLineBufA;
351
352
                  GDALColorTableH hTable;
353
        GByte      abyPCT[256][4];
354
                int i = 0;
355
356
            rb = *(GDALRasterBandH **)&cPtr;
357
358
                  if(rb!=NULL){
359
360
                  //Creamos el objeto java que contendr? la l?nea
361
362
                          class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
363
364
                          if(eBufType==1){
365
366
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaPalette", "(I)V");
367
368
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
369
                                  id_campoR = (*env)->GetFieldID(env, class_gdalbuffer, "buffRPalette", "[B");
370
                                  id_campoG = (*env)->GetFieldID(env, class_gdalbuffer, "buffGPalette", "[B");
371
                                  id_campoB = (*env)->GetFieldID(env, class_gdalbuffer, "buffBPalette", "[B");
372
                                  id_campoA = (*env)->GetFieldID(env, class_gdalbuffer, "buffAPalette", "[B");
373
374
                                //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
375
376
                                  scanLineBufR = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
377
                                  scanLineBufG = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
378
                                  scanLineBufB = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
379
                                  scanLineBufA = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
380
381
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, scanLineBufR, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0);
382
383
                                    hTable = GDALGetRasterColorTable( rb );
384
385
                                  if( hTable != NULL ){
386 3569 nacho
                                  int min = GDALGetColorEntryCount( hTable );
387 3994 nacho
                                  dfNoData = GDALGetRasterNoDataValue( rb, &bGotNodata );
388 3569 nacho
                                  if(256 < min)
389
                                   min = 256;
390
                                         for( i = 0; i < min; i++ ){
391 3540 nacho
                                    GDALColorEntry sEntry;
392
393
                                    GDALGetColorEntryAsRGB( hTable, i, &sEntry );
394
                                    abyPCT[i][0] = sEntry.c1;
395
                                    abyPCT[i][1] = sEntry.c2;
396
                                    abyPCT[i][2] = sEntry.c3;
397 3994 nacho
                                    abyPCT[i][3] = sEntry.c4;
398
                                    if(sEntry.c4 == 0){
399
                                            abyPCT[i][0] = 255;
400
                                            abyPCT[i][1] = 255;
401
                                            abyPCT[i][2] = 255;
402
                                            abyPCT[i][3] = 0;
403
                                    }
404
                                    //printf("%d %d %d %d\n", sEntry.c1,sEntry.c2, sEntry.c3,sEntry.c4);
405 3540 nacho
                                }
406
407
                                for( i = GDALGetColorEntryCount( hTable ); i < 256; i++ ){
408 3994 nacho
                                    abyPCT[i][0] = 0;
409
                                    abyPCT[i][1] = 0;
410
                                    abyPCT[i][2] = 0;
411 3540 nacho
                                    abyPCT[i][3] = 255;
412
                                }
413
414
                                for( i = nXSize * nYSize - 1; i >= 0; i-- ){
415
                                    scanLineBufG[i] = abyPCT[scanLineBufR[i]][1];
416
                                    scanLineBufB[i] = abyPCT[scanLineBufR[i]][2];
417
                                           scanLineBufA[i] = abyPCT[scanLineBufR[i]][3];
418
                                           scanLineBufR[i] = abyPCT[scanLineBufR[i]][0];
419
                                }
420 3994 nacho
                                //printf("-%d %d %d %d\n", scanLineBufR[0], scanLineBufG[0], scanLineBufB[0],scanLineBufA[0]);
421 3540 nacho
                                  }
422
423
                                bytearrayR = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
424
                                bytearrayG = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
425
                                bytearrayB = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
426
                                bytearrayA = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
427
                                if(bytearrayR!=NULL){
428
                                          (*env)->SetByteArrayRegion(env, bytearrayR, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufR);
429
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoR, bytearrayR);
430
                                }
431
                                if(scanLineBufR != NULL)
432
                                        CPLFree(scanLineBufR);
433
434
                                if(bytearrayG!=NULL){
435
                                          (*env)->SetByteArrayRegion(env, bytearrayG, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufG);
436
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoG, bytearrayG);
437
                                }
438
                                if(scanLineBufG != NULL)
439
                                        CPLFree(scanLineBufG);
440
441
                                if(bytearrayB!=NULL){
442
                                          (*env)->SetByteArrayRegion(env, bytearrayB, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufB);
443
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoB, bytearrayB);
444
                                }
445
                                if(scanLineBufB != NULL)
446
                                        CPLFree(scanLineBufB);
447
448
                                if(bytearrayA!=NULL){
449
                                          (*env)->SetByteArrayRegion(env, bytearrayA, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufA);
450
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoA, bytearrayA);
451
                                }
452
                                if(scanLineBufA != NULL)
453
                                        CPLFree(scanLineBufA);
454
455
                          }
456
                  }
457
                  //CPLFree(hTable);
458
459
                  return obj_gdalbuffer;
460
461
  }
462
463
/******************************************************************************/
464
//                                                                GetRasterColorTable
465
/******************************************************************************/
466
467
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterColorTableNat
468
  (JNIEnv *env, jobject obj, jlong cPtr){
469
470
        GDALColorTableH hTable = NULL;
471
        jlong jresult = 0;
472
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
473
474
          rb = *(GDALRasterBandH **)&cPtr;
475
        hTable = GDALGetRasterColorTable( rb );
476 716 igbrotru
477 3540 nacho
    *(GDALColorTableH **)&jresult = hTable;
478
479
    if(hTable == NULL)
480
            return -1;
481
    else
482
            return jresult;
483
  }
484
485 716 igbrotru
/******************************************************************************/
486
//                                                                GetBlockXSize
487
/******************************************************************************/
488
489
490 791 igbrotru
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockXSizeNat
491 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
492
493
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
494
          int pnXSize=-1,pnYSize=-1;
495
496
    rb = *(GDALRasterBandH **)&cPtr;
497
498
    if(rb!=NULL)
499
            GDALGetBlockSize( rb,&pnXSize, &pnYSize );
500
501
    return pnXSize;
502
  }
503
504
505
/******************************************************************************/
506
//                                                                WriteRaster
507
/******************************************************************************/
508
509 791 igbrotru
JNIEXPORT void JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_writeRasterNat
510 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jobject buffer, jint eBufType){
511
512
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
513
                  jclass clase;
514
                  jfieldID id_campo;
515
                  jmethodID metodo;
516
                  jbyteArray bytearray;
517
                  int tam;
518
                  unsigned char *abyRaster;
519
520 833 igbrotru
                char funcion[11];
521
                char signature[3];
522
523
                switch(eBufType){
524
                        case 1:
525
                                        strncpy(funcion,"buffByte\0",9);
526
                                        strncpy(signature,"[B\0",3);
527
                                        break;
528
                        case 2:
529
                        case 3:
530
                        case 8:
531
                                        strncpy(funcion,"buffShort\0",10);
532
                                        strncpy(signature,"[S\0",3);
533
                                        break;
534
                        case 4:
535
                        case 5:
536
                        case 9:
537
                                        strncpy(funcion,"buffInt\0",8);
538
                                        strncpy(signature,"[I\0",3);
539
                                        break;
540
                        case 6:
541
                        case 10:
542
                                        strncpy(funcion,"buffFloat\0",10);
543
                                        strncpy(signature,"[F\0",3);
544
                                        break;
545
                        case 7:
546
                        case 11:
547
                                        strncpy(funcion,"buffDouble\0",11);
548
                                        strncpy(signature,"[D\0",3);
549
                                        break;
550
                }
551 716 igbrotru
552
553
                  clase = (*env)->GetObjectClass(env, buffer);
554 833 igbrotru
                  id_campo = (*env)->GetFieldID(env, clase, funcion, signature);
555 716 igbrotru
                  metodo = (*env)->GetMethodID(env, clase, "getSize","()I");
556
                  tam = (*env)->CallIntMethod(env,buffer,metodo);
557
558
                  bytearray =(jbyteArray)(*env)->GetObjectField(env, buffer, id_campo);
559
560
                  abyRaster=(unsigned char *)malloc(sizeof(unsigned char)*tam);
561
562
                  if(bytearray!=NULL){
563
                      (*env)->GetByteArrayRegion(env,bytearray,0,tam,(jbyte *)abyRaster);
564
                }
565
566
                  rb = *(GDALRasterBandH **)&cPtr;
567
568
                  if(rb!=NULL)
569
                          GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize,
570 833 igbrotru
                  abyRaster, nXSize, nYSize, eBufType, 0, 0 );
571 716 igbrotru
572
        free(abyRaster);
573
  }
574
575
/******************************************************************************/
576
//                                                                GetBlockYSize
577
/******************************************************************************/
578
579
580 791 igbrotru
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockYSizeNat
581 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
582
583
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
584
          int pnXSize=-1,pnYSize=-1;
585
586
    rb = *(GDALRasterBandH **)&cPtr;
587
588
    if(rb!=NULL)
589
            GDALGetBlockSize( rb,&pnXSize, &pnYSize );
590
591
    return pnYSize;
592
  }
593
594 823 igbrotru
/******************************************************************************/
595
//                                                                GetRasterDataType
596
/******************************************************************************/
597
598
  JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterDataTypeNat
599
  (JNIEnv *env, jobject obj, jlong cPtr){
600
601
          int datatype = -1;
602
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
603
604
          rb = *(GDALRasterBandH **)&cPtr;
605
606
          if(rb!=NULL)
607
            datatype = GDALGetRasterDataType( rb );
608
609
    return datatype;
610
  }
611