Statistics
| Revision:

gvsig-raster / libjni-potrace / trunk / libjni-potrace / src / main / native / jpotrace / potrace.c @ 1780

History | View | Annotate | Download (2.15 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 <stdlib.h>
22
#include <string.h>
23
#include "potrace_raster.h"
24

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

    
37
        cbufferIn = (*env)->GetIntArrayElements(env, bufferIn, NULL);
38

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

    
46
        values = vectorizarBuffer((long *) cbufferIn, width, height, length, list);
47
        // we release the used memory here
48
        (*env)->ReleaseIntArrayElements(env, bufferIn, cbufferIn, 0);
49
        size = (jsize) values[0];
50
        jvalues = (*env)->NewDoubleArray(env, size);
51
        (*env)->SetDoubleArrayRegion(env, jvalues, 0, size, values);
52

    
53
        free(values);
54

    
55
        for (i = 0; i < length; i++) {
56
                jobject string = (*env)->GetObjectArrayElement(env, array, i);
57
                (*env)->ReleaseStringUTFChars(env, string, list[i]);
58
        }
59
        free (list);
60

    
61
        return jvalues;
62
}