Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_909 / libraries / libjni-mrsid / src / ltiscenebuffer.cpp @ 43637

History | View | Annotate | Download (6.78 KB)

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