Revision 23284

View differences:

trunk/libraries/libjni-potrace/src/test/java/org/gvsig/jpotrace/TestPotrace.java
25 25
public class TestPotrace {
26 26
	
27 27
	TestPotrace() {
28
		try {
29
			Potrace.vectorizeRaster("C:\\TEMP\\wheel.pbm", "C:\\TEMP\\nacho.eps");
30
		} catch (PotraceException e) {
31
			e.printStackTrace();
32
		}
28
//		try {
29
//			Potrace.vectorizeRaster("C:\\TEMP\\wheel.pbm", "C:\\TEMP\\nacho.eps");
30
//		} catch (PotraceException e) {
31
//			e.printStackTrace();
32
//		}
33 33
	}
34 34
	
35 35
	public static void main(String[] args) {
trunk/libraries/libjni-potrace/src/main/native/jpotrace/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
}
trunk/libraries/libjni-potrace/src/main/java/org/gvsig/jpotrace/Potrace.java
23 23
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
24 24
 */
25 25
public class Potrace extends JNIBase {
26
	private static native void vectorizeRasterNat(String filein, String fileout);
27
	private static native double[] vectorizeBufferRasterNat(int[] filein, int width, int height);
26
	private static native double[] vectorizeBufferRasterNat(int[] bufferIn, int width, int height, String[] params);
28 27

  
29 28
	/**
30
	 * Vectoriza un fichero pasado por parametro y lo guarda en fileOut
31
	 * 
32
	 * @param filein
33
	 * @param fileOut
34
	 * @throws PotraceException
35
	 */
36
	public static void vectorizeRaster(String filein, String fileOut) throws PotraceException {
37
		System.out.println("Potrace.vectorizeRaster()");
38

  
39
		if (filein == null)
40
			throw new PotraceException("El nombre del driver es null");
41

  
42
		if (fileOut == null)
43
			throw new PotraceException("El nombre del driver es null");
44
		
45
		
46
//		bufferIn.getWidth();
47
//		bufferIn.getHeight();
48
//		bufferIn.getElemInt(line, col, band)
49

  
50
		vectorizeRasterNat(filein, fileOut);
51
	}
52
	
53
	/**
54 29
	 * Vectoriza un buffer pasado por parametro y lo guarda en fileOut. Hay que
55 30
	 * especificar el ancho y alto del buffer y el buffer ha de ser pasado en el
56 31
	 * formato que soporta potrace, que es en forma de bits.
......
59 34
	 * @param fileOut
60 35
	 * @throws PotraceException
61 36
	 */
62
	public static double[] vectorizeBufferRaster(int[] bufferIn, int width, int height) throws PotraceException {
37
	public static double[] vectorizeBufferRaster(int[] bufferIn, int width, int height, String[] params) throws PotraceException {
63 38
		if (bufferIn == null)
64 39
			throw new PotraceException("El nombre del driver es null");
65 40

  
66
		return vectorizeBufferRasterNat(bufferIn, width, height);
41
		return vectorizeBufferRasterNat(bufferIn, width, height, params);
67 42
	}
68
}

43
}

Also available in: Unified diff