Statistics
| Revision:

root / trunk / libraries / libjni-potrace / src / main / native / jpotrace / potrace.c @ 23284

History | View | Annotate | Download (2.01 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
#include <jni.h>
20
#include <stdio.h>
21
#include <string.h>
22
#include "potrace_raster.h"
23

    
24
/**
25
 * Parte de jni para vectorizar un buffer
26
 */
27
JNIEXPORT jdoubleArray JNICALL Java_org_gvsig_jpotrace_Potrace_vectorizeBufferRasterNat(JNIEnv *env, jclass clase, jintArray bufferIn, jint width, jint height, jobjectArray array) {
28
        int i;
29
        jint *cbufferIn;
30
        double *values;
31
        jsize size;
32
        jdoubleArray jvalues;
33

    
34
        cbufferIn = (*env)->GetIntArrayElements(env, bufferIn, NULL);
35

    
36
        jint length = (*env)->GetArrayLength(env, array);
37
        char **list = malloc(length * sizeof(char *));
38
        for (i = 0; i < length; i++) {
39
                jobject string = (*env)->GetObjectArrayElement(env, array, i);
40
                list[i] = (char *) (*env)->GetStringUTFChars(env, string, NULL);
41
        }
42

    
43
        values = vectorizarBuffer((long *) cbufferIn, width, height, length, list);
44
        size = (jsize) values[0];
45
        jvalues = (*env)->NewDoubleArray(env, size);
46
        (*env)->SetDoubleArrayRegion(env, jvalues, 0, size, values);
47

    
48
        free(values);
49

    
50
        for (i = 0; i < length; i++) {
51
                jobject string = (*env)->GetObjectArrayElement(env, array, i);
52
                (*env)->ReleaseStringUTFChars(env, string, list[i]);
53
        }
54
        free (list);
55

    
56
        return jvalues;
57
}