entangledstate-isbn 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +0 -18
- data/VERSION +1 -0
- data/isbn.gemspec +290 -7
- data/lib/isbn.rb +6 -6
- data/src/gocr-0.48/.cvsignore +6 -0
- data/src/gocr-0.48/AUTHORS +7 -0
- data/src/gocr-0.48/BUGS +55 -0
- data/src/gocr-0.48/CREDITS +17 -0
- data/src/gocr-0.48/HISTORY +243 -0
- data/src/gocr-0.48/INSTALL +83 -0
- data/src/gocr-0.48/Makefile +193 -0
- data/src/gocr-0.48/Makefile.in +193 -0
- data/src/gocr-0.48/README +165 -0
- data/src/gocr-0.48/READMEde.txt +80 -0
- data/src/gocr-0.48/REMARK.txt +18 -0
- data/src/gocr-0.48/REVIEW +538 -0
- data/src/gocr-0.48/TODO +65 -0
- data/src/gocr-0.48/bin/.cvsignore +2 -0
- data/src/gocr-0.48/bin/create_db +38 -0
- data/src/gocr-0.48/bin/gocr.tcl +527 -0
- data/src/gocr-0.48/bin/gocr_chk.sh +44 -0
- data/src/gocr-0.48/configure +4689 -0
- data/src/gocr-0.48/configure.in +71 -0
- data/src/gocr-0.48/doc/.#Makefile.1.6 +39 -0
- data/src/gocr-0.48/doc/.cvsignore +2 -0
- data/src/gocr-0.48/doc/Makefile +39 -0
- data/src/gocr-0.48/doc/Makefile.in +39 -0
- data/src/gocr-0.48/doc/example.dtd +53 -0
- data/src/gocr-0.48/doc/example.xml +21 -0
- data/src/gocr-0.48/doc/examples.txt +67 -0
- data/src/gocr-0.48/doc/gocr.html +578 -0
- data/src/gocr-0.48/doc/unicode.txt +57 -0
- data/src/gocr-0.48/examples/.#Makefile.1.22 +166 -0
- data/src/gocr-0.48/examples/4x6.png +0 -0
- data/src/gocr-0.48/examples/4x6.txt +2 -0
- data/src/gocr-0.48/examples/5x7.png +0 -0
- data/src/gocr-0.48/examples/5x7.png.txt +2 -0
- data/src/gocr-0.48/examples/5x8.png +0 -0
- data/src/gocr-0.48/examples/5x8.png.txt +2 -0
- data/src/gocr-0.48/examples/Makefile +166 -0
- data/src/gocr-0.48/examples/color.fig +20 -0
- data/src/gocr-0.48/examples/ex.fig +16 -0
- data/src/gocr-0.48/examples/font.tex +22 -0
- data/src/gocr-0.48/examples/font1.tex +46 -0
- data/src/gocr-0.48/examples/font2.fig +27 -0
- data/src/gocr-0.48/examples/font_nw.tex +24 -0
- data/src/gocr-0.48/examples/handwrt1.jpg +0 -0
- data/src/gocr-0.48/examples/handwrt1.txt +10 -0
- data/src/gocr-0.48/examples/inverse.fig +20 -0
- data/src/gocr-0.48/examples/matrix.jpg +0 -0
- data/src/gocr-0.48/examples/ocr-a-subset.png +0 -0
- data/src/gocr-0.48/examples/ocr-a-subset.png.txt +4 -0
- data/src/gocr-0.48/examples/ocr-a.png +0 -0
- data/src/gocr-0.48/examples/ocr-a.txt +6 -0
- data/src/gocr-0.48/examples/ocr-b.png +0 -0
- data/src/gocr-0.48/examples/ocr-b.png.txt +4 -0
- data/src/gocr-0.48/examples/polish.tex +28 -0
- data/src/gocr-0.48/examples/rotate45.fig +14 -0
- data/src/gocr-0.48/examples/score +36 -0
- data/src/gocr-0.48/examples/text.tex +28 -0
- data/src/gocr-0.48/gocr.spec +143 -0
- data/src/gocr-0.48/gpl.html +537 -0
- data/src/gocr-0.48/include/.cvsignore +2 -0
- data/src/gocr-0.48/include/config.h +36 -0
- data/src/gocr-0.48/include/config.h.in +36 -0
- data/src/gocr-0.48/include/version.h +2 -0
- data/src/gocr-0.48/install-sh +3 -0
- data/src/gocr-0.48/make.bat +57 -0
- data/src/gocr-0.48/man/.cvsignore +2 -0
- data/src/gocr-0.48/man/Makefile +29 -0
- data/src/gocr-0.48/man/Makefile.in +29 -0
- data/src/gocr-0.48/man/man1/gocr.1 +166 -0
- data/src/gocr-0.48/src/.cvsignore +4 -0
- data/src/gocr-0.48/src/Makefile +132 -0
- data/src/gocr-0.48/src/Makefile.in +132 -0
- data/src/gocr-0.48/src/amiga.h +31 -0
- data/src/gocr-0.48/src/barcode.c +846 -0
- data/src/gocr-0.48/src/barcode.c.orig +593 -0
- data/src/gocr-0.48/src/barcode.h +11 -0
- data/src/gocr-0.48/src/box.c +372 -0
- data/src/gocr-0.48/src/database.c +462 -0
- data/src/gocr-0.48/src/detect.c +943 -0
- data/src/gocr-0.48/src/gocr.c +373 -0
- data/src/gocr-0.48/src/gocr.h +288 -0
- data/src/gocr-0.48/src/jconv.c +168 -0
- data/src/gocr-0.48/src/job.c +84 -0
- data/src/gocr-0.48/src/lines.c +350 -0
- data/src/gocr-0.48/src/list.c +334 -0
- data/src/gocr-0.48/src/list.h +90 -0
- data/src/gocr-0.48/src/ocr0.c +6756 -0
- data/src/gocr-0.48/src/ocr0.h +63 -0
- data/src/gocr-0.48/src/ocr0n.c +1475 -0
- data/src/gocr-0.48/src/ocr1.c +85 -0
- data/src/gocr-0.48/src/ocr1.h +3 -0
- data/src/gocr-0.48/src/otsu.c +289 -0
- data/src/gocr-0.48/src/otsu.h +23 -0
- data/src/gocr-0.48/src/output.c +289 -0
- data/src/gocr-0.48/src/output.h +37 -0
- data/src/gocr-0.48/src/pcx.c +153 -0
- data/src/gocr-0.48/src/pcx.h +9 -0
- data/src/gocr-0.48/src/pgm2asc.c +2893 -0
- data/src/gocr-0.48/src/pgm2asc.h +105 -0
- data/src/gocr-0.48/src/pixel.c +537 -0
- data/src/gocr-0.48/src/pnm.c +533 -0
- data/src/gocr-0.48/src/pnm.h +35 -0
- data/src/gocr-0.48/src/progress.c +87 -0
- data/src/gocr-0.48/src/progress.h +42 -0
- data/src/gocr-0.48/src/remove.c +703 -0
- data/src/gocr-0.48/src/tga.c +87 -0
- data/src/gocr-0.48/src/tga.h +6 -0
- data/src/gocr-0.48/src/unicode.c +1314 -0
- data/src/gocr-0.48/src/unicode.h +1257 -0
- data/src/jpeg-7/Makefile.am +133 -0
- data/src/jpeg-7/Makefile.in +1089 -0
- data/src/jpeg-7/README +322 -0
- data/src/jpeg-7/aclocal.m4 +8990 -0
- data/src/jpeg-7/ansi2knr.1 +36 -0
- data/src/jpeg-7/ansi2knr.c +739 -0
- data/src/jpeg-7/cderror.h +132 -0
- data/src/jpeg-7/cdjpeg.c +181 -0
- data/src/jpeg-7/cdjpeg.h +187 -0
- data/src/jpeg-7/change.log +270 -0
- data/src/jpeg-7/cjpeg.1 +325 -0
- data/src/jpeg-7/cjpeg.c +616 -0
- data/src/jpeg-7/ckconfig.c +402 -0
- data/src/jpeg-7/coderules.txt +118 -0
- data/src/jpeg-7/config.guess +1561 -0
- data/src/jpeg-7/config.sub +1686 -0
- data/src/jpeg-7/configure +17139 -0
- data/src/jpeg-7/configure.ac +317 -0
- data/src/jpeg-7/depcomp +630 -0
- data/src/jpeg-7/djpeg.1 +251 -0
- data/src/jpeg-7/djpeg.c +617 -0
- data/src/jpeg-7/example.c +433 -0
- data/src/jpeg-7/filelist.txt +215 -0
- data/src/jpeg-7/install-sh +520 -0
- data/src/jpeg-7/install.txt +1097 -0
- data/src/jpeg-7/jaricom.c +148 -0
- data/src/jpeg-7/jcapimin.c +282 -0
- data/src/jpeg-7/jcapistd.c +161 -0
- data/src/jpeg-7/jcarith.c +921 -0
- data/src/jpeg-7/jccoefct.c +453 -0
- data/src/jpeg-7/jccolor.c +459 -0
- data/src/jpeg-7/jcdctmgr.c +482 -0
- data/src/jpeg-7/jchuff.c +1612 -0
- data/src/jpeg-7/jcinit.c +65 -0
- data/src/jpeg-7/jcmainct.c +293 -0
- data/src/jpeg-7/jcmarker.c +667 -0
- data/src/jpeg-7/jcmaster.c +770 -0
- data/src/jpeg-7/jcomapi.c +106 -0
- data/src/jpeg-7/jconfig.bcc +48 -0
- data/src/jpeg-7/jconfig.cfg +45 -0
- data/src/jpeg-7/jconfig.dj +38 -0
- data/src/jpeg-7/jconfig.mac +43 -0
- data/src/jpeg-7/jconfig.manx +43 -0
- data/src/jpeg-7/jconfig.mc6 +52 -0
- data/src/jpeg-7/jconfig.sas +43 -0
- data/src/jpeg-7/jconfig.st +42 -0
- data/src/jpeg-7/jconfig.txt +155 -0
- data/src/jpeg-7/jconfig.vc +45 -0
- data/src/jpeg-7/jconfig.vms +37 -0
- data/src/jpeg-7/jconfig.wat +38 -0
- data/src/jpeg-7/jcparam.c +632 -0
- data/src/jpeg-7/jcprepct.c +358 -0
- data/src/jpeg-7/jcsample.c +545 -0
- data/src/jpeg-7/jctrans.c +381 -0
- data/src/jpeg-7/jdapimin.c +396 -0
- data/src/jpeg-7/jdapistd.c +275 -0
- data/src/jpeg-7/jdarith.c +762 -0
- data/src/jpeg-7/jdatadst.c +151 -0
- data/src/jpeg-7/jdatasrc.c +212 -0
- data/src/jpeg-7/jdcoefct.c +736 -0
- data/src/jpeg-7/jdcolor.c +396 -0
- data/src/jpeg-7/jdct.h +393 -0
- data/src/jpeg-7/jddctmgr.c +382 -0
- data/src/jpeg-7/jdhuff.c +1309 -0
- data/src/jpeg-7/jdinput.c +384 -0
- data/src/jpeg-7/jdmainct.c +512 -0
- data/src/jpeg-7/jdmarker.c +1360 -0
- data/src/jpeg-7/jdmaster.c +663 -0
- data/src/jpeg-7/jdmerge.c +400 -0
- data/src/jpeg-7/jdpostct.c +290 -0
- data/src/jpeg-7/jdsample.c +361 -0
- data/src/jpeg-7/jdtrans.c +136 -0
- data/src/jpeg-7/jerror.c +252 -0
- data/src/jpeg-7/jerror.h +304 -0
- data/src/jpeg-7/jfdctflt.c +174 -0
- data/src/jpeg-7/jfdctfst.c +230 -0
- data/src/jpeg-7/jfdctint.c +4348 -0
- data/src/jpeg-7/jidctflt.c +242 -0
- data/src/jpeg-7/jidctfst.c +368 -0
- data/src/jpeg-7/jidctint.c +5137 -0
- data/src/jpeg-7/jinclude.h +91 -0
- data/src/jpeg-7/jmemansi.c +167 -0
- data/src/jpeg-7/jmemdos.c +638 -0
- data/src/jpeg-7/jmemdosa.asm +379 -0
- data/src/jpeg-7/jmemmac.c +289 -0
- data/src/jpeg-7/jmemmgr.c +1118 -0
- data/src/jpeg-7/jmemname.c +276 -0
- data/src/jpeg-7/jmemnobs.c +109 -0
- data/src/jpeg-7/jmemsys.h +198 -0
- data/src/jpeg-7/jmorecfg.h +369 -0
- data/src/jpeg-7/jpegint.h +395 -0
- data/src/jpeg-7/jpeglib.h +1135 -0
- data/src/jpeg-7/jpegtran.1 +272 -0
- data/src/jpeg-7/jpegtran.c +546 -0
- data/src/jpeg-7/jquant1.c +856 -0
- data/src/jpeg-7/jquant2.c +1310 -0
- data/src/jpeg-7/jutils.c +179 -0
- data/src/jpeg-7/jversion.h +14 -0
- data/src/jpeg-7/libjpeg.map +4 -0
- data/src/jpeg-7/libjpeg.txt +3067 -0
- data/src/jpeg-7/ltmain.sh +8406 -0
- data/src/jpeg-7/makcjpeg.st +36 -0
- data/src/jpeg-7/makdjpeg.st +36 -0
- data/src/jpeg-7/makeadsw.vc6 +77 -0
- data/src/jpeg-7/makeasln.vc9 +33 -0
- data/src/jpeg-7/makecdep.vc6 +82 -0
- data/src/jpeg-7/makecdsp.vc6 +130 -0
- data/src/jpeg-7/makecmak.vc6 +159 -0
- data/src/jpeg-7/makecvcp.vc9 +186 -0
- data/src/jpeg-7/makeddep.vc6 +82 -0
- data/src/jpeg-7/makeddsp.vc6 +130 -0
- data/src/jpeg-7/makedmak.vc6 +159 -0
- data/src/jpeg-7/makedvcp.vc9 +186 -0
- data/src/jpeg-7/makefile.ansi +220 -0
- data/src/jpeg-7/makefile.bcc +291 -0
- data/src/jpeg-7/makefile.dj +226 -0
- data/src/jpeg-7/makefile.manx +220 -0
- data/src/jpeg-7/makefile.mc6 +255 -0
- data/src/jpeg-7/makefile.mms +224 -0
- data/src/jpeg-7/makefile.sas +258 -0
- data/src/jpeg-7/makefile.unix +234 -0
- data/src/jpeg-7/makefile.vc +217 -0
- data/src/jpeg-7/makefile.vms +142 -0
- data/src/jpeg-7/makefile.wat +239 -0
- data/src/jpeg-7/makejdep.vc6 +423 -0
- data/src/jpeg-7/makejdsp.vc6 +285 -0
- data/src/jpeg-7/makejdsw.vc6 +29 -0
- data/src/jpeg-7/makejmak.vc6 +425 -0
- data/src/jpeg-7/makejsln.vc9 +17 -0
- data/src/jpeg-7/makejvcp.vc9 +328 -0
- data/src/jpeg-7/makeproj.mac +213 -0
- data/src/jpeg-7/makerdep.vc6 +6 -0
- data/src/jpeg-7/makerdsp.vc6 +78 -0
- data/src/jpeg-7/makermak.vc6 +110 -0
- data/src/jpeg-7/makervcp.vc9 +133 -0
- data/src/jpeg-7/maketdep.vc6 +43 -0
- data/src/jpeg-7/maketdsp.vc6 +122 -0
- data/src/jpeg-7/maketmak.vc6 +131 -0
- data/src/jpeg-7/maketvcp.vc9 +178 -0
- data/src/jpeg-7/makewdep.vc6 +6 -0
- data/src/jpeg-7/makewdsp.vc6 +78 -0
- data/src/jpeg-7/makewmak.vc6 +110 -0
- data/src/jpeg-7/makewvcp.vc9 +133 -0
- data/src/jpeg-7/makljpeg.st +68 -0
- data/src/jpeg-7/maktjpeg.st +30 -0
- data/src/jpeg-7/makvms.opt +4 -0
- data/src/jpeg-7/missing +376 -0
- data/src/jpeg-7/rdbmp.c +439 -0
- data/src/jpeg-7/rdcolmap.c +253 -0
- data/src/jpeg-7/rdgif.c +38 -0
- data/src/jpeg-7/rdjpgcom.1 +63 -0
- data/src/jpeg-7/rdjpgcom.c +515 -0
- data/src/jpeg-7/rdppm.c +459 -0
- data/src/jpeg-7/rdrle.c +387 -0
- data/src/jpeg-7/rdswitch.c +365 -0
- data/src/jpeg-7/rdtarga.c +500 -0
- data/src/jpeg-7/structure.txt +945 -0
- data/src/jpeg-7/testimg.bmp +0 -0
- data/src/jpeg-7/testimg.jpg +0 -0
- data/src/jpeg-7/testimg.ppm +4 -0
- data/src/jpeg-7/testimgp.jpg +0 -0
- data/src/jpeg-7/testorig.jpg +0 -0
- data/src/jpeg-7/testprog.jpg +0 -0
- data/src/jpeg-7/transupp.c +1533 -0
- data/src/jpeg-7/transupp.h +205 -0
- data/src/jpeg-7/usage.txt +605 -0
- data/src/jpeg-7/wizard.txt +211 -0
- data/src/jpeg-7/wrbmp.c +442 -0
- data/src/jpeg-7/wrgif.c +399 -0
- data/src/jpeg-7/wrjpgcom.1 +103 -0
- data/src/jpeg-7/wrjpgcom.c +583 -0
- data/src/jpeg-7/wrppm.c +269 -0
- data/src/jpeg-7/wrrle.c +305 -0
- data/src/jpeg-7/wrtarga.c +253 -0
- metadata +287 -6
- data/LICENSE +0 -20
- data/VERSION.yml +0 -4
@@ -0,0 +1,533 @@
|
|
1
|
+
/*
|
2
|
+
This is a Optical-Character-Recognition program
|
3
|
+
Copyright (C) 2000-2009 Joerg Schulenburg
|
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
|
+
see README for EMAIL-address
|
20
|
+
|
21
|
+
v0.1.0 initial version (stdin added)
|
22
|
+
v0.2.0 popen added
|
23
|
+
v0.2.7 review by Bruno Barberi Gnecco
|
24
|
+
v0.39 autoconf
|
25
|
+
v0.41 fix integer and heap overflow, change color output
|
26
|
+
v0.46 fix blank spaces problem in filenames
|
27
|
+
*/
|
28
|
+
|
29
|
+
#include <stdlib.h>
|
30
|
+
#include <stdio.h>
|
31
|
+
#include <string.h>
|
32
|
+
#include <assert.h>
|
33
|
+
#ifdef HAVE_UNISTD_H
|
34
|
+
/* #include <unistd.h> */
|
35
|
+
#endif
|
36
|
+
|
37
|
+
/* Windows needs extra code to work fine, ^Z in BMP's will stop input else.
|
38
|
+
* I do not have any idea when this text mode will be an advantage
|
39
|
+
* but the MS community seems to like to do simple things in a complex way. */
|
40
|
+
#if defined(O_BINARY) && (defined(__WIN32) || defined(__WIN32__)\
|
41
|
+
|| defined(__WIN64) || defined(__WIN64__) || defined(__MSDOS__))
|
42
|
+
# include <fcntl.h>
|
43
|
+
# define SET_BINARY(_f) do {if (!isatty(_f)) setmode (_f, O_BINARY);} while (0)
|
44
|
+
#else
|
45
|
+
# define SET_BINARY(f) (void)0
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#include "pnm.h"
|
49
|
+
#ifdef HAVE_PAM_H
|
50
|
+
# include <pam.h>
|
51
|
+
# include <sys/types.h>
|
52
|
+
# include <sys/stat.h>
|
53
|
+
# include <fcntl.h>
|
54
|
+
#else
|
55
|
+
# include <ctype.h>
|
56
|
+
#endif
|
57
|
+
|
58
|
+
#define EE() fprintf(stderr,"\nERROR "__FILE__" L%d: ",__LINE__)
|
59
|
+
#define E0(x0) {EE();fprintf(stderr,x0 "\n"); }
|
60
|
+
#define F0(x0) {EE();fprintf(stderr,x0 "\n"); exit(1);}
|
61
|
+
#define F1(x0,x1) {EE();fprintf(stderr,x0 "\n",x1); exit(1);}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* Weights to use for the different colours when converting a ppm
|
65
|
+
* to greyscale. These weights should sum to 1.0
|
66
|
+
*
|
67
|
+
* The below values have been chosen to reflect the fact that paper
|
68
|
+
* goes a reddish-yellow as it ages.
|
69
|
+
*
|
70
|
+
* v0.41: for better performance, we use integer instead of double
|
71
|
+
* this integer value divided by 1024 (2^10) gives the factor
|
72
|
+
*/
|
73
|
+
#define PPM_RED_WEIGHT 511 /* .499 */
|
74
|
+
#define PPM_GREEN_WEIGHT 396 /* .387 */
|
75
|
+
#define PPM_BLUE_WEIGHT 117 /* .114 */
|
76
|
+
|
77
|
+
/*
|
78
|
+
feel free to expand this list of usable converting programs
|
79
|
+
Note 1: the last field must be NULL.
|
80
|
+
Note 2: "smaller" extensions must come later: ".pnm.gz" must come
|
81
|
+
before ".pnm".
|
82
|
+
calling external programs is a security risk
|
83
|
+
ToDo: for better security replace gzip by /usr/bin/gzip !
|
84
|
+
*/
|
85
|
+
char *xlist[]={
|
86
|
+
".pnm.gz", "gzip -cd", /* compressed pnm-files, gzip package */
|
87
|
+
".pbm.gz", "gzip -cd",
|
88
|
+
".pgm.gz", "gzip -cd",
|
89
|
+
".ppm.gz", "gzip -cd",
|
90
|
+
".pnm.bz2", "bzip2 -cd",
|
91
|
+
".pbm.bz2", "bzip2 -cd",
|
92
|
+
".pgm.bz2", "bzip2 -cd",
|
93
|
+
".ppm.bz2", "bzip2 -cd",
|
94
|
+
".jpg", "djpeg -gray -pnm", /* JPG/JPEG, jpeg package */
|
95
|
+
".jpeg", "djpeg -gray -pnm",
|
96
|
+
".gif", "giftopnm -image=all", /* GIF, netpbm package */
|
97
|
+
".bmp", "bmptoppm",
|
98
|
+
".tiff", "tifftopnm",
|
99
|
+
".png", "pngtopnm", /* Portable Network Graphics (PNG) format */
|
100
|
+
".ps", "pstopnm -stdout -portrait -pgm", /* postscript */
|
101
|
+
".eps", "pstopnm -stdout -portrait -pgm", /* encapsulated postscript */
|
102
|
+
/* gs -sDEVICE=pgmraw -sOutputFile=- -g609x235 -r141x141 -q -dNOPAUSE */
|
103
|
+
".fig", "fig2dev -L ppm -m 3", /* xfig files, transfig package */
|
104
|
+
NULL
|
105
|
+
};
|
106
|
+
|
107
|
+
/* return a pointer to command converting file to pnm or NULL */
|
108
|
+
char *testsuffix(char *name){
|
109
|
+
int i; char *rr;
|
110
|
+
|
111
|
+
for(i = 0; xlist[i] != NULL; i += 2 ) {
|
112
|
+
if((rr=strstr(name, xlist[i])) != NULL)
|
113
|
+
if(strlen(rr)==strlen(xlist[i])) /* handle *.eps.pbm correct */
|
114
|
+
return xlist[i+1];
|
115
|
+
}
|
116
|
+
return NULL;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
char read_char(FILE *f1){ // filter #-comments
|
121
|
+
char c;
|
122
|
+
int m;
|
123
|
+
for(m=0;;){
|
124
|
+
c=fgetc(f1);
|
125
|
+
if( feof(f1) ) E0("read feof");
|
126
|
+
if( ferror(f1) ) F0("read ferror");
|
127
|
+
if( c == '#' ) { m = 1; continue; }
|
128
|
+
if( m == 0 ) return c;
|
129
|
+
if( c == '\n' ) m = 0;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
/*
|
135
|
+
for simplicity only PAM of netpbm is used, the older formats
|
136
|
+
PBM, PGM and PPM can be handled implicitly by PAM routines (js05)
|
137
|
+
v0.43: return 1 if multiple file (hold it open), 0 otherwise
|
138
|
+
*/
|
139
|
+
#ifdef HAVE_PAM_H
|
140
|
+
int readpgm(char *name, pix * p, int vvv) {
|
141
|
+
static FILE *fp=NULL;
|
142
|
+
static char *pip;
|
143
|
+
char magic1, magic2;
|
144
|
+
int i, j, sample, minv = 0, maxv = 0, eofP=0;
|
145
|
+
struct pam inpam;
|
146
|
+
tuple *tuplerow;
|
147
|
+
|
148
|
+
assert(p);
|
149
|
+
|
150
|
+
if (!fp) { // fp!=0 for multi-pnm and idx>0
|
151
|
+
/* open file; test if conversion is needed. */
|
152
|
+
if (name[0] == '-' && name[1] == '\0') {
|
153
|
+
fp = stdin;
|
154
|
+
SET_BINARY (fileno(fp)); // Windows needs it for correct work
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
pip = testsuffix(name);
|
158
|
+
if (!pip) {
|
159
|
+
fp = fopen(name, "rb");
|
160
|
+
if (!fp)
|
161
|
+
F1("opening file %s", name);
|
162
|
+
}
|
163
|
+
else {
|
164
|
+
char *buf = (char *)malloc((strlen(pip)+strlen(name)+4));
|
165
|
+
sprintf(buf, "%s \"%s\"", pip, name); /* allow spaces in filename */
|
166
|
+
if (vvv) {
|
167
|
+
fprintf(stderr, "# popen( %s )\n", buf);
|
168
|
+
}
|
169
|
+
#ifdef HAVE_POPEN
|
170
|
+
/* potential security vulnerability, if name contains tricks */
|
171
|
+
/* example: gunzip -c dummy | rm -rf * */
|
172
|
+
/* windows needs "rb" for correct work, linux not, cygwin? */
|
173
|
+
/* ToDo: do you have better code to go arround this? */
|
174
|
+
#if defined(__WIN32) || defined(__WIN32__) || defined(__WIN64) || defined(__WIN64__)
|
175
|
+
fp = popen(buf, "rb"); /* ToDo: may fail, please report */
|
176
|
+
if (!fp) fp = popen(buf, "r"); /* 2nd try, the gnu way */
|
177
|
+
#else
|
178
|
+
fp = popen(buf, "r");
|
179
|
+
#endif
|
180
|
+
#else
|
181
|
+
F0("sorry, compile with HAVE_POPEN to use pipes");
|
182
|
+
#endif
|
183
|
+
if (!fp)
|
184
|
+
F1("opening pipe %s", buf);
|
185
|
+
free(buf);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
/* netpbm 0.10.36 tries to write a comment to nonzero char** comment_p */
|
191
|
+
/* patch by C.P.Schmidt 21Nov06 */
|
192
|
+
memset (&inpam, 0, sizeof(inpam));
|
193
|
+
|
194
|
+
/* read pgm-header */
|
195
|
+
/* struct pam may change between netpbm-versions, causing problems? */
|
196
|
+
#ifdef PAM_STRUCT_SIZE /* ok for netpbm-10.35 */
|
197
|
+
/* new-and-better? but PAM_STRUCT_SIZE is not defined in netpbm-10.18 */
|
198
|
+
pnm_readpaminit(fp, &inpam, PAM_STRUCT_SIZE(tuple_type));
|
199
|
+
#else /* ok for netpbm-10.18 old-and-bad for new netpbms */
|
200
|
+
pnm_readpaminit(fp, &inpam, sizeof(inpam));
|
201
|
+
#endif
|
202
|
+
|
203
|
+
p->x = inpam.width;
|
204
|
+
p->y = inpam.height;
|
205
|
+
magic1=(inpam.format >> 8) & 255; /* 'P' for PNM,PAM */
|
206
|
+
magic2=(inpam.format ) & 255; /* '7' for PAM */
|
207
|
+
minv=inpam.maxval;
|
208
|
+
if (vvv) {
|
209
|
+
fprintf(stderr, "# readpam: format=0x%04x=%c%c h*w(d*b)=%d*%d(%d*%d)\n",
|
210
|
+
inpam.format, /* magic1*256+magic2 */
|
211
|
+
((magic1>31 && magic1<127)?magic1:'.'),
|
212
|
+
((magic2>31 && magic2<127)?magic2:'.'),
|
213
|
+
inpam.height,
|
214
|
+
inpam.width,
|
215
|
+
inpam.depth,
|
216
|
+
inpam.bytes_per_sample);
|
217
|
+
}
|
218
|
+
if ( (1.*(p->x*p->y))!=((1.*p->x)*p->y) )
|
219
|
+
F0("Error integer overflow");
|
220
|
+
if ( !(p->p = (unsigned char *)malloc(p->x*p->y)) )
|
221
|
+
F1("Error at malloc: p->p: %d bytes", p->x*p->y);
|
222
|
+
tuplerow = pnm_allocpamrow(&inpam);
|
223
|
+
for ( i=0; i < inpam.height; i++ ) {
|
224
|
+
pnm_readpamrow(&inpam, tuplerow); /* exit on error */
|
225
|
+
for ( j = 0; j < inpam.width; j++ ) {
|
226
|
+
if (inpam.depth>=3)
|
227
|
+
/* tuplerow is unsigned long (see pam.h sample) */
|
228
|
+
/* we expect 8bit or 16bit integers,
|
229
|
+
no overflow up to 32-10-2=20 bits */
|
230
|
+
sample
|
231
|
+
= ((PPM_RED_WEIGHT * tuplerow[j][0] + 511)>>10)
|
232
|
+
+ ((PPM_GREEN_WEIGHT * tuplerow[j][1] + 511)>>10)
|
233
|
+
+ ((PPM_BLUE_WEIGHT * tuplerow[j][2] + 511)>>10);
|
234
|
+
else
|
235
|
+
sample = tuplerow[j][0];
|
236
|
+
sample = 255 * sample / inpam.maxval; /* normalize to 8 bit */
|
237
|
+
p->p[i*inpam.width+j] = sample;
|
238
|
+
if (maxv<sample) maxv=sample;
|
239
|
+
if (minv>sample) minv=sample;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
pnm_freepamrow(tuplerow);
|
243
|
+
pnm_nextimage(fp,&eofP);
|
244
|
+
if (vvv)
|
245
|
+
fprintf(stderr,"# readpam: min=%d max=%d eof=%d\n", minv, maxv, eofP);
|
246
|
+
p->bpp = 1;
|
247
|
+
if (eofP) {
|
248
|
+
if (!pip) fclose(fp);
|
249
|
+
#ifdef HAVE_POPEN
|
250
|
+
else pclose(fp); /* close pipe (v0.43) */
|
251
|
+
#endif
|
252
|
+
fp=NULL; return 0;
|
253
|
+
}
|
254
|
+
return 1; /* multiple image = concatenated pnm */
|
255
|
+
}
|
256
|
+
|
257
|
+
#else
|
258
|
+
/*
|
259
|
+
if PAM not installed, here is the fallback routine,
|
260
|
+
which is not so powerful but needs no dependencies from other libs
|
261
|
+
*/
|
262
|
+
static int fread_num(char *buf, int bps, FILE *f1) {
|
263
|
+
int mode, j2, j3; char c1;
|
264
|
+
for (j2=0;j2<bps;j2++) buf[j2]=0; // initialize value to zero
|
265
|
+
for(mode=0;!feof(f1);){ // mod=0 means skip leading spaces, 1 scan digits
|
266
|
+
c1=read_char(f1);
|
267
|
+
if (isspace(c1)) { if (mode==0) continue; else break; }
|
268
|
+
mode=1; // digits scan mode
|
269
|
+
if( !isdigit(c1) ) F0("unexpected char");
|
270
|
+
for (j3=j2=0;j2<bps;j2++) { // multiply bps*bytes by 10
|
271
|
+
j3 = buf[j2]*10 + j3; // j3 is used as result and carry
|
272
|
+
buf[j2]=j3 & 255; j3>>=8;
|
273
|
+
}
|
274
|
+
buf[0] += c1-'0';
|
275
|
+
}
|
276
|
+
return 0;
|
277
|
+
}
|
278
|
+
|
279
|
+
/*
|
280
|
+
* read image file, used to read the OCR-image and database images,
|
281
|
+
* image file can be PBM/PGM/PPM in RAW or TEXT
|
282
|
+
* name: filename of image (input)
|
283
|
+
* p: pointer where to store the loaded image (input)
|
284
|
+
* vvv: verbose mode (input)
|
285
|
+
* return: 0=ok, 1=further image follows (multiple image), -1 on error
|
286
|
+
* this is the fall back routine if libpnm cant be used
|
287
|
+
*/
|
288
|
+
int readpgm( char *name, pix *p, int vvv){
|
289
|
+
static char c1, c2; /* magic bytes, file type */
|
290
|
+
static char *pip; // static to survive multiple calls
|
291
|
+
int nx,ny,nc,mod,i,j; // buffer
|
292
|
+
static FILE *f1=NULL; // trigger read new file or multi image file
|
293
|
+
unsigned char *pic;
|
294
|
+
char buf[512];
|
295
|
+
int lx, ly, dx;
|
296
|
+
int bps=1; /* bytes per sample (0..255..65535...) */
|
297
|
+
|
298
|
+
if (!f1) { /* first of multiple image, on MultipleImageFiles c1 was read */
|
299
|
+
pip=NULL;
|
300
|
+
if (name[0]=='-' && name[1]==0) {
|
301
|
+
f1=stdin; /* is this correct ??? */
|
302
|
+
SET_BINARY (fileno(f1)); // Windows needs it for correct work
|
303
|
+
} else {
|
304
|
+
pip=testsuffix(name);
|
305
|
+
if (!pip) {
|
306
|
+
f1=fopen(name,"rb"); if (!f1) F1("opening file %s",name);
|
307
|
+
} else {
|
308
|
+
sprintf(buf,"%s \"%s\"",pip,name); /* ToDo: how to prevent OVL ? */
|
309
|
+
if (vvv) { fprintf(stderr,"# popen( %s )\n",buf); }
|
310
|
+
#ifdef HAVE_POPEN
|
311
|
+
#if defined(__WIN32) || defined(__WIN32__) || defined(__WIN64) || defined(__WIN64__)
|
312
|
+
f1 = popen(buf, "rb"); /* ToDo: may fail, please report */
|
313
|
+
if (!f1) f1 = popen(buf, "r"); /* 2nd try, the gnu way */
|
314
|
+
#else
|
315
|
+
f1=popen(buf,"r");
|
316
|
+
#endif
|
317
|
+
#else
|
318
|
+
F0("only PNM files supported (compiled without HAVE_POPEN)");
|
319
|
+
#endif
|
320
|
+
if (!f1) F1("opening pipe %s",buf);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
c1=fgetc(f1); if (feof(f1)) { E0("unexpected EOF"); return -1; }
|
324
|
+
}
|
325
|
+
c2=fgetc(f1); if (feof(f1)) { E0("unexpected EOF"); return -1; }
|
326
|
+
// check the first two bytes of the PNM file
|
327
|
+
// PBM PGM PPM
|
328
|
+
// TXT P1 P2 P3
|
329
|
+
// RAW P4 P5 P6
|
330
|
+
if (c1!='P' || c2 <'1' || c2 >'6') {
|
331
|
+
fprintf(stderr,"\nread-PNM-error: file number is %2d,"
|
332
|
+
" position %ld", fileno(f1), ftell(f1));
|
333
|
+
fprintf(stderr,"\nread-PNM-error: bad magic bytes, expect 0x50 0x3[1-6]"
|
334
|
+
" but got 0x%02x 0x%02x", 255&c1, 255&c2);
|
335
|
+
if (f1) fclose(f1); f1=NULL; return(-1);
|
336
|
+
}
|
337
|
+
nx=ny=nc=0; if (c2=='4' || c2=='1') nc=1;
|
338
|
+
for(mod=0;((c2=='5' || c2=='2') && (mod&7)<6)
|
339
|
+
|| ((c2=='6' || c2=='3') && (mod&7)<6)
|
340
|
+
|| ((c2=='4' || c2=='1') && (mod&7)<4);)
|
341
|
+
{ // mode: 0,2,4=[ |\t|\r|\n]
|
342
|
+
// 1=nx 3=ny 5=nc 8-13=#rem
|
343
|
+
c1=read_char(f1); // former: # mod|=8
|
344
|
+
if( (mod & 1)==0 ) // whitespaces
|
345
|
+
if( !isspace(c1) ) mod++;
|
346
|
+
if( (mod & 1)==1 ) {
|
347
|
+
if( !isdigit(c1) ) {
|
348
|
+
if( !isspace(c1) )F0("unexpected character");
|
349
|
+
mod++; }
|
350
|
+
else if(mod==1) nx=nx*10+c1-'0';
|
351
|
+
else if(mod==3) ny=ny*10+c1-'0';
|
352
|
+
else if(mod==5) nc=nc*10+c1-'0';
|
353
|
+
}
|
354
|
+
}
|
355
|
+
if(vvv)
|
356
|
+
fprintf(stderr,"# PNM P%c h*w=%d*%d c=%d head=%ld",c2,ny,nx,nc,ftell(f1));
|
357
|
+
if( c2=='4' && (nx&7)!=0 ){
|
358
|
+
/* nx=(nx+7)&~7;*/ if(vvv)fprintf(stderr," PBM2PGM nx %d",(nx+7)&~7);
|
359
|
+
}
|
360
|
+
if (nc>> 8) bps=2; // bytes per color and pixel
|
361
|
+
if (nc>>16) bps=3;
|
362
|
+
if (nc>>24) bps=4;
|
363
|
+
fflush(stdout);
|
364
|
+
if ( (1.*(nx*ny))!=((1.*nx)*ny) )
|
365
|
+
F0("Error integer overflow");
|
366
|
+
pic=(unsigned char *)malloc( nx*ny );
|
367
|
+
if(pic==NULL)F0("memory failed"); // no memory
|
368
|
+
for (i=0;i<nx*ny;i++) pic[i]=255; // init to white if reading fails
|
369
|
+
/* this is a slow but short routine for P1 to P6 formats */
|
370
|
+
if( c2=='5' || c2=='2' ) /* slow PGM-RAW/ASC read pixelwise */
|
371
|
+
for (i=0;i<nx*ny;i++) {
|
372
|
+
if (c2=='5') { if(bps!=(int)fread(buf,1,bps,f1)) {
|
373
|
+
fprintf(stderr," ERROR reading at head+%d*%d\n", bps, i); break; } }
|
374
|
+
else for (j=0;j<3;j++) fread_num(buf+j*bps, bps, f1);
|
375
|
+
pic[i]=buf[bps-1]; /* store the most significant byte */
|
376
|
+
}
|
377
|
+
// we want to normalize brightness to 0..255
|
378
|
+
if (c2=='6' || c2=='3') { // PPM-RAW/ASC
|
379
|
+
for (i=0;i<nx*ny;i++) {
|
380
|
+
if (c2=='6') { if (3*bps!=(int)fread(buf,1,3*bps,f1)){
|
381
|
+
fprintf(stderr," ERROR reading at head+3*%d*%d\n", bps, i); break; } }
|
382
|
+
else for (j=0;j<3;j++) fread_num(buf+j*bps, bps, f1);
|
383
|
+
pic[i]
|
384
|
+
= ((PPM_RED_WEIGHT * (unsigned char)buf[ bps-1] + 511)>>10)
|
385
|
+
+ ((PPM_GREEN_WEIGHT * (unsigned char)buf[2*bps-1] + 511)>>10)
|
386
|
+
+ ((PPM_BLUE_WEIGHT * (unsigned char)buf[3*bps-1] + 511)>>10);
|
387
|
+
/* normalized to 0..255 */
|
388
|
+
}
|
389
|
+
}
|
390
|
+
if( c2=='1' )
|
391
|
+
for(mod=j=i=0,nc=255;i<nx*ny && !feof(f1);){ // PBM-ASCII 0001100
|
392
|
+
c1=read_char(f1);
|
393
|
+
if( isdigit(c1) ) { pic[i]=((c1=='0')?255:0); i++; }
|
394
|
+
else if( !isspace(c1) )F0("unexpected char");
|
395
|
+
}
|
396
|
+
if( c2=='4' ){ // PBM-RAW
|
397
|
+
dx=(nx+7)&~7; // dx (mod 8)
|
398
|
+
if(ny!=(int)fread(pic,dx>>3,ny,f1))F0("read"); // read all bytes
|
399
|
+
for(ly=ny-1;ly>=0;ly--)
|
400
|
+
for(lx=nx-1;lx>=0;lx--)
|
401
|
+
pic[lx+ly*nx]=( (128 & (pic[(lx+ly*dx)>>3]<<(lx & 7))) ? 0 : 255 );
|
402
|
+
nc=255;
|
403
|
+
}
|
404
|
+
{
|
405
|
+
int minc=255, maxc=0;
|
406
|
+
for (i=0;i<nx*ny;i++) {
|
407
|
+
if (pic[i]>maxc) maxc=pic[i];
|
408
|
+
if (pic[i]<minc) minc=pic[i];
|
409
|
+
}
|
410
|
+
if (vvv) fprintf(stderr," min=%d max=%d", minc, maxc);
|
411
|
+
}
|
412
|
+
p->p=pic; p->x=nx; p->y=ny; p->bpp=1;
|
413
|
+
if (vvv) fprintf(stderr,"\n");
|
414
|
+
c1=0; c1=fgetc(f1); /* needed to trigger feof() */
|
415
|
+
if (feof(f1) || c1!='P') { /* EOF ^Z or not 'P' -> single image */
|
416
|
+
if (vvv) fprintf(stderr,"# PNM EOF\n");
|
417
|
+
if(name[0]!='-' || name[1]!=0){ /* do not close stdin */
|
418
|
+
if(!pip) fclose(f1);
|
419
|
+
#ifdef HAVE_POPEN
|
420
|
+
else pclose(f1); /* close pipe (Jul00) */
|
421
|
+
#endif
|
422
|
+
}
|
423
|
+
f1=NULL; /* set file is closed flag */
|
424
|
+
return 0;
|
425
|
+
}
|
426
|
+
return 1; /* multiple image = concatenated pnm's */
|
427
|
+
}
|
428
|
+
#endif /* HAVE_PAM_H */
|
429
|
+
|
430
|
+
int writepgm(char *nam,pix *p){// P5 raw-pgm
|
431
|
+
FILE *f1;int a,x,y;
|
432
|
+
f1=fopen(nam,"wb");if(!f1)F0("open"); // open-error
|
433
|
+
fprintf(f1,"P5\n%d %d\n255\n",p->x,p->y);
|
434
|
+
if(p->bpp==3)
|
435
|
+
for(y=0;y<p->y;y++)
|
436
|
+
for(x=0;x<p->x;x++){ // set bit
|
437
|
+
a=x+y*p->x;
|
438
|
+
p->p[a]=(p->p[3*a+0]+p->p[3*a+1]+p->p[3*a+2])/3;
|
439
|
+
}
|
440
|
+
if(p->y!=(int)fwrite(p->p,p->x,p->y,f1))F0("write"); // write all lines
|
441
|
+
fclose(f1);
|
442
|
+
return 0;
|
443
|
+
}
|
444
|
+
|
445
|
+
/* adding colours, care about range */
|
446
|
+
void addrgb(unsigned char rgb[3], int sr, int sg, int sb) {
|
447
|
+
int add[3], i;
|
448
|
+
/* add colour on dark pixels, subtract on white pixels */
|
449
|
+
add[0]=2*sr; add[1]=2*sg; add[2]=2*sb;
|
450
|
+
if (((int)rgb[0])+((int)rgb[1])+((int)rgb[2])>=3*160)
|
451
|
+
{ add[0]=(-sg-sb); add[1]=(-sr-sb); add[2]=(-sr-sg); } // rgb/2?
|
452
|
+
/* care about colour range */
|
453
|
+
for (i=0;i<3;i++)
|
454
|
+
if (add[i]<0) rgb[i]-=(( rgb[i]<-add[i])? rgb[i]:-add[i]);
|
455
|
+
else rgb[i]+=((255-rgb[i]< add[i])?255-rgb[i]: add[i]);
|
456
|
+
}
|
457
|
+
/*
|
458
|
+
* pgmtoppm or pnmtopng, use last 3 bits for farbcoding
|
459
|
+
* replaces old writebmp variant
|
460
|
+
*/
|
461
|
+
int writeppm(char *nam, pix *p){ /* P6 raw-ppm */
|
462
|
+
FILE *f1=NULL; int x,y,f1t=0; unsigned char rgb[3], gray, bits;
|
463
|
+
char buf[128];
|
464
|
+
if (strchr(nam,'|')) return -1; /* no nasty code */
|
465
|
+
if (strstr(nam,".ppm")) { f1=fopen(nam,"wb"); }
|
466
|
+
#ifdef HAVE_POPEN
|
467
|
+
/* be sure that nam contains hacker code like "dummy | rm -rf *" */
|
468
|
+
if (!f1) {
|
469
|
+
strncpy(buf,"pnmtopng > ",12); /* no spaces within filenames allowed! */
|
470
|
+
strncpy(buf+11,nam,111); buf[123]=0;
|
471
|
+
strncpy(buf+strlen(buf),".png",5);
|
472
|
+
/* we dont care about win "wb" here, never debug on win systems */
|
473
|
+
f1 = popen(buf, "w"); if(f1) f1t=1; else E0("popen pnmtopng");
|
474
|
+
}
|
475
|
+
if (!f1) {
|
476
|
+
strncpy(buf,"gzip -c > ",11);
|
477
|
+
strncpy(buf+10,nam,109); buf[120]=0;
|
478
|
+
strncpy(buf+strlen(buf),".ppm.gz",8);
|
479
|
+
/* we dont care about win "wb" here, never debug on win systems */
|
480
|
+
f1 = popen(buf, "w"); if(f1) f1t=1; else E0("popen gzip -c");
|
481
|
+
}
|
482
|
+
#endif
|
483
|
+
if (!f1) {
|
484
|
+
strncpy(buf,nam,113); buf[114]=0;
|
485
|
+
strncpy(buf+strlen(buf),".ppm",5);
|
486
|
+
f1=fopen(buf,"wb");
|
487
|
+
}
|
488
|
+
if (!f1) F0("open"); /* open-error */
|
489
|
+
fprintf(f1,"P6\n%d %d\n255\n",p->x,p->y);
|
490
|
+
if ( p->bpp==1 )
|
491
|
+
for (y=0;y<p->y;y++)
|
492
|
+
for (x=0;x<p->x;x++){
|
493
|
+
gray=p->p[x+y*p->x];
|
494
|
+
bits=(gray&0x0F); /* save marker bits */
|
495
|
+
/* replace used bits to get max. contrast, 160=0xA0 */
|
496
|
+
gray = ((gray<160) ? (gray&~0x0F)>>1 : 0xC3|(gray>>1) );
|
497
|
+
rgb[0] = rgb[1] = rgb[2] = gray;
|
498
|
+
if ((bits & 1)==1) { addrgb(rgb,0,0,8+8*((x+y)&1)); } /* dark blue */
|
499
|
+
if ((bits & 8)==8) { addrgb(rgb,0,0, 16); } /* blue (low priority) */
|
500
|
+
if ((bits & 6)==6) { addrgb(rgb,0,0, 32); } /* blue */
|
501
|
+
if ((bits & 6)==4) { addrgb(rgb,0,48,0); } /* green */
|
502
|
+
if ((bits & 6)==2) { addrgb(rgb,32,0,0); } /* red */
|
503
|
+
if ( 1!=(int)fwrite(rgb,3,1,f1) ) { E0("write"); y=p->y; break; }
|
504
|
+
}
|
505
|
+
if ( p->bpp==3 )
|
506
|
+
if ( p->y!=(int)fwrite(p->p,3*p->x,p->y,f1) ) E0("write");
|
507
|
+
#ifdef HAVE_POPEN
|
508
|
+
if (f1t) { pclose (f1); f1=NULL; }
|
509
|
+
#endif
|
510
|
+
if (f1) fclose(f1);
|
511
|
+
return 0;
|
512
|
+
}
|
513
|
+
|
514
|
+
// high bit = first,
|
515
|
+
int writepbm(char *nam,pix *p){// P4 raw-pbm
|
516
|
+
FILE *f1;int x,y,a,b,dx,i;
|
517
|
+
dx=(p->x+7)&~7; // enlarge to a factor of 8
|
518
|
+
for(y=0;y<p->y;y++)
|
519
|
+
for(x=0;x<p->x;x++){ // set bit
|
520
|
+
a=(x+y*dx)>>3;b=7-(x&7); // adress an bitisnumber
|
521
|
+
i=x+y*p->x;
|
522
|
+
if(p->bpp==3) i=(p->p[3*i+0]+p->p[3*i+1]+p->p[3*i+2])/3;
|
523
|
+
else i= p->p[ i ];
|
524
|
+
i=((i>127)?0:1);
|
525
|
+
p->p[a]=(p->p[a] & (~1<<b)) | (i<<b);
|
526
|
+
}
|
527
|
+
f1=fopen(nam,"wb");if(!f1)F0("open"); // open-error
|
528
|
+
fprintf(f1,"P4\n%d %d\n",p->x,p->y);
|
529
|
+
if(p->y!=(int)fwrite(p->p,dx>>3,p->y,f1))F0("write"); // write all lines
|
530
|
+
fclose(f1);
|
531
|
+
return 0;
|
532
|
+
}
|
533
|
+
// ------------------------------------------------------------------------
|