svn-gvsig-desktop / tags / v1_9_Build_1250 / libraries / libjni-mrsid-macosx / src / ltiscenebuffer.cpp @ 33791
History | View | Annotate | Download (6.8 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: ltiscenebuffer.cpp 9099 2006-11-29 12:16:22Z mija $
|
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 <stdlib.h> |
55 |
#include "es_gva_cit_jmrsid_LTISceneBuffer.h" |
56 |
#include "es_gva_cit_jmrsid_JNIBase.h" |
57 |
|
58 |
#include "lt_types.h" |
59 |
#include "lt_base.h" |
60 |
#include "lt_fileSpec.h" |
61 |
#include "lti_geoCoord.h" |
62 |
#include "lti_pixel.h" |
63 |
#include "lti_navigator.h" |
64 |
#include "lti_sceneBuffer.h" |
65 |
#include "lti_metadataDatabase.h" |
66 |
#include "lti_metadataRecord.h" |
67 |
#include "lti_utils.h" |
68 |
#include "MrSIDImageReader.h" |
69 |
#include "J2KImageReader.h" |
70 |
#include "lti_imageReader.h" |
71 |
#include "lti_sceneBuffer.h" |
72 |
#include "lti_scene.h" |
73 |
//#include "cpl_conv.h"
|
74 |
#include "TIFFImageWriter.h" |
75 |
#include "../include/jmrsid.h" |
76 |
|
77 |
LT_USE_NAMESPACE(LizardTech); |
78 |
|
79 |
|
80 |
|
81 |
/******************************************************************************/
|
82 |
// Constructor LTISceneBuffer
|
83 |
/******************************************************************************/
|
84 |
|
85 |
|
86 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jmrsid_LTISceneBuffer_LTISceneBufferNat |
87 |
(JNIEnv *env, jobject obj, jlong cPtr, jint tamx, jint tamy, jint flag){ |
88 |
|
89 |
LTISceneBuffer *buffer=NULL;
|
90 |
LTIPixel *pixel = (LTIPixel *) 0 ;
|
91 |
jclass class_mrsidbuffer; |
92 |
jfieldID id_ptrbuffer; |
93 |
t_buffer *datos_ventana = (t_buffer*)malloc(sizeof(t_buffer));
|
94 |
jlong jbuf = 0 ;
|
95 |
jlong jstructbuf = 0 ;
|
96 |
|
97 |
|
98 |
pixel = *(LTIPixel **)&cPtr; |
99 |
|
100 |
//Si el flag es 1 necesitamos un buffer.
|
101 |
|
102 |
if(pixel!=NULL){ |
103 |
if(flag>=1){ |
104 |
|
105 |
//Creamos el buffer
|
106 |
|
107 |
datos_ventana->siz = tamx * tamy; |
108 |
datos_ventana->membuf = new lt_uint8[datos_ventana->siz*3]; |
109 |
datos_ventana->bufs[0] = datos_ventana->membuf;
|
110 |
datos_ventana->bufs[1] = datos_ventana->membuf+datos_ventana->siz;
|
111 |
datos_ventana->bufs[2] = datos_ventana->membuf+datos_ventana->siz*2; |
112 |
|
113 |
//Obtenemos el id del campo que tiene el buffer de la clase LTISceneBuffer de java
|
114 |
|
115 |
class_mrsidbuffer = env->GetObjectClass(obj); |
116 |
id_ptrbuffer = env->GetFieldID( class_mrsidbuffer, "cPtrbuffer", "J"); |
117 |
|
118 |
|
119 |
//Llamamos al constructor pasandole el buffer creado
|
120 |
|
121 |
buffer=new LTISceneBuffer(*pixel,tamx,tamy,datos_ventana->bufs);
|
122 |
|
123 |
//Obtenemos los punteros a objeto buffer y a la estructura con el buffer de memoria
|
124 |
|
125 |
*(t_buffer **)&jstructbuf = datos_ventana; |
126 |
|
127 |
//Guardamos el id del buffer en la parte java
|
128 |
|
129 |
env->SetLongField(obj, id_ptrbuffer, jstructbuf); |
130 |
|
131 |
}else
|
132 |
buffer=new LTISceneBuffer(*pixel,tamx,tamy,NULL); |
133 |
|
134 |
|
135 |
*(LTISceneBuffer **)&jbuf = buffer; |
136 |
|
137 |
|
138 |
}else return -1; |
139 |
|
140 |
|
141 |
|
142 |
return jbuf;
|
143 |
} |
144 |
|
145 |
|
146 |
/******************************************************************************/
|
147 |
// LTISceneBuffer
|
148 |
/******************************************************************************/
|
149 |
|
150 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jmrsid_LTISceneBuffer_LTISceneBuffer1Nat__JIIIIIII |
151 |
(JNIEnv *env, jobject obj, jlong cPtr, jint totalNumCols, jint totalNumRows, jint colOffset, jint rowOffset, jint windowNumCols, jint windowNumRows, jint flag){ |
152 |
|
153 |
LTISceneBuffer *buffer=NULL;
|
154 |
LTIPixel *pixel = (LTIPixel *) 0 ;
|
155 |
jclass class_mrsidbuffer; |
156 |
jfieldID id_ptrbuffer; |
157 |
t_buffer *datos_ventana = (t_buffer*)malloc(sizeof(t_buffer));
|
158 |
jlong jbuf = 0 ;
|
159 |
jlong jstructbuf = 0 ;
|
160 |
|
161 |
|
162 |
pixel = *(LTIPixel **)&cPtr; |
163 |
|
164 |
//Si el flag es 1 necesitamos un buffer.
|
165 |
|
166 |
if(pixel!=NULL){ |
167 |
if(flag>=1){ |
168 |
|
169 |
//Creamos el buffer
|
170 |
|
171 |
datos_ventana->siz = totalNumCols * totalNumRows; |
172 |
datos_ventana->membuf = new lt_uint8[datos_ventana->siz*3]; |
173 |
datos_ventana->bufs[0] = datos_ventana->membuf;
|
174 |
datos_ventana->bufs[1] = datos_ventana->membuf+datos_ventana->siz;
|
175 |
datos_ventana->bufs[2] = datos_ventana->membuf+datos_ventana->siz*2; |
176 |
|
177 |
//Obtenemos el id del campo que tiene el buffer de la clase LTISceneBuffer de java
|
178 |
|
179 |
class_mrsidbuffer = env->GetObjectClass(obj); |
180 |
id_ptrbuffer = env->GetFieldID( class_mrsidbuffer, "cPtrbuffer", "J"); |
181 |
|
182 |
|
183 |
//Llamamos al constructor pasandole el buffer creado
|
184 |
|
185 |
buffer=new LTISceneBuffer(*pixel, totalNumCols, totalNumRows, colOffset, rowOffset, windowNumCols, windowNumRows, datos_ventana->bufs);
|
186 |
|
187 |
//Obtenemos los punteros a objeto buffer y a la estructura con el buffer de memoria
|
188 |
|
189 |
*(t_buffer **)&jstructbuf = datos_ventana; |
190 |
|
191 |
//Guardamos el id del buffer en la parte java
|
192 |
|
193 |
env->SetLongField(obj, id_ptrbuffer, jstructbuf); |
194 |
}else
|
195 |
buffer=new LTISceneBuffer(*pixel, totalNumCols, totalNumRows, colOffset, rowOffset, windowNumCols, windowNumRows, NULL); |
196 |
|
197 |
|
198 |
*(LTISceneBuffer **)&jbuf = buffer; |
199 |
|
200 |
|
201 |
}else return -1; |
202 |
|
203 |
|
204 |
|
205 |
return jbuf;
|
206 |
} |
207 |
|
208 |
/******************************************************************************/
|
209 |
// ~LTISceneBuffer
|
210 |
/******************************************************************************/
|
211 |
|
212 |
JNIEXPORT void JNICALL Java_es_gva_cit_jmrsid_LTISceneBuffer_FreeLTISceneBufferNat
|
213 |
(JNIEnv *env, jobject obj, jlong cPtr_LTISceneBuffer, jlong cPtr_tbuffer){ |
214 |
|
215 |
LTISceneBuffer *scene = (LTISceneBuffer *) 0 ;
|
216 |
t_buffer *datos_ventana; |
217 |
|
218 |
scene = *(LTISceneBuffer **)&cPtr_LTISceneBuffer; |
219 |
datos_ventana = *(t_buffer **)&cPtr_tbuffer; |
220 |
|
221 |
//Nos cepillamos el buffer y el objeto scenebuffer para que quede todo aseado
|
222 |
|
223 |
if(datos_ventana!=NULL){ |
224 |
if(datos_ventana->membuf!=NULL)delete datos_ventana->membuf; |
225 |
free(datos_ventana); |
226 |
} |
227 |
if(scene!=NULL){ |
228 |
delete scene;
|
229 |
} |
230 |
|
231 |
} |
232 |
|