gvsig-raster / org.gvsig.raster.lizardtech / trunk / org.gvsig.raster.lizardtech / org.gvsig.raster.lizardtech.jni / src / main / native / jmrsid / ltiscenebuffer.cpp @ 1019
History | View | Annotate | Download (6.42 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: ltiscenebuffer.cpp 3539 2006-01-09 12:23:20Z nacho $
|
3 |
*
|
4 |
* Name: ltiscenebuffer.c
|
5 |
* Project: JMRSID. Interfaz java to MrSID (Lizardtech).
|
6 |
* Purpose:
|
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 |
#include <jni.h> |
53 |
#include <malloc.h> |
54 |
#include "es_gva_cit_jmrsid_LTISceneBuffer.h" |
55 |
#include "es_gva_cit_jmrsid_JNIBase.h" |
56 |
#include "lti_pixel.h" |
57 |
#include "lti_sceneBuffer.h" |
58 |
#include "../include/jmrsid.h" |
59 |
|
60 |
LT_USE_NAMESPACE(LizardTech); |
61 |
|
62 |
/******************************************************************************/
|
63 |
// Constructor LTISceneBuffer
|
64 |
/******************************************************************************/
|
65 |
|
66 |
|
67 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jmrsid_LTISceneBuffer_LTISceneBufferNat |
68 |
(JNIEnv *env, jobject obj, jlong cPtr, jint tamx, jint tamy, jint flag){ |
69 |
|
70 |
LTISceneBuffer *buffer=NULL;
|
71 |
LTIPixel *pixel = (LTIPixel *) 0 ;
|
72 |
jclass class_mrsidbuffer; |
73 |
jfieldID id_ptrbuffer; |
74 |
t_buffer *datos_ventana = (t_buffer*)malloc(sizeof(t_buffer));
|
75 |
jlong jbuf = 0 ;
|
76 |
jlong jstructbuf = 0 ;
|
77 |
|
78 |
|
79 |
pixel = *(LTIPixel **)&cPtr; |
80 |
|
81 |
//Si el flag es 1 necesitamos un buffer.
|
82 |
|
83 |
if(pixel!=NULL) { |
84 |
if(flag>=1) { |
85 |
//Creamos el buffer
|
86 |
|
87 |
datos_ventana->siz = tamx * tamy; |
88 |
datos_ventana->membuf = new lt_uint8[datos_ventana->siz*3]; |
89 |
datos_ventana->bufs[0] = datos_ventana->membuf;
|
90 |
datos_ventana->bufs[1] = datos_ventana->membuf+datos_ventana->siz;
|
91 |
datos_ventana->bufs[2] = datos_ventana->membuf+datos_ventana->siz*2; |
92 |
|
93 |
//Obtenemos el id del campo que tiene el buffer de la clase LTISceneBuffer de java
|
94 |
|
95 |
class_mrsidbuffer = env->GetObjectClass(obj); |
96 |
id_ptrbuffer = env->GetFieldID( class_mrsidbuffer, "cPtrbuffer", "J"); |
97 |
|
98 |
//Llamamos al constructor pasandole el buffer creado
|
99 |
|
100 |
buffer=new LTISceneBuffer(*pixel,tamx,tamy,datos_ventana->bufs);
|
101 |
|
102 |
//Obtenemos los punteros a objeto buffer y a la estructura con el buffer de memoria
|
103 |
|
104 |
*(t_buffer **)&jstructbuf = datos_ventana; |
105 |
|
106 |
//Guardamos el id del buffer en la parte java
|
107 |
|
108 |
env->SetLongField(obj, id_ptrbuffer, jstructbuf); |
109 |
}else
|
110 |
buffer=new LTISceneBuffer(*pixel,tamx,tamy,NULL); |
111 |
|
112 |
*(LTISceneBuffer **)&jbuf = buffer; |
113 |
|
114 |
}else
|
115 |
return -1; |
116 |
|
117 |
return jbuf;
|
118 |
} |
119 |
|
120 |
|
121 |
/******************************************************************************/
|
122 |
// LTISceneBuffer
|
123 |
/******************************************************************************/
|
124 |
|
125 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jmrsid_LTISceneBuffer_LTISceneBuffer1Nat__JIIIIIII |
126 |
(JNIEnv *env, jobject obj, jlong cPtr, jint totalNumCols, jint totalNumRows, jint colOffset, jint rowOffset, jint windowNumCols, jint windowNumRows, jint flag){ |
127 |
|
128 |
LTISceneBuffer *buffer=NULL;
|
129 |
LTIPixel *pixel = (LTIPixel *) 0 ;
|
130 |
jclass class_mrsidbuffer; |
131 |
jfieldID id_ptrbuffer; |
132 |
t_buffer *datos_ventana = (t_buffer*)malloc(sizeof(t_buffer));
|
133 |
jlong jbuf = 0 ;
|
134 |
jlong jstructbuf = 0 ;
|
135 |
|
136 |
|
137 |
pixel = *(LTIPixel **)&cPtr; |
138 |
|
139 |
//Si el flag es 1 necesitamos un buffer.
|
140 |
|
141 |
if(pixel!=NULL){ |
142 |
if(flag>=1){ |
143 |
|
144 |
//Creamos el buffer
|
145 |
|
146 |
datos_ventana->siz = totalNumCols * totalNumRows; |
147 |
datos_ventana->membuf = new lt_uint8[datos_ventana->siz*3]; |
148 |
datos_ventana->bufs[0] = datos_ventana->membuf;
|
149 |
datos_ventana->bufs[1] = datos_ventana->membuf+datos_ventana->siz;
|
150 |
datos_ventana->bufs[2] = datos_ventana->membuf+datos_ventana->siz*2; |
151 |
|
152 |
//Obtenemos el id del campo que tiene el buffer de la clase LTISceneBuffer de java
|
153 |
|
154 |
class_mrsidbuffer = env->GetObjectClass(obj); |
155 |
id_ptrbuffer = env->GetFieldID( class_mrsidbuffer, "cPtrbuffer", "J"); |
156 |
|
157 |
|
158 |
//Llamamos al constructor pasandole el buffer creado
|
159 |
|
160 |
buffer=new LTISceneBuffer(*pixel, totalNumCols, totalNumRows, colOffset, rowOffset, windowNumCols, windowNumRows, datos_ventana->bufs);
|
161 |
|
162 |
//Obtenemos los punteros a objeto buffer y a la estructura con el buffer de memoria
|
163 |
|
164 |
*(t_buffer **)&jstructbuf = datos_ventana; |
165 |
|
166 |
//Guardamos el id del buffer en la parte java
|
167 |
|
168 |
env->SetLongField(obj, id_ptrbuffer, jstructbuf); |
169 |
}else
|
170 |
buffer=new LTISceneBuffer(*pixel, totalNumCols, totalNumRows, colOffset, rowOffset, windowNumCols, windowNumRows, NULL); |
171 |
|
172 |
|
173 |
*(LTISceneBuffer **)&jbuf = buffer; |
174 |
|
175 |
|
176 |
}else return -1; |
177 |
|
178 |
|
179 |
|
180 |
return jbuf;
|
181 |
} |
182 |
|
183 |
/******************************************************************************/
|
184 |
// ~LTISceneBuffer
|
185 |
/******************************************************************************/
|
186 |
|
187 |
JNIEXPORT void JNICALL Java_es_gva_cit_jmrsid_LTISceneBuffer_FreeLTISceneBufferNat
|
188 |
(JNIEnv *env, jobject obj, jlong cPtr_LTISceneBuffer, jlong cPtr_tbuffer){ |
189 |
|
190 |
LTISceneBuffer *scene = (LTISceneBuffer *) 0 ;
|
191 |
t_buffer *datos_ventana; |
192 |
|
193 |
scene = *(LTISceneBuffer **)&cPtr_LTISceneBuffer; |
194 |
datos_ventana = *(t_buffer **)&cPtr_tbuffer; |
195 |
|
196 |
//Nos cepillamos el buffer y el objeto scenebuffer para que quede todo aseado
|
197 |
|
198 |
if(datos_ventana!=NULL){ |
199 |
if(datos_ventana->membuf!=NULL)delete datos_ventana->membuf; |
200 |
free(datos_ventana); |
201 |
} |
202 |
if(scene!=NULL){ |
203 |
delete scene;
|
204 |
} |
205 |
|
206 |
} |
207 |
|