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,500 @@
1
+ /*
2
+ * rdtarga.c
3
+ *
4
+ * Copyright (C) 1991-1996, Thomas G. Lane.
5
+ * This file is part of the Independent JPEG Group's software.
6
+ * For conditions of distribution and use, see the accompanying README file.
7
+ *
8
+ * This file contains routines to read input images in Targa format.
9
+ *
10
+ * These routines may need modification for non-Unix environments or
11
+ * specialized applications. As they stand, they assume input from
12
+ * an ordinary stdio stream. They further assume that reading begins
13
+ * at the start of the file; start_input may need work if the
14
+ * user interface has already read some data (e.g., to determine that
15
+ * the file is indeed Targa format).
16
+ *
17
+ * Based on code contributed by Lee Daniel Crocker.
18
+ */
19
+
20
+ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
21
+
22
+ #ifdef TARGA_SUPPORTED
23
+
24
+
25
+ /* Macros to deal with unsigned chars as efficiently as compiler allows */
26
+
27
+ #ifdef HAVE_UNSIGNED_CHAR
28
+ typedef unsigned char U_CHAR;
29
+ #define UCH(x) ((int) (x))
30
+ #else /* !HAVE_UNSIGNED_CHAR */
31
+ #ifdef CHAR_IS_UNSIGNED
32
+ typedef char U_CHAR;
33
+ #define UCH(x) ((int) (x))
34
+ #else
35
+ typedef char U_CHAR;
36
+ #define UCH(x) ((int) (x) & 0xFF)
37
+ #endif
38
+ #endif /* HAVE_UNSIGNED_CHAR */
39
+
40
+
41
+ #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
42
+
43
+
44
+ /* Private version of data source object */
45
+
46
+ typedef struct _tga_source_struct * tga_source_ptr;
47
+
48
+ typedef struct _tga_source_struct {
49
+ struct cjpeg_source_struct pub; /* public fields */
50
+
51
+ j_compress_ptr cinfo; /* back link saves passing separate parm */
52
+
53
+ JSAMPARRAY colormap; /* Targa colormap (converted to my format) */
54
+
55
+ jvirt_sarray_ptr whole_image; /* Needed if funny input row order */
56
+ JDIMENSION current_row; /* Current logical row number to read */
57
+
58
+ /* Pointer to routine to extract next Targa pixel from input file */
59
+ JMETHOD(void, read_pixel, (tga_source_ptr sinfo));
60
+
61
+ /* Result of read_pixel is delivered here: */
62
+ U_CHAR tga_pixel[4];
63
+
64
+ int pixel_size; /* Bytes per Targa pixel (1 to 4) */
65
+
66
+ /* State info for reading RLE-coded pixels; both counts must be init to 0 */
67
+ int block_count; /* # of pixels remaining in RLE block */
68
+ int dup_pixel_count; /* # of times to duplicate previous pixel */
69
+
70
+ /* This saves the correct pixel-row-expansion method for preload_image */
71
+ JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
72
+ cjpeg_source_ptr sinfo));
73
+ } tga_source_struct;
74
+
75
+
76
+ /* For expanding 5-bit pixel values to 8-bit with best rounding */
77
+
78
+ static const UINT8 c5to8bits[32] = {
79
+ 0, 8, 16, 25, 33, 41, 49, 58,
80
+ 66, 74, 82, 90, 99, 107, 115, 123,
81
+ 132, 140, 148, 156, 165, 173, 181, 189,
82
+ 197, 206, 214, 222, 230, 239, 247, 255
83
+ };
84
+
85
+
86
+
87
+ LOCAL(int)
88
+ read_byte (tga_source_ptr sinfo)
89
+ /* Read next byte from Targa file */
90
+ {
91
+ register FILE *infile = sinfo->pub.input_file;
92
+ register int c;
93
+
94
+ if ((c = getc(infile)) == EOF)
95
+ ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
96
+ return c;
97
+ }
98
+
99
+
100
+ LOCAL(void)
101
+ read_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize)
102
+ /* Read the colormap from a Targa file */
103
+ {
104
+ int i;
105
+
106
+ /* Presently only handles 24-bit BGR format */
107
+ if (mapentrysize != 24)
108
+ ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP);
109
+
110
+ for (i = 0; i < cmaplen; i++) {
111
+ sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
112
+ sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
113
+ sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
114
+ }
115
+ }
116
+
117
+
118
+ /*
119
+ * read_pixel methods: get a single pixel from Targa file into tga_pixel[]
120
+ */
121
+
122
+ METHODDEF(void)
123
+ read_non_rle_pixel (tga_source_ptr sinfo)
124
+ /* Read one Targa pixel from the input file; no RLE expansion */
125
+ {
126
+ register FILE *infile = sinfo->pub.input_file;
127
+ register int i;
128
+
129
+ for (i = 0; i < sinfo->pixel_size; i++) {
130
+ sinfo->tga_pixel[i] = (U_CHAR) getc(infile);
131
+ }
132
+ }
133
+
134
+
135
+ METHODDEF(void)
136
+ read_rle_pixel (tga_source_ptr sinfo)
137
+ /* Read one Targa pixel from the input file, expanding RLE data as needed */
138
+ {
139
+ register FILE *infile = sinfo->pub.input_file;
140
+ register int i;
141
+
142
+ /* Duplicate previously read pixel? */
143
+ if (sinfo->dup_pixel_count > 0) {
144
+ sinfo->dup_pixel_count--;
145
+ return;
146
+ }
147
+
148
+ /* Time to read RLE block header? */
149
+ if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */
150
+ i = read_byte(sinfo);
151
+ if (i & 0x80) { /* Start of duplicate-pixel block? */
152
+ sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */
153
+ sinfo->block_count = 0; /* then read new block header */
154
+ } else {
155
+ sinfo->block_count = i & 0x7F; /* number of pixels after this one */
156
+ }
157
+ }
158
+
159
+ /* Read next pixel */
160
+ for (i = 0; i < sinfo->pixel_size; i++) {
161
+ sinfo->tga_pixel[i] = (U_CHAR) getc(infile);
162
+ }
163
+ }
164
+
165
+
166
+ /*
167
+ * Read one row of pixels.
168
+ *
169
+ * We provide several different versions depending on input file format.
170
+ */
171
+
172
+
173
+ METHODDEF(JDIMENSION)
174
+ get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
175
+ /* This version is for reading 8-bit grayscale pixels */
176
+ {
177
+ tga_source_ptr source = (tga_source_ptr) sinfo;
178
+ register JSAMPROW ptr;
179
+ register JDIMENSION col;
180
+
181
+ ptr = source->pub.buffer[0];
182
+ for (col = cinfo->image_width; col > 0; col--) {
183
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
184
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
185
+ }
186
+ return 1;
187
+ }
188
+
189
+ METHODDEF(JDIMENSION)
190
+ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
191
+ /* This version is for reading 8-bit colormap indexes */
192
+ {
193
+ tga_source_ptr source = (tga_source_ptr) sinfo;
194
+ register int t;
195
+ register JSAMPROW ptr;
196
+ register JDIMENSION col;
197
+ register JSAMPARRAY colormap = source->colormap;
198
+
199
+ ptr = source->pub.buffer[0];
200
+ for (col = cinfo->image_width; col > 0; col--) {
201
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
202
+ t = UCH(source->tga_pixel[0]);
203
+ *ptr++ = colormap[0][t];
204
+ *ptr++ = colormap[1][t];
205
+ *ptr++ = colormap[2][t];
206
+ }
207
+ return 1;
208
+ }
209
+
210
+ METHODDEF(JDIMENSION)
211
+ get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
212
+ /* This version is for reading 16-bit pixels */
213
+ {
214
+ tga_source_ptr source = (tga_source_ptr) sinfo;
215
+ register int t;
216
+ register JSAMPROW ptr;
217
+ register JDIMENSION col;
218
+
219
+ ptr = source->pub.buffer[0];
220
+ for (col = cinfo->image_width; col > 0; col--) {
221
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
222
+ t = UCH(source->tga_pixel[0]);
223
+ t += UCH(source->tga_pixel[1]) << 8;
224
+ /* We expand 5 bit data to 8 bit sample width.
225
+ * The format of the 16-bit (LSB first) input word is
226
+ * xRRRRRGGGGGBBBBB
227
+ */
228
+ ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F];
229
+ t >>= 5;
230
+ ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F];
231
+ t >>= 5;
232
+ ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F];
233
+ ptr += 3;
234
+ }
235
+ return 1;
236
+ }
237
+
238
+ METHODDEF(JDIMENSION)
239
+ get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
240
+ /* This version is for reading 24-bit pixels */
241
+ {
242
+ tga_source_ptr source = (tga_source_ptr) sinfo;
243
+ register JSAMPROW ptr;
244
+ register JDIMENSION col;
245
+
246
+ ptr = source->pub.buffer[0];
247
+ for (col = cinfo->image_width; col > 0; col--) {
248
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
249
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */
250
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]);
251
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
252
+ }
253
+ return 1;
254
+ }
255
+
256
+ /*
257
+ * Targa also defines a 32-bit pixel format with order B,G,R,A.
258
+ * We presently ignore the attribute byte, so the code for reading
259
+ * these pixels is identical to the 24-bit routine above.
260
+ * This works because the actual pixel length is only known to read_pixel.
261
+ */
262
+
263
+ #define get_32bit_row get_24bit_row
264
+
265
+
266
+ /*
267
+ * This method is for re-reading the input data in standard top-down
268
+ * row order. The entire image has already been read into whole_image
269
+ * with proper conversion of pixel format, but it's in a funny row order.
270
+ */
271
+
272
+ METHODDEF(JDIMENSION)
273
+ get_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
274
+ {
275
+ tga_source_ptr source = (tga_source_ptr) sinfo;
276
+ JDIMENSION source_row;
277
+
278
+ /* Compute row of source that maps to current_row of normal order */
279
+ /* For now, assume image is bottom-up and not interlaced. */
280
+ /* NEEDS WORK to support interlaced images! */
281
+ source_row = cinfo->image_height - source->current_row - 1;
282
+
283
+ /* Fetch that row from virtual array */
284
+ source->pub.buffer = (*cinfo->mem->access_virt_sarray)
285
+ ((j_common_ptr) cinfo, source->whole_image,
286
+ source_row, (JDIMENSION) 1, FALSE);
287
+
288
+ source->current_row++;
289
+ return 1;
290
+ }
291
+
292
+
293
+ /*
294
+ * This method loads the image into whole_image during the first call on
295
+ * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
296
+ * get_memory_row on subsequent calls.
297
+ */
298
+
299
+ METHODDEF(JDIMENSION)
300
+ preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
301
+ {
302
+ tga_source_ptr source = (tga_source_ptr) sinfo;
303
+ JDIMENSION row;
304
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
305
+
306
+ /* Read the data into a virtual array in input-file row order. */
307
+ for (row = 0; row < cinfo->image_height; row++) {
308
+ if (progress != NULL) {
309
+ progress->pub.pass_counter = (long) row;
310
+ progress->pub.pass_limit = (long) cinfo->image_height;
311
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
312
+ }
313
+ source->pub.buffer = (*cinfo->mem->access_virt_sarray)
314
+ ((j_common_ptr) cinfo, source->whole_image, row, (JDIMENSION) 1, TRUE);
315
+ (*source->get_pixel_rows) (cinfo, sinfo);
316
+ }
317
+ if (progress != NULL)
318
+ progress->completed_extra_passes++;
319
+
320
+ /* Set up to read from the virtual array in unscrambled order */
321
+ source->pub.get_pixel_rows = get_memory_row;
322
+ source->current_row = 0;
323
+ /* And read the first row */
324
+ return get_memory_row(cinfo, sinfo);
325
+ }
326
+
327
+
328
+ /*
329
+ * Read the file header; return image size and component count.
330
+ */
331
+
332
+ METHODDEF(void)
333
+ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
334
+ {
335
+ tga_source_ptr source = (tga_source_ptr) sinfo;
336
+ U_CHAR targaheader[18];
337
+ int idlen, cmaptype, subtype, flags, interlace_type, components;
338
+ unsigned int width, height, maplen;
339
+ boolean is_bottom_up;
340
+
341
+ #define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \
342
+ (((unsigned int) UCH(targaheader[offset+1])) << 8))
343
+
344
+ if (! ReadOK(source->pub.input_file, targaheader, 18))
345
+ ERREXIT(cinfo, JERR_INPUT_EOF);
346
+
347
+ /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */
348
+ if (targaheader[16] == 15)
349
+ targaheader[16] = 16;
350
+
351
+ idlen = UCH(targaheader[0]);
352
+ cmaptype = UCH(targaheader[1]);
353
+ subtype = UCH(targaheader[2]);
354
+ maplen = GET_2B(5);
355
+ width = GET_2B(12);
356
+ height = GET_2B(14);
357
+ source->pixel_size = UCH(targaheader[16]) >> 3;
358
+ flags = UCH(targaheader[17]); /* Image Descriptor byte */
359
+
360
+ is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */
361
+ interlace_type = flags >> 6; /* bits 6/7 are interlace code */
362
+
363
+ if (cmaptype > 1 || /* cmaptype must be 0 or 1 */
364
+ source->pixel_size < 1 || source->pixel_size > 4 ||
365
+ (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */
366
+ interlace_type != 0) /* currently don't allow interlaced image */
367
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
368
+
369
+ if (subtype > 8) {
370
+ /* It's an RLE-coded file */
371
+ source->read_pixel = read_rle_pixel;
372
+ source->block_count = source->dup_pixel_count = 0;
373
+ subtype -= 8;
374
+ } else {
375
+ /* Non-RLE file */
376
+ source->read_pixel = read_non_rle_pixel;
377
+ }
378
+
379
+ /* Now should have subtype 1, 2, or 3 */
380
+ components = 3; /* until proven different */
381
+ cinfo->in_color_space = JCS_RGB;
382
+
383
+ switch (subtype) {
384
+ case 1: /* Colormapped image */
385
+ if (source->pixel_size == 1 && cmaptype == 1)
386
+ source->get_pixel_rows = get_8bit_row;
387
+ else
388
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
389
+ TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);
390
+ break;
391
+ case 2: /* RGB image */
392
+ switch (source->pixel_size) {
393
+ case 2:
394
+ source->get_pixel_rows = get_16bit_row;
395
+ break;
396
+ case 3:
397
+ source->get_pixel_rows = get_24bit_row;
398
+ break;
399
+ case 4:
400
+ source->get_pixel_rows = get_32bit_row;
401
+ break;
402
+ default:
403
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
404
+ break;
405
+ }
406
+ TRACEMS2(cinfo, 1, JTRC_TGA, width, height);
407
+ break;
408
+ case 3: /* Grayscale image */
409
+ components = 1;
410
+ cinfo->in_color_space = JCS_GRAYSCALE;
411
+ if (source->pixel_size == 1)
412
+ source->get_pixel_rows = get_8bit_gray_row;
413
+ else
414
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
415
+ TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height);
416
+ break;
417
+ default:
418
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
419
+ break;
420
+ }
421
+
422
+ if (is_bottom_up) {
423
+ /* Create a virtual array to buffer the upside-down image. */
424
+ source->whole_image = (*cinfo->mem->request_virt_sarray)
425
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
426
+ (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1);
427
+ if (cinfo->progress != NULL) {
428
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
429
+ progress->total_extra_passes++; /* count file input as separate pass */
430
+ }
431
+ /* source->pub.buffer will point to the virtual array. */
432
+ source->pub.buffer_height = 1; /* in case anyone looks at it */
433
+ source->pub.get_pixel_rows = preload_image;
434
+ } else {
435
+ /* Don't need a virtual array, but do need a one-row input buffer. */
436
+ source->whole_image = NULL;
437
+ source->pub.buffer = (*cinfo->mem->alloc_sarray)
438
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
439
+ (JDIMENSION) width * components, (JDIMENSION) 1);
440
+ source->pub.buffer_height = 1;
441
+ source->pub.get_pixel_rows = source->get_pixel_rows;
442
+ }
443
+
444
+ while (idlen--) /* Throw away ID field */
445
+ (void) read_byte(source);
446
+
447
+ if (maplen > 0) {
448
+ if (maplen > 256 || GET_2B(3) != 0)
449
+ ERREXIT(cinfo, JERR_TGA_BADCMAP);
450
+ /* Allocate space to store the colormap */
451
+ source->colormap = (*cinfo->mem->alloc_sarray)
452
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3);
453
+ /* and read it from the file */
454
+ read_colormap(source, (int) maplen, UCH(targaheader[7]));
455
+ } else {
456
+ if (cmaptype) /* but you promised a cmap! */
457
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
458
+ source->colormap = NULL;
459
+ }
460
+
461
+ cinfo->input_components = components;
462
+ cinfo->data_precision = 8;
463
+ cinfo->image_width = width;
464
+ cinfo->image_height = height;
465
+ }
466
+
467
+
468
+ /*
469
+ * Finish up at the end of the file.
470
+ */
471
+
472
+ METHODDEF(void)
473
+ finish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
474
+ {
475
+ /* no work */
476
+ }
477
+
478
+
479
+ /*
480
+ * The module selection routine for Targa format input.
481
+ */
482
+
483
+ GLOBAL(cjpeg_source_ptr)
484
+ jinit_read_targa (j_compress_ptr cinfo)
485
+ {
486
+ tga_source_ptr source;
487
+
488
+ /* Create module interface object */
489
+ source = (tga_source_ptr)
490
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
491
+ SIZEOF(tga_source_struct));
492
+ source->cinfo = cinfo; /* make back link for subroutines */
493
+ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
494
+ source->pub.start_input = start_input_tga;
495
+ source->pub.finish_input = finish_input_tga;
496
+
497
+ return (cjpeg_source_ptr) source;
498
+ }
499
+
500
+ #endif /* TARGA_SUPPORTED */