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,381 @@
1
+ /*
2
+ * jctrans.c
3
+ *
4
+ * Copyright (C) 1995-1998, 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 library routines for transcoding compression,
9
+ * that is, writing raw DCT coefficient arrays to an output JPEG file.
10
+ * The routines in jcapimin.c will also be needed by a transcoder.
11
+ */
12
+
13
+ #define JPEG_INTERNALS
14
+ #include "jinclude.h"
15
+ #include "jpeglib.h"
16
+
17
+
18
+ /* Forward declarations */
19
+ LOCAL(void) transencode_master_selection
20
+ JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
21
+ LOCAL(void) transencode_coef_controller
22
+ JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
23
+
24
+
25
+ /*
26
+ * Compression initialization for writing raw-coefficient data.
27
+ * Before calling this, all parameters and a data destination must be set up.
28
+ * Call jpeg_finish_compress() to actually write the data.
29
+ *
30
+ * The number of passed virtual arrays must match cinfo->num_components.
31
+ * Note that the virtual arrays need not be filled or even realized at
32
+ * the time write_coefficients is called; indeed, if the virtual arrays
33
+ * were requested from this compression object's memory manager, they
34
+ * typically will be realized during this routine and filled afterwards.
35
+ */
36
+
37
+ GLOBAL(void)
38
+ jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
39
+ {
40
+ if (cinfo->global_state != CSTATE_START)
41
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
42
+ /* Mark all tables to be written */
43
+ jpeg_suppress_tables(cinfo, FALSE);
44
+ /* (Re)initialize error mgr and destination modules */
45
+ (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
46
+ (*cinfo->dest->init_destination) (cinfo);
47
+ /* Perform master selection of active modules */
48
+ transencode_master_selection(cinfo, coef_arrays);
49
+ /* Wait for jpeg_finish_compress() call */
50
+ cinfo->next_scanline = 0; /* so jpeg_write_marker works */
51
+ cinfo->global_state = CSTATE_WRCOEFS;
52
+ }
53
+
54
+
55
+ /*
56
+ * Initialize the compression object with default parameters,
57
+ * then copy from the source object all parameters needed for lossless
58
+ * transcoding. Parameters that can be varied without loss (such as
59
+ * scan script and Huffman optimization) are left in their default states.
60
+ */
61
+
62
+ GLOBAL(void)
63
+ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
64
+ j_compress_ptr dstinfo)
65
+ {
66
+ JQUANT_TBL ** qtblptr;
67
+ jpeg_component_info *incomp, *outcomp;
68
+ JQUANT_TBL *c_quant, *slot_quant;
69
+ int tblno, ci, coefi;
70
+
71
+ /* Safety check to ensure start_compress not called yet. */
72
+ if (dstinfo->global_state != CSTATE_START)
73
+ ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
74
+ /* Copy fundamental image dimensions */
75
+ dstinfo->image_width = srcinfo->image_width;
76
+ dstinfo->image_height = srcinfo->image_height;
77
+ dstinfo->input_components = srcinfo->num_components;
78
+ dstinfo->in_color_space = srcinfo->jpeg_color_space;
79
+ /* Initialize all parameters to default values */
80
+ jpeg_set_defaults(dstinfo);
81
+ /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
82
+ * Fix it to get the right header markers for the image colorspace.
83
+ */
84
+ jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
85
+ dstinfo->data_precision = srcinfo->data_precision;
86
+ dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
87
+ /* Copy the source's quantization tables. */
88
+ for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
89
+ if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
90
+ qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
91
+ if (*qtblptr == NULL)
92
+ *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
93
+ MEMCOPY((*qtblptr)->quantval,
94
+ srcinfo->quant_tbl_ptrs[tblno]->quantval,
95
+ SIZEOF((*qtblptr)->quantval));
96
+ (*qtblptr)->sent_table = FALSE;
97
+ }
98
+ }
99
+ /* Copy the source's per-component info.
100
+ * Note we assume jpeg_set_defaults has allocated the dest comp_info array.
101
+ */
102
+ dstinfo->num_components = srcinfo->num_components;
103
+ if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
104
+ ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
105
+ MAX_COMPONENTS);
106
+ for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
107
+ ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
108
+ outcomp->component_id = incomp->component_id;
109
+ outcomp->h_samp_factor = incomp->h_samp_factor;
110
+ outcomp->v_samp_factor = incomp->v_samp_factor;
111
+ outcomp->quant_tbl_no = incomp->quant_tbl_no;
112
+ /* Make sure saved quantization table for component matches the qtable
113
+ * slot. If not, the input file re-used this qtable slot.
114
+ * IJG encoder currently cannot duplicate this.
115
+ */
116
+ tblno = outcomp->quant_tbl_no;
117
+ if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
118
+ srcinfo->quant_tbl_ptrs[tblno] == NULL)
119
+ ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
120
+ slot_quant = srcinfo->quant_tbl_ptrs[tblno];
121
+ c_quant = incomp->quant_table;
122
+ if (c_quant != NULL) {
123
+ for (coefi = 0; coefi < DCTSIZE2; coefi++) {
124
+ if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
125
+ ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
126
+ }
127
+ }
128
+ /* Note: we do not copy the source's Huffman table assignments;
129
+ * instead we rely on jpeg_set_colorspace to have made a suitable choice.
130
+ */
131
+ }
132
+ /* Also copy JFIF version and resolution information, if available.
133
+ * Strictly speaking this isn't "critical" info, but it's nearly
134
+ * always appropriate to copy it if available. In particular,
135
+ * if the application chooses to copy JFIF 1.02 extension markers from
136
+ * the source file, we need to copy the version to make sure we don't
137
+ * emit a file that has 1.02 extensions but a claimed version of 1.01.
138
+ * We will *not*, however, copy version info from mislabeled "2.01" files.
139
+ */
140
+ if (srcinfo->saw_JFIF_marker) {
141
+ if (srcinfo->JFIF_major_version == 1) {
142
+ dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
143
+ dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
144
+ }
145
+ dstinfo->density_unit = srcinfo->density_unit;
146
+ dstinfo->X_density = srcinfo->X_density;
147
+ dstinfo->Y_density = srcinfo->Y_density;
148
+ }
149
+ }
150
+
151
+
152
+ /*
153
+ * Master selection of compression modules for transcoding.
154
+ * This substitutes for jcinit.c's initialization of the full compressor.
155
+ */
156
+
157
+ LOCAL(void)
158
+ transencode_master_selection (j_compress_ptr cinfo,
159
+ jvirt_barray_ptr * coef_arrays)
160
+ {
161
+ /* Although we don't actually use input_components for transcoding,
162
+ * jcmaster.c's initial_setup will complain if input_components is 0.
163
+ */
164
+ cinfo->input_components = 1;
165
+ /* Initialize master control (includes parameter checking/processing) */
166
+ jinit_c_master_control(cinfo, TRUE /* transcode only */);
167
+
168
+ /* Entropy encoding: either Huffman or arithmetic coding. */
169
+ if (cinfo->arith_code) {
170
+ jinit_arith_encoder(cinfo);
171
+ } else {
172
+ jinit_huff_encoder(cinfo);
173
+ }
174
+
175
+ /* We need a special coefficient buffer controller. */
176
+ transencode_coef_controller(cinfo, coef_arrays);
177
+
178
+ jinit_marker_writer(cinfo);
179
+
180
+ /* We can now tell the memory manager to allocate virtual arrays. */
181
+ (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
182
+
183
+ /* Write the datastream header (SOI, JFIF) immediately.
184
+ * Frame and scan headers are postponed till later.
185
+ * This lets application insert special markers after the SOI.
186
+ */
187
+ (*cinfo->marker->write_file_header) (cinfo);
188
+ }
189
+
190
+
191
+ /*
192
+ * The rest of this file is a special implementation of the coefficient
193
+ * buffer controller. This is similar to jccoefct.c, but it handles only
194
+ * output from presupplied virtual arrays. Furthermore, we generate any
195
+ * dummy padding blocks on-the-fly rather than expecting them to be present
196
+ * in the arrays.
197
+ */
198
+
199
+ /* Private buffer controller object */
200
+
201
+ typedef struct {
202
+ struct jpeg_c_coef_controller pub; /* public fields */
203
+
204
+ JDIMENSION iMCU_row_num; /* iMCU row # within image */
205
+ JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
206
+ int MCU_vert_offset; /* counts MCU rows within iMCU row */
207
+ int MCU_rows_per_iMCU_row; /* number of such rows needed */
208
+
209
+ /* Virtual block array for each component. */
210
+ jvirt_barray_ptr * whole_image;
211
+
212
+ /* Workspace for constructing dummy blocks at right/bottom edges. */
213
+ JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
214
+ } my_coef_controller;
215
+
216
+ typedef my_coef_controller * my_coef_ptr;
217
+
218
+
219
+ LOCAL(void)
220
+ start_iMCU_row (j_compress_ptr cinfo)
221
+ /* Reset within-iMCU-row counters for a new row */
222
+ {
223
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
224
+
225
+ /* In an interleaved scan, an MCU row is the same as an iMCU row.
226
+ * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
227
+ * But at the bottom of the image, process only what's left.
228
+ */
229
+ if (cinfo->comps_in_scan > 1) {
230
+ coef->MCU_rows_per_iMCU_row = 1;
231
+ } else {
232
+ if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
233
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
234
+ else
235
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
236
+ }
237
+
238
+ coef->mcu_ctr = 0;
239
+ coef->MCU_vert_offset = 0;
240
+ }
241
+
242
+
243
+ /*
244
+ * Initialize for a processing pass.
245
+ */
246
+
247
+ METHODDEF(void)
248
+ start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
249
+ {
250
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
251
+
252
+ if (pass_mode != JBUF_CRANK_DEST)
253
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
254
+
255
+ coef->iMCU_row_num = 0;
256
+ start_iMCU_row(cinfo);
257
+ }
258
+
259
+
260
+ /*
261
+ * Process some data.
262
+ * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
263
+ * per call, ie, v_samp_factor block rows for each component in the scan.
264
+ * The data is obtained from the virtual arrays and fed to the entropy coder.
265
+ * Returns TRUE if the iMCU row is completed, FALSE if suspended.
266
+ *
267
+ * NB: input_buf is ignored; it is likely to be a NULL pointer.
268
+ */
269
+
270
+ METHODDEF(boolean)
271
+ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
272
+ {
273
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
274
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
275
+ JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
276
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
277
+ int blkn, ci, xindex, yindex, yoffset, blockcnt;
278
+ JDIMENSION start_col;
279
+ JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
280
+ JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
281
+ JBLOCKROW buffer_ptr;
282
+ jpeg_component_info *compptr;
283
+
284
+ /* Align the virtual buffers for the components used in this scan. */
285
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
286
+ compptr = cinfo->cur_comp_info[ci];
287
+ buffer[ci] = (*cinfo->mem->access_virt_barray)
288
+ ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
289
+ coef->iMCU_row_num * compptr->v_samp_factor,
290
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
291
+ }
292
+
293
+ /* Loop to process one whole iMCU row */
294
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
295
+ yoffset++) {
296
+ for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
297
+ MCU_col_num++) {
298
+ /* Construct list of pointers to DCT blocks belonging to this MCU */
299
+ blkn = 0; /* index of current DCT block within MCU */
300
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
301
+ compptr = cinfo->cur_comp_info[ci];
302
+ start_col = MCU_col_num * compptr->MCU_width;
303
+ blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
304
+ : compptr->last_col_width;
305
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
306
+ if (coef->iMCU_row_num < last_iMCU_row ||
307
+ yindex+yoffset < compptr->last_row_height) {
308
+ /* Fill in pointers to real blocks in this row */
309
+ buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
310
+ for (xindex = 0; xindex < blockcnt; xindex++)
311
+ MCU_buffer[blkn++] = buffer_ptr++;
312
+ } else {
313
+ /* At bottom of image, need a whole row of dummy blocks */
314
+ xindex = 0;
315
+ }
316
+ /* Fill in any dummy blocks needed in this row.
317
+ * Dummy blocks are filled in the same way as in jccoefct.c:
318
+ * all zeroes in the AC entries, DC entries equal to previous
319
+ * block's DC value. The init routine has already zeroed the
320
+ * AC entries, so we need only set the DC entries correctly.
321
+ */
322
+ for (; xindex < compptr->MCU_width; xindex++) {
323
+ MCU_buffer[blkn] = coef->dummy_buffer[blkn];
324
+ MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
325
+ blkn++;
326
+ }
327
+ }
328
+ }
329
+ /* Try to write the MCU. */
330
+ if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
331
+ /* Suspension forced; update state counters and exit */
332
+ coef->MCU_vert_offset = yoffset;
333
+ coef->mcu_ctr = MCU_col_num;
334
+ return FALSE;
335
+ }
336
+ }
337
+ /* Completed an MCU row, but perhaps not an iMCU row */
338
+ coef->mcu_ctr = 0;
339
+ }
340
+ /* Completed the iMCU row, advance counters for next one */
341
+ coef->iMCU_row_num++;
342
+ start_iMCU_row(cinfo);
343
+ return TRUE;
344
+ }
345
+
346
+
347
+ /*
348
+ * Initialize coefficient buffer controller.
349
+ *
350
+ * Each passed coefficient array must be the right size for that
351
+ * coefficient: width_in_blocks wide and height_in_blocks high,
352
+ * with unitheight at least v_samp_factor.
353
+ */
354
+
355
+ LOCAL(void)
356
+ transencode_coef_controller (j_compress_ptr cinfo,
357
+ jvirt_barray_ptr * coef_arrays)
358
+ {
359
+ my_coef_ptr coef;
360
+ JBLOCKROW buffer;
361
+ int i;
362
+
363
+ coef = (my_coef_ptr)
364
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
365
+ SIZEOF(my_coef_controller));
366
+ cinfo->coef = (struct jpeg_c_coef_controller *) coef;
367
+ coef->pub.start_pass = start_pass_coef;
368
+ coef->pub.compress_data = compress_output;
369
+
370
+ /* Save pointer to virtual arrays */
371
+ coef->whole_image = coef_arrays;
372
+
373
+ /* Allocate and pre-zero space for dummy DCT blocks. */
374
+ buffer = (JBLOCKROW)
375
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
376
+ C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
377
+ jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
378
+ for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
379
+ coef->dummy_buffer[i] = buffer + i;
380
+ }
381
+ }
@@ -0,0 +1,396 @@
1
+ /*
2
+ * jdapimin.c
3
+ *
4
+ * Copyright (C) 1994-1998, Thomas G. Lane.
5
+ * Modified 2009 by Guido Vollbeding.
6
+ * This file is part of the Independent JPEG Group's software.
7
+ * For conditions of distribution and use, see the accompanying README file.
8
+ *
9
+ * This file contains application interface code for the decompression half
10
+ * of the JPEG library. These are the "minimum" API routines that may be
11
+ * needed in either the normal full-decompression case or the
12
+ * transcoding-only case.
13
+ *
14
+ * Most of the routines intended to be called directly by an application
15
+ * are in this file or in jdapistd.c. But also see jcomapi.c for routines
16
+ * shared by compression and decompression, and jdtrans.c for the transcoding
17
+ * case.
18
+ */
19
+
20
+ #define JPEG_INTERNALS
21
+ #include "jinclude.h"
22
+ #include "jpeglib.h"
23
+
24
+
25
+ /*
26
+ * Initialization of a JPEG decompression object.
27
+ * The error manager must already be set up (in case memory manager fails).
28
+ */
29
+
30
+ GLOBAL(void)
31
+ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
32
+ {
33
+ int i;
34
+
35
+ /* Guard against version mismatches between library and caller. */
36
+ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
37
+ if (version != JPEG_LIB_VERSION)
38
+ ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
39
+ if (structsize != SIZEOF(struct jpeg_decompress_struct))
40
+ ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
41
+ (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
42
+
43
+ /* For debugging purposes, we zero the whole master structure.
44
+ * But the application has already set the err pointer, and may have set
45
+ * client_data, so we have to save and restore those fields.
46
+ * Note: if application hasn't set client_data, tools like Purify may
47
+ * complain here.
48
+ */
49
+ {
50
+ struct jpeg_error_mgr * err = cinfo->err;
51
+ void * client_data = cinfo->client_data; /* ignore Purify complaint here */
52
+ MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
53
+ cinfo->err = err;
54
+ cinfo->client_data = client_data;
55
+ }
56
+ cinfo->is_decompressor = TRUE;
57
+
58
+ /* Initialize a memory manager instance for this object */
59
+ jinit_memory_mgr((j_common_ptr) cinfo);
60
+
61
+ /* Zero out pointers to permanent structures. */
62
+ cinfo->progress = NULL;
63
+ cinfo->src = NULL;
64
+
65
+ for (i = 0; i < NUM_QUANT_TBLS; i++)
66
+ cinfo->quant_tbl_ptrs[i] = NULL;
67
+
68
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
69
+ cinfo->dc_huff_tbl_ptrs[i] = NULL;
70
+ cinfo->ac_huff_tbl_ptrs[i] = NULL;
71
+ }
72
+
73
+ /* Initialize marker processor so application can override methods
74
+ * for COM, APPn markers before calling jpeg_read_header.
75
+ */
76
+ cinfo->marker_list = NULL;
77
+ jinit_marker_reader(cinfo);
78
+
79
+ /* And initialize the overall input controller. */
80
+ jinit_input_controller(cinfo);
81
+
82
+ /* OK, I'm ready */
83
+ cinfo->global_state = DSTATE_START;
84
+ }
85
+
86
+
87
+ /*
88
+ * Destruction of a JPEG decompression object
89
+ */
90
+
91
+ GLOBAL(void)
92
+ jpeg_destroy_decompress (j_decompress_ptr cinfo)
93
+ {
94
+ jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
95
+ }
96
+
97
+
98
+ /*
99
+ * Abort processing of a JPEG decompression operation,
100
+ * but don't destroy the object itself.
101
+ */
102
+
103
+ GLOBAL(void)
104
+ jpeg_abort_decompress (j_decompress_ptr cinfo)
105
+ {
106
+ jpeg_abort((j_common_ptr) cinfo); /* use common routine */
107
+ }
108
+
109
+
110
+ /*
111
+ * Set default decompression parameters.
112
+ */
113
+
114
+ LOCAL(void)
115
+ default_decompress_parms (j_decompress_ptr cinfo)
116
+ {
117
+ /* Guess the input colorspace, and set output colorspace accordingly. */
118
+ /* (Wish JPEG committee had provided a real way to specify this...) */
119
+ /* Note application may override our guesses. */
120
+ switch (cinfo->num_components) {
121
+ case 1:
122
+ cinfo->jpeg_color_space = JCS_GRAYSCALE;
123
+ cinfo->out_color_space = JCS_GRAYSCALE;
124
+ break;
125
+
126
+ case 3:
127
+ if (cinfo->saw_JFIF_marker) {
128
+ cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
129
+ } else if (cinfo->saw_Adobe_marker) {
130
+ switch (cinfo->Adobe_transform) {
131
+ case 0:
132
+ cinfo->jpeg_color_space = JCS_RGB;
133
+ break;
134
+ case 1:
135
+ cinfo->jpeg_color_space = JCS_YCbCr;
136
+ break;
137
+ default:
138
+ WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
139
+ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
140
+ break;
141
+ }
142
+ } else {
143
+ /* Saw no special markers, try to guess from the component IDs */
144
+ int cid0 = cinfo->comp_info[0].component_id;
145
+ int cid1 = cinfo->comp_info[1].component_id;
146
+ int cid2 = cinfo->comp_info[2].component_id;
147
+
148
+ if (cid0 == 1 && cid1 == 2 && cid2 == 3)
149
+ cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
150
+ else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
151
+ cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
152
+ else {
153
+ TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
154
+ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
155
+ }
156
+ }
157
+ /* Always guess RGB is proper output colorspace. */
158
+ cinfo->out_color_space = JCS_RGB;
159
+ break;
160
+
161
+ case 4:
162
+ if (cinfo->saw_Adobe_marker) {
163
+ switch (cinfo->Adobe_transform) {
164
+ case 0:
165
+ cinfo->jpeg_color_space = JCS_CMYK;
166
+ break;
167
+ case 2:
168
+ cinfo->jpeg_color_space = JCS_YCCK;
169
+ break;
170
+ default:
171
+ WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
172
+ cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
173
+ break;
174
+ }
175
+ } else {
176
+ /* No special markers, assume straight CMYK. */
177
+ cinfo->jpeg_color_space = JCS_CMYK;
178
+ }
179
+ cinfo->out_color_space = JCS_CMYK;
180
+ break;
181
+
182
+ default:
183
+ cinfo->jpeg_color_space = JCS_UNKNOWN;
184
+ cinfo->out_color_space = JCS_UNKNOWN;
185
+ break;
186
+ }
187
+
188
+ /* Set defaults for other decompression parameters. */
189
+ cinfo->scale_num = DCTSIZE; /* 1:1 scaling */
190
+ cinfo->scale_denom = DCTSIZE;
191
+ cinfo->output_gamma = 1.0;
192
+ cinfo->buffered_image = FALSE;
193
+ cinfo->raw_data_out = FALSE;
194
+ cinfo->dct_method = JDCT_DEFAULT;
195
+ cinfo->do_fancy_upsampling = TRUE;
196
+ cinfo->do_block_smoothing = TRUE;
197
+ cinfo->quantize_colors = FALSE;
198
+ /* We set these in case application only sets quantize_colors. */
199
+ cinfo->dither_mode = JDITHER_FS;
200
+ #ifdef QUANT_2PASS_SUPPORTED
201
+ cinfo->two_pass_quantize = TRUE;
202
+ #else
203
+ cinfo->two_pass_quantize = FALSE;
204
+ #endif
205
+ cinfo->desired_number_of_colors = 256;
206
+ cinfo->colormap = NULL;
207
+ /* Initialize for no mode change in buffered-image mode. */
208
+ cinfo->enable_1pass_quant = FALSE;
209
+ cinfo->enable_external_quant = FALSE;
210
+ cinfo->enable_2pass_quant = FALSE;
211
+ }
212
+
213
+
214
+ /*
215
+ * Decompression startup: read start of JPEG datastream to see what's there.
216
+ * Need only initialize JPEG object and supply a data source before calling.
217
+ *
218
+ * This routine will read as far as the first SOS marker (ie, actual start of
219
+ * compressed data), and will save all tables and parameters in the JPEG
220
+ * object. It will also initialize the decompression parameters to default
221
+ * values, and finally return JPEG_HEADER_OK. On return, the application may
222
+ * adjust the decompression parameters and then call jpeg_start_decompress.
223
+ * (Or, if the application only wanted to determine the image parameters,
224
+ * the data need not be decompressed. In that case, call jpeg_abort or
225
+ * jpeg_destroy to release any temporary space.)
226
+ * If an abbreviated (tables only) datastream is presented, the routine will
227
+ * return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then
228
+ * re-use the JPEG object to read the abbreviated image datastream(s).
229
+ * It is unnecessary (but OK) to call jpeg_abort in this case.
230
+ * The JPEG_SUSPENDED return code only occurs if the data source module
231
+ * requests suspension of the decompressor. In this case the application
232
+ * should load more source data and then re-call jpeg_read_header to resume
233
+ * processing.
234
+ * If a non-suspending data source is used and require_image is TRUE, then the
235
+ * return code need not be inspected since only JPEG_HEADER_OK is possible.
236
+ *
237
+ * This routine is now just a front end to jpeg_consume_input, with some
238
+ * extra error checking.
239
+ */
240
+
241
+ GLOBAL(int)
242
+ jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
243
+ {
244
+ int retcode;
245
+
246
+ if (cinfo->global_state != DSTATE_START &&
247
+ cinfo->global_state != DSTATE_INHEADER)
248
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
249
+
250
+ retcode = jpeg_consume_input(cinfo);
251
+
252
+ switch (retcode) {
253
+ case JPEG_REACHED_SOS:
254
+ retcode = JPEG_HEADER_OK;
255
+ break;
256
+ case JPEG_REACHED_EOI:
257
+ if (require_image) /* Complain if application wanted an image */
258
+ ERREXIT(cinfo, JERR_NO_IMAGE);
259
+ /* Reset to start state; it would be safer to require the application to
260
+ * call jpeg_abort, but we can't change it now for compatibility reasons.
261
+ * A side effect is to free any temporary memory (there shouldn't be any).
262
+ */
263
+ jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
264
+ retcode = JPEG_HEADER_TABLES_ONLY;
265
+ break;
266
+ case JPEG_SUSPENDED:
267
+ /* no work */
268
+ break;
269
+ }
270
+
271
+ return retcode;
272
+ }
273
+
274
+
275
+ /*
276
+ * Consume data in advance of what the decompressor requires.
277
+ * This can be called at any time once the decompressor object has
278
+ * been created and a data source has been set up.
279
+ *
280
+ * This routine is essentially a state machine that handles a couple
281
+ * of critical state-transition actions, namely initial setup and
282
+ * transition from header scanning to ready-for-start_decompress.
283
+ * All the actual input is done via the input controller's consume_input
284
+ * method.
285
+ */
286
+
287
+ GLOBAL(int)
288
+ jpeg_consume_input (j_decompress_ptr cinfo)
289
+ {
290
+ int retcode = JPEG_SUSPENDED;
291
+
292
+ /* NB: every possible DSTATE value should be listed in this switch */
293
+ switch (cinfo->global_state) {
294
+ case DSTATE_START:
295
+ /* Start-of-datastream actions: reset appropriate modules */
296
+ (*cinfo->inputctl->reset_input_controller) (cinfo);
297
+ /* Initialize application's data source module */
298
+ (*cinfo->src->init_source) (cinfo);
299
+ cinfo->global_state = DSTATE_INHEADER;
300
+ /*FALLTHROUGH*/
301
+ case DSTATE_INHEADER:
302
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
303
+ if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
304
+ /* Set up default parameters based on header data */
305
+ default_decompress_parms(cinfo);
306
+ /* Set global state: ready for start_decompress */
307
+ cinfo->global_state = DSTATE_READY;
308
+ }
309
+ break;
310
+ case DSTATE_READY:
311
+ /* Can't advance past first SOS until start_decompress is called */
312
+ retcode = JPEG_REACHED_SOS;
313
+ break;
314
+ case DSTATE_PRELOAD:
315
+ case DSTATE_PRESCAN:
316
+ case DSTATE_SCANNING:
317
+ case DSTATE_RAW_OK:
318
+ case DSTATE_BUFIMAGE:
319
+ case DSTATE_BUFPOST:
320
+ case DSTATE_STOPPING:
321
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
322
+ break;
323
+ default:
324
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
325
+ }
326
+ return retcode;
327
+ }
328
+
329
+
330
+ /*
331
+ * Have we finished reading the input file?
332
+ */
333
+
334
+ GLOBAL(boolean)
335
+ jpeg_input_complete (j_decompress_ptr cinfo)
336
+ {
337
+ /* Check for valid jpeg object */
338
+ if (cinfo->global_state < DSTATE_START ||
339
+ cinfo->global_state > DSTATE_STOPPING)
340
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
341
+ return cinfo->inputctl->eoi_reached;
342
+ }
343
+
344
+
345
+ /*
346
+ * Is there more than one scan?
347
+ */
348
+
349
+ GLOBAL(boolean)
350
+ jpeg_has_multiple_scans (j_decompress_ptr cinfo)
351
+ {
352
+ /* Only valid after jpeg_read_header completes */
353
+ if (cinfo->global_state < DSTATE_READY ||
354
+ cinfo->global_state > DSTATE_STOPPING)
355
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
356
+ return cinfo->inputctl->has_multiple_scans;
357
+ }
358
+
359
+
360
+ /*
361
+ * Finish JPEG decompression.
362
+ *
363
+ * This will normally just verify the file trailer and release temp storage.
364
+ *
365
+ * Returns FALSE if suspended. The return value need be inspected only if
366
+ * a suspending data source is used.
367
+ */
368
+
369
+ GLOBAL(boolean)
370
+ jpeg_finish_decompress (j_decompress_ptr cinfo)
371
+ {
372
+ if ((cinfo->global_state == DSTATE_SCANNING ||
373
+ cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
374
+ /* Terminate final pass of non-buffered mode */
375
+ if (cinfo->output_scanline < cinfo->output_height)
376
+ ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
377
+ (*cinfo->master->finish_output_pass) (cinfo);
378
+ cinfo->global_state = DSTATE_STOPPING;
379
+ } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
380
+ /* Finishing after a buffered-image operation */
381
+ cinfo->global_state = DSTATE_STOPPING;
382
+ } else if (cinfo->global_state != DSTATE_STOPPING) {
383
+ /* STOPPING = repeat call after a suspension, anything else is error */
384
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
385
+ }
386
+ /* Read until EOI */
387
+ while (! cinfo->inputctl->eoi_reached) {
388
+ if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
389
+ return FALSE; /* Suspend, come back later */
390
+ }
391
+ /* Do final cleanup */
392
+ (*cinfo->src->term_source) (cinfo);
393
+ /* We can use jpeg_abort to release memory and reset global_state */
394
+ jpeg_abort((j_common_ptr) cinfo);
395
+ return TRUE;
396
+ }