Statistics
| Revision:

root / tags / Root_v051 / libraries / libjni-gdal / src / rasterband_interfaz.c @ 3760

History | View | Annotate | Download (20.4 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
345
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
346
347
                  jbyteArray bytearrayR, bytearrayG, bytearrayB, bytearrayA;
348
349
                  unsigned char *scanLineBufR, *scanLineBufG, *scanLineBufB, *scanLineBufA;
350
351
                  GDALColorTableH hTable;
352
        GByte      abyPCT[256][4];
353
                int i = 0;
354
355
            rb = *(GDALRasterBandH **)&cPtr;
356
357
                  if(rb!=NULL){
358
359
                  //Creamos el objeto java que contendr? la l?nea
360
361
                          class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
362
363
                          if(eBufType==1){
364
365
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaPalette", "(I)V");
366
367
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
368
                                  id_campoR = (*env)->GetFieldID(env, class_gdalbuffer, "buffRPalette", "[B");
369
                                  id_campoG = (*env)->GetFieldID(env, class_gdalbuffer, "buffGPalette", "[B");
370
                                  id_campoB = (*env)->GetFieldID(env, class_gdalbuffer, "buffBPalette", "[B");
371
                                  id_campoA = (*env)->GetFieldID(env, class_gdalbuffer, "buffAPalette", "[B");
372
373
                                //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
374
375
                                  scanLineBufR = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
376
                                  scanLineBufG = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
377
                                  scanLineBufB = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
378
                                  scanLineBufA = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
379
380
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, scanLineBufR, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0);
381
382
                                    hTable = GDALGetRasterColorTable( rb );
383
384
                                  if( hTable != NULL ){
385 3569 nacho
                                  int min = GDALGetColorEntryCount( hTable );
386
                                  if(256 < min)
387
                                   min = 256;
388
                                         for( i = 0; i < min; i++ ){
389 3540 nacho
                                    GDALColorEntry sEntry;
390
391
                                    GDALGetColorEntryAsRGB( hTable, i, &sEntry );
392
                                    abyPCT[i][0] = sEntry.c1;
393
                                    abyPCT[i][1] = sEntry.c2;
394
                                    abyPCT[i][2] = sEntry.c3;
395
                                    abyPCT[i][3] = sEntry.c4;
396
                                }
397
398
                                for( i = GDALGetColorEntryCount( hTable ); i < 256; i++ ){
399
                                    abyPCT[i][0] = i;
400
                                    abyPCT[i][1] = i;
401
                                    abyPCT[i][2] = i;
402
                                    abyPCT[i][3] = 255;
403
                                }
404
405
                                for( i = nXSize * nYSize - 1; i >= 0; i-- ){
406
                                    scanLineBufG[i] = abyPCT[scanLineBufR[i]][1];
407
                                    scanLineBufB[i] = abyPCT[scanLineBufR[i]][2];
408
                                           scanLineBufA[i] = abyPCT[scanLineBufR[i]][3];
409
                                           scanLineBufR[i] = abyPCT[scanLineBufR[i]][0];
410
                                }
411
                                  }
412
413
                                bytearrayR = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
414
                                bytearrayG = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
415
                                bytearrayB = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
416
                                bytearrayA = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
417
                                if(bytearrayR!=NULL){
418
                                          (*env)->SetByteArrayRegion(env, bytearrayR, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufR);
419
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoR, bytearrayR);
420
                                }
421
                                if(scanLineBufR != NULL)
422
                                        CPLFree(scanLineBufR);
423
424
                                if(bytearrayG!=NULL){
425
                                          (*env)->SetByteArrayRegion(env, bytearrayG, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufG);
426
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoG, bytearrayG);
427
                                }
428
                                if(scanLineBufG != NULL)
429
                                        CPLFree(scanLineBufG);
430
431
                                if(bytearrayB!=NULL){
432
                                          (*env)->SetByteArrayRegion(env, bytearrayB, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufB);
433
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoB, bytearrayB);
434
                                }
435
                                if(scanLineBufB != NULL)
436
                                        CPLFree(scanLineBufB);
437
438
                                if(bytearrayA!=NULL){
439
                                          (*env)->SetByteArrayRegion(env, bytearrayA, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufA);
440
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoA, bytearrayA);
441
                                }
442
                                if(scanLineBufA != NULL)
443
                                        CPLFree(scanLineBufA);
444
445
                          }
446
                  }
447
                  //CPLFree(hTable);
448
449
                  return obj_gdalbuffer;
450
451
  }
452
453
/******************************************************************************/
454
//                                                                GetRasterColorTable
455
/******************************************************************************/
456
457
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterColorTableNat
458
  (JNIEnv *env, jobject obj, jlong cPtr){
459
460
        GDALColorTableH hTable = NULL;
461
        jlong jresult = 0;
462
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
463
464
          rb = *(GDALRasterBandH **)&cPtr;
465
        hTable = GDALGetRasterColorTable( rb );
466 716 igbrotru
467 3540 nacho
    *(GDALColorTableH **)&jresult = hTable;
468
469
    if(hTable == NULL)
470
            return -1;
471
    else
472
            return jresult;
473
  }
474
475 716 igbrotru
/******************************************************************************/
476
//                                                                GetBlockXSize
477
/******************************************************************************/
478
479
480 791 igbrotru
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockXSizeNat
481 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
482
483
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
484
          int pnXSize=-1,pnYSize=-1;
485
486
    rb = *(GDALRasterBandH **)&cPtr;
487
488
    if(rb!=NULL)
489
            GDALGetBlockSize( rb,&pnXSize, &pnYSize );
490
491
    return pnXSize;
492
  }
493
494
495
/******************************************************************************/
496
//                                                                WriteRaster
497
/******************************************************************************/
498
499 791 igbrotru
JNIEXPORT void JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_writeRasterNat
500 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jobject buffer, jint eBufType){
501
502
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
503
                  jclass clase;
504
                  jfieldID id_campo;
505
                  jmethodID metodo;
506
                  jbyteArray bytearray;
507
                  int tam;
508
                  unsigned char *abyRaster;
509
510 833 igbrotru
                char funcion[11];
511
                char signature[3];
512
513
                switch(eBufType){
514
                        case 1:
515
                                        strncpy(funcion,"buffByte\0",9);
516
                                        strncpy(signature,"[B\0",3);
517
                                        break;
518
                        case 2:
519
                        case 3:
520
                        case 8:
521
                                        strncpy(funcion,"buffShort\0",10);
522
                                        strncpy(signature,"[S\0",3);
523
                                        break;
524
                        case 4:
525
                        case 5:
526
                        case 9:
527
                                        strncpy(funcion,"buffInt\0",8);
528
                                        strncpy(signature,"[I\0",3);
529
                                        break;
530
                        case 6:
531
                        case 10:
532
                                        strncpy(funcion,"buffFloat\0",10);
533
                                        strncpy(signature,"[F\0",3);
534
                                        break;
535
                        case 7:
536
                        case 11:
537
                                        strncpy(funcion,"buffDouble\0",11);
538
                                        strncpy(signature,"[D\0",3);
539
                                        break;
540
                }
541 716 igbrotru
542
543
                  clase = (*env)->GetObjectClass(env, buffer);
544 833 igbrotru
                  id_campo = (*env)->GetFieldID(env, clase, funcion, signature);
545 716 igbrotru
                  metodo = (*env)->GetMethodID(env, clase, "getSize","()I");
546
                  tam = (*env)->CallIntMethod(env,buffer,metodo);
547
548
                  bytearray =(jbyteArray)(*env)->GetObjectField(env, buffer, id_campo);
549
550
                  abyRaster=(unsigned char *)malloc(sizeof(unsigned char)*tam);
551
552
                  if(bytearray!=NULL){
553
                      (*env)->GetByteArrayRegion(env,bytearray,0,tam,(jbyte *)abyRaster);
554
                }
555
556
                  rb = *(GDALRasterBandH **)&cPtr;
557
558
                  if(rb!=NULL)
559
                          GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize,
560 833 igbrotru
                  abyRaster, nXSize, nYSize, eBufType, 0, 0 );
561 716 igbrotru
562
        free(abyRaster);
563
  }
564
565
/******************************************************************************/
566
//                                                                GetBlockYSize
567
/******************************************************************************/
568
569
570 791 igbrotru
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockYSizeNat
571 716 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
572
573
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
574
          int pnXSize=-1,pnYSize=-1;
575
576
    rb = *(GDALRasterBandH **)&cPtr;
577
578
    if(rb!=NULL)
579
            GDALGetBlockSize( rb,&pnXSize, &pnYSize );
580
581
    return pnYSize;
582
  }
583
584 823 igbrotru
/******************************************************************************/
585
//                                                                GetRasterDataType
586
/******************************************************************************/
587
588
  JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterDataTypeNat
589
  (JNIEnv *env, jobject obj, jlong cPtr){
590
591
          int datatype = -1;
592
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
593
594
          rb = *(GDALRasterBandH **)&cPtr;
595
596
          if(rb!=NULL)
597
            datatype = GDALGetRasterDataType( rb );
598
599
    return datatype;
600
  }
601