svn-gvsig-desktop / trunk / libraries / libjni-gdal / src / rasterband_interfaz.c @ 716
History | View | Annotate | Download (7.61 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: rasterband_interfaz.c 716 2004-12-28 14:07:11Z igbrotru $
|
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 |
/*Copyright (C) 2004 Nacho Brodin <brodin_ign@gva.es>
|
11 |
|
12 |
This program is free software; you can redistribute it and/or
|
13 |
modify it under the terms of the GNU General Public License
|
14 |
as published by the Free Software Foundation; either version 2
|
15 |
of the License, or (at your option) any later version.
|
16 |
|
17 |
This program is distributed in the hope that it will be useful,
|
18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
GNU General Public License for more details.
|
21 |
|
22 |
You should have received a copy of the GNU General Public License
|
23 |
along with this program; if not, write to the Free Software
|
24 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
25 |
*/
|
26 |
|
27 |
|
28 |
|
29 |
#include <jni.h> |
30 |
#include "es_gva_cit_wrappergdal_GdalRasterBand.h" |
31 |
#include "es_gva_cit_wrappergdal_JNIBase.h" |
32 |
#include "gdal.h" |
33 |
#include "cpl_string.h" |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
/******************************************************************************/
|
40 |
// GetRasterBandXSize
|
41 |
/******************************************************************************/
|
42 |
|
43 |
|
44 |
JNIEXPORT jint JNICALL Java_es_gva_cit_wrappergdal_JNIBase_getRasterBandXSizeNat |
45 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
46 |
|
47 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
48 |
int res = -1; |
49 |
|
50 |
rb = *(GDALRasterBandH **)&cPtr; |
51 |
|
52 |
if(rb!=NULL) |
53 |
res = GDALGetRasterBandXSize(rb); |
54 |
|
55 |
|
56 |
return res;
|
57 |
} |
58 |
|
59 |
|
60 |
/******************************************************************************/
|
61 |
// GetRasterBandYSize
|
62 |
/******************************************************************************/
|
63 |
|
64 |
|
65 |
JNIEXPORT jint JNICALL Java_es_gva_cit_wrappergdal_JNIBase_getRasterBandYSizeNat |
66 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
67 |
|
68 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
69 |
int res = -1; |
70 |
|
71 |
rb = *(GDALRasterBandH **)&cPtr; |
72 |
|
73 |
if(rb!=NULL) |
74 |
res = GDALGetRasterBandYSize(rb); |
75 |
|
76 |
return res;
|
77 |
|
78 |
} |
79 |
|
80 |
/****************************************************************************/
|
81 |
// GetOverviewCount
|
82 |
/******************************************************************************/
|
83 |
|
84 |
|
85 |
JNIEXPORT jint JNICALL Java_es_gva_cit_wrappergdal_JNIBase_getOverviewCountNat |
86 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
87 |
|
88 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
89 |
int res = -1; |
90 |
|
91 |
rb = *(GDALRasterBandH **)&cPtr; |
92 |
|
93 |
if(rb!=NULL) |
94 |
res = GDALGetOverviewCount(rb); |
95 |
|
96 |
return res;
|
97 |
|
98 |
} |
99 |
|
100 |
/******************************************************************************/
|
101 |
// GetOverview
|
102 |
/******************************************************************************/
|
103 |
|
104 |
|
105 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_wrappergdal_GdalRasterBand_getOverviewNat |
106 |
(JNIEnv *env, jobject obj, jlong cPtr, jint noverview){ |
107 |
|
108 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
109 |
GDALRasterBandH *res = NULL;
|
110 |
jlong jresult = 0;
|
111 |
|
112 |
rb = *(GDALRasterBandH **)&cPtr; |
113 |
|
114 |
if(rb!=NULL) |
115 |
res = GDALGetOverview(rb,(int)noverview);
|
116 |
|
117 |
*(GDALDatasetH **)&jresult = res; |
118 |
|
119 |
if(res==NULL)return -1; |
120 |
else return jresult; |
121 |
|
122 |
} |
123 |
|
124 |
|
125 |
/******************************************************************************/
|
126 |
// ReadRaster
|
127 |
/******************************************************************************/
|
128 |
|
129 |
|
130 |
JNIEXPORT jobject JNICALL Java_es_gva_cit_wrappergdal_GdalRasterBand_readRasterNat |
131 |
(JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jint BufXSize, jint BufYSize, jint eBufType){ |
132 |
|
133 |
jclass class_gdalbuffer; |
134 |
jmethodID metodo; |
135 |
jobject obj_gdalbuffer = NULL;
|
136 |
jfieldID id_campo; |
137 |
unsigned char *pabyScanLineBuf; |
138 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
139 |
jbyteArray bytearray; |
140 |
|
141 |
|
142 |
rb = *(GDALRasterBandH **)&cPtr; |
143 |
|
144 |
if(rb!=NULL){ |
145 |
|
146 |
//Creamos el objeto java que contendr? la l?nea
|
147 |
|
148 |
class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/wrappergdal/GdalBuffer");
|
149 |
metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reserva", "(I)V"); |
150 |
obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(nXSize*nYSize));
|
151 |
id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "pabyScanLineBuf", "[B"); |
152 |
|
153 |
|
154 |
//Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
|
155 |
|
156 |
|
157 |
pabyScanLineBuf = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)nXSize * (int)nYSize); |
158 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, pabyScanLineBuf, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0); |
159 |
|
160 |
bytearray = (*env)->NewByteArray(env,(int)(nXSize*nYSize));
|
161 |
if(bytearray!=NULL){ |
162 |
(*env)->SetByteArrayRegion(env, bytearray, 0, (int)(nXSize*nYSize),(jbyte *)pabyScanLineBuf); |
163 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, bytearray); |
164 |
} |
165 |
|
166 |
|
167 |
//Liberamos la memoria de la linea le?da
|
168 |
|
169 |
|
170 |
if(pabyScanLineBuf != NULL)CPLFree(pabyScanLineBuf); |
171 |
|
172 |
} |
173 |
|
174 |
|
175 |
return obj_gdalbuffer;
|
176 |
} |
177 |
|
178 |
|
179 |
|
180 |
/******************************************************************************/
|
181 |
// GetBlockXSize
|
182 |
/******************************************************************************/
|
183 |
|
184 |
|
185 |
JNIEXPORT jint JNICALL Java_es_gva_cit_wrappergdal_JNIBase_getBlockXSizeNat |
186 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
187 |
|
188 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
189 |
int pnXSize=-1,pnYSize=-1; |
190 |
|
191 |
rb = *(GDALRasterBandH **)&cPtr; |
192 |
|
193 |
if(rb!=NULL) |
194 |
GDALGetBlockSize( rb,&pnXSize, &pnYSize ); |
195 |
|
196 |
return pnXSize;
|
197 |
} |
198 |
|
199 |
|
200 |
/******************************************************************************/
|
201 |
// WriteRaster
|
202 |
/******************************************************************************/
|
203 |
|
204 |
JNIEXPORT void JNICALL Java_es_gva_cit_wrappergdal_GdalRasterBand_writeRasterNat
|
205 |
(JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jobject buffer, jint eBufType){ |
206 |
|
207 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
208 |
jclass clase; |
209 |
jfieldID id_campo; |
210 |
jmethodID metodo; |
211 |
jbyteArray bytearray; |
212 |
int tam;
|
213 |
unsigned char *abyRaster; |
214 |
|
215 |
|
216 |
|
217 |
clase = (*env)->GetObjectClass(env, buffer); |
218 |
id_campo = (*env)->GetFieldID(env, clase, "pabyScanLineBuf", "[B"); |
219 |
metodo = (*env)->GetMethodID(env, clase, "getSize","()I"); |
220 |
tam = (*env)->CallIntMethod(env,buffer,metodo); |
221 |
|
222 |
bytearray =(jbyteArray)(*env)->GetObjectField(env, buffer, id_campo); |
223 |
|
224 |
abyRaster=(unsigned char *)malloc(sizeof(unsigned char)*tam); |
225 |
|
226 |
if(bytearray!=NULL){ |
227 |
(*env)->GetByteArrayRegion(env,bytearray,0,tam,(jbyte *)abyRaster);
|
228 |
} |
229 |
|
230 |
rb = *(GDALRasterBandH **)&cPtr; |
231 |
|
232 |
if(rb!=NULL) |
233 |
GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, |
234 |
abyRaster, nXSize, nYSize, GDT_Byte, 0, 0 ); |
235 |
|
236 |
free(abyRaster); |
237 |
} |
238 |
|
239 |
/******************************************************************************/
|
240 |
// GetBlockYSize
|
241 |
/******************************************************************************/
|
242 |
|
243 |
|
244 |
JNIEXPORT jint JNICALL Java_es_gva_cit_wrappergdal_JNIBase_getBlockYSizeNat |
245 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
246 |
|
247 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
248 |
int pnXSize=-1,pnYSize=-1; |
249 |
|
250 |
rb = *(GDALRasterBandH **)&cPtr; |
251 |
|
252 |
if(rb!=NULL) |
253 |
GDALGetBlockSize( rb,&pnXSize, &pnYSize ); |
254 |
|
255 |
return pnYSize;
|
256 |
} |
257 |
|
258 |
|