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,387 @@
1
+ /*
2
+ * rdrle.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 Utah RLE format.
9
+ * The Utah Raster Toolkit library is required (version 3.1 or later).
10
+ *
11
+ * These routines may need modification for non-Unix environments or
12
+ * specialized applications. As they stand, they assume input from
13
+ * an ordinary stdio stream. They further assume that reading begins
14
+ * at the start of the file; start_input may need work if the
15
+ * user interface has already read some data (e.g., to determine that
16
+ * the file is indeed RLE format).
17
+ *
18
+ * Based on code contributed by Mike Lijewski,
19
+ * with updates from Robert Hutchinson.
20
+ */
21
+
22
+ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
23
+
24
+ #ifdef RLE_SUPPORTED
25
+
26
+ /* rle.h is provided by the Utah Raster Toolkit. */
27
+
28
+ #include <rle.h>
29
+
30
+ /*
31
+ * We assume that JSAMPLE has the same representation as rle_pixel,
32
+ * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples.
33
+ */
34
+
35
+ #if BITS_IN_JSAMPLE != 8
36
+ Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
37
+ #endif
38
+
39
+ /*
40
+ * We support the following types of RLE files:
41
+ *
42
+ * GRAYSCALE - 8 bits, no colormap
43
+ * MAPPEDGRAY - 8 bits, 1 channel colomap
44
+ * PSEUDOCOLOR - 8 bits, 3 channel colormap
45
+ * TRUECOLOR - 24 bits, 3 channel colormap
46
+ * DIRECTCOLOR - 24 bits, no colormap
47
+ *
48
+ * For now, we ignore any alpha channel in the image.
49
+ */
50
+
51
+ typedef enum
52
+ { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;
53
+
54
+
55
+ /*
56
+ * Since RLE stores scanlines bottom-to-top, we have to invert the image
57
+ * to conform to JPEG's top-to-bottom order. To do this, we read the
58
+ * incoming image into a virtual array on the first get_pixel_rows call,
59
+ * then fetch the required row from the virtual array on subsequent calls.
60
+ */
61
+
62
+ typedef struct _rle_source_struct * rle_source_ptr;
63
+
64
+ typedef struct _rle_source_struct {
65
+ struct cjpeg_source_struct pub; /* public fields */
66
+
67
+ rle_kind visual; /* actual type of input file */
68
+ jvirt_sarray_ptr image; /* virtual array to hold the image */
69
+ JDIMENSION row; /* current row # in the virtual array */
70
+ rle_hdr header; /* Input file information */
71
+ rle_pixel** rle_row; /* holds a row returned by rle_getrow() */
72
+
73
+ } rle_source_struct;
74
+
75
+
76
+ /*
77
+ * Read the file header; return image size and component count.
78
+ */
79
+
80
+ METHODDEF(void)
81
+ start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
82
+ {
83
+ rle_source_ptr source = (rle_source_ptr) sinfo;
84
+ JDIMENSION width, height;
85
+ #ifdef PROGRESS_REPORT
86
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
87
+ #endif
88
+
89
+ /* Use RLE library routine to get the header info */
90
+ source->header = *rle_hdr_init(NULL);
91
+ source->header.rle_file = source->pub.input_file;
92
+ switch (rle_get_setup(&(source->header))) {
93
+ case RLE_SUCCESS:
94
+ /* A-OK */
95
+ break;
96
+ case RLE_NOT_RLE:
97
+ ERREXIT(cinfo, JERR_RLE_NOT);
98
+ break;
99
+ case RLE_NO_SPACE:
100
+ ERREXIT(cinfo, JERR_RLE_MEM);
101
+ break;
102
+ case RLE_EMPTY:
103
+ ERREXIT(cinfo, JERR_RLE_EMPTY);
104
+ break;
105
+ case RLE_EOF:
106
+ ERREXIT(cinfo, JERR_RLE_EOF);
107
+ break;
108
+ default:
109
+ ERREXIT(cinfo, JERR_RLE_BADERROR);
110
+ break;
111
+ }
112
+
113
+ /* Figure out what we have, set private vars and return values accordingly */
114
+
115
+ width = source->header.xmax - source->header.xmin + 1;
116
+ height = source->header.ymax - source->header.ymin + 1;
117
+ source->header.xmin = 0; /* realign horizontally */
118
+ source->header.xmax = width-1;
119
+
120
+ cinfo->image_width = width;
121
+ cinfo->image_height = height;
122
+ cinfo->data_precision = 8; /* we can only handle 8 bit data */
123
+
124
+ if (source->header.ncolors == 1 && source->header.ncmap == 0) {
125
+ source->visual = GRAYSCALE;
126
+ TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height);
127
+ } else if (source->header.ncolors == 1 && source->header.ncmap == 1) {
128
+ source->visual = MAPPEDGRAY;
129
+ TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height,
130
+ 1 << source->header.cmaplen);
131
+ } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
132
+ source->visual = PSEUDOCOLOR;
133
+ TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
134
+ 1 << source->header.cmaplen);
135
+ } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
136
+ source->visual = TRUECOLOR;
137
+ TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
138
+ 1 << source->header.cmaplen);
139
+ } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
140
+ source->visual = DIRECTCOLOR;
141
+ TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
142
+ } else
143
+ ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);
144
+
145
+ if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {
146
+ cinfo->in_color_space = JCS_GRAYSCALE;
147
+ cinfo->input_components = 1;
148
+ } else {
149
+ cinfo->in_color_space = JCS_RGB;
150
+ cinfo->input_components = 3;
151
+ }
152
+
153
+ /*
154
+ * A place to hold each scanline while it's converted.
155
+ * (GRAYSCALE scanlines don't need converting)
156
+ */
157
+ if (source->visual != GRAYSCALE) {
158
+ source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray)
159
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
160
+ (JDIMENSION) width, (JDIMENSION) cinfo->input_components);
161
+ }
162
+
163
+ /* request a virtual array to hold the image */
164
+ source->image = (*cinfo->mem->request_virt_sarray)
165
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
166
+ (JDIMENSION) (width * source->header.ncolors),
167
+ (JDIMENSION) height, (JDIMENSION) 1);
168
+
169
+ #ifdef PROGRESS_REPORT
170
+ if (progress != NULL) {
171
+ /* count file input as separate pass */
172
+ progress->total_extra_passes++;
173
+ }
174
+ #endif
175
+
176
+ source->pub.buffer_height = 1;
177
+ }
178
+
179
+
180
+ /*
181
+ * Read one row of pixels.
182
+ * Called only after load_image has read the image into the virtual array.
183
+ * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images.
184
+ */
185
+
186
+ METHODDEF(JDIMENSION)
187
+ get_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
188
+ {
189
+ rle_source_ptr source = (rle_source_ptr) sinfo;
190
+
191
+ source->row--;
192
+ source->pub.buffer = (*cinfo->mem->access_virt_sarray)
193
+ ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
194
+
195
+ return 1;
196
+ }
197
+
198
+ /*
199
+ * Read one row of pixels.
200
+ * Called only after load_image has read the image into the virtual array.
201
+ * Used for PSEUDOCOLOR images.
202
+ */
203
+
204
+ METHODDEF(JDIMENSION)
205
+ get_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
206
+ {
207
+ rle_source_ptr source = (rle_source_ptr) sinfo;
208
+ JSAMPROW src_row, dest_row;
209
+ JDIMENSION col;
210
+ rle_map *colormap;
211
+ int val;
212
+
213
+ colormap = source->header.cmap;
214
+ dest_row = source->pub.buffer[0];
215
+ source->row--;
216
+ src_row = * (*cinfo->mem->access_virt_sarray)
217
+ ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
218
+
219
+ for (col = cinfo->image_width; col > 0; col--) {
220
+ val = GETJSAMPLE(*src_row++);
221
+ *dest_row++ = (JSAMPLE) (colormap[val ] >> 8);
222
+ *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8);
223
+ *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8);
224
+ }
225
+
226
+ return 1;
227
+ }
228
+
229
+
230
+ /*
231
+ * Load the image into a virtual array. We have to do this because RLE
232
+ * files start at the lower left while the JPEG standard has them starting
233
+ * in the upper left. This is called the first time we want to get a row
234
+ * of input. What we do is load the RLE data into the array and then call
235
+ * the appropriate routine to read one row from the array. Before returning,
236
+ * we set source->pub.get_pixel_rows so that subsequent calls go straight to
237
+ * the appropriate row-reading routine.
238
+ */
239
+
240
+ METHODDEF(JDIMENSION)
241
+ load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
242
+ {
243
+ rle_source_ptr source = (rle_source_ptr) sinfo;
244
+ JDIMENSION row, col;
245
+ JSAMPROW scanline, red_ptr, green_ptr, blue_ptr;
246
+ rle_pixel **rle_row;
247
+ rle_map *colormap;
248
+ char channel;
249
+ #ifdef PROGRESS_REPORT
250
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
251
+ #endif
252
+
253
+ colormap = source->header.cmap;
254
+ rle_row = source->rle_row;
255
+
256
+ /* Read the RLE data into our virtual array.
257
+ * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
258
+ * and (b) we are not on a machine where FAR pointers differ from regular.
259
+ */
260
+ RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */
261
+
262
+ #ifdef PROGRESS_REPORT
263
+ if (progress != NULL) {
264
+ progress->pub.pass_limit = cinfo->image_height;
265
+ progress->pub.pass_counter = 0;
266
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
267
+ }
268
+ #endif
269
+
270
+ switch (source->visual) {
271
+
272
+ case GRAYSCALE:
273
+ case PSEUDOCOLOR:
274
+ for (row = 0; row < cinfo->image_height; row++) {
275
+ rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
276
+ ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
277
+ rle_getrow(&source->header, rle_row);
278
+ #ifdef PROGRESS_REPORT
279
+ if (progress != NULL) {
280
+ progress->pub.pass_counter++;
281
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
282
+ }
283
+ #endif
284
+ }
285
+ break;
286
+
287
+ case MAPPEDGRAY:
288
+ case TRUECOLOR:
289
+ for (row = 0; row < cinfo->image_height; row++) {
290
+ scanline = * (*cinfo->mem->access_virt_sarray)
291
+ ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
292
+ rle_row = source->rle_row;
293
+ rle_getrow(&source->header, rle_row);
294
+
295
+ for (col = 0; col < cinfo->image_width; col++) {
296
+ for (channel = 0; channel < source->header.ncolors; channel++) {
297
+ *scanline++ = (JSAMPLE)
298
+ (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8);
299
+ }
300
+ }
301
+
302
+ #ifdef PROGRESS_REPORT
303
+ if (progress != NULL) {
304
+ progress->pub.pass_counter++;
305
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
306
+ }
307
+ #endif
308
+ }
309
+ break;
310
+
311
+ case DIRECTCOLOR:
312
+ for (row = 0; row < cinfo->image_height; row++) {
313
+ scanline = * (*cinfo->mem->access_virt_sarray)
314
+ ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
315
+ rle_getrow(&source->header, rle_row);
316
+
317
+ red_ptr = rle_row[0];
318
+ green_ptr = rle_row[1];
319
+ blue_ptr = rle_row[2];
320
+
321
+ for (col = cinfo->image_width; col > 0; col--) {
322
+ *scanline++ = *red_ptr++;
323
+ *scanline++ = *green_ptr++;
324
+ *scanline++ = *blue_ptr++;
325
+ }
326
+
327
+ #ifdef PROGRESS_REPORT
328
+ if (progress != NULL) {
329
+ progress->pub.pass_counter++;
330
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
331
+ }
332
+ #endif
333
+ }
334
+ }
335
+
336
+ #ifdef PROGRESS_REPORT
337
+ if (progress != NULL)
338
+ progress->completed_extra_passes++;
339
+ #endif
340
+
341
+ /* Set up to call proper row-extraction routine in future */
342
+ if (source->visual == PSEUDOCOLOR) {
343
+ source->pub.buffer = source->rle_row;
344
+ source->pub.get_pixel_rows = get_pseudocolor_row;
345
+ } else {
346
+ source->pub.get_pixel_rows = get_rle_row;
347
+ }
348
+ source->row = cinfo->image_height;
349
+
350
+ /* And fetch the topmost (bottommost) row */
351
+ return (*source->pub.get_pixel_rows) (cinfo, sinfo);
352
+ }
353
+
354
+
355
+ /*
356
+ * Finish up at the end of the file.
357
+ */
358
+
359
+ METHODDEF(void)
360
+ finish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
361
+ {
362
+ /* no work */
363
+ }
364
+
365
+
366
+ /*
367
+ * The module selection routine for RLE format input.
368
+ */
369
+
370
+ GLOBAL(cjpeg_source_ptr)
371
+ jinit_read_rle (j_compress_ptr cinfo)
372
+ {
373
+ rle_source_ptr source;
374
+
375
+ /* Create module interface object */
376
+ source = (rle_source_ptr)
377
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
378
+ SIZEOF(rle_source_struct));
379
+ /* Fill in method ptrs */
380
+ source->pub.start_input = start_input_rle;
381
+ source->pub.finish_input = finish_input_rle;
382
+ source->pub.get_pixel_rows = load_image;
383
+
384
+ return (cjpeg_source_ptr) source;
385
+ }
386
+
387
+ #endif /* RLE_SUPPORTED */
@@ -0,0 +1,365 @@
1
+ /*
2
+ * rdswitch.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 process some of cjpeg's more complicated
9
+ * command-line switches. Switches processed here are:
10
+ * -qtables file Read quantization tables from text file
11
+ * -scans file Read scan script from text file
12
+ * -quality N[,N,...] Set quality ratings
13
+ * -qslots N[,N,...] Set component quantization table selectors
14
+ * -sample HxV[,HxV,...] Set component sampling factors
15
+ */
16
+
17
+ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
18
+ #include <ctype.h> /* to declare isdigit(), isspace() */
19
+
20
+
21
+ LOCAL(int)
22
+ text_getc (FILE * file)
23
+ /* Read next char, skipping over any comments (# to end of line) */
24
+ /* A comment/newline sequence is returned as a newline */
25
+ {
26
+ register int ch;
27
+
28
+ ch = getc(file);
29
+ if (ch == '#') {
30
+ do {
31
+ ch = getc(file);
32
+ } while (ch != '\n' && ch != EOF);
33
+ }
34
+ return ch;
35
+ }
36
+
37
+
38
+ LOCAL(boolean)
39
+ read_text_integer (FILE * file, long * result, int * termchar)
40
+ /* Read an unsigned decimal integer from a file, store it in result */
41
+ /* Reads one trailing character after the integer; returns it in termchar */
42
+ {
43
+ register int ch;
44
+ register long val;
45
+
46
+ /* Skip any leading whitespace, detect EOF */
47
+ do {
48
+ ch = text_getc(file);
49
+ if (ch == EOF) {
50
+ *termchar = ch;
51
+ return FALSE;
52
+ }
53
+ } while (isspace(ch));
54
+
55
+ if (! isdigit(ch)) {
56
+ *termchar = ch;
57
+ return FALSE;
58
+ }
59
+
60
+ val = ch - '0';
61
+ while ((ch = text_getc(file)) != EOF) {
62
+ if (! isdigit(ch))
63
+ break;
64
+ val *= 10;
65
+ val += ch - '0';
66
+ }
67
+ *result = val;
68
+ *termchar = ch;
69
+ return TRUE;
70
+ }
71
+
72
+
73
+ GLOBAL(boolean)
74
+ read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline)
75
+ /* Read a set of quantization tables from the specified file.
76
+ * The file is plain ASCII text: decimal numbers with whitespace between.
77
+ * Comments preceded by '#' may be included in the file.
78
+ * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
79
+ * The tables are implicitly numbered 0,1,etc.
80
+ * NOTE: does not affect the qslots mapping, which will default to selecting
81
+ * table 0 for luminance (or primary) components, 1 for chrominance components.
82
+ * You must use -qslots if you want a different component->table mapping.
83
+ */
84
+ {
85
+ FILE * fp;
86
+ int tblno, i, termchar;
87
+ long val;
88
+ unsigned int table[DCTSIZE2];
89
+
90
+ if ((fp = fopen(filename, "r")) == NULL) {
91
+ fprintf(stderr, "Can't open table file %s\n", filename);
92
+ return FALSE;
93
+ }
94
+ tblno = 0;
95
+
96
+ while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
97
+ if (tblno >= NUM_QUANT_TBLS) {
98
+ fprintf(stderr, "Too many tables in file %s\n", filename);
99
+ fclose(fp);
100
+ return FALSE;
101
+ }
102
+ table[0] = (unsigned int) val;
103
+ for (i = 1; i < DCTSIZE2; i++) {
104
+ if (! read_text_integer(fp, &val, &termchar)) {
105
+ fprintf(stderr, "Invalid table data in file %s\n", filename);
106
+ fclose(fp);
107
+ return FALSE;
108
+ }
109
+ table[i] = (unsigned int) val;
110
+ }
111
+ jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],
112
+ force_baseline);
113
+ tblno++;
114
+ }
115
+
116
+ if (termchar != EOF) {
117
+ fprintf(stderr, "Non-numeric data in file %s\n", filename);
118
+ fclose(fp);
119
+ return FALSE;
120
+ }
121
+
122
+ fclose(fp);
123
+ return TRUE;
124
+ }
125
+
126
+
127
+ #ifdef C_MULTISCAN_FILES_SUPPORTED
128
+
129
+ LOCAL(boolean)
130
+ read_scan_integer (FILE * file, long * result, int * termchar)
131
+ /* Variant of read_text_integer that always looks for a non-space termchar;
132
+ * this simplifies parsing of punctuation in scan scripts.
133
+ */
134
+ {
135
+ register int ch;
136
+
137
+ if (! read_text_integer(file, result, termchar))
138
+ return FALSE;
139
+ ch = *termchar;
140
+ while (ch != EOF && isspace(ch))
141
+ ch = text_getc(file);
142
+ if (isdigit(ch)) { /* oops, put it back */
143
+ if (ungetc(ch, file) == EOF)
144
+ return FALSE;
145
+ ch = ' ';
146
+ } else {
147
+ /* Any separators other than ';' and ':' are ignored;
148
+ * this allows user to insert commas, etc, if desired.
149
+ */
150
+ if (ch != EOF && ch != ';' && ch != ':')
151
+ ch = ' ';
152
+ }
153
+ *termchar = ch;
154
+ return TRUE;
155
+ }
156
+
157
+
158
+ GLOBAL(boolean)
159
+ read_scan_script (j_compress_ptr cinfo, char * filename)
160
+ /* Read a scan script from the specified text file.
161
+ * Each entry in the file defines one scan to be emitted.
162
+ * Entries are separated by semicolons ';'.
163
+ * An entry contains one to four component indexes,
164
+ * optionally followed by a colon ':' and four progressive-JPEG parameters.
165
+ * The component indexes denote which component(s) are to be transmitted
166
+ * in the current scan. The first component has index 0.
167
+ * Sequential JPEG is used if the progressive-JPEG parameters are omitted.
168
+ * The file is free format text: any whitespace may appear between numbers
169
+ * and the ':' and ';' punctuation marks. Also, other punctuation (such
170
+ * as commas or dashes) can be placed between numbers if desired.
171
+ * Comments preceded by '#' may be included in the file.
172
+ * Note: we do very little validity checking here;
173
+ * jcmaster.c will validate the script parameters.
174
+ */
175
+ {
176
+ FILE * fp;
177
+ int scanno, ncomps, termchar;
178
+ long val;
179
+ jpeg_scan_info * scanptr;
180
+ #define MAX_SCANS 100 /* quite arbitrary limit */
181
+ jpeg_scan_info scans[MAX_SCANS];
182
+
183
+ if ((fp = fopen(filename, "r")) == NULL) {
184
+ fprintf(stderr, "Can't open scan definition file %s\n", filename);
185
+ return FALSE;
186
+ }
187
+ scanptr = scans;
188
+ scanno = 0;
189
+
190
+ while (read_scan_integer(fp, &val, &termchar)) {
191
+ if (scanno >= MAX_SCANS) {
192
+ fprintf(stderr, "Too many scans defined in file %s\n", filename);
193
+ fclose(fp);
194
+ return FALSE;
195
+ }
196
+ scanptr->component_index[0] = (int) val;
197
+ ncomps = 1;
198
+ while (termchar == ' ') {
199
+ if (ncomps >= MAX_COMPS_IN_SCAN) {
200
+ fprintf(stderr, "Too many components in one scan in file %s\n",
201
+ filename);
202
+ fclose(fp);
203
+ return FALSE;
204
+ }
205
+ if (! read_scan_integer(fp, &val, &termchar))
206
+ goto bogus;
207
+ scanptr->component_index[ncomps] = (int) val;
208
+ ncomps++;
209
+ }
210
+ scanptr->comps_in_scan = ncomps;
211
+ if (termchar == ':') {
212
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
213
+ goto bogus;
214
+ scanptr->Ss = (int) val;
215
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
216
+ goto bogus;
217
+ scanptr->Se = (int) val;
218
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
219
+ goto bogus;
220
+ scanptr->Ah = (int) val;
221
+ if (! read_scan_integer(fp, &val, &termchar))
222
+ goto bogus;
223
+ scanptr->Al = (int) val;
224
+ } else {
225
+ /* set non-progressive parameters */
226
+ scanptr->Ss = 0;
227
+ scanptr->Se = DCTSIZE2-1;
228
+ scanptr->Ah = 0;
229
+ scanptr->Al = 0;
230
+ }
231
+ if (termchar != ';' && termchar != EOF) {
232
+ bogus:
233
+ fprintf(stderr, "Invalid scan entry format in file %s\n", filename);
234
+ fclose(fp);
235
+ return FALSE;
236
+ }
237
+ scanptr++, scanno++;
238
+ }
239
+
240
+ if (termchar != EOF) {
241
+ fprintf(stderr, "Non-numeric data in file %s\n", filename);
242
+ fclose(fp);
243
+ return FALSE;
244
+ }
245
+
246
+ if (scanno > 0) {
247
+ /* Stash completed scan list in cinfo structure.
248
+ * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data,
249
+ * but if you want to compress multiple images you'd want JPOOL_PERMANENT.
250
+ */
251
+ scanptr = (jpeg_scan_info *)
252
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
253
+ scanno * SIZEOF(jpeg_scan_info));
254
+ MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info));
255
+ cinfo->scan_info = scanptr;
256
+ cinfo->num_scans = scanno;
257
+ }
258
+
259
+ fclose(fp);
260
+ return TRUE;
261
+ }
262
+
263
+ #endif /* C_MULTISCAN_FILES_SUPPORTED */
264
+
265
+
266
+ GLOBAL(boolean)
267
+ set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
268
+ /* Process a quality-ratings parameter string, of the form
269
+ * N[,N,...]
270
+ * If there are more q-table slots than parameters, the last value is replicated.
271
+ */
272
+ {
273
+ int val = 75; /* default value */
274
+ int tblno;
275
+ char ch;
276
+
277
+ for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
278
+ if (*arg) {
279
+ ch = ','; /* if not set by sscanf, will be ',' */
280
+ if (sscanf(arg, "%d%c", &val, &ch) < 1)
281
+ return FALSE;
282
+ if (ch != ',') /* syntax check */
283
+ return FALSE;
284
+ /* Convert user 0-100 rating to percentage scaling */
285
+ cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
286
+ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
287
+ ;
288
+ } else {
289
+ /* reached end of parameter, set remaining factors to last value */
290
+ cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
291
+ }
292
+ }
293
+ jpeg_default_qtables(cinfo, force_baseline);
294
+ return TRUE;
295
+ }
296
+
297
+
298
+ GLOBAL(boolean)
299
+ set_quant_slots (j_compress_ptr cinfo, char *arg)
300
+ /* Process a quantization-table-selectors parameter string, of the form
301
+ * N[,N,...]
302
+ * If there are more components than parameters, the last value is replicated.
303
+ */
304
+ {
305
+ int val = 0; /* default table # */
306
+ int ci;
307
+ char ch;
308
+
309
+ for (ci = 0; ci < MAX_COMPONENTS; ci++) {
310
+ if (*arg) {
311
+ ch = ','; /* if not set by sscanf, will be ',' */
312
+ if (sscanf(arg, "%d%c", &val, &ch) < 1)
313
+ return FALSE;
314
+ if (ch != ',') /* syntax check */
315
+ return FALSE;
316
+ if (val < 0 || val >= NUM_QUANT_TBLS) {
317
+ fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
318
+ NUM_QUANT_TBLS-1);
319
+ return FALSE;
320
+ }
321
+ cinfo->comp_info[ci].quant_tbl_no = val;
322
+ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
323
+ ;
324
+ } else {
325
+ /* reached end of parameter, set remaining components to last table */
326
+ cinfo->comp_info[ci].quant_tbl_no = val;
327
+ }
328
+ }
329
+ return TRUE;
330
+ }
331
+
332
+
333
+ GLOBAL(boolean)
334
+ set_sample_factors (j_compress_ptr cinfo, char *arg)
335
+ /* Process a sample-factors parameter string, of the form
336
+ * HxV[,HxV,...]
337
+ * If there are more components than parameters, "1x1" is assumed for the rest.
338
+ */
339
+ {
340
+ int ci, val1, val2;
341
+ char ch1, ch2;
342
+
343
+ for (ci = 0; ci < MAX_COMPONENTS; ci++) {
344
+ if (*arg) {
345
+ ch2 = ','; /* if not set by sscanf, will be ',' */
346
+ if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
347
+ return FALSE;
348
+ if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
349
+ return FALSE;
350
+ if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
351
+ fprintf(stderr, "JPEG sampling factors must be 1..4\n");
352
+ return FALSE;
353
+ }
354
+ cinfo->comp_info[ci].h_samp_factor = val1;
355
+ cinfo->comp_info[ci].v_samp_factor = val2;
356
+ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
357
+ ;
358
+ } else {
359
+ /* reached end of parameter, set remaining components to 1x1 sampling */
360
+ cinfo->comp_info[ci].h_samp_factor = 1;
361
+ cinfo->comp_info[ci].v_samp_factor = 1;
362
+ }
363
+ }
364
+ return TRUE;
365
+ }