Revision 1780
libjni-potrace/trunk/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) |
libjni-potrace/trunk/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 |
#) |
libjni-potrace/trunk/libjni-potrace/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|
2 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.jpotrace</artifactId> |
|
6 |
<packaging>jar</packaging> |
|
7 |
<version>2.0.0-SNAPSHOT</version> |
|
8 |
<name>libjni-potrace</name> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>gvsig-base-library-jni-pom</artifactId> |
|
12 |
<version>2.0-SNAPSHOT</version> |
|
13 |
</parent> |
|
14 |
<properties> |
|
15 |
<build-dir>${basedir}/../build</build-dir> |
|
16 |
<eclipse.project.name>libjni-potrace</eclipse.project.name> |
|
17 |
</properties> |
|
18 |
<build> |
|
19 |
<plugins> |
|
20 |
<!-- TODO: MAKE TESTS WORK AND REMOVE THIS OPTION --> |
|
21 |
<plugin> |
|
22 |
<groupId>org.apache.maven.plugins</groupId> |
|
23 |
<artifactId>maven-surefire-plugin</artifactId> |
|
24 |
<configuration> |
|
25 |
<skipTests>true</skipTests> |
|
26 |
</configuration> |
|
27 |
</plugin> |
|
28 |
</plugins> |
|
29 |
</build> |
|
30 |
<profiles> |
|
31 |
<profile> |
|
32 |
<id>windows-profile</id> |
|
33 |
<activation> |
|
34 |
<property> |
|
35 |
<name>native-platform</name> |
|
36 |
<value>win</value> |
|
37 |
</property> |
|
38 |
</activation> |
|
39 |
<properties> |
|
40 |
<build-dir>${basedir}\..\build</build-dir> |
|
41 |
</properties> |
|
42 |
<dependencies> |
|
43 |
<dependency> |
|
44 |
<groupId>com.microsoft</groupId> |
|
45 |
<artifactId>visualcppredist</artifactId> |
|
46 |
<version>2008</version> |
|
47 |
<classifier>${native-classifier}</classifier> |
|
48 |
<type>tar.gz</type> |
|
49 |
</dependency> |
|
50 |
</dependencies> |
|
51 |
</profile> |
|
52 |
<profile> |
|
53 |
<id>linux-profile</id> |
|
54 |
<activation> |
|
55 |
<property> |
|
56 |
<name>native-platform</name> |
|
57 |
<value>linux</value> |
|
58 |
</property> |
|
59 |
</activation> |
|
60 |
</profile> |
|
61 |
<profile> |
|
62 |
<id>mac-profile</id> |
|
63 |
<activation> |
|
64 |
<property> |
|
65 |
<name>native-platform</name> |
|
66 |
<value>mac</value> |
|
67 |
</property> |
|
68 |
</activation> |
|
69 |
</profile> |
|
70 |
</profiles> |
|
71 |
</project> |
|
0 | 72 |
libjni-potrace/trunk/libjni-potrace/resources/potrace-1.8/CMakeLists.txt | ||
---|---|---|
1 |
|
|
2 |
CMAKE_MINIMUM_REQUIRED(VERSION 2.4) |
|
3 |
#cmake_minimum_required(VERSION 2.6) |
|
4 |
|
|
5 |
PROJECT(potrace) |
|
6 |
|
|
7 |
SET(VERSION "1.8") |
|
8 |
|
|
9 |
SET(POTRACE "potrace") |
|
10 |
SET(MKBITMAP "mkbitmap") |
|
11 |
|
|
12 |
SET(MAKELIBRARY 1) |
|
13 |
|
|
14 |
ADD_DEFINITIONS(-DPOTRACE=\\"${POTRACE}\\") |
|
15 |
ADD_DEFINITIONS(-DVERSION=\\"${VERSION}\\") |
|
16 |
ADD_DEFINITIONS(-DMKBITMAP=\\"${MKBITMAP}\\") |
|
17 |
|
|
18 |
ADD_SUBDIRECTORY(src) |
|
0 | 19 |
libjni-potrace/trunk/libjni-potrace/resources/potrace-1.8/build.xml | ||
---|---|---|
1 |
<project name="potrace-1.8" default="main" basedir="."> |
|
2 |
<description> |
|
3 |
Compila la librería potrace 1.8 |
|
4 |
</description> |
|
5 |
<property name="build" location="bin/" /> |
|
6 |
<property name="cmake_build" location="." /> |
|
7 |
<property environment="env"/> |
|
8 |
<condition property="potrace_version" value="1.8.0"> |
|
9 |
<os family="unix"/> |
|
10 |
</condition> |
|
11 |
<condition property="potrace_version" value="180"> |
|
12 |
<os family="windows"/> |
|
13 |
</condition> |
|
14 |
<condition property="cmake_generator" value="'Unix Makefiles'"> |
|
15 |
<os family="unix"/> |
|
16 |
</condition> |
|
17 |
<condition property="cmake_generator" value="'Eclipse CDT4 - MinGW Makefiles'"> |
|
18 |
<os family="windows"/> |
|
19 |
</condition> |
|
20 |
|
|
21 |
<target name="main" description="prepare and compile natives" depends="clean,prepare-natives,compile-natives"> |
|
22 |
</target> |
|
23 |
|
|
24 |
<target name="prepare-natives" description="prepares the natives to be compiled"> |
|
25 |
<mkdir dir="${cmake_build}"/> |
|
26 |
<delete file="${cmake_build}/CMakeCache.txt"/> |
|
27 |
<exec dir="${cmake_build}" executable="cmake" os="Linux" > |
|
28 |
<arg line="." /> |
|
29 |
<arg line="-G${cmake_generator}" /> |
|
30 |
<arg line="-DCMAKE_BUILD_TYPE=Release" /> |
|
31 |
<arg line="-DJPOTRACE_VERSION=${jpotrace_version}" /> |
|
32 |
</exec> |
|
33 |
<exec dir="${cmake_build}" executable="cmake" os="Windows 98,Windows 2000,Windows XP,Windows NT (Unknown)"> |
|
34 |
<arg line="." /> |
|
35 |
<arg line="-G${cmake_generator}" /> |
|
36 |
<arg line="-DCMAKE_BUILD_TYPE=Release" /> |
|
37 |
<arg line="-DJPOTRACE_VERSION=${jpotrace_version}" /> |
|
38 |
</exec> |
|
39 |
</target> |
|
40 |
|
|
41 |
<target name="compile-natives" description="compiles natives"> |
|
42 |
<exec dir="${cmake_build}" executable="make" os="Linux"> |
|
43 |
</exec> |
|
44 |
<exec dir="${cmake_build}" executable="nmake" os="Windows 98,Windows 2000,Windows XP,Windows NT (Unknown)"> |
|
45 |
<arg line="install" /> |
|
46 |
</exec> |
|
47 |
</target> |
|
48 |
|
|
49 |
<target name="clean" description="clean distribution"> |
|
50 |
<delete dir="lib-dist"/> |
|
51 |
<delete dir="BMCMake"/> |
|
52 |
</target> |
|
53 |
|
|
54 |
</project> |
|
0 | 55 |
libjni-potrace/trunk/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> |
|
0 | 111 |
libjni-potrace/trunk/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> |
|
0 | 116 |
libjni-potrace/trunk/libjni-potrace/resources/potrace-1.8/src/lzw.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: lzw.c 147 2007-04-09 00:44:09Z selinger $ */ |
|
6 |
|
|
7 |
/* code for adaptive LZW compression, as used in PostScript. */ |
|
8 |
|
|
9 |
#include <stdlib.h> |
|
10 |
#include <stdio.h> |
|
11 |
#include <errno.h> |
|
12 |
#include <string.h> |
|
13 |
|
|
14 |
#include "lists.h" |
|
15 |
#include "bitops.h" |
|
16 |
#include "lzw.h" |
|
17 |
|
|
18 |
/* ---------------------------------------------------------------------- */ |
|
19 |
/* compression state specification */ |
|
20 |
|
|
21 |
/* The compression algorithm follows the following specification, |
|
22 |
expressed as a state machine. A state is a triple {s,d,n}, where s |
|
23 |
is a string of input symbols, d is a dictionary, which is a |
|
24 |
function from strings to output symbols, and n is the dictionary |
|
25 |
size, or equivalently, the next unused output symbol. There are |
|
26 |
also special states init and stop. (emit.c[b]ode) is a function |
|
27 |
which emits the code code as a b-bit value into the output |
|
28 |
bitstream. hibit(n) returns the least number of binary digits |
|
29 |
required to represent n. |
|
30 |
|
|
31 |
init ---> {[], newdict, 258} |
|
32 |
|
|
33 |
where [] is the empty string, and newdict maps each of the 256 |
|
34 |
singleton strings to itself. (Note that there are two special |
|
35 |
output symbols 256 and 257, so that the next available one is |
|
36 |
258). Note: hibit(258)=9. |
|
37 |
|
|
38 |
{[], d, n} (input c) ---> (emit[hibit(n)] 256) {c, d, n} |
|
39 |
|
|
40 |
{s,d,n} (input c) ---> {s*c,d,n} |
|
41 |
|
|
42 |
if s!=[], s*c is in the domain of d. Here s*c is the strings s |
|
43 |
extended by the character c. |
|
44 |
|
|
45 |
{s,d,n} (input c) ---> (emit.c[hibit(n)]ode) {c,d',n+1} |
|
46 |
|
|
47 |
if s!=[], s*c is not in the domain of d, and hibit(n+2) <= 12. |
|
48 |
Here, d(s)=code, and d'=d+{s*c->n}. |
|
49 |
|
|
50 |
{s,d,n} (input c) ---> |
|
51 |
(emit.c[hibit(n)]ode) (emit[hibit(n+1)] 256) {c, newdict, 258} |
|
52 |
|
|
53 |
if s!=[], s*c is not in the domain of d, and hibit(n+2) > 12. |
|
54 |
Here, d(s)=code, and d'=d+{s*c->n}. |
|
55 |
|
|
56 |
{s,d,n} (input EOD) ---> (emit.c[hibit(n)]ode) (emit[hibit(n+1)] 257) stop |
|
57 |
|
|
58 |
where s != [], code = d(s). Here, EOD stands for end-of-data. |
|
59 |
|
|
60 |
{[],d,n} (input EOD) ---> (emit[hibit(n)] 256) (emit[hibit(258)] 257) stop |
|
61 |
|
|
62 |
Notes: |
|
63 |
|
|
64 |
* Each reachable state {s,d,n} satisfies hibit(n+1) <= 12. |
|
65 |
* Only codes of 12 or fewer bits are emitted. |
|
66 |
* Each reachable state {s,d,n} satisfies s=[] or s is in the domain of d. |
|
67 |
* The domain of d is always prefix closed (except for the empty prefix) |
|
68 |
* The state machine is deterministic and non-blocking. |
|
69 |
|
|
70 |
*/ |
|
71 |
|
|
72 |
|
|
73 |
/* ---------------------------------------------------------------------- */ |
|
74 |
/* private state */ |
|
75 |
|
|
76 |
#define BITBUF_TYPE unsigned int |
|
77 |
|
|
78 |
/* the dictionary is implemented as a tree of strings under the prefix |
|
79 |
order. The tree is in turns represented as a linked list of |
|
80 |
lzw_dict_t structures, with "children" pointing to a node's first |
|
81 |
child, and "next" pointing to a node's next sibling. As an |
|
82 |
optimization, the top-level nodes (singleton strings) are |
|
83 |
implemented lazily, i.e., the corresponding entry is not actually |
|
84 |
created until it is accessed. */ |
|
85 |
|
|
86 |
struct lzw_dict_s { |
|
87 |
char c; /* last character of string represented by this entry */ |
|
88 |
int code; /* code for the string represented by this entry */ |
|
89 |
int freq; /* how often searched? For optimization only */ |
|
90 |
struct lzw_dict_s *children; /* list of sub-entries */ |
|
91 |
struct lzw_dict_s *next; /* for making a linked list */ |
|
92 |
}; |
|
93 |
typedef struct lzw_dict_s lzw_dict_t; |
|
94 |
|
|
95 |
/* A state {s,d,n} is represented by the "dictionary state" part of |
|
96 |
the lzw_state_t structure. Here, s is a pointer directly to the node |
|
97 |
of the dictionary structure corresponding to the string s, or NULL |
|
98 |
if s=[]. Further, the lzw_state_t structure contains a buffer of |
|
99 |
pending output bits, and a flag indicating whether the EOD (end of |
|
100 |
data) has been reached in the input. */ |
|
101 |
|
|
102 |
struct lzw_state_s { |
|
103 |
/* dictionary state */ |
|
104 |
int n; /* current size of the dictionary */ |
|
105 |
lzw_dict_t *d; /* pointer to dictionary */ |
|
106 |
lzw_dict_t *s; /* pointer to current string, or NULL at beginning */ |
|
107 |
|
|
108 |
/* buffers for pending output */ |
|
109 |
BITBUF_TYPE buf; /* bits scheduled for output - left aligned, 0 padded */ |
|
110 |
int bufsize; /* number of bits scheduled for output. */ |
|
111 |
int eod; /* flush buffer? */ |
|
112 |
}; |
|
113 |
typedef struct lzw_state_s lzw_state_t; |
|
114 |
|
|
115 |
/* ---------------------------------------------------------------------- */ |
|
116 |
/* auxiliary functions which operate on dictionary states */ |
|
117 |
|
|
118 |
/* recursively free an lzw_dict_t object */ |
|
119 |
static void lzw_free_dict(lzw_dict_t *s) { |
|
120 |
lzw_dict_t *e; |
|
121 |
|
|
122 |
list_forall_unlink(e, s) { |
|
123 |
lzw_free_dict(e->children); |
|
124 |
free(e); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
/* re-initialize the lzw state's dictionary state to "newdict", |
|
129 |
freeing any old dictionary. */ |
|
130 |
static void lzw_clear_table(lzw_state_t *st) { |
|
131 |
|
|
132 |
lzw_free_dict(st->d); |
|
133 |
st->d = NULL; |
|
134 |
st->n = 258; |
|
135 |
st->s = NULL; |
|
136 |
} |
|
137 |
|
|
138 |
/* ---------------------------------------------------------------------- */ |
|
139 |
/* auxiliary functions for reading/writing the bit buffer */ |
|
140 |
|
|
141 |
/* write the code to the bit buffer. Precondition st->bufsize <= 7. |
|
142 |
Note: this does not change the dictionary state; in particular, |
|
143 |
n must be updated between consecutive calls. */ |
|
144 |
static inline void lzw_emit(int code, lzw_state_t *st) { |
|
145 |
BITBUF_TYPE mask; |
|
146 |
int bits = hibit(st->n); |
|
147 |
|
|
148 |
/* fill bit buffer */ |
|
149 |
mask = (1 << bits) - 1; |
|
150 |
code &= mask; |
|
151 |
|
|
152 |
st->buf |= code << (8*sizeof(BITBUF_TYPE) - st->bufsize - bits); |
|
153 |
st->bufsize += bits; |
|
154 |
} |
|
155 |
|
|
156 |
/* transfer one byte from bit buffer to output. Precondition: |
|
157 |
s->avail_out > 0. */ |
|
158 |
static inline void lzw_read_bitbuf(lzw_stream_t *s) { |
|
159 |
int ch; |
|
160 |
lzw_state_t *st = (lzw_state_t *)s->internal; |
|
161 |
|
|
162 |
ch = st->buf >> (8*sizeof(BITBUF_TYPE)-8); |
|
163 |
st->buf <<= 8; |
|
164 |
st->bufsize -= 8; |
|
165 |
|
|
166 |
s->next_out[0] = ch; |
|
167 |
s->next_out++; |
|
168 |
s->avail_out--; |
|
169 |
} |
|
170 |
|
|
171 |
/* ---------------------------------------------------------------------- */ |
|
172 |
/* The following functions implement the state machine. */ |
|
173 |
|
|
174 |
/* perform state transition of the state st on input character |
|
175 |
ch. This updates the dictionary state and/or writes to the bit |
|
176 |
buffer. Precondition: st->bufsize <= 7. Return 0 on success, or 1 |
|
177 |
on error with errno set. */ |
|
178 |
static int lzw_encode_char(lzw_state_t *st, char c) { |
|
179 |
lzw_dict_t *e; |
|
180 |
|
|
181 |
/* st = {s,d,n}. hibit(n+1)<=12. */ |
|
182 |
|
|
183 |
/* {[], d, n} (input c) ---> (emit[hibit(n)] 256) {c, d, n} */ |
|
184 |
if (st->s == NULL) { |
|
185 |
lzw_emit(256, st); |
|
186 |
goto singleton; /* enter singleton state c */ |
|
187 |
} |
|
188 |
|
|
189 |
/* {s,d,n} (input c) ---> {s*c,d,n} */ |
|
190 |
list_find(e, st->s->children, e->c == c); |
|
191 |
if (e) { |
|
192 |
e->freq++; |
|
193 |
st->s = e; |
|
194 |
return 0; |
|
195 |
} |
|
196 |
|
|
197 |
/* {s,d,n} (input c) ---> (emit.c[hibit(n)]ode) {c,d',n+1} */ |
|
198 |
/* {s,d,n} (input c) ---> |
|
199 |
(emit.c[hibit(n)]ode) (emit[hibit(n+1)] 256) {c, newdict, 258} */ |
|
200 |
|
|
201 |
lzw_emit(st->s->code, st); /* 9-12 bits */ |
|
202 |
if (st->n >= 4094) { /* hibit(n+2) > 12 */ /* ### was: 4093 */ |
|
203 |
st->n++; |
|
204 |
lzw_emit(256, st); |
|
205 |
goto dictfull; /* reset dictionary and enter singleton state c */ |
|
206 |
} |
|
207 |
|
|
208 |
/* insert new code in dictionary, if possible */ |
|
209 |
e = (lzw_dict_t *)malloc(sizeof(lzw_dict_t)); |
|
210 |
if (!e) { |
|
211 |
return 1; |
|
212 |
} |
|
213 |
e->c = c; |
|
214 |
e->code = st->n; |
|
215 |
e->freq = 1; |
|
216 |
e->children = NULL; |
|
217 |
list_prepend(st->s->children, e); |
|
218 |
st->n++; |
|
219 |
goto singleton; /* enter singleton state c */ |
|
220 |
|
|
221 |
dictfull: /* reset dictionary and enter singleton state c */ |
|
222 |
lzw_clear_table(st); |
|
223 |
/* fall through */ |
|
224 |
|
|
225 |
singleton: /* enter singleton state c */ |
|
226 |
list_find(e, st->d, e->c == c); |
|
227 |
if (!e) { /* not found: lazily add it */ |
|
228 |
e = (lzw_dict_t *)malloc(sizeof(lzw_dict_t)); |
|
229 |
if (!e) { |
|
230 |
return 1; |
|
231 |
} |
|
232 |
e->c = c; |
|
233 |
e->code = (int)(unsigned char)c; |
|
234 |
e->freq = 0; |
|
235 |
e->children = NULL; |
|
236 |
list_prepend(st->d, e); |
|
237 |
} |
|
238 |
e->freq++; |
|
239 |
st->s = e; |
|
240 |
return 0; |
|
241 |
} |
|
242 |
|
|
243 |
/* perform state transition of the state st on input EOD. The leaves |
|
244 |
the dictionary state undefined and writes to the bit buffer. |
|
245 |
Precondition: st->bufsize <= 7. This function must be called |
|
246 |
exactly once, at the end of the stream. */ |
|
247 |
static void lzw_encode_eod(lzw_state_t *st) { |
|
248 |
|
|
249 |
/* {[],d,n} (input EOD) ---> |
|
250 |
(emit[hibit(n)] 256) (emit[hibit(n+1)] 257) stop */ |
|
251 |
if (st->s == NULL) { |
|
252 |
lzw_emit(256, st); /* 9 bits */ |
|
253 |
st->n=258; |
|
254 |
lzw_emit(257, st); /* 9 bits */ |
|
255 |
return; |
|
256 |
} |
|
257 |
|
|
258 |
/* {s,d,n} (input EOD) ---> |
|
259 |
(emit.c[hibit(n)]ode) (emit[hibit(n+1)] 257) stop */ |
|
260 |
|
|
261 |
lzw_emit(st->s->code, st); /* 9-12 bits */ |
|
262 |
st->n++; |
|
263 |
lzw_emit(257, st); /* 9-12 bits */ |
|
264 |
return; |
|
265 |
} |
|
266 |
|
|
267 |
/* ---------------------------------------------------------------------- */ |
|
268 |
/* User visible functions. These implement a buffer interface. See |
|
269 |
lzw.h for the API description. */ |
|
270 |
|
|
271 |
lzw_stream_t *lzw_init(void) { |
|
272 |
lzw_stream_t *s = NULL; |
|
273 |
lzw_state_t *st = NULL; |
|
274 |
|
|
275 |
s = (lzw_stream_t *)malloc(sizeof(lzw_stream_t)); |
|
276 |
if (s==NULL) { |
|
277 |
goto fail; |
|
278 |
} |
|
279 |
st = (lzw_state_t *)malloc(sizeof(lzw_state_t)); |
|
280 |
if (st==NULL) { |
|
281 |
goto fail; |
|
282 |
} |
|
283 |
st->buf = 0; |
|
284 |
st->bufsize = 0; |
|
285 |
st->eod = 0; |
|
286 |
st->d = NULL; |
|
287 |
lzw_clear_table(st); |
|
288 |
s->internal = (void *) st; |
|
289 |
return s; |
|
290 |
|
|
291 |
fail: |
|
292 |
free(s); |
|
293 |
free(st); |
|
294 |
return NULL; |
|
295 |
} |
|
296 |
|
|
297 |
int lzw_compress(lzw_stream_t *s, int mode) { |
|
298 |
int r; |
|
299 |
lzw_state_t *st = (lzw_state_t *)s->internal; |
|
300 |
|
|
301 |
while (st->eod == 0) { |
|
302 |
/* empty bit buffer */ |
|
303 |
while (st->bufsize > 7) { |
|
304 |
if (s->avail_out == 0) { |
|
305 |
return 0; |
|
306 |
} else { |
|
307 |
lzw_read_bitbuf(s); |
|
308 |
} |
|
309 |
} |
|
310 |
/* fill bit buffer */ |
|
311 |
if (s->avail_in == 0) { |
|
312 |
break; |
|
313 |
} else { |
|
314 |
r = lzw_encode_char(st, s->next_in[0]); |
|
315 |
if (r) { |
|
316 |
if (r==2) { |
|
317 |
errno = EINVAL; |
|
318 |
} |
|
319 |
return 1; |
|
320 |
} |
|
321 |
s->next_in++; |
|
322 |
s->avail_in--; |
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
if (mode==LZW_EOD && st->eod == 0) { |
|
327 |
st->eod = 1; |
|
328 |
lzw_encode_eod(st); |
|
329 |
} |
|
330 |
|
|
331 |
/* flush bit buffer */ |
|
332 |
if (st->eod) { |
|
333 |
while (st->bufsize > 0) { |
|
334 |
if (s->avail_out == 0) { |
|
335 |
return 0; |
|
336 |
} else { |
|
337 |
lzw_read_bitbuf(s); |
|
338 |
} |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
return 0; |
|
343 |
} |
|
344 |
|
|
345 |
void lzw_free(lzw_stream_t *s) { |
|
346 |
lzw_state_t *st = (lzw_state_t *)s->internal; |
|
347 |
|
|
348 |
lzw_free_dict(st->d); |
|
349 |
free(st); |
|
350 |
free(s); |
|
351 |
} |
|
352 |
|
|
353 |
/* ---------------------------------------------------------------------- */ |
|
354 |
/* main function for testing and illustration purposes */ |
|
355 |
|
|
356 |
#ifdef LZW_MAIN |
|
357 |
|
|
358 |
int main() { |
|
359 |
lzw_stream_t *s; |
|
360 |
int ch; |
|
361 |
char inbuf[100]; |
|
362 |
char outbuf[100]; |
|
363 |
int i, r; |
|
364 |
int mode; |
|
365 |
|
|
366 |
s = lzw_init(); |
|
367 |
if (!s) { |
|
368 |
goto error; |
|
369 |
} |
|
370 |
mode = LZW_NORMAL; |
|
371 |
|
|
372 |
while (1) { |
|
373 |
/* fill inbuf */ |
|
374 |
for (i=0; i<100; i++) { |
|
375 |
ch = fgetc(stdin); |
|
376 |
if (ch==EOF) { |
|
377 |
break; |
|
378 |
} |
|
379 |
inbuf[i] = ch; |
|
380 |
} |
|
381 |
if (i<100) { /* end of input */ |
|
382 |
mode = LZW_EOD; |
|
383 |
} |
|
384 |
|
|
385 |
/* compress */ |
|
386 |
s->next_in = inbuf; |
|
387 |
s->avail_in = i; |
|
388 |
do { |
|
389 |
s->next_out = outbuf; |
|
390 |
s->avail_out = 100; |
|
391 |
r = lzw_compress(s, mode); |
|
392 |
if (r) { |
|
393 |
goto error; |
|
394 |
} |
|
395 |
fwrite(outbuf, 1, 100-s->avail_out, stdout); |
|
396 |
} while (s->avail_out==0); |
|
397 |
if (mode == LZW_EOD) { |
|
398 |
break; |
|
399 |
} |
|
400 |
} |
|
401 |
fflush(stdout); |
|
402 |
lzw_free(s); |
|
403 |
|
|
404 |
return 0; |
|
405 |
|
|
406 |
error: |
|
407 |
fprintf(stderr, "lzw: %s\n", strerror(errno)); |
|
408 |
lzw_free(s); |
|
409 |
return 1; |
|
410 |
|
|
411 |
} |
|
412 |
#endif |
|
413 |
|
|
0 | 414 |
libjni-potrace/trunk/libjni-potrace/resources/potrace-1.8/src/potrace_raster.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 <stdio.h> |
|
20 |
#include <errno.h> |
|
21 |
#include <math.h> |
|
22 |
#include "getopt.h" |
|
23 |
|
|
24 |
#include "main.h" |
|
25 |
#include "platform.h" |
|
26 |
|
|
27 |
#include "backend_pdf.h" |
|
28 |
#include "backend_eps.h" |
|
29 |
#include "backend_pgm.h" |
|
30 |
#include "backend_svg.h" |
|
31 |
#include "backend_gimp.h" |
|
32 |
#include "backend_xfig.h" |
|
33 |
#include "bitmap_io.h" |
|
34 |
#include "auxiliary.h" |
|
35 |
|
|
36 |
#ifndef M_PI |
|
37 |
#define M_PI 3.14159265358979323846 |
|
38 |
#endif |
|
39 |
|
|
40 |
#define UNDEF ((double)(1e30)) /* a value to represent "undefined" */ |
|
41 |
#define INFTY ((double)(1e30)) /* a value to represent +infinity */ |
|
42 |
|
|
43 |
/* backends and their characteristics */ |
|
44 |
struct backend_s { |
|
45 |
char *name; /* name of this backend */ |
|
46 |
char *ext; /* file extension */ |
|
47 |
int fixed; /* fixed page size backend? */ |
|
48 |
int pixel; /* pixel-based backend? */ |
|
49 |
int multi; /* multi-page backend? */ |
|
50 |
int (*init_f)(FILE *fout); /* initialization function */ |
|
51 |
int (*page_f)(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo); |
|
52 |
/* per-bitmap function */ |
|
53 |
int (*term_f)(FILE *fout); /* finalization function */ |
|
54 |
int opticurve; /* opticurve capable (true Bezier curves?) */ |
|
55 |
}; |
|
56 |
typedef struct backend_s backend_t; |
|
57 |
|
|
58 |
static backend_t backend[] = { {"eps", ".eps", 0, 0, 0, NULL, page_eps, NULL, 1}, {"postscript", ".ps", 1, 0, 1, |
|
59 |
init_ps, page_ps, term_ps, 1}, {"ps", ".ps", 1, 0, 1, init_ps, page_ps, term_ps, 1}, {"pdf", ".pdf", 0, 0, 1, |
|
60 |
init_pdf, page_pdf, term_pdf, 1}, {"svg", ".svg", 0, 0, 0, NULL, page_svg, NULL, 1}, {"pgm", ".pgm", 0, 1, 1, NULL, |
|
61 |
page_pgm, NULL, 1}, {"gimppath", ".gimppath", 0, 1, 0, NULL, page_gimp, NULL, 1}, {"xfig", ".fig", 1, 0, 0, NULL, |
|
62 |
page_xfig, NULL, 0}, {NULL, NULL, 0, 0, 0, NULL, NULL, NULL}, }; |
|
63 |
|
|
64 |
struct info_s info; |
|
65 |
|
|
66 |
#define COL0 "\033[G" /* reset cursor to column 0 */ |
|
67 |
|
|
68 |
/* ---------------------------------------------------------------------- */ |
|
69 |
/* callback function for progress bar */ |
|
70 |
|
|
71 |
struct simple_progress_s { |
|
72 |
char name[22]; /* filename for status bar */ |
|
73 |
double dnext; /* threshold value for next tick */ |
|
74 |
}; |
|
75 |
typedef struct simple_progress_s simple_progress_t; |
|
76 |
|
|
77 |
static inline double double_of_dim(dim_t d, double def) { |
|
78 |
if (d.d) { |
|
79 |
return d.x * d.d; |
|
80 |
} else { |
|
81 |
return d.x * def; |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
/* ---------------------------------------------------------------------- */ |
|
86 |
/* calculations with bitmap dimensions, positioning etc */ |
|
87 |
|
|
88 |
/* consider a rectangle spanned by the vectors (w,0) and (0,h). Rotate |
|
89 |
it counterclockwise by angle alpha. Then set the rect_t structure |
|
90 |
to the resulting rectangle, setting its bounding box, origin, |
|
91 |
x-basis and y-basis. */ |
|
92 |
|
|
93 |
static void rotate_dim(double alpha, double w, double h, rect_t *r) { |
|
94 |
double s, c, x0, x1, y0, y1; |
|
95 |
|
|
96 |
s = sin(alpha / 180 * M_PI); |
|
97 |
c = cos(alpha / 180 * M_PI); |
|
98 |
|
|
99 |
/* apply the transformation matrix to the basis vectors */ |
|
100 |
x0 = c * w; |
|
101 |
x1 = s * w; |
|
102 |
y0 = -s * h; |
|
103 |
y1 = c * h; |
|
104 |
|
|
105 |
/* determine bounding box and origin relative to bounding box */ |
|
106 |
r->bb[0] = fabs(x0) + fabs(y0); |
|
107 |
r->bb[1] = fabs(x1) + fabs(y1); |
|
108 |
r->orig[0] = -min(x0, 0) - min(y0, 0); |
|
109 |
r->orig[1] = -min(x1, 0) - min(y1, 0); |
|
110 |
} |
|
111 |
|
|
112 |
/* determine the dimensions of the output based on command line and |
|
113 |
image dimensions */ |
|
114 |
static void calc_dimensions(imginfo_t *imginfo) { |
|
115 |
double dim_def; |
|
116 |
double maxwidth, maxheight, sc; |
|
117 |
rect_t r; |
|
118 |
|
|
119 |
/* we take care of a special case: if one of the image dimensions is |
|
120 |
0, we change it to 1. Such an image is empty anyway, so there |
|
121 |
will be 0 paths in it. Changing the dimensions avoids division by |
|
122 |
0 error in calculating scaling factors, bounding boxes and |
|
123 |
such. This doesn't quite do the right thing in all cases, but it |
|
124 |
is better than causing overflow errors or "nan" output in |
|
125 |
backends. Human users don't tend to process images of size 0 |
|
126 |
anyway; they might occur in some pipelines. */ |
|
127 |
if (imginfo->pixwidth == 0) { |
|
128 |
imginfo->pixwidth = 1; |
|
129 |
} |
|
130 |
if (imginfo->pixheight == 0) { |
|
131 |
imginfo->pixheight = 1; |
|
132 |
} |
|
133 |
|
|
134 |
/* set the default dimension for width, height, margins */ |
|
135 |
if (info.backend->pixel) { |
|
136 |
dim_def = DIM_PT; |
|
137 |
} else { |
|
138 |
dim_def = DEFAULT_DIM; |
|
139 |
} |
|
140 |
|
|
141 |
/* apply default dimension to width, height, margins */ |
|
142 |
imginfo->width = info.width_d.x == UNDEF ? UNDEF : double_of_dim(info.width_d, dim_def); |
|
143 |
imginfo->height = info.height_d.x == UNDEF ? UNDEF : double_of_dim(info.height_d, dim_def); |
|
144 |
imginfo->lmar = info.lmar_d.x == UNDEF ? UNDEF : double_of_dim(info.lmar_d, dim_def); |
|
145 |
imginfo->rmar = info.rmar_d.x == UNDEF ? UNDEF : double_of_dim(info.rmar_d, dim_def); |
|
146 |
imginfo->tmar = info.tmar_d.x == UNDEF ? UNDEF : double_of_dim(info.tmar_d, dim_def); |
|
147 |
imginfo->bmar = info.bmar_d.x == UNDEF ? UNDEF : double_of_dim(info.bmar_d, dim_def); |
|
148 |
|
|
149 |
/* determine width and height from desired resolution / scaling |
|
150 |
factor, if given */ |
|
151 |
if (info.backend->pixel) { |
|
152 |
if (imginfo->width == UNDEF && info.sx != UNDEF) { |
|
153 |
imginfo->width = imginfo->pixwidth * info.sx; |
|
154 |
} |
|
155 |
if (imginfo->height == UNDEF && info.sy != UNDEF) { |
|
156 |
imginfo->height = imginfo->pixheight * info.sy; |
|
157 |
} |
|
158 |
} else { |
|
159 |
if (imginfo->width == UNDEF && info.rx != UNDEF) { |
|
160 |
imginfo->width = imginfo->pixwidth / info.rx * 72; |
|
161 |
} |
|
162 |
if (imginfo->height == UNDEF && info.ry != UNDEF) { |
|
163 |
imginfo->height = imginfo->pixheight / info.ry * 72; |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/* if one of width/height is specified, determine the other */ |
|
168 |
if (imginfo->width == UNDEF && imginfo->height != UNDEF) { |
|
169 |
imginfo->width = imginfo->height / imginfo->pixheight * imginfo->pixwidth / info.stretch; |
|
170 |
} else |
|
171 |
if (imginfo->width != UNDEF && imginfo->height == UNDEF) { |
|
172 |
imginfo->height = imginfo->width / imginfo->pixwidth * imginfo->pixheight * info.stretch; |
|
173 |
} |
|
174 |
|
|
175 |
/* if width and height are still variable, figure them out */ |
|
176 |
if (imginfo->width == UNDEF && imginfo->height == UNDEF) { |
|
177 |
|
|
178 |
if (info.backend->fixed) { |
|
179 |
|
|
180 |
/* in fixed-size backends, try to squeeze it between margins */ |
|
181 |
maxwidth = UNDEF; |
|
182 |
maxheight = UNDEF; |
|
183 |
|
|
184 |
if (imginfo->lmar != UNDEF && imginfo->rmar != UNDEF) { |
|
185 |
maxwidth = info.paperwidth - imginfo->lmar - imginfo->rmar; |
|
186 |
} |
|
187 |
if (imginfo->bmar != UNDEF && imginfo->tmar != UNDEF) { |
|
188 |
maxheight = info.paperheight - imginfo->bmar - imginfo->tmar; |
|
189 |
} |
|
190 |
if (maxwidth == UNDEF && maxheight == UNDEF) { |
|
191 |
maxwidth = max(info.paperwidth - 144, info.paperwidth * 0.75); |
|
192 |
maxheight = max(info.paperheight - 144, info.paperheight * 0.75); |
|
193 |
} |
|
194 |
|
|
195 |
rotate_dim(info.angle, imginfo->pixwidth, imginfo->pixheight * info.stretch, &r); |
|
196 |
|
|
197 |
sc = min(maxwidth == UNDEF ? INFTY : maxwidth / r.bb[0], maxheight == UNDEF ? INFTY : maxheight / r.bb[1]); |
|
198 |
imginfo->width = imginfo->pixwidth * sc; |
|
199 |
imginfo->height = imginfo->pixheight * info.stretch * sc; |
|
200 |
|
|
201 |
} else |
|
202 |
if (info.backend->pixel) { |
|
203 |
|
|
204 |
/* in pixel-based backends, assume default scaling factor of 1 */ |
|
205 |
|
|
206 |
imginfo->width = imginfo->pixwidth; |
|
207 |
imginfo->height = imginfo->pixheight * info.stretch; |
|
208 |
} else { |
|
209 |
|
|
210 |
/* otherwise, choose a default size based on the default paper format */ |
|
211 |
|
|
212 |
maxwidth = max(info.paperwidth - 144, info.paperwidth * 0.75); |
|
213 |
maxheight = max(info.paperheight - 144, info.paperheight * 0.75); |
|
214 |
|
|
215 |
sc = min(maxwidth / imginfo->pixwidth, maxheight / imginfo->pixheight / info.stretch); |
|
216 |
imginfo->width = imginfo->pixwidth * sc; |
|
217 |
imginfo->height = imginfo->pixheight * info.stretch * sc; |
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
/* calculate coordinate system */ |
|
222 |
rotate_dim(info.angle, imginfo->width, imginfo->height, &imginfo->trans); |
|
223 |
|
|
224 |
/* adjust margins */ |
|
225 |
if (info.backend->fixed) { |
|
226 |
if (imginfo->lmar == UNDEF && imginfo->rmar == UNDEF) { |
|
227 |
imginfo->lmar = (info.paperwidth - imginfo->trans.bb[0]) / 2; |
|
228 |
} else |
|
229 |
if (imginfo->lmar == UNDEF) { |
|
230 |
imginfo->lmar = (info.paperwidth - imginfo->trans.bb[0] - imginfo->rmar); |
|
231 |
} else |
|
232 |
if (imginfo->lmar != UNDEF && imginfo->rmar != UNDEF) { |
|
233 |
imginfo->lmar += (info.paperwidth - imginfo->trans.bb[0] - imginfo->lmar - imginfo->rmar) / 2; |
|
234 |
} |
|
235 |
if (imginfo->bmar == UNDEF && imginfo->tmar == UNDEF) { |
|
236 |
imginfo->bmar = (info.paperheight - imginfo->trans.bb[1]) / 2; |
|
237 |
} else |
|
238 |
if (imginfo->bmar == UNDEF) { |
|
239 |
imginfo->bmar = (info.paperheight - imginfo->trans.bb[1] - imginfo->tmar); |
|
240 |
} else |
|
241 |
if (imginfo->bmar != UNDEF && imginfo->tmar != UNDEF) { |
|
242 |
imginfo->bmar += (info.paperheight - imginfo->trans.bb[1] - imginfo->bmar - imginfo->tmar) / 2; |
|
243 |
} |
|
244 |
} else { |
|
245 |
if (imginfo->lmar == UNDEF) { |
|
246 |
imginfo->lmar = 0; |
|
247 |
} |
|
248 |
if (imginfo->rmar == UNDEF) { |
|
249 |
imginfo->rmar = 0; |
|
250 |
} |
|
251 |
if (imginfo->bmar == UNDEF) { |
|
252 |
imginfo->bmar = 0; |
|
253 |
} |
|
254 |
if (imginfo->tmar == UNDEF) { |
|
255 |
imginfo->tmar = 0; |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
static FILE *my_fopen_read(const char *filename) { |
|
261 |
if (filename == NULL || strcmp(filename, "-") == 0) { |
|
262 |
return stdin; |
|
263 |
} |
|
264 |
return fopen(filename, "rb"); |
|
265 |
} |
|
266 |
|
|
267 |
static FILE *my_fopen_write(const char *filename) { |
|
268 |
if (filename == NULL || strcmp(filename, "-") == 0) { |
|
269 |
return stdout; |
|
270 |
} |
|
271 |
return fopen(filename, "wb"); |
|
272 |
} |
|
273 |
|
|
274 |
/* close a file, but do nothing is filename is NULL or "-" */ |
|
275 |
static void my_fclose(FILE *f, const char *filename) { |
|
276 |
if (filename == NULL || strcmp(filename, "-") == 0) { |
|
277 |
return; |
|
278 |
} |
|
279 |
fclose(f); |
|
280 |
} |
|
281 |
|
|
282 |
/* print a simple progress bar. This is a callback function that is |
|
283 |
potentially called often; thus, it has been optimized for the |
|
284 |
typical case, which is when the progress bar does not need updating. */ |
|
285 |
static void simple_progress(double d, void *data) { |
|
286 |
simple_progress_t *p = (simple_progress_t *) data; |
|
287 |
static char b[] = "========================================"; |
|
288 |
int tick; /* number of visible tickmarks, 0..40 */ |
|
289 |
int perc; /* visible percentage, 0..100 */ |
|
290 |
|
|
291 |
/* note: the 0.01 and 0.025 ensure that we always end on 40 |
|
292 |
tickmarks and 100%, despite any rounding errors. The 0.995 |
|
293 |
ensures that tick always increases when d >= p->dnext. */ |
|
294 |
if (d >= p->dnext) { |
|
295 |
tick = (int) floor(d * 40 + 0.01); |
|
296 |
perc = (int) floor(d * 100 + 0.025); |
|
297 |
fprintf(stderr, "%-21s |%-40s| %d%% "COL0"", p->name, b + 40 - tick, perc); |
|
298 |
p->dnext = (tick + 0.995) / 40.0; |
|
299 |
} |
|
300 |
} |
|
301 |
|
|
302 |
/* Initialize parameters for simple progress bar. The caller passes an |
|
303 |
allocated simple_progress_t structure to avoid having to malloc it |
|
304 |
here and free it later. */ |
|
305 |
static inline void init_progress(potrace_progress_t *prog, simple_progress_t *p, const char *filename, int count) { |
|
306 |
const char *q, *s; |
|
307 |
int len; |
|
308 |
|
|
309 |
/* initialize callback function's data */ |
|
310 |
p->dnext = 0; |
|
311 |
|
|
312 |
if (count != 0) { |
|
313 |
sprintf(p->name, " (p.%d):", count + 1); |
|
314 |
} else { |
|
315 |
s = filename; |
|
316 |
if ((q = strrchr(s, '/')) != NULL) { |
|
317 |
s = q + 1; |
|
318 |
} |
|
319 |
len = strlen(s); |
|
320 |
strncpy(p->name, s, 21); |
|
321 |
p->name[20] = 0; |
|
322 |
if (len > 20) { |
|
323 |
p->name[17] = '.'; |
|
324 |
p->name[18] = '.'; |
|
325 |
p->name[19] = '.'; |
|
326 |
} |
|
327 |
strcat(p->name, ":"); |
|
328 |
} |
|
329 |
|
|
330 |
/* initialize progress parameters */ |
|
331 |
prog->callback = &simple_progress; |
|
332 |
prog->data = (void *) p; |
|
333 |
prog->min = 0.0; |
|
334 |
prog->max = 1.0; |
|
335 |
prog->epsilon = 0.0; |
|
336 |
|
|
337 |
/* draw first progress bar */ |
|
338 |
simple_progress(0.0, prog->data); |
|
339 |
return; |
|
340 |
} |
|
341 |
|
|
342 |
struct pageformat_s { |
|
343 |
char *name; |
|
344 |
int w, h; |
|
345 |
}; |
|
346 |
typedef struct pageformat_s pageformat_t; |
|
347 |
|
|
348 |
/* dimensions of the various page formats, in postscript points */ |
|
349 |
static pageformat_t pageformat[] = { |
|
350 |
{ "a4", 595, 842 }, |
|
351 |
{ "a3", 842, 1191 }, |
|
352 |
{ "a5", 421, 595 }, |
|
353 |
{ "b5", 516, 729 }, |
|
354 |
{ "letter", 612, 792 }, |
|
355 |
{ "legal", 612, 1008 }, |
|
356 |
{ "tabloid", 792, 1224 }, |
|
357 |
{ "statement", 396, 612 }, |
|
358 |
{ "executive", 540, 720 }, |
|
359 |
{ "folio", 612, 936 }, |
|
360 |
{ "quarto", 610, 780 }, |
|
361 |
{ "10x14", 720, 1008 }, |
|
362 |
{ NULL, 0, 0 }, |
|
363 |
}; |
|
364 |
|
|
365 |
struct turnpolicy_s { |
|
366 |
char *name; |
|
367 |
int n; |
|
368 |
}; |
|
369 |
typedef struct turnpolicy_s turnpolicy_t; |
|
370 |
|
|
371 |
/* names of turn policies */ |
|
372 |
static turnpolicy_t turnpolicy[] = { |
|
373 |
{"black", POTRACE_TURNPOLICY_BLACK}, |
|
374 |
{"white", POTRACE_TURNPOLICY_WHITE}, |
|
375 |
{"left", POTRACE_TURNPOLICY_LEFT}, |
|
376 |
{"right", POTRACE_TURNPOLICY_RIGHT}, |
|
377 |
{"minority", POTRACE_TURNPOLICY_MINORITY}, |
|
378 |
{"majority", POTRACE_TURNPOLICY_MAJORITY}, |
|
379 |
{"random", POTRACE_TURNPOLICY_RANDOM}, |
|
380 |
{NULL, 0}, |
|
381 |
}; |
|
382 |
|
|
383 |
static dim_t parse_dimension(char *s, char **endptr) { |
|
384 |
char *p; |
|
385 |
dim_t res; |
|
386 |
|
|
387 |
res.x = strtod(s, &p); |
|
388 |
res.d = 0; |
|
389 |
if (p!=s) { |
|
390 |
if (!strncasecmp(p, "in", 2)) { |
|
391 |
res.d = DIM_IN; |
|
392 |
p += 2; |
|
393 |
} else if (!strncasecmp(p, "cm", 2)) { |
|
394 |
res.d = DIM_CM; |
|
395 |
p += 2; |
|
396 |
} else if (!strncasecmp(p, "mm", 2)) { |
|
397 |
res.d = DIM_MM; |
|
398 |
p += 2; |
|
399 |
} else if (!strncasecmp(p, "pt", 2)) { |
|
400 |
res.d = DIM_PT; |
|
401 |
p += 2; |
|
402 |
} |
|
403 |
} |
|
404 |
if (endptr!=NULL) { |
|
405 |
*endptr = p; |
|
406 |
} |
|
407 |
return res; |
|
408 |
} |
|
409 |
|
|
410 |
/* parse a pair of dimensions, such as "8.5x11in", "30mmx4cm" */ |
|
411 |
static void parse_dimensions(char *s, char **endptr, dim_t *dxp, dim_t *dyp) { |
|
412 |
char *p, *q; |
|
413 |
dim_t dx, dy; |
|
414 |
|
|
415 |
dx = parse_dimension(s, &p); |
|
416 |
if (p==s) { |
|
417 |
goto fail; |
|
418 |
} |
|
419 |
if (*p != 'x') { |
|
420 |
goto fail; |
|
421 |
} |
|
422 |
p++; |
|
423 |
dy = parse_dimension(p, &q); |
|
424 |
if (q==p) { |
|
425 |
goto fail; |
|
426 |
} |
|
427 |
if (dx.d && !dy.d) { |
|
428 |
dy.d = dx.d; |
|
429 |
} else if (!dx.d && dy.d) { |
|
430 |
dx.d = dy.d; |
|
431 |
} |
|
432 |
*dxp = dx; |
|
433 |
*dyp = dy; |
|
434 |
if (endptr != NULL) { |
|
435 |
*endptr = q; |
|
436 |
} |
|
437 |
return; |
|
438 |
|
|
439 |
fail: |
|
440 |
dx.x = dx.d = dy.x = dy.d = 0; |
|
441 |
*dxp = dx; |
|
442 |
*dyp = dy; |
|
443 |
if (endptr != NULL) { |
|
444 |
*endptr = s; |
|
445 |
} |
|
446 |
return; |
|
447 |
} |
|
448 |
|
|
449 |
#define OPT_GROUP 300 |
|
450 |
#define OPT_OPAQUE 301 |
|
451 |
#define OPT_FILLCOLOR 302 |
|
452 |
#define OPT_PROGRESS 303 |
|
453 |
|
|
454 |
static struct option longopts[] = { |
|
455 |
{"help", 0, 0, 'h'}, |
|
456 |
{"version", 0, 0, 'v'}, |
|
457 |
{"license", 0, 0, 'l'}, |
|
458 |
{"show-defaults", 0, 0, 'V'}, |
|
459 |
{"progress", 0, 0, OPT_PROGRESS}, |
|
460 |
{"width", 1, 0, 'W'}, |
|
461 |
{"height", 1, 0, 'H'}, |
|
462 |
{"resolution", 1, 0, 'r'}, |
|
463 |
{"scale", 1, 0, 'x'}, |
|
464 |
{"stretch", 1, 0, 'S'}, |
|
465 |
{"margin", 1, 0, 'M'}, |
|
466 |
{"leftmargin", 1, 0, 'L'}, |
|
467 |
{"rightmargin", 1, 0, 'R'}, |
|
468 |
{"topmargin", 1, 0, 'T'}, |
|
469 |
{"bottommargin", 1, 0, 'B'}, |
|
470 |
{"rotate", 1, 0, 'A'}, |
|
471 |
{"pagesize", 1, 0, 'P'}, |
|
472 |
{"turdsize", 1, 0, 't'}, |
|
473 |
{"unit", 1, 0, 'u'}, |
|
474 |
{"cleartext", 0, 0, 'c'}, |
|
475 |
{"level2", 0, 0, '2'}, |
|
476 |
{"level3", 0, 0, '3'}, |
|
477 |
{"eps", 0, 0, 'e'}, |
|
478 |
{"postscript", 0, 0, 'p'}, |
|
479 |
{"svg", 0, 0, 's'}, |
|
480 |
{"pgm", 0, 0, 'g'}, |
|
481 |
{"backend", 1, 0, 'b'}, |
|
482 |
{"debug", 1, 0, 'd'}, |
|
483 |
{"color", 1, 0, 'C'}, |
|
484 |
{"fillcolor", 1, 0, OPT_FILLCOLOR}, |
|
485 |
{"turnpolicy", 1, 0, 'z'}, |
|
486 |
{"gamma", 1, 0, 'G'}, |
|
487 |
{"longcurve", 0, 0, 'n'}, |
|
488 |
{"longcoding", 0, 0, 'q'}, |
|
489 |
{"alphamax", 1, 0, 'a'}, |
|
490 |
{"opttolerance", 1, 0, 'O'}, |
|
491 |
{"output", 1, 0, 'o'}, |
|
492 |
{"blacklevel", 1, 0, 'k'}, |
|
493 |
{"invert", 0, 0, 'i'}, |
|
494 |
{"opaque", 0, 0, OPT_OPAQUE}, |
|
495 |
{"group", 0, 0, OPT_GROUP}, |
|
496 |
|
|
497 |
{0, 0, 0, 0} |
|
498 |
}; |
|
499 |
|
|
500 |
static char *shortopts = "hvlVW:H:r:x:S:M:L:R:T:B:A:P:t:u:c23epsgb:d:C:z:G:nqa:O:o:k:i"; |
|
501 |
|
|
502 |
static void dopts(int ac, char *av[]) { |
|
503 |
int c; |
|
504 |
char *p; |
|
505 |
int i, j, r; |
|
506 |
dim_t dim, dimx, dimy; |
|
507 |
int matches, bestmatch; |
|
508 |
|
|
509 |
/* defaults */ |
|
510 |
info.backend = &backend[0]; |
|
511 |
|
|
512 |
info.debug = 0; |
|
513 |
info.width_d.x = UNDEF; |
|
514 |
info.height_d.x = UNDEF; |
|
515 |
info.rx = UNDEF; |
|
516 |
info.ry = UNDEF; |
|
517 |
info.sx = UNDEF; |
|
518 |
info.sy = UNDEF; |
|
519 |
info.stretch = 1; |
|
520 |
info.lmar_d.x = UNDEF; |
|
521 |
info.rmar_d.x = UNDEF; |
|
522 |
info.tmar_d.x = UNDEF; |
|
523 |
info.bmar_d.x = UNDEF; |
|
524 |
info.angle = 0; |
|
525 |
info.paperwidth = DEFAULT_PAPERWIDTH; |
|
526 |
info.paperheight = DEFAULT_PAPERHEIGHT; |
|
527 |
info.unit = 10; |
|
528 |
info.compress = 1; |
|
529 |
info.pslevel = 2; |
|
530 |
info.color = 0x000000; |
|
531 |
info.gamma = 2.2; |
|
532 |
info.param = potrace_param_default(); |
|
533 |
if (!info.param) { |
|
534 |
fprintf(stderr, ""POTRACE": %s\n", strerror(errno)); |
|
535 |
exit(1); |
|
536 |
} |
|
537 |
info.longcoding = 0; |
|
538 |
info.outfile = NULL; |
|
539 |
info.blacklevel = 0.5; |
|
540 |
info.invert = 0; |
|
541 |
info.opaque = 0; |
|
542 |
info.group = 0; |
|
543 |
info.fillcolor = 0xffffff; |
|
544 |
info.progress = 0; |
|
545 |
|
|
546 |
while ((c = getopt_long(ac, av, shortopts, longopts, NULL)) != -1) { |
|
547 |
switch (c) { |
|
548 |
case OPT_PROGRESS: |
|
549 |
info.progress = 1; |
|
550 |
break; |
|
551 |
case 'W': |
|
552 |
info.width_d = parse_dimension(optarg, &p); |
|
553 |
if (*p) { |
|
554 |
fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg); |
|
555 |
exit(1); |
|
556 |
} |
|
557 |
break; |
|
558 |
case 'H': |
|
559 |
info.height_d = parse_dimension(optarg, &p); |
Also available in: Unified diff