root / trunk / libraries / libjni-mrsid / src / ltiscenebuffer.cpp @ 1180
History | View | Annotate | Download (6.36 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: ltiscenebuffer.cpp 1180 2005-01-25 12:04:45Z igbrotru $
|
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 |
/*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 |
#include <jni.h> |
29 |
#include <malloc.h> |
30 |
#include "es_gva_cit_jmrsid_LTISceneBuffer.h" |
31 |
#include "es_gva_cit_jmrsid_JNIBase.h" |
32 |
|
33 |
#include "lt_types.h" |
34 |
#include "lt_base.h" |
35 |
#include "lt_fileSpec.h" |
36 |
#include "lti_geoCoord.h" |
37 |
#include "lti_pixel.h" |
38 |
#include "lti_navigator.h" |
39 |
#include "lti_sceneBuffer.h" |
40 |
#include "lti_metadataDatabase.h" |
41 |
#include "lti_metadataRecord.h" |
42 |
#include "lti_utils.h" |
43 |
#include "MrSIDImageReader.h" |
44 |
#include "J2KImageReader.h" |
45 |
#include "lti_imageReader.h" |
46 |
#include "lti_sceneBuffer.h" |
47 |
#include "lti_scene.h" |
48 |
//#include "cpl_conv.h"
|
49 |
#include "TIFFImageWriter.h" |
50 |
#include "../include/jmrsid.h" |
51 |
|
52 |
LT_USE_NAMESPACE(LizardTech); |
53 |
|
54 |
|
55 |
|
56 |
/******************************************************************************/
|
57 |
// Constructor LTISceneBuffer
|
58 |
/******************************************************************************/
|
59 |
|
60 |
|
61 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jmrsid_LTISceneBuffer_LTISceneBufferNat |
62 |
(JNIEnv *env, jobject obj, jlong cPtr, jint tamx, jint tamy, jint flag){ |
63 |
|
64 |
LTISceneBuffer *buffer=NULL;
|
65 |
LTIPixel *pixel = (LTIPixel *) 0 ;
|
66 |
jclass class_mrsidbuffer; |
67 |
jfieldID id_ptrbuffer; |
68 |
t_buffer *datos_ventana = (t_buffer*)malloc(sizeof(t_buffer));
|
69 |
jlong jbuf = 0 ;
|
70 |
jlong jstructbuf = 0 ;
|
71 |
|
72 |
|
73 |
pixel = *(LTIPixel **)&cPtr; |
74 |
|
75 |
//Si el flag es 1 necesitamos un buffer.
|
76 |
|
77 |
if(pixel!=NULL){ |
78 |
if(flag>=1){ |
79 |
|
80 |
//Creamos el buffer
|
81 |
|
82 |
datos_ventana->siz = tamx * tamy; |
83 |
datos_ventana->membuf = new lt_uint8[datos_ventana->siz*3]; |
84 |
datos_ventana->bufs[0] = datos_ventana->membuf;
|
85 |
datos_ventana->bufs[1] = datos_ventana->membuf+datos_ventana->siz;
|
86 |
datos_ventana->bufs[2] = datos_ventana->membuf+datos_ventana->siz*2; |
87 |
|
88 |
//Obtenemos el id del campo que tiene el buffer de la clase LTISceneBuffer de java
|
89 |
|
90 |
class_mrsidbuffer = env->GetObjectClass(obj); |
91 |
id_ptrbuffer = env->GetFieldID( class_mrsidbuffer, "cPtrbuffer", "J"); |
92 |
|
93 |
|
94 |
//Llamamos al constructor pasandole el buffer creado
|
95 |
|
96 |
buffer=new LTISceneBuffer(*pixel,tamx,tamy,datos_ventana->bufs);
|
97 |
|
98 |
//Obtenemos los punteros a objeto buffer y a la estructura con el buffer de memoria
|
99 |
|
100 |
*(t_buffer **)&jstructbuf = datos_ventana; |
101 |
|
102 |
//Guardamos el id del buffer en la parte java
|
103 |
|
104 |
env->SetLongField(obj, id_ptrbuffer, jstructbuf); |
105 |
|
106 |
}else
|
107 |
buffer=new LTISceneBuffer(*pixel,tamx,tamy,NULL); |
108 |
|
109 |
|
110 |
*(LTISceneBuffer **)&jbuf = buffer; |
111 |
|
112 |
|
113 |
}else return -1; |
114 |
|
115 |
|
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 |
|