isbn 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. data/{README → README.md} +5 -11
  2. data/Rakefile +20 -14
  3. data/isbn.gemspec +23 -0
  4. data/lib/isbn.rb +2 -0
  5. data/test/isbn_spec.rb +1 -1
  6. metadata +29 -316
  7. data/VERSION +0 -1
  8. data/src/gocr-0.48/.cvsignore +0 -6
  9. data/src/gocr-0.48/AUTHORS +0 -7
  10. data/src/gocr-0.48/BUGS +0 -55
  11. data/src/gocr-0.48/CREDITS +0 -17
  12. data/src/gocr-0.48/HISTORY +0 -243
  13. data/src/gocr-0.48/INSTALL +0 -83
  14. data/src/gocr-0.48/Makefile +0 -193
  15. data/src/gocr-0.48/Makefile.in +0 -193
  16. data/src/gocr-0.48/README +0 -165
  17. data/src/gocr-0.48/READMEde.txt +0 -80
  18. data/src/gocr-0.48/REMARK.txt +0 -18
  19. data/src/gocr-0.48/REVIEW +0 -538
  20. data/src/gocr-0.48/TODO +0 -65
  21. data/src/gocr-0.48/bin/.cvsignore +0 -2
  22. data/src/gocr-0.48/bin/create_db +0 -38
  23. data/src/gocr-0.48/bin/gocr.tcl +0 -527
  24. data/src/gocr-0.48/bin/gocr_chk.sh +0 -44
  25. data/src/gocr-0.48/configure +0 -4689
  26. data/src/gocr-0.48/configure.in +0 -71
  27. data/src/gocr-0.48/doc/.#Makefile.1.6 +0 -39
  28. data/src/gocr-0.48/doc/.cvsignore +0 -2
  29. data/src/gocr-0.48/doc/Makefile +0 -39
  30. data/src/gocr-0.48/doc/Makefile.in +0 -39
  31. data/src/gocr-0.48/doc/example.dtd +0 -53
  32. data/src/gocr-0.48/doc/example.xml +0 -21
  33. data/src/gocr-0.48/doc/examples.txt +0 -67
  34. data/src/gocr-0.48/doc/gocr.html +0 -578
  35. data/src/gocr-0.48/doc/unicode.txt +0 -57
  36. data/src/gocr-0.48/examples/.#Makefile.1.22 +0 -166
  37. data/src/gocr-0.48/examples/4x6.png +0 -0
  38. data/src/gocr-0.48/examples/4x6.txt +0 -2
  39. data/src/gocr-0.48/examples/5x7.png +0 -0
  40. data/src/gocr-0.48/examples/5x7.png.txt +0 -2
  41. data/src/gocr-0.48/examples/5x8.png +0 -0
  42. data/src/gocr-0.48/examples/5x8.png.txt +0 -2
  43. data/src/gocr-0.48/examples/Makefile +0 -166
  44. data/src/gocr-0.48/examples/color.fig +0 -20
  45. data/src/gocr-0.48/examples/ex.fig +0 -16
  46. data/src/gocr-0.48/examples/font.tex +0 -22
  47. data/src/gocr-0.48/examples/font1.tex +0 -46
  48. data/src/gocr-0.48/examples/font2.fig +0 -27
  49. data/src/gocr-0.48/examples/font_nw.tex +0 -24
  50. data/src/gocr-0.48/examples/handwrt1.jpg +0 -0
  51. data/src/gocr-0.48/examples/handwrt1.txt +0 -10
  52. data/src/gocr-0.48/examples/inverse.fig +0 -20
  53. data/src/gocr-0.48/examples/matrix.jpg +0 -0
  54. data/src/gocr-0.48/examples/ocr-a-subset.png +0 -0
  55. data/src/gocr-0.48/examples/ocr-a-subset.png.txt +0 -4
  56. data/src/gocr-0.48/examples/ocr-a.png +0 -0
  57. data/src/gocr-0.48/examples/ocr-a.txt +0 -6
  58. data/src/gocr-0.48/examples/ocr-b.png +0 -0
  59. data/src/gocr-0.48/examples/ocr-b.png.txt +0 -4
  60. data/src/gocr-0.48/examples/polish.tex +0 -28
  61. data/src/gocr-0.48/examples/rotate45.fig +0 -14
  62. data/src/gocr-0.48/examples/score +0 -36
  63. data/src/gocr-0.48/examples/text.tex +0 -28
  64. data/src/gocr-0.48/gpl.html +0 -537
  65. data/src/gocr-0.48/include/.cvsignore +0 -2
  66. data/src/gocr-0.48/include/config.h +0 -36
  67. data/src/gocr-0.48/include/config.h.in +0 -36
  68. data/src/gocr-0.48/include/version.h +0 -2
  69. data/src/gocr-0.48/install-sh +0 -3
  70. data/src/gocr-0.48/make.bat +0 -57
  71. data/src/gocr-0.48/man/.cvsignore +0 -2
  72. data/src/gocr-0.48/man/Makefile +0 -29
  73. data/src/gocr-0.48/man/Makefile.in +0 -29
  74. data/src/gocr-0.48/man/man1/gocr.1 +0 -166
  75. data/src/gocr-0.48/src/.cvsignore +0 -4
  76. data/src/gocr-0.48/src/Makefile +0 -132
  77. data/src/gocr-0.48/src/Makefile.in +0 -132
  78. data/src/gocr-0.48/src/amiga.h +0 -31
  79. data/src/gocr-0.48/src/barcode.c +0 -846
  80. data/src/gocr-0.48/src/barcode.c.orig +0 -593
  81. data/src/gocr-0.48/src/barcode.h +0 -11
  82. data/src/gocr-0.48/src/box.c +0 -372
  83. data/src/gocr-0.48/src/database.c +0 -462
  84. data/src/gocr-0.48/src/detect.c +0 -943
  85. data/src/gocr-0.48/src/gocr.c +0 -373
  86. data/src/gocr-0.48/src/gocr.h +0 -288
  87. data/src/gocr-0.48/src/jconv.c +0 -168
  88. data/src/gocr-0.48/src/job.c +0 -84
  89. data/src/gocr-0.48/src/lines.c +0 -350
  90. data/src/gocr-0.48/src/list.c +0 -334
  91. data/src/gocr-0.48/src/list.h +0 -90
  92. data/src/gocr-0.48/src/ocr0.c +0 -6756
  93. data/src/gocr-0.48/src/ocr0.h +0 -63
  94. data/src/gocr-0.48/src/ocr0n.c +0 -1475
  95. data/src/gocr-0.48/src/ocr1.c +0 -85
  96. data/src/gocr-0.48/src/ocr1.h +0 -3
  97. data/src/gocr-0.48/src/otsu.c +0 -289
  98. data/src/gocr-0.48/src/otsu.h +0 -23
  99. data/src/gocr-0.48/src/output.c +0 -289
  100. data/src/gocr-0.48/src/output.h +0 -37
  101. data/src/gocr-0.48/src/pcx.c +0 -153
  102. data/src/gocr-0.48/src/pcx.h +0 -9
  103. data/src/gocr-0.48/src/pgm2asc.c +0 -2893
  104. data/src/gocr-0.48/src/pgm2asc.h +0 -105
  105. data/src/gocr-0.48/src/pixel.c +0 -537
  106. data/src/gocr-0.48/src/pnm.c +0 -533
  107. data/src/gocr-0.48/src/pnm.h +0 -35
  108. data/src/gocr-0.48/src/progress.c +0 -87
  109. data/src/gocr-0.48/src/progress.h +0 -42
  110. data/src/gocr-0.48/src/remove.c +0 -703
  111. data/src/gocr-0.48/src/tga.c +0 -87
  112. data/src/gocr-0.48/src/tga.h +0 -6
  113. data/src/gocr-0.48/src/unicode.c +0 -1314
  114. data/src/gocr-0.48/src/unicode.h +0 -1257
  115. data/src/jpeg-7/Makefile.am +0 -133
  116. data/src/jpeg-7/Makefile.in +0 -1089
  117. data/src/jpeg-7/README +0 -322
  118. data/src/jpeg-7/aclocal.m4 +0 -8990
  119. data/src/jpeg-7/ansi2knr.1 +0 -36
  120. data/src/jpeg-7/ansi2knr.c +0 -739
  121. data/src/jpeg-7/cderror.h +0 -132
  122. data/src/jpeg-7/cdjpeg.c +0 -181
  123. data/src/jpeg-7/cdjpeg.h +0 -187
  124. data/src/jpeg-7/change.log +0 -270
  125. data/src/jpeg-7/cjpeg.1 +0 -325
  126. data/src/jpeg-7/cjpeg.c +0 -616
  127. data/src/jpeg-7/ckconfig.c +0 -402
  128. data/src/jpeg-7/coderules.txt +0 -118
  129. data/src/jpeg-7/config.guess +0 -1561
  130. data/src/jpeg-7/config.sub +0 -1686
  131. data/src/jpeg-7/configure +0 -17139
  132. data/src/jpeg-7/configure.ac +0 -317
  133. data/src/jpeg-7/depcomp +0 -630
  134. data/src/jpeg-7/djpeg.1 +0 -251
  135. data/src/jpeg-7/djpeg.c +0 -617
  136. data/src/jpeg-7/example.c +0 -433
  137. data/src/jpeg-7/filelist.txt +0 -215
  138. data/src/jpeg-7/install-sh +0 -520
  139. data/src/jpeg-7/install.txt +0 -1097
  140. data/src/jpeg-7/jaricom.c +0 -148
  141. data/src/jpeg-7/jcapimin.c +0 -282
  142. data/src/jpeg-7/jcapistd.c +0 -161
  143. data/src/jpeg-7/jcarith.c +0 -921
  144. data/src/jpeg-7/jccoefct.c +0 -453
  145. data/src/jpeg-7/jccolor.c +0 -459
  146. data/src/jpeg-7/jcdctmgr.c +0 -482
  147. data/src/jpeg-7/jchuff.c +0 -1612
  148. data/src/jpeg-7/jcinit.c +0 -65
  149. data/src/jpeg-7/jcmainct.c +0 -293
  150. data/src/jpeg-7/jcmarker.c +0 -667
  151. data/src/jpeg-7/jcmaster.c +0 -770
  152. data/src/jpeg-7/jcomapi.c +0 -106
  153. data/src/jpeg-7/jconfig.bcc +0 -48
  154. data/src/jpeg-7/jconfig.cfg +0 -45
  155. data/src/jpeg-7/jconfig.dj +0 -38
  156. data/src/jpeg-7/jconfig.mac +0 -43
  157. data/src/jpeg-7/jconfig.manx +0 -43
  158. data/src/jpeg-7/jconfig.mc6 +0 -52
  159. data/src/jpeg-7/jconfig.sas +0 -43
  160. data/src/jpeg-7/jconfig.st +0 -42
  161. data/src/jpeg-7/jconfig.txt +0 -155
  162. data/src/jpeg-7/jconfig.vc +0 -45
  163. data/src/jpeg-7/jconfig.vms +0 -37
  164. data/src/jpeg-7/jconfig.wat +0 -38
  165. data/src/jpeg-7/jcparam.c +0 -632
  166. data/src/jpeg-7/jcprepct.c +0 -358
  167. data/src/jpeg-7/jcsample.c +0 -545
  168. data/src/jpeg-7/jctrans.c +0 -381
  169. data/src/jpeg-7/jdapimin.c +0 -396
  170. data/src/jpeg-7/jdapistd.c +0 -275
  171. data/src/jpeg-7/jdarith.c +0 -762
  172. data/src/jpeg-7/jdatadst.c +0 -151
  173. data/src/jpeg-7/jdatasrc.c +0 -212
  174. data/src/jpeg-7/jdcoefct.c +0 -736
  175. data/src/jpeg-7/jdcolor.c +0 -396
  176. data/src/jpeg-7/jdct.h +0 -393
  177. data/src/jpeg-7/jddctmgr.c +0 -382
  178. data/src/jpeg-7/jdhuff.c +0 -1309
  179. data/src/jpeg-7/jdinput.c +0 -384
  180. data/src/jpeg-7/jdmainct.c +0 -512
  181. data/src/jpeg-7/jdmarker.c +0 -1360
  182. data/src/jpeg-7/jdmaster.c +0 -663
  183. data/src/jpeg-7/jdmerge.c +0 -400
  184. data/src/jpeg-7/jdpostct.c +0 -290
  185. data/src/jpeg-7/jdsample.c +0 -361
  186. data/src/jpeg-7/jdtrans.c +0 -136
  187. data/src/jpeg-7/jerror.c +0 -252
  188. data/src/jpeg-7/jerror.h +0 -304
  189. data/src/jpeg-7/jfdctflt.c +0 -174
  190. data/src/jpeg-7/jfdctfst.c +0 -230
  191. data/src/jpeg-7/jfdctint.c +0 -4348
  192. data/src/jpeg-7/jidctflt.c +0 -242
  193. data/src/jpeg-7/jidctfst.c +0 -368
  194. data/src/jpeg-7/jidctint.c +0 -5137
  195. data/src/jpeg-7/jinclude.h +0 -91
  196. data/src/jpeg-7/jmemansi.c +0 -167
  197. data/src/jpeg-7/jmemdos.c +0 -638
  198. data/src/jpeg-7/jmemdosa.asm +0 -379
  199. data/src/jpeg-7/jmemmac.c +0 -289
  200. data/src/jpeg-7/jmemmgr.c +0 -1118
  201. data/src/jpeg-7/jmemname.c +0 -276
  202. data/src/jpeg-7/jmemnobs.c +0 -109
  203. data/src/jpeg-7/jmemsys.h +0 -198
  204. data/src/jpeg-7/jmorecfg.h +0 -369
  205. data/src/jpeg-7/jpegint.h +0 -395
  206. data/src/jpeg-7/jpeglib.h +0 -1135
  207. data/src/jpeg-7/jpegtran.1 +0 -272
  208. data/src/jpeg-7/jpegtran.c +0 -546
  209. data/src/jpeg-7/jquant1.c +0 -856
  210. data/src/jpeg-7/jquant2.c +0 -1310
  211. data/src/jpeg-7/jutils.c +0 -179
  212. data/src/jpeg-7/jversion.h +0 -14
  213. data/src/jpeg-7/libjpeg.map +0 -4
  214. data/src/jpeg-7/libjpeg.txt +0 -3067
  215. data/src/jpeg-7/ltmain.sh +0 -8406
  216. data/src/jpeg-7/makcjpeg.st +0 -36
  217. data/src/jpeg-7/makdjpeg.st +0 -36
  218. data/src/jpeg-7/makeadsw.vc6 +0 -77
  219. data/src/jpeg-7/makeasln.vc9 +0 -33
  220. data/src/jpeg-7/makecdep.vc6 +0 -82
  221. data/src/jpeg-7/makecdsp.vc6 +0 -130
  222. data/src/jpeg-7/makecmak.vc6 +0 -159
  223. data/src/jpeg-7/makecvcp.vc9 +0 -186
  224. data/src/jpeg-7/makeddep.vc6 +0 -82
  225. data/src/jpeg-7/makeddsp.vc6 +0 -130
  226. data/src/jpeg-7/makedmak.vc6 +0 -159
  227. data/src/jpeg-7/makedvcp.vc9 +0 -186
  228. data/src/jpeg-7/makefile.ansi +0 -220
  229. data/src/jpeg-7/makefile.bcc +0 -291
  230. data/src/jpeg-7/makefile.dj +0 -226
  231. data/src/jpeg-7/makefile.manx +0 -220
  232. data/src/jpeg-7/makefile.mc6 +0 -255
  233. data/src/jpeg-7/makefile.mms +0 -224
  234. data/src/jpeg-7/makefile.sas +0 -258
  235. data/src/jpeg-7/makefile.unix +0 -234
  236. data/src/jpeg-7/makefile.vc +0 -217
  237. data/src/jpeg-7/makefile.vms +0 -142
  238. data/src/jpeg-7/makefile.wat +0 -239
  239. data/src/jpeg-7/makejdep.vc6 +0 -423
  240. data/src/jpeg-7/makejdsp.vc6 +0 -285
  241. data/src/jpeg-7/makejdsw.vc6 +0 -29
  242. data/src/jpeg-7/makejmak.vc6 +0 -425
  243. data/src/jpeg-7/makejsln.vc9 +0 -17
  244. data/src/jpeg-7/makejvcp.vc9 +0 -328
  245. data/src/jpeg-7/makeproj.mac +0 -213
  246. data/src/jpeg-7/makerdep.vc6 +0 -6
  247. data/src/jpeg-7/makerdsp.vc6 +0 -78
  248. data/src/jpeg-7/makermak.vc6 +0 -110
  249. data/src/jpeg-7/makervcp.vc9 +0 -133
  250. data/src/jpeg-7/maketdep.vc6 +0 -43
  251. data/src/jpeg-7/maketdsp.vc6 +0 -122
  252. data/src/jpeg-7/maketmak.vc6 +0 -131
  253. data/src/jpeg-7/maketvcp.vc9 +0 -178
  254. data/src/jpeg-7/makewdep.vc6 +0 -6
  255. data/src/jpeg-7/makewdsp.vc6 +0 -78
  256. data/src/jpeg-7/makewmak.vc6 +0 -110
  257. data/src/jpeg-7/makewvcp.vc9 +0 -133
  258. data/src/jpeg-7/makljpeg.st +0 -68
  259. data/src/jpeg-7/maktjpeg.st +0 -30
  260. data/src/jpeg-7/makvms.opt +0 -4
  261. data/src/jpeg-7/missing +0 -376
  262. data/src/jpeg-7/rdbmp.c +0 -439
  263. data/src/jpeg-7/rdcolmap.c +0 -253
  264. data/src/jpeg-7/rdgif.c +0 -38
  265. data/src/jpeg-7/rdjpgcom.1 +0 -63
  266. data/src/jpeg-7/rdjpgcom.c +0 -515
  267. data/src/jpeg-7/rdppm.c +0 -459
  268. data/src/jpeg-7/rdrle.c +0 -387
  269. data/src/jpeg-7/rdswitch.c +0 -365
  270. data/src/jpeg-7/rdtarga.c +0 -500
  271. data/src/jpeg-7/structure.txt +0 -945
  272. data/src/jpeg-7/testimg.bmp +0 -0
  273. data/src/jpeg-7/testimg.jpg +0 -0
  274. data/src/jpeg-7/testimg.ppm +0 -4
  275. data/src/jpeg-7/testimgp.jpg +0 -0
  276. data/src/jpeg-7/testorig.jpg +0 -0
  277. data/src/jpeg-7/testprog.jpg +0 -0
  278. data/src/jpeg-7/transupp.c +0 -1533
  279. data/src/jpeg-7/transupp.h +0 -205
  280. data/src/jpeg-7/usage.txt +0 -605
  281. data/src/jpeg-7/wizard.txt +0 -211
  282. data/src/jpeg-7/wrbmp.c +0 -442
  283. data/src/jpeg-7/wrgif.c +0 -399
  284. data/src/jpeg-7/wrjpgcom.1 +0 -103
  285. data/src/jpeg-7/wrjpgcom.c +0 -583
  286. data/src/jpeg-7/wrppm.c +0 -269
  287. data/src/jpeg-7/wrrle.c +0 -305
  288. data/src/jpeg-7/wrtarga.c +0 -253
@@ -1,533 +0,0 @@
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
- // ------------------------------------------------------------------------