Revision 31777
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/src/main/java/org/gvsig/jpotrace/JNIBase.java | ||
---|---|---|
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 |
package org.gvsig.jpotrace; |
|
20 |
/** |
|
21 |
* La clase <code>JNIBase</code> sirve para cargar la libreria de jpotrace |
|
22 |
* |
|
23 |
* @version 31/07/2008 |
|
24 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
25 |
*/ |
|
26 |
public class JNIBase { |
|
27 |
static { |
|
28 |
String os = System.getProperty("os.name"); |
|
29 |
if (os.toLowerCase().startsWith("windows")) |
|
30 |
System.loadLibrary("jpotrace001"); |
|
31 |
else |
|
32 |
System.loadLibrary("jpotrace"); |
|
33 |
} |
|
34 |
} |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/src/main/java/org/gvsig/jpotrace/PotraceException.java | ||
---|---|---|
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 |
package org.gvsig.jpotrace; |
|
20 |
/** |
|
21 |
* La clase <code>PotraceException</code> es una forma de expresar que un |
|
22 |
* parametro ha sido mal usado en la libreria de jpotrace |
|
23 |
|
|
24 |
* @version 31/07/2008 |
|
25 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
26 |
*/ |
|
27 |
public class PotraceException extends Exception { |
|
28 |
private static final long serialVersionUID = -5761750440639572006L; |
|
29 |
|
|
30 |
public PotraceException(String msg) { |
|
31 |
super(msg); |
|
32 |
} |
|
33 |
} |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/src/main/java/org/gvsig/jpotrace/Potrace.java | ||
---|---|---|
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 |
package org.gvsig.jpotrace; |
|
20 |
/** |
|
21 |
* La clase <code>Potrace</code> contiene los metodos que comunican la libreria |
|
22 |
* nativa con Java |
|
23 |
* |
|
24 |
* @version 31/07/2008 |
|
25 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
26 |
*/ |
|
27 |
public class Potrace extends JNIBase { |
|
28 |
private static native double[] vectorizeBufferRasterNat(int[] bufferIn, int width, int height, String[] params); |
|
29 |
|
|
30 |
/** |
|
31 |
* Vectoriza un buffer pasado por parametro y es devuelto en forma de array |
|
32 |
* de doubles. Hay que especificar el ancho y alto del buffer y el buffer ha |
|
33 |
* de ser pasado en el formato que soporta potrace, que es en forma de bits. |
|
34 |
* |
|
35 |
* El parametro params es un array de Strings como se usaria en el tipico |
|
36 |
* main(char[]) para expresar los parametros de potrace, es una forma de poder |
|
37 |
* aprovechar todos los parametros del comando potrace desde Java. Algunos |
|
38 |
* no funcionan, como especificar el fichero origen o destino |
|
39 |
* |
|
40 |
* @param bufferIn |
|
41 |
* @param width |
|
42 |
* @param height |
|
43 |
* @param params |
|
44 |
* @return |
|
45 |
* @throws PotraceException |
|
46 |
*/ |
|
47 |
public static double[] vectorizeBufferRaster(int[] bufferIn, int width, int height, String[] params) throws PotraceException { |
|
48 |
if (bufferIn == null) |
|
49 |
throw new PotraceException("El parametro Buffer no puede estar vacio"); |
|
50 |
|
|
51 |
if (width <= 0) |
|
52 |
throw new PotraceException("El ancho del buffer ha de ser mayor a 0"); |
|
53 |
|
|
54 |
if (height <= 0) |
|
55 |
throw new PotraceException("El alto del buffer ha de ser mayor a 0"); |
|
56 |
|
|
57 |
return vectorizeBufferRasterNat(bufferIn, width, height, params); |
|
58 |
} |
|
59 |
} |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/src/main/native/jpotrace/potrace.c | ||
---|---|---|
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 |
size = (jsize) values[0]; |
|
48 |
jvalues = (*env)->NewDoubleArray(env, size); |
|
49 |
(*env)->SetDoubleArrayRegion(env, jvalues, 0, size, values); |
|
50 |
|
|
51 |
free(values); |
|
52 |
|
|
53 |
for (i = 0; i < length; i++) { |
|
54 |
jobject string = (*env)->GetObjectArrayElement(env, array, i); |
|
55 |
(*env)->ReleaseStringUTFChars(env, string, list[i]); |
|
56 |
} |
|
57 |
free (list); |
|
58 |
|
|
59 |
return jvalues; |
|
60 |
} |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/src/main/native/jpotrace/CMakeLists.txt | ||
---|---|---|
1 |
set(LIB_NAME jpotrace) |
|
2 |
|
|
3 |
FILE(GLOB LIB_PUBLIC_HEADERS "${HEADER_PATH}/*.h") |
|
4 |
FILE(GLOB LIB_COMMON_FILES "*.c*") |
|
5 |
|
|
6 |
include_directories( |
|
7 |
${CMAKE_SOURCE_DIR}/include |
|
8 |
${JAVA_INCLUDE_PATH} |
|
9 |
${JAVA_INCLUDE_PATH2} |
|
10 |
${POTRACE_INCLUDE_DIR} |
|
11 |
) |
|
12 |
|
|
13 |
add_library(${LIB_NAME} SHARED |
|
14 |
${LIB_PUBLIC_HEADERS} |
|
15 |
${LIB_COMMON_FILES} |
|
16 |
) |
|
17 |
|
|
18 |
target_link_libraries(${LIB_NAME} |
|
19 |
${POTRACE_LIBRARY} |
|
20 |
) |
|
21 |
|
|
22 |
if(APPLE) |
|
23 |
SET_TARGET_PROPERTIES(${LIB_NAME} |
|
24 |
PROPERTIES |
|
25 |
SUFFIX .jnilib) |
|
26 |
endif(APPLE) |
|
27 |
|
|
28 |
INCLUDE(ModuleInstall OPTIONAL) |
|
29 |
|
|
30 |
SET_TARGET_PROPERTIES(jpotrace PROPERTIES VERSION "${JPOTRACE_VERSION}") |
|
31 |
IF(WIN32) |
|
32 |
SET_TARGET_PROPERTIES(jpotrace PROPERTIES OUTPUT_NAME "jpotrace${JPOTRACE_VERSION}") |
|
33 |
ENDIF(WIN32) |
|
34 |
IF(UNIX) |
|
35 |
SET_TARGET_PROPERTIES(jpotrace PROPERTIES OUTPUT_NAME "jpotrace${VERSION}") |
|
36 |
ENDIF(UNIX) |
|
37 |
|
|
38 |
IF(UNIX AND NOT APPLE) |
|
39 |
SET_TARGET_PROPERTIES ( ${LIB_NAME} PROPERTIES LINK_FLAGS "-Wl,-E") |
|
40 |
ENDIF(UNIX AND NOT APPLE) |
|
41 |
|
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/CMakeModules/ModuleInstall.cmake | ||
---|---|---|
1 |
# INSTALL and SOURCE_GROUP commands for OSG/OT/Producer Modules |
|
2 |
|
|
3 |
# Required Vars: |
|
4 |
# ${LIB_NAME} |
|
5 |
# ${LIB_PUBLIC_HEADERS} |
|
6 |
|
|
7 |
SET(INSTALL_INCDIR include) |
|
8 |
SET(INSTALL_BINDIR bin) |
|
9 |
IF(WIN32) |
|
10 |
SET(INSTALL_BINDIR .) |
|
11 |
SET(INSTALL_LIBDIR .) |
|
12 |
SET(INSTALL_ARCHIVEDIR lib) |
|
13 |
ELSE(WIN32) |
|
14 |
SET(INSTALL_BINDIR .) |
|
15 |
SET(INSTALL_LIBDIR .) |
|
16 |
SET(INSTALL_ARCHIVEDIR lib) |
|
17 |
ENDIF(WIN32) |
|
18 |
|
|
19 |
SET(HEADERS_GROUP "Header Files") |
|
20 |
|
|
21 |
SOURCE_GROUP( |
|
22 |
${HEADERS_GROUP} |
|
23 |
FILES ${LIB_PUBLIC_HEADERS} |
|
24 |
) |
|
25 |
|
|
26 |
|
|
27 |
INSTALL( |
|
28 |
TARGETS ${LIB_NAME} |
|
29 |
RUNTIME DESTINATION ${INSTALL_BINDIR} |
|
30 |
LIBRARY DESTINATION ${INSTALL_LIBDIR} |
|
31 |
ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR} |
|
32 |
) |
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
# FIXME: Do not run for OS X framework |
|
37 |
#INSTALL( |
|
38 |
# FILES ${LIB_PUBLIC_HEADERS} |
|
39 |
# DESTINATION ${INSTALL_INCDIR}/${LIB_NAME} |
|
40 |
#) |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/CMakeModules/FindPOTRACE.cmake | ||
---|---|---|
1 |
# Locate potrace |
|
2 |
# This module defines |
|
3 |
# POTRACE_LIBRARY |
|
4 |
# POTRACE_FOUND, if false, do not try to link to potrace |
|
5 |
# POTRACE_INCLUDE_DIR, where to find the headers |
|
6 |
# |
|
7 |
# $POTRACE_DIR is an environment variable that would |
|
8 |
# correspond to the ./configure --prefix=$POTRACE_DIR |
|
9 |
# |
|
10 |
# Created by Borja Sanchez Zamorano |
|
11 |
|
|
12 |
FIND_PATH(POTRACE_INCLUDE_DIR potracelib.h |
|
13 |
C:/workspace/workspace-HEADRASTER/potrace-1.8/src |
|
14 |
/home/borsanza/nacho/WRaster/potrace/src |
|
15 |
) |
|
16 |
|
|
17 |
FIND_LIBRARY(POTRACE_LIBRARY |
|
18 |
NAMES libpotrace180 potrace POTRACE |
|
19 |
PATHS |
|
20 |
C:/workspace/workspace-HEADRASTER/binaries/w32 |
|
21 |
/home/borsanza/nacho/WRaster/binaries/linux |
|
22 |
) |
|
23 |
|
|
24 |
SET(POTRACE_FOUND "NO") |
|
25 |
IF(POTRACE_LIBRARY AND POTRACE_INCLUDE_DIR) |
|
26 |
SET(POTRACE_FOUND "YES") |
|
27 |
ENDIF(POTRACE_LIBRARY AND POTRACE_INCLUDE_DIR) |
|
28 |
|
|
29 |
IF(POTRACE_LIBRARY) |
|
30 |
MESSAGE(STATUS "POTRACE_LIBRARY: " ${POTRACE_LIBRARY}) |
|
31 |
ELSE(POTRACE_LIBRARY) |
|
32 |
MESSAGE(STATUS "POTRACE_LIBRARY: NOT FOUND") |
|
33 |
ENDIF(POTRACE_LIBRARY) |
|
34 |
|
|
35 |
IF(POTRACE_INCLUDE_DIR) |
|
36 |
MESSAGE(STATUS "POTRACE_INCLUDE_DIR: " ${POTRACE_INCLUDE_DIR}) |
|
37 |
ELSE(POTRACE_INCLUDE_DIR) |
|
38 |
MESSAGE(STATUS "POTRACE_INCLUDE_DIR: NOT FOUND") |
|
39 |
ENDIF(POTRACE_INCLUDE_DIR) |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/resources/potrace-1.8/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>potrace-Release@potrace-1.8</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.cdt.make.core.makeBuilder</name> |
|
10 |
<triggers>clean,full,incremental,</triggers> |
|
11 |
<arguments> |
|
12 |
<dictionary> |
|
13 |
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key> |
|
14 |
<value>clean</value> |
|
15 |
</dictionary> |
|
16 |
<dictionary> |
|
17 |
<key>org.eclipse.cdt.make.core.enableCleanBuild</key> |
|
18 |
<value>true</value> |
|
19 |
</dictionary> |
|
20 |
<dictionary> |
|
21 |
<key>org.eclipse.cdt.make.core.append_environment</key> |
|
22 |
<value>true</value> |
|
23 |
</dictionary> |
|
24 |
<dictionary> |
|
25 |
<key>org.eclipse.cdt.make.core.stopOnError</key> |
|
26 |
<value>true</value> |
|
27 |
</dictionary> |
|
28 |
<dictionary> |
|
29 |
<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key> |
|
30 |
<value>true</value> |
|
31 |
</dictionary> |
|
32 |
<dictionary> |
|
33 |
<key>org.eclipse.cdt.make.core.build.command</key> |
|
34 |
<value>C:/MinGW/bin/mingw32-make.exe</value> |
|
35 |
</dictionary> |
|
36 |
<dictionary> |
|
37 |
<key>org.eclipse.cdt.make.core.contents</key> |
|
38 |
<value>org.eclipse.cdt.make.core.activeConfigSettings</value> |
|
39 |
</dictionary> |
|
40 |
<dictionary> |
|
41 |
<key>org.eclipse.cdt.make.core.build.target.inc</key> |
|
42 |
<value>all</value> |
|
43 |
</dictionary> |
|
44 |
<dictionary> |
|
45 |
<key>org.eclipse.cdt.make.core.build.arguments</key> |
|
46 |
<value></value> |
|
47 |
</dictionary> |
|
48 |
<dictionary> |
|
49 |
<key>org.eclipse.cdt.make.core.buildLocation</key> |
|
50 |
<value>C:/workspace/workspace-HEADRASTER/potrace-1.8</value> |
|
51 |
</dictionary> |
|
52 |
<dictionary> |
|
53 |
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key> |
|
54 |
<value>false</value> |
|
55 |
</dictionary> |
|
56 |
<dictionary> |
|
57 |
<key>org.eclipse.cdt.make.core.environment</key> |
|
58 |
<value></value> |
|
59 |
</dictionary> |
|
60 |
<dictionary> |
|
61 |
<key>org.eclipse.cdt.make.core.enableFullBuild</key> |
|
62 |
<value>true</value> |
|
63 |
</dictionary> |
|
64 |
<dictionary> |
|
65 |
<key>org.eclipse.cdt.make.core.build.target.auto</key> |
|
66 |
<value>all</value> |
|
67 |
</dictionary> |
|
68 |
<dictionary> |
|
69 |
<key>org.eclipse.cdt.make.core.enableAutoBuild</key> |
|
70 |
<value>false</value> |
|
71 |
</dictionary> |
|
72 |
<dictionary> |
|
73 |
<key>org.eclipse.cdt.make.core.build.target.clean</key> |
|
74 |
<value>clean</value> |
|
75 |
</dictionary> |
|
76 |
<dictionary> |
|
77 |
<key>org.eclipse.cdt.make.core.fullBuildTarget</key> |
|
78 |
<value>all</value> |
|
79 |
</dictionary> |
|
80 |
<dictionary> |
|
81 |
<key>org.eclipse.cdt.make.core.buildArguments</key> |
|
82 |
<value></value> |
|
83 |
</dictionary> |
|
84 |
<dictionary> |
|
85 |
<key>org.eclipse.cdt.make.core.build.location</key> |
|
86 |
<value>C:/workspace/workspace-HEADRASTER/potrace-1.8</value> |
|
87 |
</dictionary> |
|
88 |
<dictionary> |
|
89 |
<key>org.eclipse.cdt.make.core.autoBuildTarget</key> |
|
90 |
<value>all</value> |
|
91 |
</dictionary> |
|
92 |
<dictionary> |
|
93 |
<key>org.eclipse.cdt.core.errorOutputParser</key> |
|
94 |
<value>org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;</value> |
|
95 |
</dictionary> |
|
96 |
</arguments> |
|
97 |
</buildCommand> |
|
98 |
<buildCommand> |
|
99 |
<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name> |
|
100 |
<arguments> |
|
101 |
</arguments> |
|
102 |
</buildCommand> |
|
103 |
</buildSpec> |
|
104 |
<natures> |
|
105 |
<nature>org.eclipse.cdt.core.ccnature</nature> |
|
106 |
<nature>org.eclipse.cdt.make.core.makeNature</nature> |
|
107 |
<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature> |
|
108 |
<nature>org.eclipse.cdt.core.cnature</nature> |
|
109 |
</natures> |
|
110 |
</projectDescription> |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/resources/potrace-1.8/.cproject | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?fileVersion 4.0.0?> |
|
3 |
|
|
4 |
<cproject> |
|
5 |
<storageModule moduleId="org.eclipse.cdt.core.settings"> |
|
6 |
<cconfiguration id="org.eclipse.cdt.core.default.config.1"> |
|
7 |
<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.1" moduleId="org.eclipse.cdt.core.settings" name="Configuration"> |
|
8 |
<externalSettings/> |
|
9 |
<extensions> |
|
10 |
<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/> |
|
11 |
</extensions> |
|
12 |
</storageModule> |
|
13 |
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"> |
|
14 |
<project-mappings/> |
|
15 |
</storageModule> |
|
16 |
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> |
|
17 |
<storageModule moduleId="org.eclipse.cdt.core.pathentry"> |
|
18 |
<pathentry excluding="**/CMakeFiles/" kind="out" path=""/> |
|
19 |
</storageModule> |
|
20 |
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"> |
|
21 |
<buildTargets> |
|
22 |
<target name="all" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
23 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
24 |
<buildArguments/> |
|
25 |
<buildTarget>all</buildTarget> |
|
26 |
<stopOnError>true</stopOnError> |
|
27 |
<useDefaultCommand>false</useDefaultCommand> |
|
28 |
</target> |
|
29 |
<target name="preinstall" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
30 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
31 |
<buildArguments/> |
|
32 |
<buildTarget>preinstall</buildTarget> |
|
33 |
<stopOnError>true</stopOnError> |
|
34 |
<useDefaultCommand>false</useDefaultCommand> |
|
35 |
</target> |
|
36 |
<target name="clean" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
37 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
38 |
<buildArguments/> |
|
39 |
<buildTarget>clean</buildTarget> |
|
40 |
<stopOnError>true</stopOnError> |
|
41 |
<useDefaultCommand>false</useDefaultCommand> |
|
42 |
</target> |
|
43 |
<target name="edit_cache" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
44 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
45 |
<buildArguments/> |
|
46 |
<buildTarget>edit_cache</buildTarget> |
|
47 |
<stopOnError>true</stopOnError> |
|
48 |
<useDefaultCommand>false</useDefaultCommand> |
|
49 |
</target> |
|
50 |
<target name="install" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
51 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
52 |
<buildArguments/> |
|
53 |
<buildTarget>install</buildTarget> |
|
54 |
<stopOnError>true</stopOnError> |
|
55 |
<useDefaultCommand>false</useDefaultCommand> |
|
56 |
</target> |
|
57 |
<target name="install/strip" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
58 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
59 |
<buildArguments/> |
|
60 |
<buildTarget>install/strip</buildTarget> |
|
61 |
<stopOnError>true</stopOnError> |
|
62 |
<useDefaultCommand>false</useDefaultCommand> |
|
63 |
</target> |
|
64 |
<target name="rebuild_cache" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
65 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
66 |
<buildArguments/> |
|
67 |
<buildTarget>rebuild_cache</buildTarget> |
|
68 |
<stopOnError>true</stopOnError> |
|
69 |
<useDefaultCommand>false</useDefaultCommand> |
|
70 |
</target> |
|
71 |
<target name="potrace" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
72 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
73 |
<buildArguments/> |
|
74 |
<buildTarget>potrace</buildTarget> |
|
75 |
<stopOnError>true</stopOnError> |
|
76 |
<useDefaultCommand>false</useDefaultCommand> |
|
77 |
</target> |
|
78 |
<target name="potrace180" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> |
|
79 |
<buildCommand>C:/MinGW/bin/mingw32-make.exe</buildCommand> |
|
80 |
<buildArguments/> |
|
81 |
<buildTarget>potrace180</buildTarget> |
|
82 |
<stopOnError>true</stopOnError> |
|
83 |
<useDefaultCommand>false</useDefaultCommand> |
|
84 |
</target> |
|
85 |
</buildTargets> |
|
86 |
</storageModule> |
|
87 |
<storageModule moduleId="scannerConfiguration"> |
|
88 |
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/> |
|
89 |
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"> |
|
90 |
<buildOutputProvider> |
|
91 |
<openAction enabled="true" filePath=""/> |
|
92 |
<parser enabled="true"/> |
|
93 |
</buildOutputProvider> |
|
94 |
<scannerInfoProvider id="specsFile"> |
|
95 |
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> |
|
96 |
<parser enabled="true"/> |
|
97 |
</scannerInfoProvider> |
|
98 |
</profile> |
|
99 |
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"> |
|
100 |
<buildOutputProvider> |
|
101 |
<openAction enabled="true" filePath=""/> |
|
102 |
<parser enabled="true"/> |
|
103 |
</buildOutputProvider> |
|
104 |
<scannerInfoProvider id="makefileGenerator"> |
|
105 |
<runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/> |
|
106 |
<parser enabled="true"/> |
|
107 |
</scannerInfoProvider> |
|
108 |
</profile> |
|
109 |
</storageModule> |
|
110 |
</cconfiguration> |
|
111 |
</storageModule> |
|
112 |
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> |
|
113 |
<project id="potrace.null.1" name="potrace"/> |
|
114 |
</storageModule> |
|
115 |
</cproject> |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/resources/potrace-1.8/src/decompose.c | ||
---|---|---|
1 |
/* Copyright (C) 2001-2007 Peter Selinger. |
|
2 |
This file is part of Potrace. It is free software and it is covered |
|
3 |
by the GNU General Public License. See the file COPYING for details. */ |
|
4 |
|
|
5 |
/* $Id: decompose.c 146 2007-04-09 00:43:46Z selinger $ */ |
|
6 |
|
|
7 |
#include <stdio.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <string.h> |
|
10 |
#include <limits.h> |
|
11 |
|
|
12 |
#include "potracelib.h" |
|
13 |
#include "curve.h" |
|
14 |
#include "lists.h" |
|
15 |
#include "auxiliary.h" |
|
16 |
#include "bitmap.h" |
|
17 |
#include "decompose.h" |
|
18 |
#include "progress.h" |
|
19 |
|
|
20 |
/* ---------------------------------------------------------------------- */ |
|
21 |
/* auxiliary bitmap manipulations */ |
|
22 |
|
|
23 |
/* set the excess padding to 0 */ |
|
24 |
static void bm_clearexcess(potrace_bitmap_t *bm) { |
|
25 |
potrace_word mask; |
|
26 |
int y; |
|
27 |
|
|
28 |
if (bm->w % BM_WORDBITS != 0) { |
|
29 |
mask = BM_ALLBITS << (BM_WORDBITS - (bm->w % BM_WORDBITS)); |
|
30 |
for (y=0; y<bm->h; y++) { |
|
31 |
*bm_index(bm, bm->w, y) &= mask; |
|
32 |
} |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
36 |
struct bbox_s { |
|
37 |
int x0, x1, y0, y1; /* bounding box */ |
|
38 |
}; |
|
39 |
typedef struct bbox_s bbox_t; |
|
40 |
|
|
41 |
/* clear the bm, assuming the bounding box is set correctly (faster |
|
42 |
than clearing the whole bitmap) */ |
|
43 |
static void clear_bm_with_bbox(potrace_bitmap_t *bm, bbox_t *bbox) { |
|
44 |
int imin = (bbox->x0 / BM_WORDBITS); |
|
45 |
int imax = ((bbox->x1 + BM_WORDBITS-1) / BM_WORDBITS); |
|
46 |
int i, y; |
|
47 |
|
|
48 |
for (y=bbox->y0; y<bbox->y1; y++) { |
|
49 |
for (i=imin; i<imax; i++) { |
|
50 |
bm_scanline(bm, y)[i] = 0; |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/* ---------------------------------------------------------------------- */ |
|
56 |
/* auxiliary functions */ |
|
57 |
|
|
58 |
/* deterministically and efficiently hash (x,y) into a pseudo-random bit */ |
|
59 |
static inline int detrand(int x, int y) { |
|
60 |
unsigned int z; |
|
61 |
static const unsigned char t[256] = { |
|
62 |
/* non-linear sequence: constant term of inverse in GF(8), |
|
63 |
mod x^8+x^4+x^3+x+1 */ |
|
64 |
0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, |
|
65 |
0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, |
|
66 |
0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, |
|
67 |
1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, |
|
68 |
0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, |
|
69 |
0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, |
|
70 |
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, |
|
71 |
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, |
|
72 |
1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, |
|
73 |
0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, |
|
74 |
1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, |
|
75 |
}; |
|
76 |
|
|
77 |
/* 0x04b3e375 and 0x05a8ef93 are chosen to contain every possible |
|
78 |
5-bit sequence */ |
|
79 |
z = ((0x04b3e375 * x) ^ y) * 0x05a8ef93; |
|
80 |
z = t[z & 0xff] ^ t[(z>>8) & 0xff] ^ t[(z>>16) & 0xff] ^ t[(z>>24) & 0xff]; |
|
81 |
return z & 1; |
|
82 |
} |
|
83 |
|
|
84 |
/* return the "majority" value of bitmap bm at intersection (x,y). We |
|
85 |
assume that the bitmap is balanced at "radius" 1. */ |
|
86 |
static int majority(potrace_bitmap_t *bm, int x, int y) { |
|
87 |
int i, a, ct; |
|
88 |
|
|
89 |
for (i=2; i<5; i++) { /* check at "radius" i */ |
|
90 |
ct = 0; |
|
91 |
for (a=-i+1; a<=i-1; a++) { |
|
92 |
ct += BM_GET(bm, x+a, y+i-1) ? 1 : -1; |
|
93 |
ct += BM_GET(bm, x+i-1, y+a-1) ? 1 : -1; |
|
94 |
ct += BM_GET(bm, x+a-1, y-i) ? 1 : -1; |
|
95 |
ct += BM_GET(bm, x-i, y+a) ? 1 : -1; |
|
96 |
} |
|
97 |
if (ct>0) { |
|
98 |
return 1; |
|
99 |
} else if (ct<0) { |
|
100 |
return 0; |
|
101 |
} |
|
102 |
} |
|
103 |
return 0; |
|
104 |
} |
|
105 |
|
|
106 |
/* ---------------------------------------------------------------------- */ |
|
107 |
/* decompose image into paths */ |
|
108 |
|
|
109 |
/* efficiently invert bits [x,infty) and [xa,infty) in line y. Here xa |
|
110 |
must be a multiple of BM_WORDBITS. */ |
|
111 |
static void xor_to_ref(potrace_bitmap_t *bm, int x, int y, int xa) { |
|
112 |
int xhi = x & -BM_WORDBITS; |
|
113 |
int xlo = x & (BM_WORDBITS-1); /* = x % BM_WORDBITS */ |
|
114 |
int i; |
|
115 |
|
|
116 |
if (xhi<xa) { |
|
117 |
for (i = xhi; i < xa; i+=BM_WORDBITS) { |
|
118 |
*bm_index(bm, i, y) ^= BM_ALLBITS; |
|
119 |
} |
|
120 |
} else { |
|
121 |
for (i = xa; i < xhi; i+=BM_WORDBITS) { |
|
122 |
*bm_index(bm, i, y) ^= BM_ALLBITS; |
|
123 |
} |
|
124 |
} |
|
125 |
/* note: the following "if" is needed because x86 treats a<<b as |
|
126 |
a<<(b&31). I spent hours looking for this bug. */ |
|
127 |
if (xlo) { |
|
128 |
*bm_index(bm, xhi, y) ^= (BM_ALLBITS << (BM_WORDBITS - xlo)); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
/* a path is represented as an array of points, which are thought to |
|
133 |
lie on the corners of pixels (not on their centers). The path point |
|
134 |
(x,y) is the lower left corner of the pixel (x,y). Paths are |
|
135 |
represented by the len/pt components of a path_t object (which |
|
136 |
also stores other information about the path) */ |
|
137 |
|
|
138 |
/* xor the given pixmap with the interior of the given path. Note: the |
|
139 |
path must be within the dimensions of the pixmap. */ |
|
140 |
static void xor_path(potrace_bitmap_t *bm, path_t *p) { |
|
141 |
int xa, x, y, k, y1; |
|
142 |
|
|
143 |
if (p->priv->len <= 0) { /* a path of length 0 is silly, but legal */ |
|
144 |
return; |
|
145 |
} |
|
146 |
|
|
147 |
y1 = p->priv->pt[p->priv->len-1].y; |
|
148 |
|
|
149 |
xa = p->priv->pt[0].x & -BM_WORDBITS; |
|
150 |
for (k=0; k<p->priv->len; k++) { |
|
151 |
x = p->priv->pt[k].x; |
|
152 |
y = p->priv->pt[k].y; |
|
153 |
|
|
154 |
if (y != y1) { |
|
155 |
/* efficiently invert the rectangle [x,xa] x [y,y1] */ |
|
156 |
xor_to_ref(bm, x, min(y,y1), xa); |
|
157 |
y1 = y; |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
/* Find the bounding box of a given path. Path is assumed to be of |
|
163 |
non-zero length. */ |
|
164 |
static void setbbox_path(bbox_t *bbox, path_t *p) { |
|
165 |
int x, y; |
|
166 |
int k; |
|
167 |
|
|
168 |
bbox->y0 = INT_MAX; |
|
169 |
bbox->y1 = 0; |
|
170 |
bbox->x0 = INT_MAX; |
|
171 |
bbox->x1 = 0; |
|
172 |
|
|
173 |
for (k=0; k<p->priv->len; k++) { |
|
174 |
x = p->priv->pt[k].x; |
|
175 |
y = p->priv->pt[k].y; |
|
176 |
|
|
177 |
if (x < bbox->x0) { |
|
178 |
bbox->x0 = x; |
|
179 |
} |
|
180 |
if (x > bbox->x1) { |
|
181 |
bbox->x1 = x; |
|
182 |
} |
|
183 |
if (y < bbox->y0) { |
|
184 |
bbox->y0 = y; |
|
185 |
} |
|
186 |
if (y > bbox->y1) { |
|
187 |
bbox->y1 = y; |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
/* compute a path in the given pixmap, separating black from white. |
|
193 |
Start path at the point (x0,x1), which must be an upper left corner |
|
194 |
of the path. Also compute the area enclosed by the path. Return a |
|
195 |
new path_t object, or NULL on error (note that a legitimate path |
|
196 |
cannot have length 0). Sign is required for correct interpretation |
|
197 |
of turnpolicies. */ |
|
198 |
static path_t *findpath(potrace_bitmap_t *bm, int x0, int y0, int sign, int turnpolicy) { |
|
199 |
int x, y, dirx, diry, len, size, area; |
|
200 |
int c, d, tmp; |
|
201 |
point_t *pt, *pt1; |
|
202 |
path_t *p = NULL; |
|
203 |
|
|
204 |
x = x0; |
|
205 |
y = y0; |
|
206 |
dirx = 0; |
|
207 |
diry = -1; |
|
208 |
|
|
209 |
len = size = 0; |
|
210 |
pt = NULL; |
|
211 |
area = 0; |
|
212 |
|
|
213 |
while (1) { |
|
214 |
/* add point to path */ |
|
215 |
if (len>=size) { |
|
216 |
size += 100; |
|
217 |
size = (int)(1.3 * size); |
|
218 |
pt1 = (point_t *)realloc(pt, size * sizeof(point_t)); |
|
219 |
if (!pt1) { |
|
220 |
goto error; |
|
221 |
} |
|
222 |
pt = pt1; |
|
223 |
} |
|
224 |
pt[len].x = x; |
|
225 |
pt[len].y = y; |
|
226 |
len++; |
|
227 |
|
|
228 |
/* move to next point */ |
|
229 |
x += dirx; |
|
230 |
y += diry; |
|
231 |
area += x*diry; |
|
232 |
|
|
233 |
/* path complete? */ |
|
234 |
if (x==x0 && y==y0) { |
|
235 |
break; |
|
236 |
} |
|
237 |
|
|
238 |
/* determine next direction */ |
|
239 |
c = BM_GET(bm, x + (dirx+diry-1)/2, y + (diry-dirx-1)/2); |
|
240 |
d = BM_GET(bm, x + (dirx-diry-1)/2, y + (diry+dirx-1)/2); |
|
241 |
|
|
242 |
if (c && !d) { /* ambiguous turn */ |
|
243 |
if (turnpolicy == POTRACE_TURNPOLICY_RIGHT |
|
244 |
|| (turnpolicy == POTRACE_TURNPOLICY_BLACK && sign == '+') |
|
245 |
|| (turnpolicy == POTRACE_TURNPOLICY_WHITE && sign == '-') |
|
246 |
|| (turnpolicy == POTRACE_TURNPOLICY_RANDOM && detrand(x,y)) |
|
247 |
|| (turnpolicy == POTRACE_TURNPOLICY_MAJORITY && majority(bm, x, y)) |
|
248 |
|| (turnpolicy == POTRACE_TURNPOLICY_MINORITY && !majority(bm, x, y))) { |
|
249 |
tmp = dirx; /* right turn */ |
|
250 |
dirx = diry; |
|
251 |
diry = -tmp; |
|
252 |
} else { |
|
253 |
tmp = dirx; /* left turn */ |
|
254 |
dirx = -diry; |
|
255 |
diry = tmp; |
|
256 |
} |
|
257 |
} else if (c) { /* right turn */ |
|
258 |
tmp = dirx; |
|
259 |
dirx = diry; |
|
260 |
diry = -tmp; |
|
261 |
} else if (!d) { /* left turn */ |
|
262 |
tmp = dirx; |
|
263 |
dirx = -diry; |
|
264 |
diry = tmp; |
|
265 |
} |
|
266 |
} /* while this path */ |
|
267 |
|
|
268 |
/* allocate new path object */ |
|
269 |
p = path_new(); |
|
270 |
if (!p) { |
|
271 |
goto error; |
|
272 |
} |
|
273 |
|
|
274 |
p->priv->pt = pt; |
|
275 |
p->priv->len = len; |
|
276 |
p->area = area; |
|
277 |
p->sign = sign; |
|
278 |
|
|
279 |
return p; |
|
280 |
|
|
281 |
error: |
|
282 |
free(pt); |
|
283 |
return NULL; |
|
284 |
} |
|
285 |
|
|
286 |
/* Give a tree structure to the given path list, based on "insideness" |
|
287 |
testing. I.e., path A is considered "below" path B if it is inside |
|
288 |
path B. The input pathlist is assumed to be ordered so that "outer" |
|
289 |
paths occur before "inner" paths. The tree structure is stored in |
|
290 |
the "childlist" and "sibling" components of the path_t |
|
291 |
structure. The linked list structure is also changed so that |
|
292 |
negative path components are listed immediately after their |
|
293 |
positive parent. Note: some backends may ignore the tree |
|
294 |
structure, others may use it e.g. to group path components. We |
|
295 |
assume that in the input, point 0 of each path is an "upper left" |
|
296 |
corner of the path, as returned by bm_to_pathlist. This makes it |
|
297 |
easy to find an "interior" point. The bm argument should be a |
|
298 |
bitmap of the correct size (large enough to hold all the paths), |
|
299 |
and will be used as scratch space. Return 0 on success or -1 on |
|
300 |
error with errno set. */ |
|
301 |
|
|
302 |
static void pathlist_to_tree(path_t *plist, potrace_bitmap_t *bm) { |
|
303 |
path_t *p, *p1; |
|
304 |
path_t *heap, *heap1; |
|
305 |
path_t *cur; |
|
306 |
path_t *head; |
|
307 |
path_t **hook, **hook_in, **hook_out; /* for fast appending to linked list */ |
|
308 |
bbox_t bbox; |
|
309 |
|
|
310 |
bm_clear(bm, 0); |
|
311 |
|
|
312 |
/* save original "next" pointers */ |
|
313 |
list_forall(p, plist) { |
|
314 |
p->sibling = p->next; |
|
315 |
p->childlist = NULL; |
|
316 |
} |
|
317 |
|
|
318 |
heap = plist; |
|
319 |
|
|
320 |
/* the heap holds a list of lists of paths. Use "childlist" field |
|
321 |
for outer list, "next" field for inner list. Each of the sublists |
|
322 |
is to be turned into a tree. This code is messy, but it is |
|
323 |
actually fast. Each path is rendered exactly once. We use the |
|
324 |
heap to get a tail recursive algorithm: the heap holds a list of |
|
325 |
pathlists which still need to be transformed. */ |
|
326 |
|
|
327 |
while (heap) { |
|
328 |
/* unlink first sublist */ |
|
329 |
cur = heap; |
|
330 |
heap = heap->childlist; |
|
331 |
cur->childlist = NULL; |
|
332 |
|
|
333 |
/* unlink first path */ |
|
334 |
head = cur; |
|
335 |
cur = cur->next; |
|
336 |
head->next = NULL; |
|
337 |
|
|
338 |
/* render path */ |
|
339 |
xor_path(bm, head); |
|
340 |
setbbox_path(&bbox, head); |
|
341 |
|
|
342 |
/* now do insideness test for each element of cur; append it to |
|
343 |
head->childlist if it's inside head, else append it to |
|
344 |
head->next. */ |
|
345 |
hook_in=&head->childlist; |
|
346 |
hook_out=&head->next; |
|
347 |
list_forall_unlink(p, cur) { |
|
348 |
if (p->priv->pt[0].y <= bbox.y0) { |
|
349 |
list_insert_beforehook(p, hook_out); |
|
350 |
/* append the remainder of the list to hook_out */ |
|
351 |
*hook_out = cur; |
|
352 |
break; |
|
353 |
} |
|
354 |
if (BM_GET(bm, p->priv->pt[0].x, p->priv->pt[0].y-1)) { |
|
355 |
list_insert_beforehook(p, hook_in); |
|
356 |
} else { |
|
357 |
list_insert_beforehook(p, hook_out); |
|
358 |
} |
|
359 |
} |
|
360 |
|
|
361 |
/* clear bm */ |
|
362 |
clear_bm_with_bbox(bm, &bbox); |
|
363 |
|
|
364 |
/* now schedule head->childlist and head->next for further |
|
365 |
processing */ |
|
366 |
if (head->next) { |
|
367 |
head->next->childlist = heap; |
|
368 |
heap = head->next; |
|
369 |
} |
|
370 |
if (head->childlist) { |
|
371 |
head->childlist->childlist = heap; |
|
372 |
heap = head->childlist; |
|
373 |
} |
|
374 |
} |
|
375 |
|
|
376 |
/* copy sibling structure from "next" to "sibling" component */ |
|
377 |
p = plist; |
|
378 |
while (p) { |
|
379 |
p1 = p->sibling; |
|
380 |
p->sibling = p->next; |
|
381 |
p = p1; |
|
382 |
} |
|
383 |
|
|
384 |
/* reconstruct a new linked list ("next") structure from tree |
|
385 |
("childlist", "sibling") structure. This code is slightly messy, |
|
386 |
because we use a heap to make it tail recursive: the heap |
|
387 |
contains a list of childlists which still need to be |
|
388 |
processed. */ |
|
389 |
heap = plist; |
|
390 |
if (heap) { |
|
391 |
heap->next = NULL; /* heap is a linked list of childlists */ |
|
392 |
} |
|
393 |
plist = NULL; |
|
394 |
hook = &plist; |
|
395 |
while (heap) { |
|
396 |
heap1 = heap->next; |
|
397 |
for (p=heap; p; p=p->sibling) { |
|
398 |
/* p is a positive path */ |
|
399 |
/* append to linked list */ |
|
400 |
list_insert_beforehook(p, hook); |
|
401 |
|
|
402 |
/* go through its children */ |
|
403 |
for (p1=p->childlist; p1; p1=p1->sibling) { |
|
404 |
/* append to linked list */ |
|
405 |
list_insert_beforehook(p1, hook); |
|
406 |
/* append its childlist to heap, if non-empty */ |
|
407 |
if (p1->childlist) { |
|
408 |
list_append(path_t, heap1, p1->childlist); |
|
409 |
} |
|
410 |
} |
|
411 |
} |
|
412 |
heap = heap1; |
|
413 |
} |
|
414 |
|
|
415 |
return; |
|
416 |
} |
|
417 |
|
|
418 |
/* find the next set pixel in a row <= y. Pixels are searched first |
|
419 |
left-to-right, then top-down. In other words, (x,y)<(x',y') if y>y' |
|
420 |
or y=y' and x<x'. If found, return 0 and store pixel in |
|
421 |
(*xp,*yp). Else return 1. Note that this function assumes that |
|
422 |
excess bytes have been cleared with bm_clearexcess. */ |
|
423 |
static int findnext(potrace_bitmap_t *bm, int *xp, int *yp) { |
|
424 |
int x; |
|
425 |
int y; |
|
426 |
|
|
427 |
for (y=*yp; y>=0; y--) { |
|
428 |
for (x=0; x<bm->w; x+=BM_WORDBITS) { |
|
429 |
if (*bm_index(bm, x, y)) { |
|
430 |
while (!BM_GET(bm, x, y)) { |
|
431 |
x++; |
|
432 |
} |
|
433 |
/* found */ |
|
434 |
*xp = x; |
|
435 |
*yp = y; |
|
436 |
return 0; |
|
437 |
} |
|
438 |
} |
|
439 |
} |
|
440 |
/* not found */ |
|
441 |
return 1; |
|
442 |
} |
|
443 |
|
|
444 |
/* Decompose the given bitmap into paths. Returns a linked list of |
|
445 |
path_t objects with the fields len, pt, area, sign filled |
|
446 |
in. Returns 0 on success with plistp set, or -1 on error with errno |
|
447 |
set. */ |
|
448 |
|
|
449 |
int bm_to_pathlist(const potrace_bitmap_t *bm, path_t **plistp, const potrace_param_t *param, progress_t *progress) { |
|
450 |
int x; |
|
451 |
int y; |
|
452 |
path_t *p; |
|
453 |
path_t *plist = NULL; /* linked list of path objects */ |
|
454 |
path_t **hook = &plist; /* used to speed up appending to linked list */ |
|
455 |
potrace_bitmap_t *bm1 = NULL; |
|
456 |
int sign; |
|
457 |
|
|
458 |
bm1 = bm_dup(bm); |
|
459 |
if (!bm1) { |
|
460 |
goto error; |
|
461 |
} |
|
462 |
|
|
463 |
/* be sure the byte padding on the right is set to 0, as the fast |
|
464 |
pixel search below relies on it */ |
|
465 |
bm_clearexcess(bm1); |
|
466 |
|
|
467 |
/* iterate through components */ |
|
468 |
y = bm1->h - 1; |
|
469 |
while (findnext(bm1, &x, &y) == 0) { |
|
470 |
/* calculate the sign by looking at the original */ |
|
471 |
sign = BM_GET(bm, x, y) ? '+' : '-'; |
|
472 |
|
|
473 |
/* calculate the path */ |
|
474 |
p = findpath(bm1, x, y+1, sign, param->turnpolicy); |
|
475 |
if (p==NULL) { |
|
476 |
goto error; |
|
477 |
} |
|
478 |
|
|
479 |
/* update buffered image */ |
|
480 |
xor_path(bm1, p); |
|
481 |
|
|
482 |
/* if it's a turd, eliminate it, else append it to the list */ |
|
483 |
if (p->area <= param->turdsize) { |
|
484 |
path_free(p); |
|
485 |
} else { |
|
486 |
list_insert_beforehook(p, hook); |
|
487 |
} |
|
488 |
|
|
489 |
if (bm1->h > 0) { /* to be sure */ |
|
490 |
progress_update(1-y/(double)bm1->h, progress); |
|
491 |
} |
|
492 |
} |
|
493 |
|
|
494 |
pathlist_to_tree(plist, bm1); |
|
495 |
bm_free(bm1); |
|
496 |
*plistp = plist; |
|
497 |
|
|
498 |
progress_update(1.0, progress); |
|
499 |
|
|
500 |
return 0; |
|
501 |
|
|
502 |
error: |
|
503 |
bm_free(bm1); |
|
504 |
list_forall_unlink(p, plist) { |
|
505 |
path_free(p); |
|
506 |
} |
|
507 |
return -1; |
|
508 |
} |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/resources/potrace-1.8/src/render.c | ||
---|---|---|
1 |
/* Copyright (C) 2001-2007 Peter Selinger. |
|
2 |
This file is part of Potrace. It is free software and it is covered |
|
3 |
by the GNU General Public License. See the file COPYING for details. */ |
|
4 |
|
|
5 |
/* $Id: render.c 147 2007-04-09 00:44:09Z selinger $ */ |
|
6 |
|
|
7 |
#include <stdio.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <math.h> |
|
10 |
#include <string.h> |
|
11 |
|
|
12 |
#include "render.h" |
|
13 |
#include "greymap.h" |
|
14 |
#include "auxiliary.h" |
|
15 |
|
|
16 |
/* ---------------------------------------------------------------------- */ |
|
17 |
/* routines for anti-aliased rendering of curves */ |
|
18 |
|
|
19 |
/* we use the following method. Given a point (x,y) (with real-valued |
|
20 |
coordinates) in the plane, let (xi,yi) be the integer part of the |
|
21 |
coordinates, i.e., xi=floor(x), yi=floor(y). Define a path from |
|
22 |
(x,y) to infinity as follows: path(x,y) = |
|
23 |
(x,y)--(xi+1,y)--(xi+1,yi)--(+infty,yi). Now as the point (x,y) |
|
24 |
moves smoothly across the plane, the path path(x,y) sweeps |
|
25 |
(non-smoothly) across a certain area. We proportionately blacken |
|
26 |
the area as the path moves "downward", and we whiten the area as |
|
27 |
the path moves "upward". This way, after the point has traversed a |
|
28 |
closed curve, the interior of the curve has been darkened |
|
29 |
(counterclockwise movement) or lightened (clockwise movement). (The |
|
30 |
"grey shift" is actually proportional to the winding number). By |
|
31 |
choosing the above path with mostly integer coordinates, we achieve |
|
32 |
that only pixels close to (x,y) receive grey values and are subject |
|
33 |
to round-off errors. The grey value of pixels far away from (x,y) |
|
34 |
is always in "integer" (where 0=black, 1=white). As a special |
|
35 |
trick, we keep an accumulator rm->a1, which holds a double value to |
|
36 |
be added to the grey value to be added to the current pixel |
|
37 |
(xi,yi). Only when changing "current" pixels, we convert this |
|
38 |
double value to an integer. This way we avoid round-off errors at |
|
39 |
the meeting points of line segments. Another speedup measure is |
|
40 |
that we sometimes use the rm->incrow_buf array to postpone |
|
41 |
incrementing or decrementing an entire row. If incrow_buf[y]=x+1!=0, |
|
42 |
then all the pixels (x,y),(x+1,y),(x+2,y),... are scheduled to be |
|
43 |
incremented/decremented (which one is the case will be clear from |
|
44 |
context). This keeps the greymap operations reasonably local. */ |
|
45 |
|
|
46 |
/* allocate a new rendering state */ |
|
47 |
render_t *render_new(greymap_t *gm) { |
|
48 |
render_t *rm; |
|
49 |
|
|
50 |
rm = (render_t *) malloc(sizeof(render_t)); |
|
51 |
if (!rm) { |
|
52 |
return NULL; |
|
53 |
} |
|
54 |
memset(rm, 0, sizeof(render_t)); |
|
55 |
rm->gm = gm; |
|
56 |
rm->incrow_buf = (int *) malloc(gm->h * sizeof(int)); |
|
57 |
if (!rm->incrow_buf) { |
|
58 |
free(rm); |
|
59 |
return NULL; |
|
60 |
} |
|
61 |
memset(rm->incrow_buf, 0, gm->h * sizeof(int)); |
|
62 |
return rm; |
|
63 |
} |
|
64 |
|
|
65 |
/* free a given rendering state. Note: this does not free the |
|
66 |
underlying greymap. */ |
|
67 |
void render_free(render_t *rm) { |
|
68 |
free(rm->incrow_buf); |
|
69 |
free(rm); |
|
70 |
} |
|
71 |
|
|
72 |
/* close path */ |
|
73 |
void render_close(render_t *rm) { |
|
74 |
if (rm->x0 != rm->x1 || rm->y0 != rm->y1) { |
|
75 |
render_lineto(rm, rm->x0, rm->y0); |
|
76 |
} |
|
77 |
GM_INC(rm->gm, rm->x0i, rm->y0i, (rm->a0+rm->a1)*255); |
|
78 |
|
|
79 |
/* assert (rm->x0i != rm->x1i || rm->y0i != rm->y1i); */ |
|
80 |
|
|
81 |
/* the persistent state is now undefined */ |
|
82 |
} |
|
83 |
|
|
84 |
/* move point */ |
|
85 |
void render_moveto(render_t *rm, double x, double y) { |
|
86 |
/* close the previous path */ |
|
87 |
render_close(rm); |
|
88 |
|
|
89 |
rm->x0 = rm->x1 = x; |
|
90 |
rm->y0 = rm->y1 = y; |
|
91 |
rm->x0i = (int)floor(rm->x0); |
|
92 |
rm->x1i = (int)floor(rm->x1); |
|
93 |
rm->y0i = (int)floor(rm->y0); |
|
94 |
rm->y1i = (int)floor(rm->y1); |
|
95 |
rm->a0 = rm->a1 = 0; |
|
96 |
} |
|
97 |
|
|
98 |
/* add b to pixels (x,y) and all pixels to the right of it. However, |
|
99 |
use rm->incrow_buf as a buffer to economize on multiple calls */ |
|
100 |
static void incrow(render_t *rm, int x, int y, int b) { |
|
101 |
int i, x0; |
|
102 |
|
|
103 |
if (y < 0 || y >= rm->gm->h) { |
|
104 |
return; |
|
105 |
} |
|
106 |
|
|
107 |
if (x < 0) { |
|
108 |
x = 0; |
|
109 |
} else if (x > rm->gm->w) { |
|
110 |
x = rm->gm->w; |
|
111 |
} |
|
112 |
if (rm->incrow_buf[y] == 0) { |
|
113 |
rm->incrow_buf[y] = x+1; /* store x+1 so that we can use 0 for "vacant" */ |
|
114 |
return; |
|
115 |
} |
|
116 |
x0 = rm->incrow_buf[y]-1; |
|
117 |
rm->incrow_buf[y] = 0; |
|
118 |
if (x0 < x) { |
|
119 |
for (i=x0; i<x; i++) { |
|
120 |
GM_INC(rm->gm, i, y, -b); |
|
121 |
} |
|
122 |
} else { |
|
123 |
for (i=x; i<x0; i++) { |
|
124 |
GM_INC(rm->gm, i, y, b); |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
/* render a straight line */ |
|
130 |
void render_lineto(render_t *rm, double x2, double y2) { |
|
131 |
int x2i, y2i; |
|
132 |
double t0=2, s0=2; |
|
133 |
int sn, tn; |
|
134 |
double ss=2, ts=2; |
|
135 |
double r0, r1; |
|
136 |
int i, j; |
|
137 |
int rxi, ryi; |
|
138 |
int s; |
|
139 |
|
|
140 |
x2i = (int)floor(x2); |
|
141 |
y2i = (int)floor(y2); |
|
142 |
|
|
143 |
sn = abs(x2i - rm->x1i); |
|
144 |
tn = abs(y2i - rm->y1i); |
|
145 |
|
|
146 |
if (sn) { |
|
147 |
s0 = ((x2>rm->x1 ? rm->x1i+1 : rm->x1i) - rm->x1)/(x2-rm->x1); |
|
148 |
ss = fabs(1.0/(x2-rm->x1)); |
|
149 |
} |
|
150 |
if (tn) { |
|
151 |
t0 = ((y2>rm->y1 ? rm->y1i+1 : rm->y1i) - rm->y1)/(y2-rm->y1); |
|
152 |
ts = fabs(1.0/(y2-rm->y1)); |
|
153 |
} |
|
154 |
|
|
155 |
r0 = 0; |
|
156 |
|
|
157 |
i = 0; |
|
158 |
j = 0; |
|
159 |
|
|
160 |
rxi = rm->x1i; |
|
161 |
ryi = rm->y1i; |
|
162 |
|
|
163 |
while (i<sn || j<tn) { |
|
164 |
if (j>=tn || (i<sn && s0+i*ss < t0+j*ts)) { |
|
165 |
r1 = s0+i*ss; |
|
166 |
i++; |
|
167 |
s = 1; |
|
168 |
} else { |
|
169 |
r1 = t0+j*ts; |
|
170 |
j++; |
|
171 |
s = 0; |
|
172 |
} |
|
173 |
/* render line from r0 to r1 segment of (rm->x1,rm->y1)..(x2,y2) */ |
|
174 |
|
|
175 |
/* move point to r1 */ |
|
176 |
rm->a1 += (r1-r0)*(y2-rm->y1)*(rxi+1-((r0+r1)/2.0*(x2-rm->x1)+rm->x1)); |
|
177 |
|
|
178 |
/* move point across pixel boundary */ |
|
179 |
if (s && x2>rm->x1) { |
|
180 |
GM_INC(rm->gm, rxi, ryi, rm->a1*255); |
|
181 |
rm->a1 = 0; |
|
182 |
rxi++; |
|
183 |
rm->a1 += rm->y1+r1*(y2-rm->y1)-ryi; |
|
184 |
} else if (!s && y2>rm->y1) { |
|
185 |
GM_INC(rm->gm, rxi, ryi, rm->a1*255); |
|
186 |
rm->a1 = 0; |
|
187 |
incrow(rm, rxi+1, ryi, 255); |
|
188 |
ryi++; |
|
189 |
} else if (s && x2<=rm->x1) { |
|
190 |
rm->a1 -= rm->y1+r1*(y2-rm->y1)-ryi; |
|
191 |
GM_INC(rm->gm, rxi, ryi, rm->a1*255); |
|
192 |
rm->a1 = 0; |
|
193 |
rxi--; |
|
194 |
} else if (!s && y2<=rm->y1) { |
|
195 |
GM_INC(rm->gm, rxi, ryi, rm->a1*255); |
|
196 |
rm->a1 = 0; |
|
197 |
ryi--; |
|
198 |
incrow(rm, rxi+1, ryi, -255); |
|
199 |
} |
|
200 |
|
|
201 |
r0 = r1; |
|
202 |
} |
|
203 |
|
|
204 |
/* move point to (x2,y2) */ |
|
205 |
|
|
206 |
r1 = 1; |
|
207 |
rm->a1 += (r1-r0)*(y2-rm->y1)*(rxi+1-((r0+r1)/2.0*(x2-rm->x1)+rm->x1)); |
|
208 |
|
|
209 |
rm->x1i = x2i; |
|
210 |
rm->y1i = y2i; |
|
211 |
rm->x1 = x2; |
|
212 |
rm->y1 = y2; |
|
213 |
|
|
214 |
/* assert (rxi != rm->x1i || ryi != rm->y1i); */ |
|
215 |
} |
|
216 |
|
|
217 |
/* render a Bezier curve. */ |
|
218 |
void render_curveto(render_t *rm, double x2, double y2, double x3, double y3, double x4, double y4) { |
|
219 |
double x1, y1, dd0, dd1, dd, delta, e2, epsilon, t; |
|
220 |
|
|
221 |
x1 = rm->x1; /* starting point */ |
|
222 |
y1 = rm->y1; |
|
223 |
|
|
224 |
/* we approximate the curve by small line segments. The interval |
|
225 |
size, epsilon, is determined on the fly so that the distance |
|
226 |
between the true curve and its approximation does not exceed the |
|
227 |
desired accuracy delta. */ |
|
228 |
|
|
229 |
delta = .1; /* desired accuracy, in pixels */ |
|
230 |
|
|
231 |
/* let dd = maximal value of 2nd derivative over curve - this must |
|
232 |
occur at an endpoint. */ |
|
233 |
dd0 = sq(x1-2*x2+x3) + sq(y1-2*y2+y3); |
|
234 |
dd1 = sq(x2-2*x3+x4) + sq(y2-2*y3+y4); |
|
235 |
dd = 6*sqrt(max(dd0, dd1)); |
|
236 |
e2 = 8*delta <= dd ? 8*delta/dd : 1; |
|
237 |
epsilon = sqrt(e2); /* necessary interval size */ |
|
238 |
|
|
239 |
for (t=epsilon; t<1; t+=epsilon) { |
|
240 |
render_lineto(rm, x1*cu(1-t)+3*x2*sq(1-t)*t+3*x3*(1-t)*sq(t)+x4*cu(t), |
|
241 |
y1*cu(1-t)+3*y2*sq(1-t)*t+3*y3*(1-t)*sq(t)+y4*cu(t)); |
|
242 |
} |
|
243 |
render_lineto(rm, x4, y4); |
|
244 |
} |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/resources/potrace-1.8/src/bitmap.h | ||
---|---|---|
1 |
/* Copyright (C) 2001-2007 Peter Selinger. |
|
2 |
This file is part of Potrace. It is free software and it is covered |
|
3 |
by the GNU General Public License. See the file COPYING for details. */ |
|
4 |
|
|
5 |
#ifndef BITMAP_H |
|
6 |
#define BITMAP_H |
|
7 |
|
|
8 |
#ifdef HAVE_CONFIG_H |
|
9 |
#include "config.h" |
|
10 |
#endif |
|
11 |
|
|
12 |
#include <string.h> |
|
13 |
#include <stdlib.h> |
|
14 |
|
|
15 |
/* The bitmap type is defined in potracelib.h */ |
|
16 |
#include "potracelib.h" |
|
17 |
|
|
18 |
/* The present file defines some convenient macros and static inline |
|
19 |
functions for accessing bitmaps. Since they only produce inline |
|
20 |
code, they can be conveniently shared by the library and frontends, |
|
21 |
if desired */ |
|
22 |
|
|
23 |
/* ---------------------------------------------------------------------- */ |
|
24 |
/* some measurements */ |
|
25 |
|
|
26 |
#define BM_WORDSIZE ((int)sizeof(potrace_word)) |
|
27 |
#define BM_WORDBITS (8*BM_WORDSIZE) |
|
28 |
#define BM_HIBIT (((potrace_word)1)<<(BM_WORDBITS-1)) |
|
29 |
#define BM_ALLBITS (~(potrace_word)0) |
|
30 |
|
|
31 |
/* macros for accessing pixel at index (x,y). U* macros omit the |
|
32 |
bounds check. */ |
|
33 |
|
|
34 |
#define bm_scanline(bm, y) ((bm)->map + (y)*(bm)->dy) |
|
35 |
#define bm_index(bm, x, y) (&bm_scanline(bm, y)[(x)/BM_WORDBITS]) |
|
36 |
#define bm_mask(x) (BM_HIBIT >> ((x) & (BM_WORDBITS-1))) |
|
37 |
#define bm_range(x, a) ((int)(x) >= 0 && (int)(x) < (a)) |
|
38 |
#define bm_safe(bm, x, y) (bm_range(x, (bm)->w) && bm_range(y, (bm)->h)) |
|
39 |
#define BM_UGET(bm, x, y) ((*bm_index(bm, x, y) & bm_mask(x)) != 0) |
|
40 |
#define BM_USET(bm, x, y) (*bm_index(bm, x, y) |= bm_mask(x)) |
|
41 |
#define BM_UCLR(bm, x, y) (*bm_index(bm, x, y) &= ~bm_mask(x)) |
|
42 |
#define BM_UINV(bm, x, y) (*bm_index(bm, x, y) ^= bm_mask(x)) |
|
43 |
#define BM_UPUT(bm, x, y, b) ((b) ? BM_USET(bm, x, y) : BM_UCLR(bm, x, y)) |
|
44 |
#define BM_GET(bm, x, y) (bm_safe(bm, x, y) ? BM_UGET(bm, x, y) : 0) |
|
45 |
#define BM_SET(bm, x, y) (bm_safe(bm, x, y) ? BM_USET(bm, x, y) : 0) |
|
46 |
#define BM_CLR(bm, x, y) (bm_safe(bm, x, y) ? BM_UCLR(bm, x, y) : 0) |
|
47 |
#define BM_INV(bm, x, y) (bm_safe(bm, x, y) ? BM_UINV(bm, x, y) : 0) |
|
48 |
#define BM_PUT(bm, x, y, b) (bm_safe(bm, x, y) ? BM_UPUT(bm, x, y, b) : 0) |
|
49 |
|
|
50 |
/* free the given bitmap. Leaves errno untouched. */ |
|
51 |
static inline void bm_free(potrace_bitmap_t *bm) { |
|
52 |
if (bm) { |
|
53 |
free(bm->map); |
|
54 |
} |
|
55 |
free(bm); |
|
56 |
} |
|
57 |
|
|
58 |
/* return new un-initialized bitmap. NULL with errno on error */ |
|
59 |
static inline potrace_bitmap_t *bm_new(int w, int h) { |
|
60 |
potrace_bitmap_t *bm; |
|
61 |
int dy = (w + BM_WORDBITS - 1) / BM_WORDBITS; |
|
62 |
|
|
63 |
bm = (potrace_bitmap_t *) malloc(sizeof(potrace_bitmap_t)); |
|
64 |
if (!bm) { |
|
65 |
return NULL; |
|
66 |
} |
|
67 |
bm->w = w; |
|
68 |
bm->h = h; |
|
69 |
bm->dy = dy; |
|
70 |
bm->map = (potrace_word *) malloc(dy * h * BM_WORDSIZE); |
|
71 |
if (!bm->map) { |
|
72 |
free(bm); |
|
73 |
return NULL; |
|
74 |
} |
|
75 |
return bm; |
|
76 |
} |
|
77 |
|
|
78 |
/* clear the given bitmap. Set all bits to c. */ |
|
79 |
static inline void bm_clear(potrace_bitmap_t *bm, int c) { |
|
80 |
memset(bm->map, c ? -1 : 0, bm->dy * bm->h * BM_WORDSIZE); |
|
81 |
} |
|
82 |
|
|
83 |
/* duplicate the given bitmap. Return NULL on error with errno set. */ |
|
84 |
static inline potrace_bitmap_t *bm_dup(const potrace_bitmap_t *bm) { |
|
85 |
potrace_bitmap_t *bm1 = bm_new(bm->w, bm->h); |
|
86 |
if (!bm1) { |
|
87 |
return NULL; |
|
88 |
} |
|
89 |
memcpy(bm1->map, bm->map, bm->dy * bm->h * BM_WORDSIZE); |
|
90 |
return bm1; |
|
91 |
} |
|
92 |
|
|
93 |
/* invert the given bitmap. */ |
|
94 |
static inline void bm_invert(potrace_bitmap_t *bm) { |
|
95 |
int i; |
|
96 |
for (i = 0; i < bm->dy * bm->h; i++) { |
|
97 |
bm->map[i] ^= BM_ALLBITS; |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
#endif /* BITMAP_H */ |
branches/gvSIG_19_ext3D_osgVP_2_2_0/libraries/libjni-potrace/resources/potrace-1.8/src/lzw.h | ||
---|---|---|
1 |
/* Copyright (C) 2001-2007 Peter Selinger. |
|
2 |
This file is part of Potrace. It is free software and it is covered |
|
3 |
by the GNU General Public License. See the file COPYING for details. */ |
|
4 |
|
|
5 |
/* $Id: lzw.h 147 2007-04-09 00:44:09Z selinger $ */ |
|
6 |
|
|
7 |
#define LZW_NORMAL 0 |
|
8 |
#define LZW_EOD 1 |
|
9 |
|
|
10 |
/* user visible state */ |
|
11 |
|
|
12 |
struct lzw_stream_s { |
|
13 |
char *next_in; /* pointer to next input character */ |
|
14 |
int avail_in; /* number of input chars available */ |
|
15 |
char *next_out; /* pointer to next free byte in output buffer */ |
|
16 |
int avail_out; /* remaining size of output buffer */ |
|
17 |
|
|
18 |
void *internal; /* internal state, not user accessible */ |
|
19 |
}; |
|
20 |
typedef struct lzw_stream_s lzw_stream_t; |
|
21 |
|
|
22 |
/* user visible functions */ |
|
23 |
|
|
24 |
/* The interface for compression and decompression is the same. The |
|
25 |
application must first call lzw_init to create and initialize a |
|
26 |
compression object. Then it calls lzw_compress on this object |
|
27 |
repeatedly, as follows: next_in and next_out must point to valid, |
|
28 |
non-overlapping regions of memory of size at least avail_in and |
|
29 |
avail_out, respectively. The lzw_compress function will read and |
|
30 |
process as many input bytes as possible as long as there is room in |
|
31 |
the output buffer. It will update next_in, avail_in, next_out, and |
|
32 |
avail_out accordingly. Some input may be consumed without producing |
|
33 |
any output, or some output may be produced without consuming any |
|
34 |
input. However, the lzw_compress function makes progress in the |
|
35 |
sense that, after calling this function, at least one of avail_in |
|
36 |
or avail_out is guaranteed to be 0. The mode flag is normally set |
|
37 |
to LZW_NORMAL. It can be set to LZW_EOD (end of data) to indicate |
|
38 |
that the current input buffer represents the entire remaining input |
|
39 |
data stream. When called with mode=LZW_EOD, and avail_out is |
|
40 |
non-zero after the call, then the application may conclude that the |
|
41 |
end of output has been reached. (However, if avail_out==0 after the |
|
42 |
call, then lzw_compress should be called again with the remaining |
|
43 |
input, if any). Finally, lzw_free should be called to deallocate |
|
44 |
the lzw_stream. Lzw_init returns NULL on error, with errno |
|
45 |
set. Lzw_compress returns 0 on success, and 1 on error with errno |
|
46 |
set. EINVAL is used to indicate an internal error, which should not |
|
47 |
happen. */ |
|
48 |
|
|
49 |
lzw_stream_t *lzw_init(void); |
|
50 |
int lzw_compress(lzw_stream_t *s, int mode); |
|
51 |
void lzw_free(lzw_stream_t *s); |
Also available in: Unified diff