Statistics
| Revision:

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

History | View | Annotate | Download (20.9 KB)

1
/**********************************************************************
2
 * $Id: rasterband_interfaz.c 4812 2006-04-11 15:11:52Z  $
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
/* 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

    
51

    
52

    
53
#include <jni.h>
54
#include "es_gva_cit_jgdal_GdalRasterBand.h"
55
#include "es_gva_cit_jgdal_JNIBase.h"
56
#include "gdal.h"
57
#include "cpl_string.h"
58

    
59

    
60

    
61

    
62
  
63
/******************************************************************************/
64
//                                                        GetRasterBandXSize
65
/******************************************************************************/
66

    
67

    
68
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterBandXSizeNat
69
  (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
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterBandYSizeNat
90
  (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
  JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getOverviewCountNat
110
  (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
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getOverviewNat
130
  (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
/******************************************************************************/     
149
//                                                                min
150
/******************************************************************************/    
151
  
152
/*int min(int x, int y){
153
        if(x < y)
154
                return x;
155
        else
156
                return y;        
157
}*/
158
  
159
/******************************************************************************/     
160
//                                                                ReadRaster
161
/******************************************************************************/  
162
  
163
  
164
JNIEXPORT jobject JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_readRasterNat
165
  (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
                  
172
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
173
                  
174
                  jbyteArray bytearray;
175
                  jshortArray shortarray;
176
                  jintArray intarray;
177
                  jfloatArray floatarray;
178
                  jdoubleArray doublearray;
179
                  
180
                  unsigned char *pabyScanLineBuf;
181
                  int *buffInt=NULL;
182
                  unsigned int *buffUInt=NULL;
183
                  long *buffLong=NULL;
184
                  unsigned long *buffULong=NULL;
185
                  float *buffFloat=NULL;
186
                  double *buffDouble=NULL;
187
                                   
188
            rb = *(GDALRasterBandH **)&cPtr;
189
                  
190
                  if(rb!=NULL){
191
                          
192
                  //Creamos el objeto java que contendr? la l?nea
193
                  
194
                          class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
195
                          
196
                          if(eBufType==1){
197
                                  
198
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaByte", "(I)V");
199
                                          
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
                                          (*env)->SetByteArrayRegion(env, bytearray, 0, (int)(BufXSize*BufYSize),(jbyte *)pabyScanLineBuf); 
210
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, bytearray);
211
                                }
212
                                if(pabyScanLineBuf != NULL)CPLFree(pabyScanLineBuf);
213
                                
214
                          }else
215
                          
216
                          //------------------------------------------------------------------
217
                          
218
                          if(eBufType==2 || eBufType==3 || eBufType==8){
219
                                  
220
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaShort", "(I)V");
221
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
222
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffShort", "[S");
223
                                            
224
                           //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
225
                                                                              
226
                                  if(eBufType==2){
227
                                          buffUInt = (unsigned int*) CPLMalloc(sizeof(unsigned int) *(int)BufXSize * (int)BufYSize);
228
                                          GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffUInt, (int)BufXSize, (int)BufYSize, GDT_UInt16, 0, 0);
229
                                            shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
230
                                    if(shortarray!=NULL){
231
                                                  (*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffUInt); 
232
                                                  (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray);
233
                                        }
234
                                        if(buffUInt != NULL)CPLFree(buffUInt);
235
                                        return obj_gdalbuffer;                
236
                                  }
237
                                  
238
                                  buffInt = (int*) CPLMalloc(sizeof(int) *(int)BufXSize * (int)BufYSize);
239
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffInt, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
240
                                  shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
241
                            if(shortarray!=NULL){
242
                                          (*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffInt); 
243
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray);
244
                                }
245

    
246
                                if(buffInt != NULL)CPLFree(buffInt);
247
                                
248
                          }else
249
                          
250
                          //------------------------------------------------------------------
251
                          
252
                          if(eBufType==4 || eBufType==5 || eBufType==9){
253
                                  
254
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaInt", "(I)V");
255
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
256
                                  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
                                          buffULong = (unsigned long*) CPLMalloc(sizeof(unsigned long) *(int)BufXSize * (int)BufYSize);
262
                                          GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffULong, (int)BufXSize, (int)BufYSize, GDT_UInt32, 0, 0);
263
                                          intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
264
                                    if(intarray!=NULL){
265
                                                  (*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffULong); 
266
                                                  (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, intarray);
267
                                        }
268
                                        if(buffULong != NULL)CPLFree(buffULong);
269
                                        return obj_gdalbuffer;
270
                                  }
271
                                  
272
                                  buffLong = (long*) CPLMalloc(sizeof(long) *(int)BufXSize * (int)BufYSize);
273
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffLong, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
274
                                  intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
275
                            if(intarray!=NULL){
276
                                          (*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffLong); 
277
                                         (*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
                                  
288
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaFloat", "(I)V");
289
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
290
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffFloat", "[F");
291
                                            
292
                                   //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
293
                           
294
                                   buffFloat = (float*) CPLMalloc(sizeof(float) *(int)BufXSize * (int)BufYSize);
295
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffFloat, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
296
                                  floatarray = (*env)->NewFloatArray(env,(int)(BufXSize*BufYSize));
297
                            if(floatarray!=NULL){
298
                                          (*env)->SetFloatArrayRegion(env, floatarray, 0, (int)(BufXSize*BufYSize),(jfloat *)buffFloat); 
299
                                         (*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
                                  
309
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaDouble", "(I)V");
310
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
311
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffDouble", "[D");
312
                                            
313
                                   //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
314
                           
315
                                   buffDouble = (double*) CPLMalloc(sizeof(double) *(int)BufXSize * (int)BufYSize);
316
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffDouble, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
317
                                  doublearray = (*env)->NewDoubleArray(env,(int)(BufXSize*BufYSize));
318
                            if(doublearray!=NULL){
319
                                          (*env)->SetDoubleArrayRegion(env, doublearray, 0, (int)(BufXSize*BufYSize),(jdouble *)buffDouble); 
320
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, doublearray);
321
                                }
322

    
323
                                if(buffDouble != NULL)CPLFree(buffDouble);
324
                          }
325
                          
326
                  }//if(rb!=NULL)
327
                                    
328
                  return obj_gdalbuffer;
329
                  
330
  } 
331
  
332
/******************************************************************************/     
333
//                                                                ReadRaster
334
/******************************************************************************/  
335
  
336
  
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
                  int dfNoData, bGotNodata;
345
                  
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
                                  int min = GDALGetColorEntryCount( hTable );
387
                                  dfNoData = GDALGetRasterNoDataValue( rb, &bGotNodata );
388
                                  if(256 < min)
389
                                   min = 256;
390
                                         for( i = 0; i < min; i++ ){
391
                                    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
                                    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
                                }
406
                                
407
                                for( i = GDALGetColorEntryCount( hTable ); i < 256; i++ ){
408
                                    abyPCT[i][0] = 0;
409
                                    abyPCT[i][1] = 0;
410
                                    abyPCT[i][2] = 0;
411
                                    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
                                //printf("-%d %d %d %d\n", scanLineBufR[0], scanLineBufG[0], scanLineBufB[0],scanLineBufA[0]);
421
                                  }
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
    
477
    *(GDALColorTableH **)&jresult = hTable;
478
        
479
    if(hTable == NULL)
480
            return -1;
481
    else 
482
            return jresult;
483
  }
484
  
485
/******************************************************************************/
486
//                                                                GetBlockXSize
487
/******************************************************************************/
488

    
489

    
490
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockXSizeNat
491
  (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
JNIEXPORT void JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_writeRasterNat
510
  (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
                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
                  
552
                  
553
                  clase = (*env)->GetObjectClass(env, buffer);
554
                  id_campo = (*env)->GetFieldID(env, clase, funcion, signature);
555
                  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
                  abyRaster, nXSize, nYSize, eBufType, 0, 0 );
571
                  
572
        free(abyRaster);
573
  }
574
    
575
/******************************************************************************/
576
//                                                                GetBlockYSize
577
/******************************************************************************/
578

    
579

    
580
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockYSizeNat
581
  (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
/******************************************************************************/
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
  
612