Revision 23284 trunk/libraries/libjni-potrace/src/main/native/jpotrace/potrace.c
potrace.c | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
4 | 4 |
* |
... | ... | |
22 | 22 |
#include "potrace_raster.h" |
23 | 23 |
|
24 | 24 |
/** |
25 |
* Parte de jni para vectorizar un fichero de disco |
|
26 |
*/ |
|
27 |
JNIEXPORT void JNICALL Java_org_gvsig_jpotrace_Potrace_vectorizeRasterNat(JNIEnv *env, jclass clase, jstring filein, jstring fileout) { |
|
28 |
const char *infile; |
|
29 |
const char *outfile; |
|
30 |
|
|
31 |
printf("potrace.c: Java_org_gvsig_jpotrace_Potrace_vectorizeRasterNat\n"); |
|
32 |
|
|
33 |
infile = (*env)->GetStringUTFChars(env, filein, 0); |
|
34 |
outfile = (*env)->GetStringUTFChars(env, fileout, 0); |
|
35 |
|
|
36 |
printf("potrace.c: Filein: %s\n", infile); |
|
37 |
printf("potrace.c: Fileout: %s\n", outfile); |
|
38 |
|
|
39 |
vectorizar(infile, outfile); |
|
40 |
|
|
41 |
(*env)->ReleaseStringUTFChars(env, filein, infile); |
|
42 |
(*env)->ReleaseStringUTFChars(env, fileout, outfile); |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 | 25 |
* Parte de jni para vectorizar un buffer |
47 | 26 |
*/ |
48 |
JNIEXPORT jdoubleArray JNICALL Java_org_gvsig_jpotrace_Potrace_vectorizeBufferRasterNat(JNIEnv *env, jclass clase, jintArray bufferIn, jint width, jint height) { |
|
27 |
JNIEXPORT jdoubleArray JNICALL Java_org_gvsig_jpotrace_Potrace_vectorizeBufferRasterNat(JNIEnv *env, jclass clase, jintArray bufferIn, jint width, jint height, jobjectArray array) {
|
|
49 | 28 |
int i; |
50 | 29 |
jint *cbufferIn; |
51 | 30 |
double *values; |
... | ... | |
54 | 33 |
|
55 | 34 |
cbufferIn = (*env)->GetIntArrayElements(env, bufferIn, NULL); |
56 | 35 |
|
57 |
values = vectorizarBuffer((long *) cbufferIn, width, height); |
|
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); |
|
58 | 44 |
size = (jsize) values[0]; |
59 | 45 |
jvalues = (*env)->NewDoubleArray(env, size); |
60 | 46 |
(*env)->SetDoubleArrayRegion(env, jvalues, 0, size, values); |
61 | 47 |
|
62 |
(*env)->ReleaseIntArrayElements(env, bufferIn, cbufferIn, 0);
|
|
48 |
free(values);
|
|
63 | 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 |
|
|
64 | 56 |
return jvalues; |
65 | 57 |
} |
Also available in: Unified diff