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.
Files changed (290) hide show
  1. data/README +1 -1
  2. data/Rakefile +0 -18
  3. data/VERSION +1 -0
  4. data/isbn.gemspec +290 -7
  5. data/lib/isbn.rb +6 -6
  6. data/src/gocr-0.48/.cvsignore +6 -0
  7. data/src/gocr-0.48/AUTHORS +7 -0
  8. data/src/gocr-0.48/BUGS +55 -0
  9. data/src/gocr-0.48/CREDITS +17 -0
  10. data/src/gocr-0.48/HISTORY +243 -0
  11. data/src/gocr-0.48/INSTALL +83 -0
  12. data/src/gocr-0.48/Makefile +193 -0
  13. data/src/gocr-0.48/Makefile.in +193 -0
  14. data/src/gocr-0.48/README +165 -0
  15. data/src/gocr-0.48/READMEde.txt +80 -0
  16. data/src/gocr-0.48/REMARK.txt +18 -0
  17. data/src/gocr-0.48/REVIEW +538 -0
  18. data/src/gocr-0.48/TODO +65 -0
  19. data/src/gocr-0.48/bin/.cvsignore +2 -0
  20. data/src/gocr-0.48/bin/create_db +38 -0
  21. data/src/gocr-0.48/bin/gocr.tcl +527 -0
  22. data/src/gocr-0.48/bin/gocr_chk.sh +44 -0
  23. data/src/gocr-0.48/configure +4689 -0
  24. data/src/gocr-0.48/configure.in +71 -0
  25. data/src/gocr-0.48/doc/.#Makefile.1.6 +39 -0
  26. data/src/gocr-0.48/doc/.cvsignore +2 -0
  27. data/src/gocr-0.48/doc/Makefile +39 -0
  28. data/src/gocr-0.48/doc/Makefile.in +39 -0
  29. data/src/gocr-0.48/doc/example.dtd +53 -0
  30. data/src/gocr-0.48/doc/example.xml +21 -0
  31. data/src/gocr-0.48/doc/examples.txt +67 -0
  32. data/src/gocr-0.48/doc/gocr.html +578 -0
  33. data/src/gocr-0.48/doc/unicode.txt +57 -0
  34. data/src/gocr-0.48/examples/.#Makefile.1.22 +166 -0
  35. data/src/gocr-0.48/examples/4x6.png +0 -0
  36. data/src/gocr-0.48/examples/4x6.txt +2 -0
  37. data/src/gocr-0.48/examples/5x7.png +0 -0
  38. data/src/gocr-0.48/examples/5x7.png.txt +2 -0
  39. data/src/gocr-0.48/examples/5x8.png +0 -0
  40. data/src/gocr-0.48/examples/5x8.png.txt +2 -0
  41. data/src/gocr-0.48/examples/Makefile +166 -0
  42. data/src/gocr-0.48/examples/color.fig +20 -0
  43. data/src/gocr-0.48/examples/ex.fig +16 -0
  44. data/src/gocr-0.48/examples/font.tex +22 -0
  45. data/src/gocr-0.48/examples/font1.tex +46 -0
  46. data/src/gocr-0.48/examples/font2.fig +27 -0
  47. data/src/gocr-0.48/examples/font_nw.tex +24 -0
  48. data/src/gocr-0.48/examples/handwrt1.jpg +0 -0
  49. data/src/gocr-0.48/examples/handwrt1.txt +10 -0
  50. data/src/gocr-0.48/examples/inverse.fig +20 -0
  51. data/src/gocr-0.48/examples/matrix.jpg +0 -0
  52. data/src/gocr-0.48/examples/ocr-a-subset.png +0 -0
  53. data/src/gocr-0.48/examples/ocr-a-subset.png.txt +4 -0
  54. data/src/gocr-0.48/examples/ocr-a.png +0 -0
  55. data/src/gocr-0.48/examples/ocr-a.txt +6 -0
  56. data/src/gocr-0.48/examples/ocr-b.png +0 -0
  57. data/src/gocr-0.48/examples/ocr-b.png.txt +4 -0
  58. data/src/gocr-0.48/examples/polish.tex +28 -0
  59. data/src/gocr-0.48/examples/rotate45.fig +14 -0
  60. data/src/gocr-0.48/examples/score +36 -0
  61. data/src/gocr-0.48/examples/text.tex +28 -0
  62. data/src/gocr-0.48/gocr.spec +143 -0
  63. data/src/gocr-0.48/gpl.html +537 -0
  64. data/src/gocr-0.48/include/.cvsignore +2 -0
  65. data/src/gocr-0.48/include/config.h +36 -0
  66. data/src/gocr-0.48/include/config.h.in +36 -0
  67. data/src/gocr-0.48/include/version.h +2 -0
  68. data/src/gocr-0.48/install-sh +3 -0
  69. data/src/gocr-0.48/make.bat +57 -0
  70. data/src/gocr-0.48/man/.cvsignore +2 -0
  71. data/src/gocr-0.48/man/Makefile +29 -0
  72. data/src/gocr-0.48/man/Makefile.in +29 -0
  73. data/src/gocr-0.48/man/man1/gocr.1 +166 -0
  74. data/src/gocr-0.48/src/.cvsignore +4 -0
  75. data/src/gocr-0.48/src/Makefile +132 -0
  76. data/src/gocr-0.48/src/Makefile.in +132 -0
  77. data/src/gocr-0.48/src/amiga.h +31 -0
  78. data/src/gocr-0.48/src/barcode.c +846 -0
  79. data/src/gocr-0.48/src/barcode.c.orig +593 -0
  80. data/src/gocr-0.48/src/barcode.h +11 -0
  81. data/src/gocr-0.48/src/box.c +372 -0
  82. data/src/gocr-0.48/src/database.c +462 -0
  83. data/src/gocr-0.48/src/detect.c +943 -0
  84. data/src/gocr-0.48/src/gocr.c +373 -0
  85. data/src/gocr-0.48/src/gocr.h +288 -0
  86. data/src/gocr-0.48/src/jconv.c +168 -0
  87. data/src/gocr-0.48/src/job.c +84 -0
  88. data/src/gocr-0.48/src/lines.c +350 -0
  89. data/src/gocr-0.48/src/list.c +334 -0
  90. data/src/gocr-0.48/src/list.h +90 -0
  91. data/src/gocr-0.48/src/ocr0.c +6756 -0
  92. data/src/gocr-0.48/src/ocr0.h +63 -0
  93. data/src/gocr-0.48/src/ocr0n.c +1475 -0
  94. data/src/gocr-0.48/src/ocr1.c +85 -0
  95. data/src/gocr-0.48/src/ocr1.h +3 -0
  96. data/src/gocr-0.48/src/otsu.c +289 -0
  97. data/src/gocr-0.48/src/otsu.h +23 -0
  98. data/src/gocr-0.48/src/output.c +289 -0
  99. data/src/gocr-0.48/src/output.h +37 -0
  100. data/src/gocr-0.48/src/pcx.c +153 -0
  101. data/src/gocr-0.48/src/pcx.h +9 -0
  102. data/src/gocr-0.48/src/pgm2asc.c +2893 -0
  103. data/src/gocr-0.48/src/pgm2asc.h +105 -0
  104. data/src/gocr-0.48/src/pixel.c +537 -0
  105. data/src/gocr-0.48/src/pnm.c +533 -0
  106. data/src/gocr-0.48/src/pnm.h +35 -0
  107. data/src/gocr-0.48/src/progress.c +87 -0
  108. data/src/gocr-0.48/src/progress.h +42 -0
  109. data/src/gocr-0.48/src/remove.c +703 -0
  110. data/src/gocr-0.48/src/tga.c +87 -0
  111. data/src/gocr-0.48/src/tga.h +6 -0
  112. data/src/gocr-0.48/src/unicode.c +1314 -0
  113. data/src/gocr-0.48/src/unicode.h +1257 -0
  114. data/src/jpeg-7/Makefile.am +133 -0
  115. data/src/jpeg-7/Makefile.in +1089 -0
  116. data/src/jpeg-7/README +322 -0
  117. data/src/jpeg-7/aclocal.m4 +8990 -0
  118. data/src/jpeg-7/ansi2knr.1 +36 -0
  119. data/src/jpeg-7/ansi2knr.c +739 -0
  120. data/src/jpeg-7/cderror.h +132 -0
  121. data/src/jpeg-7/cdjpeg.c +181 -0
  122. data/src/jpeg-7/cdjpeg.h +187 -0
  123. data/src/jpeg-7/change.log +270 -0
  124. data/src/jpeg-7/cjpeg.1 +325 -0
  125. data/src/jpeg-7/cjpeg.c +616 -0
  126. data/src/jpeg-7/ckconfig.c +402 -0
  127. data/src/jpeg-7/coderules.txt +118 -0
  128. data/src/jpeg-7/config.guess +1561 -0
  129. data/src/jpeg-7/config.sub +1686 -0
  130. data/src/jpeg-7/configure +17139 -0
  131. data/src/jpeg-7/configure.ac +317 -0
  132. data/src/jpeg-7/depcomp +630 -0
  133. data/src/jpeg-7/djpeg.1 +251 -0
  134. data/src/jpeg-7/djpeg.c +617 -0
  135. data/src/jpeg-7/example.c +433 -0
  136. data/src/jpeg-7/filelist.txt +215 -0
  137. data/src/jpeg-7/install-sh +520 -0
  138. data/src/jpeg-7/install.txt +1097 -0
  139. data/src/jpeg-7/jaricom.c +148 -0
  140. data/src/jpeg-7/jcapimin.c +282 -0
  141. data/src/jpeg-7/jcapistd.c +161 -0
  142. data/src/jpeg-7/jcarith.c +921 -0
  143. data/src/jpeg-7/jccoefct.c +453 -0
  144. data/src/jpeg-7/jccolor.c +459 -0
  145. data/src/jpeg-7/jcdctmgr.c +482 -0
  146. data/src/jpeg-7/jchuff.c +1612 -0
  147. data/src/jpeg-7/jcinit.c +65 -0
  148. data/src/jpeg-7/jcmainct.c +293 -0
  149. data/src/jpeg-7/jcmarker.c +667 -0
  150. data/src/jpeg-7/jcmaster.c +770 -0
  151. data/src/jpeg-7/jcomapi.c +106 -0
  152. data/src/jpeg-7/jconfig.bcc +48 -0
  153. data/src/jpeg-7/jconfig.cfg +45 -0
  154. data/src/jpeg-7/jconfig.dj +38 -0
  155. data/src/jpeg-7/jconfig.mac +43 -0
  156. data/src/jpeg-7/jconfig.manx +43 -0
  157. data/src/jpeg-7/jconfig.mc6 +52 -0
  158. data/src/jpeg-7/jconfig.sas +43 -0
  159. data/src/jpeg-7/jconfig.st +42 -0
  160. data/src/jpeg-7/jconfig.txt +155 -0
  161. data/src/jpeg-7/jconfig.vc +45 -0
  162. data/src/jpeg-7/jconfig.vms +37 -0
  163. data/src/jpeg-7/jconfig.wat +38 -0
  164. data/src/jpeg-7/jcparam.c +632 -0
  165. data/src/jpeg-7/jcprepct.c +358 -0
  166. data/src/jpeg-7/jcsample.c +545 -0
  167. data/src/jpeg-7/jctrans.c +381 -0
  168. data/src/jpeg-7/jdapimin.c +396 -0
  169. data/src/jpeg-7/jdapistd.c +275 -0
  170. data/src/jpeg-7/jdarith.c +762 -0
  171. data/src/jpeg-7/jdatadst.c +151 -0
  172. data/src/jpeg-7/jdatasrc.c +212 -0
  173. data/src/jpeg-7/jdcoefct.c +736 -0
  174. data/src/jpeg-7/jdcolor.c +396 -0
  175. data/src/jpeg-7/jdct.h +393 -0
  176. data/src/jpeg-7/jddctmgr.c +382 -0
  177. data/src/jpeg-7/jdhuff.c +1309 -0
  178. data/src/jpeg-7/jdinput.c +384 -0
  179. data/src/jpeg-7/jdmainct.c +512 -0
  180. data/src/jpeg-7/jdmarker.c +1360 -0
  181. data/src/jpeg-7/jdmaster.c +663 -0
  182. data/src/jpeg-7/jdmerge.c +400 -0
  183. data/src/jpeg-7/jdpostct.c +290 -0
  184. data/src/jpeg-7/jdsample.c +361 -0
  185. data/src/jpeg-7/jdtrans.c +136 -0
  186. data/src/jpeg-7/jerror.c +252 -0
  187. data/src/jpeg-7/jerror.h +304 -0
  188. data/src/jpeg-7/jfdctflt.c +174 -0
  189. data/src/jpeg-7/jfdctfst.c +230 -0
  190. data/src/jpeg-7/jfdctint.c +4348 -0
  191. data/src/jpeg-7/jidctflt.c +242 -0
  192. data/src/jpeg-7/jidctfst.c +368 -0
  193. data/src/jpeg-7/jidctint.c +5137 -0
  194. data/src/jpeg-7/jinclude.h +91 -0
  195. data/src/jpeg-7/jmemansi.c +167 -0
  196. data/src/jpeg-7/jmemdos.c +638 -0
  197. data/src/jpeg-7/jmemdosa.asm +379 -0
  198. data/src/jpeg-7/jmemmac.c +289 -0
  199. data/src/jpeg-7/jmemmgr.c +1118 -0
  200. data/src/jpeg-7/jmemname.c +276 -0
  201. data/src/jpeg-7/jmemnobs.c +109 -0
  202. data/src/jpeg-7/jmemsys.h +198 -0
  203. data/src/jpeg-7/jmorecfg.h +369 -0
  204. data/src/jpeg-7/jpegint.h +395 -0
  205. data/src/jpeg-7/jpeglib.h +1135 -0
  206. data/src/jpeg-7/jpegtran.1 +272 -0
  207. data/src/jpeg-7/jpegtran.c +546 -0
  208. data/src/jpeg-7/jquant1.c +856 -0
  209. data/src/jpeg-7/jquant2.c +1310 -0
  210. data/src/jpeg-7/jutils.c +179 -0
  211. data/src/jpeg-7/jversion.h +14 -0
  212. data/src/jpeg-7/libjpeg.map +4 -0
  213. data/src/jpeg-7/libjpeg.txt +3067 -0
  214. data/src/jpeg-7/ltmain.sh +8406 -0
  215. data/src/jpeg-7/makcjpeg.st +36 -0
  216. data/src/jpeg-7/makdjpeg.st +36 -0
  217. data/src/jpeg-7/makeadsw.vc6 +77 -0
  218. data/src/jpeg-7/makeasln.vc9 +33 -0
  219. data/src/jpeg-7/makecdep.vc6 +82 -0
  220. data/src/jpeg-7/makecdsp.vc6 +130 -0
  221. data/src/jpeg-7/makecmak.vc6 +159 -0
  222. data/src/jpeg-7/makecvcp.vc9 +186 -0
  223. data/src/jpeg-7/makeddep.vc6 +82 -0
  224. data/src/jpeg-7/makeddsp.vc6 +130 -0
  225. data/src/jpeg-7/makedmak.vc6 +159 -0
  226. data/src/jpeg-7/makedvcp.vc9 +186 -0
  227. data/src/jpeg-7/makefile.ansi +220 -0
  228. data/src/jpeg-7/makefile.bcc +291 -0
  229. data/src/jpeg-7/makefile.dj +226 -0
  230. data/src/jpeg-7/makefile.manx +220 -0
  231. data/src/jpeg-7/makefile.mc6 +255 -0
  232. data/src/jpeg-7/makefile.mms +224 -0
  233. data/src/jpeg-7/makefile.sas +258 -0
  234. data/src/jpeg-7/makefile.unix +234 -0
  235. data/src/jpeg-7/makefile.vc +217 -0
  236. data/src/jpeg-7/makefile.vms +142 -0
  237. data/src/jpeg-7/makefile.wat +239 -0
  238. data/src/jpeg-7/makejdep.vc6 +423 -0
  239. data/src/jpeg-7/makejdsp.vc6 +285 -0
  240. data/src/jpeg-7/makejdsw.vc6 +29 -0
  241. data/src/jpeg-7/makejmak.vc6 +425 -0
  242. data/src/jpeg-7/makejsln.vc9 +17 -0
  243. data/src/jpeg-7/makejvcp.vc9 +328 -0
  244. data/src/jpeg-7/makeproj.mac +213 -0
  245. data/src/jpeg-7/makerdep.vc6 +6 -0
  246. data/src/jpeg-7/makerdsp.vc6 +78 -0
  247. data/src/jpeg-7/makermak.vc6 +110 -0
  248. data/src/jpeg-7/makervcp.vc9 +133 -0
  249. data/src/jpeg-7/maketdep.vc6 +43 -0
  250. data/src/jpeg-7/maketdsp.vc6 +122 -0
  251. data/src/jpeg-7/maketmak.vc6 +131 -0
  252. data/src/jpeg-7/maketvcp.vc9 +178 -0
  253. data/src/jpeg-7/makewdep.vc6 +6 -0
  254. data/src/jpeg-7/makewdsp.vc6 +78 -0
  255. data/src/jpeg-7/makewmak.vc6 +110 -0
  256. data/src/jpeg-7/makewvcp.vc9 +133 -0
  257. data/src/jpeg-7/makljpeg.st +68 -0
  258. data/src/jpeg-7/maktjpeg.st +30 -0
  259. data/src/jpeg-7/makvms.opt +4 -0
  260. data/src/jpeg-7/missing +376 -0
  261. data/src/jpeg-7/rdbmp.c +439 -0
  262. data/src/jpeg-7/rdcolmap.c +253 -0
  263. data/src/jpeg-7/rdgif.c +38 -0
  264. data/src/jpeg-7/rdjpgcom.1 +63 -0
  265. data/src/jpeg-7/rdjpgcom.c +515 -0
  266. data/src/jpeg-7/rdppm.c +459 -0
  267. data/src/jpeg-7/rdrle.c +387 -0
  268. data/src/jpeg-7/rdswitch.c +365 -0
  269. data/src/jpeg-7/rdtarga.c +500 -0
  270. data/src/jpeg-7/structure.txt +945 -0
  271. data/src/jpeg-7/testimg.bmp +0 -0
  272. data/src/jpeg-7/testimg.jpg +0 -0
  273. data/src/jpeg-7/testimg.ppm +4 -0
  274. data/src/jpeg-7/testimgp.jpg +0 -0
  275. data/src/jpeg-7/testorig.jpg +0 -0
  276. data/src/jpeg-7/testprog.jpg +0 -0
  277. data/src/jpeg-7/transupp.c +1533 -0
  278. data/src/jpeg-7/transupp.h +205 -0
  279. data/src/jpeg-7/usage.txt +605 -0
  280. data/src/jpeg-7/wizard.txt +211 -0
  281. data/src/jpeg-7/wrbmp.c +442 -0
  282. data/src/jpeg-7/wrgif.c +399 -0
  283. data/src/jpeg-7/wrjpgcom.1 +103 -0
  284. data/src/jpeg-7/wrjpgcom.c +583 -0
  285. data/src/jpeg-7/wrppm.c +269 -0
  286. data/src/jpeg-7/wrrle.c +305 -0
  287. data/src/jpeg-7/wrtarga.c +253 -0
  288. metadata +287 -6
  289. data/LICENSE +0 -20
  290. data/VERSION.yml +0 -4
@@ -0,0 +1,85 @@
1
+ // test routines - faster to compile
2
+ #include <stdlib.h>
3
+ #include <stdio.h>
4
+ #include "pgm2asc.h"
5
+ #include "unicode.h"
6
+ #include "amiga.h"
7
+ #include "gocr.h"
8
+
9
+ // for learn_mode/analyze_mode high, with, yoffset, num of pattern_i,
10
+ // - holes (center,radius in relative coordinates) etc. => cluster analyze
11
+ // num_hole => min-volume, tolerance border
12
+ // pattern: @@ @. @@
13
+ // .@ @. ..
14
+ // regular filter for large resolutions to make edges more smooth (on boxes)
15
+ // extra-filter (only if not recognized?)
16
+ // map + same color to (#==change)
17
+ // - anti color
18
+ // . not used
19
+ // strongest neighbour pixels (3x3) => directions
20
+ // second/third run with more and more tolerance!?
21
+
22
+ /* FIXME jb: following is unused */
23
+ #if 0
24
+ struct lobj { // line-object (for fitting to near lines)
25
+ int x0,y0; // starting point (left up)
26
+ int x1,y1; // end point (right down)
27
+ int mt; // minimum thickness
28
+ int q; // quality, overlapp
29
+ };
30
+
31
+ /* FIXME jb global */
32
+ struct lobj obj1;
33
+ #endif
34
+
35
+ // that is the first draft of feature extraction
36
+ // detect main lines and bows
37
+ // seems bad implemented, looking for better algorithms (ToDo: use autotrace)
38
+ #define MAXL 10
39
+ void ocr2(pix *b,int cs){
40
+ int x1,y1,x2,y2,l,i,j,xa[MAXL],ya[MAXL],xb[MAXL],yb[MAXL],ll[MAXL];
41
+ for(i=0;i<MAXL;i++)xa[i]=ya[i]=xb[i]=yb[i]=ll[i]=0;
42
+ for(x1=0;x1<b->x;x1++) // very slowly, but simple to program
43
+ for(y1=0;y1<b->y;y1++) // brute force
44
+ for(x2=0;x2<b->x;x2++)
45
+ for(y2=y1+1;y2<b->y;y2++)
46
+ {
47
+ if( get_line2(x1,y1,x2,y2,b,cs,100)>99 )
48
+ { // line ???
49
+ l=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); // len
50
+ for(i=0;i<MAXL;i++)
51
+ { // remove similar lines (same middle point) IMPROVE IT !!!!!! ???
52
+ if(
53
+ abs(x1+x2-xa[i]-xb[i])<1+b->x/2
54
+ && abs(y1+y2-ya[i]-yb[i])<1+b->y/2
55
+ && abs(y1-ya[i])<1+b->y/4
56
+ && abs(x1-xa[i])<1+b->x/4
57
+ )
58
+ {
59
+ if( l>ll[i] )
60
+ {
61
+ for(j=i;j<MAXL-1;j++)
62
+ { // shift table
63
+ xa[j]=xa[j+1];ya[j]=ya[j+1];
64
+ xb[j]=xb[j+1];yb[j]=yb[j+1];ll[j]=ll[j+1];
65
+ }
66
+ ll[MAXL-1]=0;
67
+ }
68
+ else break; // forget it if shorter
69
+ }
70
+ if( l>ll[i] ){ // insert if larger
71
+ for(j=MAXL-1;j>i;j--){ // shift table
72
+ xa[j]=xa[j-1];ya[j]=ya[j-1];
73
+ xb[j]=xb[j-1];yb[j]=yb[j-1];ll[j]=ll[j-1];
74
+ }
75
+ xa[i]=x1;ya[i]=y1;xb[i]=x2;yb[i]=y2;ll[i]=l;
76
+ break;
77
+ }
78
+ }
79
+ }
80
+ }
81
+ for(i=0;i<MAXL;i++){
82
+ printf(" %2d %2d %2d %2d %3d\n",xa[i],ya[i],xb[i],yb[i],ll[i]);
83
+ }
84
+ }
85
+
@@ -0,0 +1,3 @@
1
+ /* #include "pgm2asc.h" */
2
+ #include "pnm.h"
3
+ /* wchar_t ocr1(struct box *box1, pix *b, int cs); */
@@ -0,0 +1,289 @@
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
+ the following code was send by Ryan Dibble <dibbler@umich.edu>
22
+
23
+ The algorithm is very simple but works good hopefully.
24
+
25
+ Compare the grayscale histogram with a mass density diagram:
26
+ I think the algorithm is a kind of
27
+ divide a body into two parts in a way that the mass
28
+ centers have the largest distance from each other,
29
+ the function is weighted in a way that same masses have a advantage
30
+
31
+ - otsu algorithm is failing on diskrete multi color images
32
+
33
+ TODO:
34
+ RGB: do the same with all colors (CMYG?) seperately
35
+
36
+ test: hardest case = two colors
37
+ bbg: test done, using a two color gray file. Output:
38
+ # threshold: Value = 43 gmin=43 gmax=188
39
+
40
+ my changes:
41
+ - float -> double
42
+ - debug option added (vvv & 1..2)
43
+ - **image => *image, &image[i][1] => &image[i*cols+1]
44
+ - do only count pixels near contrast regions
45
+ this makes otsu much better for shadowed fonts or multi colored text
46
+ on white background
47
+
48
+ (m) Joerg Schulenburg (see README for email address)
49
+
50
+ ToDo:
51
+ - measure contrast
52
+ - detect low-contrast regions
53
+
54
+ */
55
+
56
+ #include <stdio.h>
57
+ #include <string.h>
58
+
59
+ #define Abs(x) ((x<0)?-(x):x)
60
+
61
+ /*======================================================================*
62
+ * global thresholding routine *
63
+ * takes a 2D unsigned char array pointer, number of rows, and *
64
+ * number of cols in the array. returns the value of the threshold *
65
+ * x0,y0,x0+dx,y0+dy are the edgepoints of the interesting region *
66
+ * vvv is the verbosity for debugging purpose *
67
+ *======================================================================*/
68
+ int
69
+ otsu (unsigned char *image, int rows, int cols,
70
+ int x0, int y0, int dx, int dy, int vvv) {
71
+
72
+ unsigned char *np; // pointer to position in the image we are working with
73
+ unsigned char op1, op2; // predecessor of pixel *np (start value)
74
+ int maxc=0; // maximum contrast (start value)
75
+ int thresholdValue=1; // value we will threshold at
76
+ int ihist[256]; // image histogram
77
+ int chist[256]; // contrast histogram
78
+
79
+ int i, j, k; // various counters
80
+ int is, i1, i2, ns, n1, n2, gmin, gmax;
81
+ double m1, m2, sum, csum, fmax, sb;
82
+
83
+ // zero out histogram ...
84
+ memset(ihist, 0, sizeof(ihist));
85
+ memset(chist, 0, sizeof(chist));
86
+ op1=op2=0;
87
+
88
+ gmin=255; gmax=0; k=dy/512+1;
89
+ // v0.43 first get max contrast, dont do it together with next step
90
+ // because it failes if we have pattern as background (on top)
91
+ for (i = 0; i < dy ; i+=k) {
92
+ np = &image[(y0+i)*cols+x0];
93
+ for (j = 0; j < dx ; j++) {
94
+ ihist[*np]++;
95
+ if(*np > gmax) gmax=*np;
96
+ if(*np < gmin) gmin=*np;
97
+ if (Abs(*np-op1)>maxc) maxc=Abs(*np-op1); /* new maximum contrast */
98
+ if (Abs(*np-op2)>maxc) maxc=Abs(*np-op2); /* new maximum contrast */
99
+ /* we hope that maxc will be find its maximum very fast */
100
+ op2=op1; /* shift old pixel to next older */
101
+ op1=*np; /* store old pixel for contrast check */
102
+ np++; /* next pixel */
103
+ }
104
+ }
105
+
106
+ // generate the histogram
107
+ // Aug06 images with large white or black homogeneous
108
+ // areas give bad results, so we only add pixels on contrast edges
109
+ for (i = 0; i < dy ; i+=k) {
110
+ np = &image[(y0+i)*cols+x0];
111
+ for (j = 0; j < dx ; j++) {
112
+ if (Abs(*np-op1)>maxc/4
113
+ || Abs(*np-op2)>maxc/4)
114
+ chist[*np]++; // count only relevant pixels
115
+ op2=op1; /* shift old pixel to next older */
116
+ op1=*np; /* store old pixel for contrast check */
117
+ np++; /* next pixel */
118
+ }
119
+ }
120
+
121
+ // set up everything
122
+ sum = csum = 0.0;
123
+ ns = 0;
124
+ is = 0;
125
+
126
+ for (k = 0; k <= 255; k++) {
127
+ sum += (double) k * (double) chist[k]; /* x*f(x) cmass moment */
128
+ ns += chist[k]; /* f(x) cmass */
129
+ is += ihist[k]; /* f(x) imass */
130
+ // Debug: output to out_hist.dat?
131
+ // fprintf(stderr,"\chistogram %3d %6d (brightness weight)", k, ihist[k]);
132
+ }
133
+
134
+ if (!ns) {
135
+ // if n has no value we have problems...
136
+ fprintf (stderr, "NOT NORMAL, thresholdValue = 160\n");
137
+ return (160);
138
+ }
139
+
140
+ // ToDo: only care about extremas in a 3 pixel environment
141
+ // check if there are more than 2 mass centers (more colors)
142
+ // return object colors and color radius instead of threshold value
143
+ // also the reagion, where colored objects are found
144
+ // what if more than one background color? no otsu at all?
145
+ // whats background? box with lot of other boxes in it
146
+ // threshold each box (examples/invers.png,colors.png)
147
+ // get maximum white and minimum black pixel color (possible range)
148
+ // check range between them for low..high contrast ???
149
+ // typical scenes (which must be covered):
150
+ // - white page with text of different colors (gray values)
151
+ // - binear page: background (gray=1) + black text (gray=0)
152
+ // - text mixed with big (dark) images
153
+ // ToDo: recursive clustering for maximum multipol moments?
154
+ // idea: normalize ihist to max=1024 before otsu?
155
+
156
+ // do the otsu global thresholding method
157
+
158
+ if ((vvv&1)) // Debug
159
+ fprintf(stderr,"# threshold: value ihist chist mass_dipol_moment\n");
160
+ fmax = -1.0;
161
+ n1 = 0;
162
+ for (k = 0; k < 255; k++) {
163
+ n1 += chist[k]; // left mass (integration)
164
+ if (!n1) continue; // we need at least one foreground pixel
165
+ n2 = ns - n1; // right mass (num pixels - left mass)
166
+ if (n2 == 0) break; // we need at least one background pixel
167
+ csum += (double) k *chist[k]; // left mass moment
168
+ m1 = csum / n1; // left mass center (black chars)
169
+ m2 = (sum - csum) / n2; // right mass center (white background)
170
+ // max. dipol moment?
171
+ // orig: sb = (double) n1 *(double) n2 * (m1 - m2) * (m1 - m2);
172
+ sb = (double) n1 *(double) n2 * (m2 - m1); // seems to be better Aug06
173
+ /* bbg: note: can be optimized. */
174
+ if (sb > fmax) {
175
+ fmax = sb;
176
+ thresholdValue = k + 1;
177
+ // thresholdValue = (m1 + 3 * m2) / 4;
178
+ }
179
+ if ((vvv&1) && ihist[k]) // Debug
180
+ fprintf(stderr,"# threshold: %3d %6d %6d %8.2f\n",
181
+ k, ihist[k], chist[k],
182
+ sb/(dx*dy)); /* normalized dipol moment */
183
+ }
184
+ // ToDo: error = left/right point where sb is 90% of maximum?
185
+ // now we count all pixels for background detection
186
+ i1 = 0;
187
+ for (k = 0; k < thresholdValue; k++) {
188
+ i1 += ihist[k]; // left mass (integration)
189
+ }
190
+ i2 = is - i1; // right mass (num pixels - left mass)
191
+
192
+ // at this point we have our thresholding value
193
+ // black_char: value<cs, white_background: value>=cs
194
+
195
+ // can it happen? check for sureness
196
+ if (thresholdValue > gmax) {
197
+ fprintf(stderr,"# threshold: Value >gmax\n");
198
+ thresholdValue = gmax;
199
+ }
200
+ if (thresholdValue <= gmin) {
201
+ fprintf(stderr,"# threshold: Value<=gmin\n");
202
+ thresholdValue = gmin+1;
203
+ }
204
+
205
+ // debug code to display thresholding values
206
+ if ( vvv & 1 )
207
+ fprintf(stderr,"# threshold: Value = %d gmin=%d gmax=%d cmax=%d"
208
+ " b/w= %d %d\n",
209
+ thresholdValue, gmin, gmax, maxc, i1, i2);
210
+
211
+ // this is a primitive criteria for inversion and should be improved
212
+ // old: i1 >= 4*i2, but 0811qemu1.png has a bit above 1/4
213
+ if (2*i1 > 7*i2) { // more black than white, obviously black is background
214
+ if ( vvv & 1 )
215
+ fprintf(stderr,"# threshold: invert the image\n");
216
+ // we do inversion here (no data lost)
217
+ for (i = 0; i < dy ; i++) {
218
+ np = &image[(y0+i)*cols+x0];
219
+ for (j = 0; j < dx ; j++) {
220
+ *np=255-*np;
221
+ np++; /* next pixel */
222
+ }
223
+ }
224
+ thresholdValue=255-thresholdValue+1;
225
+ }
226
+
227
+ return(thresholdValue);
228
+ /* range: 0 < thresholdValue <= 255, example: 1 on b/w images */
229
+ /* 0..threshold-1 is foreground */
230
+ /* threshold..255 is background */
231
+ /* ToDo: min=blackmasscenter/2,thresh,max=(whitemasscenter+255)/2 */
232
+ }
233
+
234
+ /*======================================================================*/
235
+ /* thresholding the image (set threshold to 128+32=160=0xA0) */
236
+ /* now we have a fixed thresholdValue good to recognize on gray image */
237
+ /* - so lower bits can used for other things (bad design?) */
238
+ /* ToDo: different foreground colors, gray on black/white background */
239
+ /*======================================================================*/
240
+ int
241
+ thresholding (unsigned char *image, int rows, int cols,
242
+ int x0, int y0, int dx, int dy, int thresholdValue) {
243
+
244
+ unsigned char *np; // pointer to position in the image we are working with
245
+
246
+ int i, j; // various counters
247
+ int gmin=255,gmax=0;
248
+ int nmin=255,nmax=0;
249
+
250
+ // calculate min/max (twice?)
251
+ for (i = y0 + 1; i < y0 + dy - 1; i++) {
252
+ np = &image[i*cols+x0+1];
253
+ for (j = x0 + 1; j < x0 + dx - 1; j++) {
254
+ if(*np > gmax) gmax=*np;
255
+ if(*np < gmin) gmin=*np;
256
+ np++; /* next pixel */
257
+ }
258
+ }
259
+
260
+ /* allowed_threshold=gmin+1..gmax v0.43 */
261
+ if (thresholdValue<=gmin || thresholdValue>gmax){
262
+ thresholdValue=(gmin+gmax+1)/2; /* range=0..1 -> threshold=1 */
263
+ fprintf(stderr,"# thresholdValue out of range %d..%d, reset to %d\n",
264
+ gmin, gmax, thresholdValue);
265
+ }
266
+
267
+ /* b/w: min=0,tresh=1,max=1 v0.43 */
268
+ // actually performs the thresholding of the image...
269
+ // later: grayvalues should also be used, only rescaling threshold=160=0xA0
270
+ // sometimes images have no contrast (thresholdValue == gmin)
271
+ for (i = y0; i < y0+dy; i++) {
272
+ np = &image[i*cols+x0];
273
+ for (j = x0; j < x0+dx; j++) {
274
+ *np = (unsigned char) (*np >= thresholdValue || thresholdValue == gmin ?
275
+ (255-(gmax - *np)* 80/(gmax - thresholdValue + 1)) :
276
+ ( 0+(*np - gmin)*150/(thresholdValue - gmin )) );
277
+ if(*np > nmax) nmax=*np;
278
+ if(*np < nmin) nmin=*np;
279
+ np++;
280
+ }
281
+ }
282
+
283
+ // fprintf(stderr,"# thresholding: nmin=%d nmax=%d\n", nmin, nmax);
284
+
285
+ return(128+32); // return the new normalized threshold value
286
+ /* 0..159 is foreground */
287
+ /* 160..255 is background */
288
+ }
289
+
@@ -0,0 +1,23 @@
1
+ /*
2
+
3
+ see README for EMAIL-address
4
+
5
+ */
6
+
7
+
8
+ /*======================================================================*/
9
+ /* OTSU global thresholding routine */
10
+ /* takes a 2D unsigned char array pointer, number of rows, and */
11
+ /* number of cols in the array. returns the value of the threshold */
12
+ /*======================================================================*/
13
+ int
14
+ otsu (unsigned char *image, int rows, int cols, int x0, int y0, int dx, int dy, int vvv);
15
+
16
+
17
+ /*======================================================================*/
18
+ /* thresholding the image (set threshold to 128+32=160=0xA0) */
19
+ /* now we have a fixed thresholdValue good to recognize on gray image */
20
+ /* - so lower bits can used for other things (bad design?) */
21
+ /*======================================================================*/
22
+ int
23
+ thresholding (unsigned char *image, int rows, int cols, int x0, int y0, int dx, int dy, int thresholdValue);
@@ -0,0 +1,289 @@
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
+
22
+ #include <string.h>
23
+ #include "unicode.h"
24
+ #include "output.h"
25
+ #include "pcx.h"
26
+ #include "gocr.h" /* extern job_t JOB; */
27
+
28
+ /* function is only for debugging and for developing
29
+ it prints out a part of pixmap b at point x0,y0 to stderr
30
+ using dots .,; if no pixel, and @xoO for pixels
31
+ modify n_run and print out what would happen on 2nd, 3th loop!
32
+ new: output original and copied pixmap in the same figure
33
+ */
34
+ void out_b(struct box *px, pix *b, int x0, int y0, int dx, int dy, int cs ){
35
+ int x,y,x2,y2,yy0,tx,ty,n1,i;
36
+ char c1, c2;
37
+ yy0=y0;
38
+ if (px) { /* overwrite rest of arguments */
39
+ if (!b) {
40
+ b=px->p;
41
+ x0=px->x0; dx=px->x1-px->x0+1;
42
+ y0=px->y0; dy=px->y1-px->y0+1; yy0=y0;
43
+ }
44
+ if(cs==0) cs=JOB->cfg.cs;
45
+ fprintf(stderr,"\n# list box x= %4d %4d d= %3d %3d r= %3d %3d"
46
+ " nrun=%d p=%p", /* ToDo: r,nrun is obsolete */
47
+ px->x0, px->y0, px->x1 - px->x0 + 1, px->y1 - px->y0 + 1,
48
+ px->x - px->x0, px->y - px->y0, JOB->tmp.n_run, (void*)px);
49
+ fprintf(stderr,"\n# dots=%d boxes=%d subboxes=%d c=%s mod=%s"
50
+ " line=%d m= %d %d %d %d",
51
+ px->dots, px->num_boxes, px->num_subboxes,
52
+ decode(px->c,ASCII), decode(px->modifier,ASCII), px->line,
53
+ px->m1 - px->y0, px->m2 - px->y0, px->m3 - px->y0, px->m4 - px->y0);
54
+ if (px->num_frames) {
55
+ int i,j,jo;
56
+ fprintf(stderr,"\n# frames= %d (sumvects=%d)",px->num_frames,
57
+ ((px->num_frames)?px->num_frame_vectors[px->num_frames-1]:-1));
58
+ for (jo=j=i=0; i<px->num_frames; i++, jo=j) {
59
+ fprintf(stderr,"\n# frame %d (%+4d,%3d,%2d) ",
60
+ i, px->frame_vol[i], px->frame_per[i],
61
+ px->num_frame_vectors[i]-jo);
62
+ /* print only the first vectors of each frame */
63
+ for (;j<px->num_frame_vectors[i] && j<MaxFrameVectors; j++)
64
+ fprintf(stderr," #%02d %2d %2d", j,
65
+ px->frame_vector[j][0] - px->x0,
66
+ px->frame_vector[j][1] - px->y0);
67
+ }
68
+ }
69
+ if (px->num_ac){ /* output table of chars and its probabilities */
70
+ fprintf(stderr,"\n# list box char: ");
71
+ for(i=0;i<px->num_ac && i<NumAlt;i++)
72
+ /* output the (xml-)string (picture position, barcodes, glyphs, ...) */
73
+ if (px->tas[i])
74
+ fprintf(stderr," %s(%d)", px->tas[i] ,px->wac[i]);
75
+ else
76
+ fprintf(stderr," %s(%d)",decode(px->tac[i],ASCII),px->wac[i]);
77
+ }
78
+ fprintf(stderr,"\n");
79
+ if (px->m2 && px->m1<y0 && (px->dots || y0>px->m2)) {
80
+ yy0=px->m1; dy=px->y1-yy0+1;
81
+ }
82
+ }
83
+ tx=dx/80+1;
84
+ ty=dy/40+1; /* step, usually 1, but greater on large maps */
85
+ fprintf(stderr,"# list pattern x= %4d %4d d= %3d %3d t= %d %d yy0= %d\n",
86
+ x0,y0,dx,dy,tx,ty,yy0);
87
+ if (dx>0)
88
+ for(y=yy0;y<yy0+dy;y+=ty) { /* reduce the output to max 78x40 */
89
+ /* first image is the copied and modified bitmap of the box */
90
+ if (px)
91
+ for(x=x0;x<x0+dx;x+=tx){ /* by merging sub-pixels */
92
+ n1=0; c1='.';
93
+ for(y2=y;y2<y+ty && y2<y0+dy;y2++) /* sub-pixels */
94
+ for(x2=x;x2<x+tx && x2<x0+dx;x2++)
95
+ {
96
+ if((getpixel(px->p,x2-x0+px->x0,
97
+ y2-y0+px->y0)<cs)) c1='@';
98
+ }
99
+ if (px->num_frames) { /* mark vectors */
100
+ int i;
101
+ if (c1!='$' && c1!='S') /* dont mark twice */
102
+ for (i=0;i<px->num_frame_vectors[px->num_frames-1];i++)
103
+ if ((px->frame_vector[i][0]-px->x0)/tx==(x-x0)/tx
104
+ && (px->frame_vector[i][1]-px->y0)/ty==(y-y0)/ty)
105
+ { c1=((c1=='@')?'$':'S'); break; }
106
+ }
107
+ fprintf(stderr,"%c", c1 );
108
+ }
109
+
110
+ /* 2nd image is the boxframe in the original bitmap */
111
+ if (dx<40) fprintf(stderr," ");
112
+ if (dx<40) /* do it only, if we have enough place */
113
+ for(x=x0;x<x0+dx;x+=tx){ /* by merging sub-pixels */
114
+ c1='.';
115
+ for(y2=y;y2<y+ty && y2<y0+dy;y2++) /* sub-pixels */
116
+ for(x2=x;x2<x+tx && x2<x0+dx;x2++)
117
+ { if((getpixel(b,x2,y2)<cs)) c1='@'; }
118
+ fprintf(stderr,"%c", c1 );
119
+ }
120
+
121
+ c1=c2=' ';
122
+ /* mark lines with < */
123
+ if (px) if (y-y0+px->y0==px->m1 || y-y0+px->y0==px->m2
124
+ || y-y0+px->y0==px->m3 || y-y0+px->y0==px->m4) c1='<';
125
+ if (y==y0 || y==yy0+dy-1) c2='-'; /* boxmarks */
126
+
127
+ fprintf(stderr,"%c%c\n",c1,c2);
128
+ }
129
+ }
130
+
131
+ /* same as out_b, but for faster use, only a box as argument
132
+ */
133
+ void out_x(struct box *px) {
134
+ out_b(px,NULL,0, 0, 0, 0, JOB->cfg.cs);
135
+ }
136
+
137
+
138
+ /* print out two boxes side by side, for debugging comparision algos */
139
+ void out_x2(struct box *box1, struct box *box2){
140
+ int x,y,i,tx,ty,dy;
141
+ /*FIXME jb static*/static char *c1="OXXXXxx@.,,,,,,,";
142
+ pix *b=&JOB->src.p;
143
+ dy=(box1->y1-box1->y0+1);
144
+ if(dy<box2->y1-box2->y0+1)dy=box2->y1-box2->y0+1;
145
+ tx=(box1->x1-box1->x0)/40+1;
146
+ ty=(box1->y1-box1->y0)/40+1; /* step, usually 1, but greater on large maps */
147
+ if(box2)fprintf(stderr,"\n# list 2 patterns");
148
+ for(i=0;i<dy;i+=ty) { /* reduce the output to max 78x40??? */
149
+ fprintf(stderr,"\n"); y=box1->y0+i;
150
+ for(x=box1->x0;x<=box1->x1;x+=tx)
151
+ fprintf(stderr,"%c", c1[ ((getpixel(b,x,y)<JOB->cfg.cs)?0:8)+marked(b,x,y) ] );
152
+ if(!box2) continue;
153
+ fprintf(stderr," "); y=box2->y0+i;
154
+ for(x=box2->x0;x<=box2->x1;x+=tx)
155
+ fprintf(stderr,"%c", c1[ ((getpixel(b,x,y)<JOB->cfg.cs)?0:8)+marked(b,x,y) ] );
156
+ }
157
+ }
158
+
159
+
160
+ /* ---- list output ---- for debugging ---
161
+ * list all boxes where the results can be found within the c-option
162
+ */
163
+ int output_list(job_t *job) {
164
+ int i = 0, j;
165
+ struct box *box2;
166
+ pix *pp = &job->src.p;
167
+ char *lc = job->cfg.lc;
168
+
169
+ fprintf(stderr,"\n# list shape for charlist %s",lc);
170
+ for_each_data(&(JOB->res.boxlist)) {
171
+ box2 = (struct box *) list_get_current(&(JOB->res.boxlist));
172
+ for (j=0; j<box2->num_ac; j++)
173
+ if (!lc || (box2->tac[j] && strchr(lc, box2->tac[j]))
174
+ || (box2->tas[j] && strstr(lc, box2->tas[j]))) break;
175
+ if (j<box2->num_ac)
176
+ fprintf(stderr,"\n# box found in charlist");
177
+ if (!lc || (strchr(lc, box2->c) && box2->c < 256 && box2->c)
178
+ || (strchr(lc, '_') && box2->c==UNKNOWN) /* for compability */
179
+ || j<box2->num_ac ){ /* also list alternative chars */
180
+ if (!pp) pp=box2->p;
181
+ fprintf(stderr,
182
+ "\n# list shape %3d x=%4d %4d d= %3d %3d vf=%d ac=%d %04x %s",
183
+ i, box2->x0, box2->y0,
184
+ box2->x1 - box2->x0 + 1,
185
+ box2->y1 - box2->y0 + 1,
186
+ box2->num_frames, box2->num_ac,
187
+ (int)box2->c, /* wchar_t -> char ???? */
188
+ decode(box2->c,ASCII) );
189
+ if (JOB->cfg.verbose & 4) out_x(box2);
190
+ }
191
+ i++;
192
+ } end_for_each(&(JOB->res.boxlist));
193
+ fprintf(stderr,"\n");
194
+ return 0;
195
+ }
196
+
197
+ /* --- output of image incl. corored lines usefull for developers ---
198
+ * debugging
199
+ * bit 0+1 is used for color coding (optical marker)
200
+ * color/gray: 0x01=red, 0x02=blue, 0x04=green???
201
+ * opt: 1 - mark unknown boxes red (first pass)
202
+ * 2 - mark unknown boxes more red (final pass)
203
+ * 4 - mark lines blue
204
+ * 8 - reset coloring (remove old marker)
205
+ */
206
+ int debug_img(char *fname, struct job_s *job, int opt) {
207
+ struct box *box2;
208
+ int x, y, ic, dx, i, j, col;
209
+ unsigned char *np;
210
+ pix *pp = &job->tmp.ppo;
211
+
212
+ if ( opt & 8 ) { /* clear debug bits in image */
213
+ for(y=0;y<pp->y;y++) {
214
+ np=&pp->p[(pp->x)*y];
215
+ for(x=0;x<pp->x;x++) {
216
+ *np = *np & 0xF1;
217
+ np++;
218
+ }
219
+ }
220
+ }
221
+
222
+ /* mark longest line which was used to estimate the rotation angle */
223
+ if ((job->cfg.verbose&32) && job->res.lines.dx)
224
+ for(i=0;i<pp->x;i++) {
225
+ y=pp->y/2;
226
+ if (job->res.lines.dx) y+=job->res.lines.dy*i/job->res.lines.dx;
227
+ x=i;
228
+ if (x<0 || x>=pp->x || y<0 || y>=pp->y) continue;
229
+ np=&pp->p[x + (pp->x)*y];
230
+ if (*np<160) continue;
231
+ if((x&7)<5 && !(x&1)) /* dotted line */
232
+ put(pp,x,y,255,8);
233
+ }
234
+
235
+ ic = ((opt & 2) ? 1 : 2); /* obsolete */
236
+ for_each_data(&(job->res.boxlist)) {
237
+ box2 = (struct box *) list_get_current(&(job->res.boxlist));
238
+ /* mark boxes in 32=0x40=blue */
239
+ if (box2->c == ' ' || box2->c == '\n') continue;
240
+ /* mark chars with green left and under line */
241
+ col = 4; /* green */
242
+ if (box2->c == UNKNOWN && (opt & 3)) col=2; /* red */
243
+ if (box2->x0>1)
244
+ for (y = box2->y0; y <= box2->y1; y++) {
245
+ np=&pp->p[box2->x0-1 + y * pp->x]; if (*np<160) continue; *np|=col; }
246
+ if (box2->y1+1<pp->y)
247
+ for (x = box2->x0; x <= box2->x1; x++) {
248
+ np=&pp->p[x + (box2->y1+1) * pp->x]; if (*np<160) continue; *np|=col; }
249
+ /* mark pictures by green cross */
250
+ if (box2->c == PICTURE)
251
+ for (x = 0; x < box2->x1-box2->x0+1; x++){
252
+ y=(box2->y1-box2->y0+1)*x/(box2->x1-box2->x0+1);
253
+ pp->p[(box2->x0+x) + (box2->y0+y) * pp->x] |= 4;
254
+ pp->p[(box2->x1-x) + (box2->y0+y) * pp->x] |= 4;
255
+ }
256
+ } end_for_each(&(job->res.boxlist));
257
+
258
+ if( opt & 4 )
259
+ {
260
+ struct tlines *lines = &job->res.lines;
261
+ int yr;
262
+ if (job->cfg.verbose)
263
+ fprintf(stderr, "# mark lines for %s.ppm\n", fname);
264
+ /* or read from outside??? */
265
+ for (i = 0; i < lines->num; i++) { /* mark lines by 0x08 = blue */
266
+ dx = lines->x1[i] - lines->x0[i] + 1;
267
+ for (j = -1; j < dx+1; j++) {
268
+ x = lines->x0[i] + j;
269
+ if (x<0 || x>=pp->x) continue;
270
+ for (y=lines->m1[i];y<=lines->m4[i];y++) {
271
+ /* box arround m2-m3 */
272
+ if (y>=lines->m2[i] && y<=lines->m3[i] && j>-1 && j<dx) continue;
273
+ yr = y; /* y.rotated */
274
+ if (lines->dx) yr += lines->dy * x / (lines->dx);
275
+ if (yr<0 || yr>=pp->y) continue;
276
+ np = &(pp->p[x + (pp->x)*yr]);
277
+ if (*np<160) continue; /* do not touch dark pixels */
278
+ if ((*np&6)!=0) continue; /* only change white pixels */
279
+ put(pp, x, yr, 255, 6); /* UPN: 255 and 6 or */
280
+ }
281
+ }
282
+ }
283
+ }
284
+
285
+ if (job->cfg.verbose&1)
286
+ fprintf(stderr,"# writing %s.ppm\n", fname);
287
+ writeppm(fname, pp);
288
+ return 0;
289
+ }