isbn 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. data/{README → README.md} +5 -11
  2. data/Rakefile +20 -14
  3. data/isbn.gemspec +23 -0
  4. data/lib/isbn.rb +2 -0
  5. data/test/isbn_spec.rb +1 -1
  6. metadata +29 -316
  7. data/VERSION +0 -1
  8. data/src/gocr-0.48/.cvsignore +0 -6
  9. data/src/gocr-0.48/AUTHORS +0 -7
  10. data/src/gocr-0.48/BUGS +0 -55
  11. data/src/gocr-0.48/CREDITS +0 -17
  12. data/src/gocr-0.48/HISTORY +0 -243
  13. data/src/gocr-0.48/INSTALL +0 -83
  14. data/src/gocr-0.48/Makefile +0 -193
  15. data/src/gocr-0.48/Makefile.in +0 -193
  16. data/src/gocr-0.48/README +0 -165
  17. data/src/gocr-0.48/READMEde.txt +0 -80
  18. data/src/gocr-0.48/REMARK.txt +0 -18
  19. data/src/gocr-0.48/REVIEW +0 -538
  20. data/src/gocr-0.48/TODO +0 -65
  21. data/src/gocr-0.48/bin/.cvsignore +0 -2
  22. data/src/gocr-0.48/bin/create_db +0 -38
  23. data/src/gocr-0.48/bin/gocr.tcl +0 -527
  24. data/src/gocr-0.48/bin/gocr_chk.sh +0 -44
  25. data/src/gocr-0.48/configure +0 -4689
  26. data/src/gocr-0.48/configure.in +0 -71
  27. data/src/gocr-0.48/doc/.#Makefile.1.6 +0 -39
  28. data/src/gocr-0.48/doc/.cvsignore +0 -2
  29. data/src/gocr-0.48/doc/Makefile +0 -39
  30. data/src/gocr-0.48/doc/Makefile.in +0 -39
  31. data/src/gocr-0.48/doc/example.dtd +0 -53
  32. data/src/gocr-0.48/doc/example.xml +0 -21
  33. data/src/gocr-0.48/doc/examples.txt +0 -67
  34. data/src/gocr-0.48/doc/gocr.html +0 -578
  35. data/src/gocr-0.48/doc/unicode.txt +0 -57
  36. data/src/gocr-0.48/examples/.#Makefile.1.22 +0 -166
  37. data/src/gocr-0.48/examples/4x6.png +0 -0
  38. data/src/gocr-0.48/examples/4x6.txt +0 -2
  39. data/src/gocr-0.48/examples/5x7.png +0 -0
  40. data/src/gocr-0.48/examples/5x7.png.txt +0 -2
  41. data/src/gocr-0.48/examples/5x8.png +0 -0
  42. data/src/gocr-0.48/examples/5x8.png.txt +0 -2
  43. data/src/gocr-0.48/examples/Makefile +0 -166
  44. data/src/gocr-0.48/examples/color.fig +0 -20
  45. data/src/gocr-0.48/examples/ex.fig +0 -16
  46. data/src/gocr-0.48/examples/font.tex +0 -22
  47. data/src/gocr-0.48/examples/font1.tex +0 -46
  48. data/src/gocr-0.48/examples/font2.fig +0 -27
  49. data/src/gocr-0.48/examples/font_nw.tex +0 -24
  50. data/src/gocr-0.48/examples/handwrt1.jpg +0 -0
  51. data/src/gocr-0.48/examples/handwrt1.txt +0 -10
  52. data/src/gocr-0.48/examples/inverse.fig +0 -20
  53. data/src/gocr-0.48/examples/matrix.jpg +0 -0
  54. data/src/gocr-0.48/examples/ocr-a-subset.png +0 -0
  55. data/src/gocr-0.48/examples/ocr-a-subset.png.txt +0 -4
  56. data/src/gocr-0.48/examples/ocr-a.png +0 -0
  57. data/src/gocr-0.48/examples/ocr-a.txt +0 -6
  58. data/src/gocr-0.48/examples/ocr-b.png +0 -0
  59. data/src/gocr-0.48/examples/ocr-b.png.txt +0 -4
  60. data/src/gocr-0.48/examples/polish.tex +0 -28
  61. data/src/gocr-0.48/examples/rotate45.fig +0 -14
  62. data/src/gocr-0.48/examples/score +0 -36
  63. data/src/gocr-0.48/examples/text.tex +0 -28
  64. data/src/gocr-0.48/gpl.html +0 -537
  65. data/src/gocr-0.48/include/.cvsignore +0 -2
  66. data/src/gocr-0.48/include/config.h +0 -36
  67. data/src/gocr-0.48/include/config.h.in +0 -36
  68. data/src/gocr-0.48/include/version.h +0 -2
  69. data/src/gocr-0.48/install-sh +0 -3
  70. data/src/gocr-0.48/make.bat +0 -57
  71. data/src/gocr-0.48/man/.cvsignore +0 -2
  72. data/src/gocr-0.48/man/Makefile +0 -29
  73. data/src/gocr-0.48/man/Makefile.in +0 -29
  74. data/src/gocr-0.48/man/man1/gocr.1 +0 -166
  75. data/src/gocr-0.48/src/.cvsignore +0 -4
  76. data/src/gocr-0.48/src/Makefile +0 -132
  77. data/src/gocr-0.48/src/Makefile.in +0 -132
  78. data/src/gocr-0.48/src/amiga.h +0 -31
  79. data/src/gocr-0.48/src/barcode.c +0 -846
  80. data/src/gocr-0.48/src/barcode.c.orig +0 -593
  81. data/src/gocr-0.48/src/barcode.h +0 -11
  82. data/src/gocr-0.48/src/box.c +0 -372
  83. data/src/gocr-0.48/src/database.c +0 -462
  84. data/src/gocr-0.48/src/detect.c +0 -943
  85. data/src/gocr-0.48/src/gocr.c +0 -373
  86. data/src/gocr-0.48/src/gocr.h +0 -288
  87. data/src/gocr-0.48/src/jconv.c +0 -168
  88. data/src/gocr-0.48/src/job.c +0 -84
  89. data/src/gocr-0.48/src/lines.c +0 -350
  90. data/src/gocr-0.48/src/list.c +0 -334
  91. data/src/gocr-0.48/src/list.h +0 -90
  92. data/src/gocr-0.48/src/ocr0.c +0 -6756
  93. data/src/gocr-0.48/src/ocr0.h +0 -63
  94. data/src/gocr-0.48/src/ocr0n.c +0 -1475
  95. data/src/gocr-0.48/src/ocr1.c +0 -85
  96. data/src/gocr-0.48/src/ocr1.h +0 -3
  97. data/src/gocr-0.48/src/otsu.c +0 -289
  98. data/src/gocr-0.48/src/otsu.h +0 -23
  99. data/src/gocr-0.48/src/output.c +0 -289
  100. data/src/gocr-0.48/src/output.h +0 -37
  101. data/src/gocr-0.48/src/pcx.c +0 -153
  102. data/src/gocr-0.48/src/pcx.h +0 -9
  103. data/src/gocr-0.48/src/pgm2asc.c +0 -2893
  104. data/src/gocr-0.48/src/pgm2asc.h +0 -105
  105. data/src/gocr-0.48/src/pixel.c +0 -537
  106. data/src/gocr-0.48/src/pnm.c +0 -533
  107. data/src/gocr-0.48/src/pnm.h +0 -35
  108. data/src/gocr-0.48/src/progress.c +0 -87
  109. data/src/gocr-0.48/src/progress.h +0 -42
  110. data/src/gocr-0.48/src/remove.c +0 -703
  111. data/src/gocr-0.48/src/tga.c +0 -87
  112. data/src/gocr-0.48/src/tga.h +0 -6
  113. data/src/gocr-0.48/src/unicode.c +0 -1314
  114. data/src/gocr-0.48/src/unicode.h +0 -1257
  115. data/src/jpeg-7/Makefile.am +0 -133
  116. data/src/jpeg-7/Makefile.in +0 -1089
  117. data/src/jpeg-7/README +0 -322
  118. data/src/jpeg-7/aclocal.m4 +0 -8990
  119. data/src/jpeg-7/ansi2knr.1 +0 -36
  120. data/src/jpeg-7/ansi2knr.c +0 -739
  121. data/src/jpeg-7/cderror.h +0 -132
  122. data/src/jpeg-7/cdjpeg.c +0 -181
  123. data/src/jpeg-7/cdjpeg.h +0 -187
  124. data/src/jpeg-7/change.log +0 -270
  125. data/src/jpeg-7/cjpeg.1 +0 -325
  126. data/src/jpeg-7/cjpeg.c +0 -616
  127. data/src/jpeg-7/ckconfig.c +0 -402
  128. data/src/jpeg-7/coderules.txt +0 -118
  129. data/src/jpeg-7/config.guess +0 -1561
  130. data/src/jpeg-7/config.sub +0 -1686
  131. data/src/jpeg-7/configure +0 -17139
  132. data/src/jpeg-7/configure.ac +0 -317
  133. data/src/jpeg-7/depcomp +0 -630
  134. data/src/jpeg-7/djpeg.1 +0 -251
  135. data/src/jpeg-7/djpeg.c +0 -617
  136. data/src/jpeg-7/example.c +0 -433
  137. data/src/jpeg-7/filelist.txt +0 -215
  138. data/src/jpeg-7/install-sh +0 -520
  139. data/src/jpeg-7/install.txt +0 -1097
  140. data/src/jpeg-7/jaricom.c +0 -148
  141. data/src/jpeg-7/jcapimin.c +0 -282
  142. data/src/jpeg-7/jcapistd.c +0 -161
  143. data/src/jpeg-7/jcarith.c +0 -921
  144. data/src/jpeg-7/jccoefct.c +0 -453
  145. data/src/jpeg-7/jccolor.c +0 -459
  146. data/src/jpeg-7/jcdctmgr.c +0 -482
  147. data/src/jpeg-7/jchuff.c +0 -1612
  148. data/src/jpeg-7/jcinit.c +0 -65
  149. data/src/jpeg-7/jcmainct.c +0 -293
  150. data/src/jpeg-7/jcmarker.c +0 -667
  151. data/src/jpeg-7/jcmaster.c +0 -770
  152. data/src/jpeg-7/jcomapi.c +0 -106
  153. data/src/jpeg-7/jconfig.bcc +0 -48
  154. data/src/jpeg-7/jconfig.cfg +0 -45
  155. data/src/jpeg-7/jconfig.dj +0 -38
  156. data/src/jpeg-7/jconfig.mac +0 -43
  157. data/src/jpeg-7/jconfig.manx +0 -43
  158. data/src/jpeg-7/jconfig.mc6 +0 -52
  159. data/src/jpeg-7/jconfig.sas +0 -43
  160. data/src/jpeg-7/jconfig.st +0 -42
  161. data/src/jpeg-7/jconfig.txt +0 -155
  162. data/src/jpeg-7/jconfig.vc +0 -45
  163. data/src/jpeg-7/jconfig.vms +0 -37
  164. data/src/jpeg-7/jconfig.wat +0 -38
  165. data/src/jpeg-7/jcparam.c +0 -632
  166. data/src/jpeg-7/jcprepct.c +0 -358
  167. data/src/jpeg-7/jcsample.c +0 -545
  168. data/src/jpeg-7/jctrans.c +0 -381
  169. data/src/jpeg-7/jdapimin.c +0 -396
  170. data/src/jpeg-7/jdapistd.c +0 -275
  171. data/src/jpeg-7/jdarith.c +0 -762
  172. data/src/jpeg-7/jdatadst.c +0 -151
  173. data/src/jpeg-7/jdatasrc.c +0 -212
  174. data/src/jpeg-7/jdcoefct.c +0 -736
  175. data/src/jpeg-7/jdcolor.c +0 -396
  176. data/src/jpeg-7/jdct.h +0 -393
  177. data/src/jpeg-7/jddctmgr.c +0 -382
  178. data/src/jpeg-7/jdhuff.c +0 -1309
  179. data/src/jpeg-7/jdinput.c +0 -384
  180. data/src/jpeg-7/jdmainct.c +0 -512
  181. data/src/jpeg-7/jdmarker.c +0 -1360
  182. data/src/jpeg-7/jdmaster.c +0 -663
  183. data/src/jpeg-7/jdmerge.c +0 -400
  184. data/src/jpeg-7/jdpostct.c +0 -290
  185. data/src/jpeg-7/jdsample.c +0 -361
  186. data/src/jpeg-7/jdtrans.c +0 -136
  187. data/src/jpeg-7/jerror.c +0 -252
  188. data/src/jpeg-7/jerror.h +0 -304
  189. data/src/jpeg-7/jfdctflt.c +0 -174
  190. data/src/jpeg-7/jfdctfst.c +0 -230
  191. data/src/jpeg-7/jfdctint.c +0 -4348
  192. data/src/jpeg-7/jidctflt.c +0 -242
  193. data/src/jpeg-7/jidctfst.c +0 -368
  194. data/src/jpeg-7/jidctint.c +0 -5137
  195. data/src/jpeg-7/jinclude.h +0 -91
  196. data/src/jpeg-7/jmemansi.c +0 -167
  197. data/src/jpeg-7/jmemdos.c +0 -638
  198. data/src/jpeg-7/jmemdosa.asm +0 -379
  199. data/src/jpeg-7/jmemmac.c +0 -289
  200. data/src/jpeg-7/jmemmgr.c +0 -1118
  201. data/src/jpeg-7/jmemname.c +0 -276
  202. data/src/jpeg-7/jmemnobs.c +0 -109
  203. data/src/jpeg-7/jmemsys.h +0 -198
  204. data/src/jpeg-7/jmorecfg.h +0 -369
  205. data/src/jpeg-7/jpegint.h +0 -395
  206. data/src/jpeg-7/jpeglib.h +0 -1135
  207. data/src/jpeg-7/jpegtran.1 +0 -272
  208. data/src/jpeg-7/jpegtran.c +0 -546
  209. data/src/jpeg-7/jquant1.c +0 -856
  210. data/src/jpeg-7/jquant2.c +0 -1310
  211. data/src/jpeg-7/jutils.c +0 -179
  212. data/src/jpeg-7/jversion.h +0 -14
  213. data/src/jpeg-7/libjpeg.map +0 -4
  214. data/src/jpeg-7/libjpeg.txt +0 -3067
  215. data/src/jpeg-7/ltmain.sh +0 -8406
  216. data/src/jpeg-7/makcjpeg.st +0 -36
  217. data/src/jpeg-7/makdjpeg.st +0 -36
  218. data/src/jpeg-7/makeadsw.vc6 +0 -77
  219. data/src/jpeg-7/makeasln.vc9 +0 -33
  220. data/src/jpeg-7/makecdep.vc6 +0 -82
  221. data/src/jpeg-7/makecdsp.vc6 +0 -130
  222. data/src/jpeg-7/makecmak.vc6 +0 -159
  223. data/src/jpeg-7/makecvcp.vc9 +0 -186
  224. data/src/jpeg-7/makeddep.vc6 +0 -82
  225. data/src/jpeg-7/makeddsp.vc6 +0 -130
  226. data/src/jpeg-7/makedmak.vc6 +0 -159
  227. data/src/jpeg-7/makedvcp.vc9 +0 -186
  228. data/src/jpeg-7/makefile.ansi +0 -220
  229. data/src/jpeg-7/makefile.bcc +0 -291
  230. data/src/jpeg-7/makefile.dj +0 -226
  231. data/src/jpeg-7/makefile.manx +0 -220
  232. data/src/jpeg-7/makefile.mc6 +0 -255
  233. data/src/jpeg-7/makefile.mms +0 -224
  234. data/src/jpeg-7/makefile.sas +0 -258
  235. data/src/jpeg-7/makefile.unix +0 -234
  236. data/src/jpeg-7/makefile.vc +0 -217
  237. data/src/jpeg-7/makefile.vms +0 -142
  238. data/src/jpeg-7/makefile.wat +0 -239
  239. data/src/jpeg-7/makejdep.vc6 +0 -423
  240. data/src/jpeg-7/makejdsp.vc6 +0 -285
  241. data/src/jpeg-7/makejdsw.vc6 +0 -29
  242. data/src/jpeg-7/makejmak.vc6 +0 -425
  243. data/src/jpeg-7/makejsln.vc9 +0 -17
  244. data/src/jpeg-7/makejvcp.vc9 +0 -328
  245. data/src/jpeg-7/makeproj.mac +0 -213
  246. data/src/jpeg-7/makerdep.vc6 +0 -6
  247. data/src/jpeg-7/makerdsp.vc6 +0 -78
  248. data/src/jpeg-7/makermak.vc6 +0 -110
  249. data/src/jpeg-7/makervcp.vc9 +0 -133
  250. data/src/jpeg-7/maketdep.vc6 +0 -43
  251. data/src/jpeg-7/maketdsp.vc6 +0 -122
  252. data/src/jpeg-7/maketmak.vc6 +0 -131
  253. data/src/jpeg-7/maketvcp.vc9 +0 -178
  254. data/src/jpeg-7/makewdep.vc6 +0 -6
  255. data/src/jpeg-7/makewdsp.vc6 +0 -78
  256. data/src/jpeg-7/makewmak.vc6 +0 -110
  257. data/src/jpeg-7/makewvcp.vc9 +0 -133
  258. data/src/jpeg-7/makljpeg.st +0 -68
  259. data/src/jpeg-7/maktjpeg.st +0 -30
  260. data/src/jpeg-7/makvms.opt +0 -4
  261. data/src/jpeg-7/missing +0 -376
  262. data/src/jpeg-7/rdbmp.c +0 -439
  263. data/src/jpeg-7/rdcolmap.c +0 -253
  264. data/src/jpeg-7/rdgif.c +0 -38
  265. data/src/jpeg-7/rdjpgcom.1 +0 -63
  266. data/src/jpeg-7/rdjpgcom.c +0 -515
  267. data/src/jpeg-7/rdppm.c +0 -459
  268. data/src/jpeg-7/rdrle.c +0 -387
  269. data/src/jpeg-7/rdswitch.c +0 -365
  270. data/src/jpeg-7/rdtarga.c +0 -500
  271. data/src/jpeg-7/structure.txt +0 -945
  272. data/src/jpeg-7/testimg.bmp +0 -0
  273. data/src/jpeg-7/testimg.jpg +0 -0
  274. data/src/jpeg-7/testimg.ppm +0 -4
  275. data/src/jpeg-7/testimgp.jpg +0 -0
  276. data/src/jpeg-7/testorig.jpg +0 -0
  277. data/src/jpeg-7/testprog.jpg +0 -0
  278. data/src/jpeg-7/transupp.c +0 -1533
  279. data/src/jpeg-7/transupp.h +0 -205
  280. data/src/jpeg-7/usage.txt +0 -605
  281. data/src/jpeg-7/wizard.txt +0 -211
  282. data/src/jpeg-7/wrbmp.c +0 -442
  283. data/src/jpeg-7/wrgif.c +0 -399
  284. data/src/jpeg-7/wrjpgcom.1 +0 -103
  285. data/src/jpeg-7/wrjpgcom.c +0 -583
  286. data/src/jpeg-7/wrppm.c +0 -269
  287. data/src/jpeg-7/wrrle.c +0 -305
  288. data/src/jpeg-7/wrtarga.c +0 -253
@@ -1,275 +0,0 @@
1
- /*
2
- * jdapistd.c
3
- *
4
- * Copyright (C) 1994-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 application interface code for the decompression half
9
- * of the JPEG library. These are the "standard" API routines that are
10
- * used in the normal full-decompression case. They are not used by a
11
- * transcoding-only application. Note that if an application links in
12
- * jpeg_start_decompress, it will end up linking in the entire decompressor.
13
- * We thus must separate this file from jdapimin.c to avoid linking the
14
- * whole decompression library into a transcoder.
15
- */
16
-
17
- #define JPEG_INTERNALS
18
- #include "jinclude.h"
19
- #include "jpeglib.h"
20
-
21
-
22
- /* Forward declarations */
23
- LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
24
-
25
-
26
- /*
27
- * Decompression initialization.
28
- * jpeg_read_header must be completed before calling this.
29
- *
30
- * If a multipass operating mode was selected, this will do all but the
31
- * last pass, and thus may take a great deal of time.
32
- *
33
- * Returns FALSE if suspended. The return value need be inspected only if
34
- * a suspending data source is used.
35
- */
36
-
37
- GLOBAL(boolean)
38
- jpeg_start_decompress (j_decompress_ptr cinfo)
39
- {
40
- if (cinfo->global_state == DSTATE_READY) {
41
- /* First call: initialize master control, select active modules */
42
- jinit_master_decompress(cinfo);
43
- if (cinfo->buffered_image) {
44
- /* No more work here; expecting jpeg_start_output next */
45
- cinfo->global_state = DSTATE_BUFIMAGE;
46
- return TRUE;
47
- }
48
- cinfo->global_state = DSTATE_PRELOAD;
49
- }
50
- if (cinfo->global_state == DSTATE_PRELOAD) {
51
- /* If file has multiple scans, absorb them all into the coef buffer */
52
- if (cinfo->inputctl->has_multiple_scans) {
53
- #ifdef D_MULTISCAN_FILES_SUPPORTED
54
- for (;;) {
55
- int retcode;
56
- /* Call progress monitor hook if present */
57
- if (cinfo->progress != NULL)
58
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
59
- /* Absorb some more input */
60
- retcode = (*cinfo->inputctl->consume_input) (cinfo);
61
- if (retcode == JPEG_SUSPENDED)
62
- return FALSE;
63
- if (retcode == JPEG_REACHED_EOI)
64
- break;
65
- /* Advance progress counter if appropriate */
66
- if (cinfo->progress != NULL &&
67
- (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
68
- if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
69
- /* jdmaster underestimated number of scans; ratchet up one scan */
70
- cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
71
- }
72
- }
73
- }
74
- #else
75
- ERREXIT(cinfo, JERR_NOT_COMPILED);
76
- #endif /* D_MULTISCAN_FILES_SUPPORTED */
77
- }
78
- cinfo->output_scan_number = cinfo->input_scan_number;
79
- } else if (cinfo->global_state != DSTATE_PRESCAN)
80
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
81
- /* Perform any dummy output passes, and set up for the final pass */
82
- return output_pass_setup(cinfo);
83
- }
84
-
85
-
86
- /*
87
- * Set up for an output pass, and perform any dummy pass(es) needed.
88
- * Common subroutine for jpeg_start_decompress and jpeg_start_output.
89
- * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
90
- * Exit: If done, returns TRUE and sets global_state for proper output mode.
91
- * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
92
- */
93
-
94
- LOCAL(boolean)
95
- output_pass_setup (j_decompress_ptr cinfo)
96
- {
97
- if (cinfo->global_state != DSTATE_PRESCAN) {
98
- /* First call: do pass setup */
99
- (*cinfo->master->prepare_for_output_pass) (cinfo);
100
- cinfo->output_scanline = 0;
101
- cinfo->global_state = DSTATE_PRESCAN;
102
- }
103
- /* Loop over any required dummy passes */
104
- while (cinfo->master->is_dummy_pass) {
105
- #ifdef QUANT_2PASS_SUPPORTED
106
- /* Crank through the dummy pass */
107
- while (cinfo->output_scanline < cinfo->output_height) {
108
- JDIMENSION last_scanline;
109
- /* Call progress monitor hook if present */
110
- if (cinfo->progress != NULL) {
111
- cinfo->progress->pass_counter = (long) cinfo->output_scanline;
112
- cinfo->progress->pass_limit = (long) cinfo->output_height;
113
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
114
- }
115
- /* Process some data */
116
- last_scanline = cinfo->output_scanline;
117
- (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
118
- &cinfo->output_scanline, (JDIMENSION) 0);
119
- if (cinfo->output_scanline == last_scanline)
120
- return FALSE; /* No progress made, must suspend */
121
- }
122
- /* Finish up dummy pass, and set up for another one */
123
- (*cinfo->master->finish_output_pass) (cinfo);
124
- (*cinfo->master->prepare_for_output_pass) (cinfo);
125
- cinfo->output_scanline = 0;
126
- #else
127
- ERREXIT(cinfo, JERR_NOT_COMPILED);
128
- #endif /* QUANT_2PASS_SUPPORTED */
129
- }
130
- /* Ready for application to drive output pass through
131
- * jpeg_read_scanlines or jpeg_read_raw_data.
132
- */
133
- cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
134
- return TRUE;
135
- }
136
-
137
-
138
- /*
139
- * Read some scanlines of data from the JPEG decompressor.
140
- *
141
- * The return value will be the number of lines actually read.
142
- * This may be less than the number requested in several cases,
143
- * including bottom of image, data source suspension, and operating
144
- * modes that emit multiple scanlines at a time.
145
- *
146
- * Note: we warn about excess calls to jpeg_read_scanlines() since
147
- * this likely signals an application programmer error. However,
148
- * an oversize buffer (max_lines > scanlines remaining) is not an error.
149
- */
150
-
151
- GLOBAL(JDIMENSION)
152
- jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
153
- JDIMENSION max_lines)
154
- {
155
- JDIMENSION row_ctr;
156
-
157
- if (cinfo->global_state != DSTATE_SCANNING)
158
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
159
- if (cinfo->output_scanline >= cinfo->output_height) {
160
- WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
161
- return 0;
162
- }
163
-
164
- /* Call progress monitor hook if present */
165
- if (cinfo->progress != NULL) {
166
- cinfo->progress->pass_counter = (long) cinfo->output_scanline;
167
- cinfo->progress->pass_limit = (long) cinfo->output_height;
168
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
169
- }
170
-
171
- /* Process some data */
172
- row_ctr = 0;
173
- (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
174
- cinfo->output_scanline += row_ctr;
175
- return row_ctr;
176
- }
177
-
178
-
179
- /*
180
- * Alternate entry point to read raw data.
181
- * Processes exactly one iMCU row per call, unless suspended.
182
- */
183
-
184
- GLOBAL(JDIMENSION)
185
- jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
186
- JDIMENSION max_lines)
187
- {
188
- JDIMENSION lines_per_iMCU_row;
189
-
190
- if (cinfo->global_state != DSTATE_RAW_OK)
191
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
192
- if (cinfo->output_scanline >= cinfo->output_height) {
193
- WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
194
- return 0;
195
- }
196
-
197
- /* Call progress monitor hook if present */
198
- if (cinfo->progress != NULL) {
199
- cinfo->progress->pass_counter = (long) cinfo->output_scanline;
200
- cinfo->progress->pass_limit = (long) cinfo->output_height;
201
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
202
- }
203
-
204
- /* Verify that at least one iMCU row can be returned. */
205
- lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;
206
- if (max_lines < lines_per_iMCU_row)
207
- ERREXIT(cinfo, JERR_BUFFER_SIZE);
208
-
209
- /* Decompress directly into user's buffer. */
210
- if (! (*cinfo->coef->decompress_data) (cinfo, data))
211
- return 0; /* suspension forced, can do nothing more */
212
-
213
- /* OK, we processed one iMCU row. */
214
- cinfo->output_scanline += lines_per_iMCU_row;
215
- return lines_per_iMCU_row;
216
- }
217
-
218
-
219
- /* Additional entry points for buffered-image mode. */
220
-
221
- #ifdef D_MULTISCAN_FILES_SUPPORTED
222
-
223
- /*
224
- * Initialize for an output pass in buffered-image mode.
225
- */
226
-
227
- GLOBAL(boolean)
228
- jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
229
- {
230
- if (cinfo->global_state != DSTATE_BUFIMAGE &&
231
- cinfo->global_state != DSTATE_PRESCAN)
232
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
233
- /* Limit scan number to valid range */
234
- if (scan_number <= 0)
235
- scan_number = 1;
236
- if (cinfo->inputctl->eoi_reached &&
237
- scan_number > cinfo->input_scan_number)
238
- scan_number = cinfo->input_scan_number;
239
- cinfo->output_scan_number = scan_number;
240
- /* Perform any dummy output passes, and set up for the real pass */
241
- return output_pass_setup(cinfo);
242
- }
243
-
244
-
245
- /*
246
- * Finish up after an output pass in buffered-image mode.
247
- *
248
- * Returns FALSE if suspended. The return value need be inspected only if
249
- * a suspending data source is used.
250
- */
251
-
252
- GLOBAL(boolean)
253
- jpeg_finish_output (j_decompress_ptr cinfo)
254
- {
255
- if ((cinfo->global_state == DSTATE_SCANNING ||
256
- cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
257
- /* Terminate this pass. */
258
- /* We do not require the whole pass to have been completed. */
259
- (*cinfo->master->finish_output_pass) (cinfo);
260
- cinfo->global_state = DSTATE_BUFPOST;
261
- } else if (cinfo->global_state != DSTATE_BUFPOST) {
262
- /* BUFPOST = repeat call after a suspension, anything else is error */
263
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
264
- }
265
- /* Read markers looking for SOS or EOI */
266
- while (cinfo->input_scan_number <= cinfo->output_scan_number &&
267
- ! cinfo->inputctl->eoi_reached) {
268
- if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
269
- return FALSE; /* Suspend, come back later */
270
- }
271
- cinfo->global_state = DSTATE_BUFIMAGE;
272
- return TRUE;
273
- }
274
-
275
- #endif /* D_MULTISCAN_FILES_SUPPORTED */
data/src/jpeg-7/jdarith.c DELETED
@@ -1,762 +0,0 @@
1
- /*
2
- * jdarith.c
3
- *
4
- * Developed 1997 by Guido Vollbeding.
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 portable arithmetic entropy decoding routines for JPEG
9
- * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).
10
- *
11
- * Both sequential and progressive modes are supported in this single module.
12
- *
13
- * Suspension is not currently supported in this module.
14
- */
15
-
16
- #define JPEG_INTERNALS
17
- #include "jinclude.h"
18
- #include "jpeglib.h"
19
-
20
-
21
- /* Expanded entropy decoder object for arithmetic decoding. */
22
-
23
- typedef struct {
24
- struct jpeg_entropy_decoder pub; /* public fields */
25
-
26
- INT32 c; /* C register, base of coding interval + input bit buffer */
27
- INT32 a; /* A register, normalized size of coding interval */
28
- int ct; /* bit shift counter, # of bits left in bit buffer part of C */
29
- /* init: ct = -16 */
30
- /* run: ct = 0..7 */
31
- /* error: ct = -1 */
32
- int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
33
- int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
34
-
35
- unsigned int restarts_to_go; /* MCUs left in this restart interval */
36
-
37
- /* Pointers to statistics areas (these workspaces have image lifespan) */
38
- unsigned char * dc_stats[NUM_ARITH_TBLS];
39
- unsigned char * ac_stats[NUM_ARITH_TBLS];
40
- } arith_entropy_decoder;
41
-
42
- typedef arith_entropy_decoder * arith_entropy_ptr;
43
-
44
- /* The following two definitions specify the allocation chunk size
45
- * for the statistics area.
46
- * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least
47
- * 49 statistics bins for DC, and 245 statistics bins for AC coding.
48
- * Note that we use one additional AC bin for codings with fixed
49
- * probability (0.5), thus the minimum number for AC is 246.
50
- *
51
- * We use a compact representation with 1 byte per statistics bin,
52
- * thus the numbers directly represent byte sizes.
53
- * This 1 byte per statistics bin contains the meaning of the MPS
54
- * (more probable symbol) in the highest bit (mask 0x80), and the
55
- * index into the probability estimation state machine table
56
- * in the lower bits (mask 0x7F).
57
- */
58
-
59
- #define DC_STAT_BINS 64
60
- #define AC_STAT_BINS 256
61
-
62
-
63
- LOCAL(int)
64
- get_byte (j_decompress_ptr cinfo)
65
- /* Read next input byte; we do not support suspension in this module. */
66
- {
67
- struct jpeg_source_mgr * src = cinfo->src;
68
-
69
- if (src->bytes_in_buffer == 0)
70
- if (! (*src->fill_input_buffer) (cinfo))
71
- ERREXIT(cinfo, JERR_CANT_SUSPEND);
72
- src->bytes_in_buffer--;
73
- return GETJOCTET(*src->next_input_byte++);
74
- }
75
-
76
-
77
- /*
78
- * The core arithmetic decoding routine (common in JPEG and JBIG).
79
- * This needs to go as fast as possible.
80
- * Machine-dependent optimization facilities
81
- * are not utilized in this portable implementation.
82
- * However, this code should be fairly efficient and
83
- * may be a good base for further optimizations anyway.
84
- *
85
- * Return value is 0 or 1 (binary decision).
86
- *
87
- * Note: I've changed the handling of the code base & bit
88
- * buffer register C compared to other implementations
89
- * based on the standards layout & procedures.
90
- * While it also contains both the actual base of the
91
- * coding interval (16 bits) and the next-bits buffer,
92
- * the cut-point between these two parts is floating
93
- * (instead of fixed) with the bit shift counter CT.
94
- * Thus, we also need only one (variable instead of
95
- * fixed size) shift for the LPS/MPS decision, and
96
- * we can get away with any renormalization update
97
- * of C (except for new data insertion, of course).
98
- *
99
- * I've also introduced a new scheme for accessing
100
- * the probability estimation state machine table,
101
- * derived from Markus Kuhn's JBIG implementation.
102
- */
103
-
104
- LOCAL(int)
105
- arith_decode (j_decompress_ptr cinfo, unsigned char *st)
106
- {
107
- extern const INT32 jaritab[];
108
- register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
109
- register unsigned char nl, nm;
110
- register INT32 qe, temp;
111
- register int sv, data;
112
-
113
- /* Renormalization & data input per section D.2.6 */
114
- while (e->a < 0x8000L) {
115
- if (--e->ct < 0) {
116
- /* Need to fetch next data byte */
117
- if (cinfo->unread_marker)
118
- data = 0; /* stuff zero data */
119
- else {
120
- data = get_byte(cinfo); /* read next input byte */
121
- if (data == 0xFF) { /* zero stuff or marker code */
122
- do data = get_byte(cinfo);
123
- while (data == 0xFF); /* swallow extra 0xFF bytes */
124
- if (data == 0)
125
- data = 0xFF; /* discard stuffed zero byte */
126
- else {
127
- /* Note: Different from the Huffman decoder, hitting
128
- * a marker while processing the compressed data
129
- * segment is legal in arithmetic coding.
130
- * The convention is to supply zero data
131
- * then until decoding is complete.
132
- */
133
- cinfo->unread_marker = data;
134
- data = 0;
135
- }
136
- }
137
- }
138
- e->c = (e->c << 8) | data; /* insert data into C register */
139
- if ((e->ct += 8) < 0) /* update bit shift counter */
140
- /* Need more initial bytes */
141
- if (++e->ct == 0)
142
- /* Got 2 initial bytes -> re-init A and exit loop */
143
- e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */
144
- }
145
- e->a <<= 1;
146
- }
147
-
148
- /* Fetch values from our compact representation of Table D.2:
149
- * Qe values and probability estimation state machine
150
- */
151
- sv = *st;
152
- qe = jaritab[sv & 0x7F]; /* => Qe_Value */
153
- nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
154
- nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
155
-
156
- /* Decode & estimation procedures per sections D.2.4 & D.2.5 */
157
- temp = e->a - qe;
158
- e->a = temp;
159
- temp <<= e->ct;
160
- if (e->c >= temp) {
161
- e->c -= temp;
162
- /* Conditional LPS (less probable symbol) exchange */
163
- if (e->a < qe) {
164
- e->a = qe;
165
- *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
166
- } else {
167
- e->a = qe;
168
- *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
169
- sv ^= 0x80; /* Exchange LPS/MPS */
170
- }
171
- } else if (e->a < 0x8000L) {
172
- /* Conditional MPS (more probable symbol) exchange */
173
- if (e->a < qe) {
174
- *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
175
- sv ^= 0x80; /* Exchange LPS/MPS */
176
- } else {
177
- *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
178
- }
179
- }
180
-
181
- return sv >> 7;
182
- }
183
-
184
-
185
- /*
186
- * Check for a restart marker & resynchronize decoder.
187
- */
188
-
189
- LOCAL(void)
190
- process_restart (j_decompress_ptr cinfo)
191
- {
192
- arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
193
- int ci;
194
- jpeg_component_info * compptr;
195
-
196
- /* Advance past the RSTn marker */
197
- if (! (*cinfo->marker->read_restart_marker) (cinfo))
198
- ERREXIT(cinfo, JERR_CANT_SUSPEND);
199
-
200
- for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
201
- compptr = cinfo->cur_comp_info[ci];
202
- /* Re-initialize statistics areas */
203
- if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
204
- MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
205
- /* Reset DC predictions to 0 */
206
- entropy->last_dc_val[ci] = 0;
207
- entropy->dc_context[ci] = 0;
208
- }
209
- if (cinfo->progressive_mode == 0 || cinfo->Ss) {
210
- MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
211
- }
212
- }
213
-
214
- /* Reset arithmetic decoding variables */
215
- entropy->c = 0;
216
- entropy->a = 0;
217
- entropy->ct = -16; /* force reading 2 initial bytes to fill C */
218
-
219
- /* Reset restart counter */
220
- entropy->restarts_to_go = cinfo->restart_interval;
221
- }
222
-
223
-
224
- /*
225
- * Arithmetic MCU decoding.
226
- * Each of these routines decodes and returns one MCU's worth of
227
- * arithmetic-compressed coefficients.
228
- * The coefficients are reordered from zigzag order into natural array order,
229
- * but are not dequantized.
230
- *
231
- * The i'th block of the MCU is stored into the block pointed to by
232
- * MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.
233
- */
234
-
235
- /*
236
- * MCU decoding for DC initial scan (either spectral selection,
237
- * or first pass of successive approximation).
238
- */
239
-
240
- METHODDEF(boolean)
241
- decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
242
- {
243
- arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
244
- JBLOCKROW block;
245
- unsigned char *st;
246
- int blkn, ci, tbl, sign;
247
- int v, m;
248
-
249
- /* Process restart marker if needed */
250
- if (cinfo->restart_interval) {
251
- if (entropy->restarts_to_go == 0)
252
- process_restart(cinfo);
253
- entropy->restarts_to_go--;
254
- }
255
-
256
- if (entropy->ct == -1) return TRUE; /* if error do nothing */
257
-
258
- /* Outer loop handles each block in the MCU */
259
-
260
- for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
261
- block = MCU_data[blkn];
262
- ci = cinfo->MCU_membership[blkn];
263
- tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
264
-
265
- /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */
266
-
267
- /* Table F.4: Point to statistics bin S0 for DC coefficient coding */
268
- st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
269
-
270
- /* Figure F.19: Decode_DC_DIFF */
271
- if (arith_decode(cinfo, st) == 0)
272
- entropy->dc_context[ci] = 0;
273
- else {
274
- /* Figure F.21: Decoding nonzero value v */
275
- /* Figure F.22: Decoding the sign of v */
276
- sign = arith_decode(cinfo, st + 1);
277
- st += 2; st += sign;
278
- /* Figure F.23: Decoding the magnitude category of v */
279
- if ((m = arith_decode(cinfo, st)) != 0) {
280
- st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
281
- while (arith_decode(cinfo, st)) {
282
- if ((m <<= 1) == 0x8000) {
283
- WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
284
- entropy->ct = -1; /* magnitude overflow */
285
- return TRUE;
286
- }
287
- st += 1;
288
- }
289
- }
290
- /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
291
- if (m < (int) (((INT32) 1 << cinfo->arith_dc_L[tbl]) >> 1))
292
- entropy->dc_context[ci] = 0; /* zero diff category */
293
- else if (m > (int) (((INT32) 1 << cinfo->arith_dc_U[tbl]) >> 1))
294
- entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
295
- else
296
- entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
297
- v = m;
298
- /* Figure F.24: Decoding the magnitude bit pattern of v */
299
- st += 14;
300
- while (m >>= 1)
301
- if (arith_decode(cinfo, st)) v |= m;
302
- v += 1; if (sign) v = -v;
303
- entropy->last_dc_val[ci] += v;
304
- }
305
-
306
- /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */
307
- (*block)[0] = (JCOEF) (entropy->last_dc_val[ci] << cinfo->Al);
308
- }
309
-
310
- return TRUE;
311
- }
312
-
313
-
314
- /*
315
- * MCU decoding for AC initial scan (either spectral selection,
316
- * or first pass of successive approximation).
317
- */
318
-
319
- METHODDEF(boolean)
320
- decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
321
- {
322
- arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
323
- JBLOCKROW block;
324
- unsigned char *st;
325
- int tbl, sign, k;
326
- int v, m;
327
-
328
- /* Process restart marker if needed */
329
- if (cinfo->restart_interval) {
330
- if (entropy->restarts_to_go == 0)
331
- process_restart(cinfo);
332
- entropy->restarts_to_go--;
333
- }
334
-
335
- if (entropy->ct == -1) return TRUE; /* if error do nothing */
336
-
337
- /* There is always only one block per MCU */
338
- block = MCU_data[0];
339
- tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
340
-
341
- /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
342
-
343
- /* Figure F.20: Decode_AC_coefficients */
344
- for (k = cinfo->Ss; k <= cinfo->Se; k++) {
345
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
346
- if (arith_decode(cinfo, st)) break; /* EOB flag */
347
- while (arith_decode(cinfo, st + 1) == 0) {
348
- st += 3; k++;
349
- if (k > cinfo->Se) {
350
- WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
351
- entropy->ct = -1; /* spectral overflow */
352
- return TRUE;
353
- }
354
- }
355
- /* Figure F.21: Decoding nonzero value v */
356
- /* Figure F.22: Decoding the sign of v */
357
- entropy->ac_stats[tbl][245] = 0;
358
- sign = arith_decode(cinfo, entropy->ac_stats[tbl] + 245);
359
- st += 2;
360
- /* Figure F.23: Decoding the magnitude category of v */
361
- if ((m = arith_decode(cinfo, st)) != 0) {
362
- if (arith_decode(cinfo, st)) {
363
- m <<= 1;
364
- st = entropy->ac_stats[tbl] +
365
- (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
366
- while (arith_decode(cinfo, st)) {
367
- if ((m <<= 1) == 0x8000) {
368
- WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
369
- entropy->ct = -1; /* magnitude overflow */
370
- return TRUE;
371
- }
372
- st += 1;
373
- }
374
- }
375
- }
376
- v = m;
377
- /* Figure F.24: Decoding the magnitude bit pattern of v */
378
- st += 14;
379
- while (m >>= 1)
380
- if (arith_decode(cinfo, st)) v |= m;
381
- v += 1; if (sign) v = -v;
382
- /* Scale and output coefficient in natural (dezigzagged) order */
383
- (*block)[jpeg_natural_order[k]] = (JCOEF) (v << cinfo->Al);
384
- }
385
-
386
- return TRUE;
387
- }
388
-
389
-
390
- /*
391
- * MCU decoding for DC successive approximation refinement scan.
392
- */
393
-
394
- METHODDEF(boolean)
395
- decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
396
- {
397
- arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
398
- unsigned char st[4];
399
- int p1, blkn;
400
-
401
- /* Process restart marker if needed */
402
- if (cinfo->restart_interval) {
403
- if (entropy->restarts_to_go == 0)
404
- process_restart(cinfo);
405
- entropy->restarts_to_go--;
406
- }
407
-
408
- p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
409
-
410
- /* Outer loop handles each block in the MCU */
411
-
412
- for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
413
- st[0] = 0; /* use fixed probability estimation */
414
- /* Encoded data is simply the next bit of the two's-complement DC value */
415
- if (arith_decode(cinfo, st))
416
- MCU_data[blkn][0][0] |= p1;
417
- }
418
-
419
- return TRUE;
420
- }
421
-
422
-
423
- /*
424
- * MCU decoding for AC successive approximation refinement scan.
425
- */
426
-
427
- METHODDEF(boolean)
428
- decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
429
- {
430
- arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
431
- JBLOCKROW block;
432
- JCOEFPTR thiscoef;
433
- unsigned char *st;
434
- int tbl, k, kex;
435
- int p1, m1;
436
-
437
- /* Process restart marker if needed */
438
- if (cinfo->restart_interval) {
439
- if (entropy->restarts_to_go == 0)
440
- process_restart(cinfo);
441
- entropy->restarts_to_go--;
442
- }
443
-
444
- if (entropy->ct == -1) return TRUE; /* if error do nothing */
445
-
446
- /* There is always only one block per MCU */
447
- block = MCU_data[0];
448
- tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
449
-
450
- p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
451
- m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
452
-
453
- /* Establish EOBx (previous stage end-of-block) index */
454
- for (kex = cinfo->Se + 1; kex > 1; kex--)
455
- if ((*block)[jpeg_natural_order[kex - 1]]) break;
456
-
457
- for (k = cinfo->Ss; k <= cinfo->Se; k++) {
458
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
459
- if (k >= kex)
460
- if (arith_decode(cinfo, st)) break; /* EOB flag */
461
- for (;;) {
462
- thiscoef = *block + jpeg_natural_order[k];
463
- if (*thiscoef) { /* previously nonzero coef */
464
- if (arith_decode(cinfo, st + 2)) {
465
- if (*thiscoef < 0)
466
- *thiscoef += m1;
467
- else
468
- *thiscoef += p1;
469
- }
470
- break;
471
- }
472
- if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */
473
- entropy->ac_stats[tbl][245] = 0;
474
- if (arith_decode(cinfo, entropy->ac_stats[tbl] + 245))
475
- *thiscoef = m1;
476
- else
477
- *thiscoef = p1;
478
- break;
479
- }
480
- st += 3; k++;
481
- if (k > cinfo->Se) {
482
- WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
483
- entropy->ct = -1; /* spectral overflow */
484
- return TRUE;
485
- }
486
- }
487
- }
488
-
489
- return TRUE;
490
- }
491
-
492
-
493
- /*
494
- * Decode one MCU's worth of arithmetic-compressed coefficients.
495
- */
496
-
497
- METHODDEF(boolean)
498
- decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
499
- {
500
- arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
501
- jpeg_component_info * compptr;
502
- JBLOCKROW block;
503
- unsigned char *st;
504
- int blkn, ci, tbl, sign, k;
505
- int v, m;
506
-
507
- /* Process restart marker if needed */
508
- if (cinfo->restart_interval) {
509
- if (entropy->restarts_to_go == 0)
510
- process_restart(cinfo);
511
- entropy->restarts_to_go--;
512
- }
513
-
514
- if (entropy->ct == -1) return TRUE; /* if error do nothing */
515
-
516
- /* Outer loop handles each block in the MCU */
517
-
518
- for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
519
- block = MCU_data[blkn];
520
- ci = cinfo->MCU_membership[blkn];
521
- compptr = cinfo->cur_comp_info[ci];
522
-
523
- /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */
524
-
525
- tbl = compptr->dc_tbl_no;
526
-
527
- /* Table F.4: Point to statistics bin S0 for DC coefficient coding */
528
- st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
529
-
530
- /* Figure F.19: Decode_DC_DIFF */
531
- if (arith_decode(cinfo, st) == 0)
532
- entropy->dc_context[ci] = 0;
533
- else {
534
- /* Figure F.21: Decoding nonzero value v */
535
- /* Figure F.22: Decoding the sign of v */
536
- sign = arith_decode(cinfo, st + 1);
537
- st += 2; st += sign;
538
- /* Figure F.23: Decoding the magnitude category of v */
539
- if ((m = arith_decode(cinfo, st)) != 0) {
540
- st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
541
- while (arith_decode(cinfo, st)) {
542
- if ((m <<= 1) == 0x8000) {
543
- WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
544
- entropy->ct = -1; /* magnitude overflow */
545
- return TRUE;
546
- }
547
- st += 1;
548
- }
549
- }
550
- /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
551
- if (m < (int) (((INT32) 1 << cinfo->arith_dc_L[tbl]) >> 1))
552
- entropy->dc_context[ci] = 0; /* zero diff category */
553
- else if (m > (int) (((INT32) 1 << cinfo->arith_dc_U[tbl]) >> 1))
554
- entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
555
- else
556
- entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
557
- v = m;
558
- /* Figure F.24: Decoding the magnitude bit pattern of v */
559
- st += 14;
560
- while (m >>= 1)
561
- if (arith_decode(cinfo, st)) v |= m;
562
- v += 1; if (sign) v = -v;
563
- entropy->last_dc_val[ci] += v;
564
- }
565
-
566
- (*block)[0] = (JCOEF) entropy->last_dc_val[ci];
567
-
568
- /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
569
-
570
- tbl = compptr->ac_tbl_no;
571
-
572
- /* Figure F.20: Decode_AC_coefficients */
573
- for (k = 1; k < DCTSIZE2; k++) {
574
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
575
- if (arith_decode(cinfo, st)) break; /* EOB flag */
576
- while (arith_decode(cinfo, st + 1) == 0) {
577
- st += 3; k++;
578
- if (k >= DCTSIZE2) {
579
- WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
580
- entropy->ct = -1; /* spectral overflow */
581
- return TRUE;
582
- }
583
- }
584
- /* Figure F.21: Decoding nonzero value v */
585
- /* Figure F.22: Decoding the sign of v */
586
- entropy->ac_stats[tbl][245] = 0;
587
- sign = arith_decode(cinfo, entropy->ac_stats[tbl] + 245);
588
- st += 2;
589
- /* Figure F.23: Decoding the magnitude category of v */
590
- if ((m = arith_decode(cinfo, st)) != 0) {
591
- if (arith_decode(cinfo, st)) {
592
- m <<= 1;
593
- st = entropy->ac_stats[tbl] +
594
- (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
595
- while (arith_decode(cinfo, st)) {
596
- if ((m <<= 1) == 0x8000) {
597
- WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
598
- entropy->ct = -1; /* magnitude overflow */
599
- return TRUE;
600
- }
601
- st += 1;
602
- }
603
- }
604
- }
605
- v = m;
606
- /* Figure F.24: Decoding the magnitude bit pattern of v */
607
- st += 14;
608
- while (m >>= 1)
609
- if (arith_decode(cinfo, st)) v |= m;
610
- v += 1; if (sign) v = -v;
611
- (*block)[jpeg_natural_order[k]] = (JCOEF) v;
612
- }
613
- }
614
-
615
- return TRUE;
616
- }
617
-
618
-
619
- /*
620
- * Initialize for an arithmetic-compressed scan.
621
- */
622
-
623
- METHODDEF(void)
624
- start_pass (j_decompress_ptr cinfo)
625
- {
626
- arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
627
- int ci, tbl;
628
- jpeg_component_info * compptr;
629
-
630
- if (cinfo->progressive_mode) {
631
- /* Validate progressive scan parameters */
632
- if (cinfo->Ss == 0) {
633
- if (cinfo->Se != 0)
634
- goto bad;
635
- } else {
636
- /* need not check Ss/Se < 0 since they came from unsigned bytes */
637
- if (cinfo->Se < cinfo->Ss || cinfo->Se >= DCTSIZE2)
638
- goto bad;
639
- /* AC scans may have only one component */
640
- if (cinfo->comps_in_scan != 1)
641
- goto bad;
642
- }
643
- if (cinfo->Ah != 0) {
644
- /* Successive approximation refinement scan: must have Al = Ah-1. */
645
- if (cinfo->Ah-1 != cinfo->Al)
646
- goto bad;
647
- }
648
- if (cinfo->Al > 13) { /* need not check for < 0 */
649
- bad:
650
- ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
651
- cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
652
- }
653
- /* Update progression status, and verify that scan order is legal.
654
- * Note that inter-scan inconsistencies are treated as warnings
655
- * not fatal errors ... not clear if this is right way to behave.
656
- */
657
- for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
658
- int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;
659
- int *coef_bit_ptr = & cinfo->coef_bits[cindex][0];
660
- if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
661
- WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
662
- for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
663
- int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
664
- if (cinfo->Ah != expected)
665
- WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
666
- coef_bit_ptr[coefi] = cinfo->Al;
667
- }
668
- }
669
- /* Select MCU decoding routine */
670
- if (cinfo->Ah == 0) {
671
- if (cinfo->Ss == 0)
672
- entropy->pub.decode_mcu = decode_mcu_DC_first;
673
- else
674
- entropy->pub.decode_mcu = decode_mcu_AC_first;
675
- } else {
676
- if (cinfo->Ss == 0)
677
- entropy->pub.decode_mcu = decode_mcu_DC_refine;
678
- else
679
- entropy->pub.decode_mcu = decode_mcu_AC_refine;
680
- }
681
- } else {
682
- /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
683
- * This ought to be an error condition, but we make it a warning because
684
- * there are some baseline files out there with all zeroes in these bytes.
685
- */
686
- if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
687
- cinfo->Ah != 0 || cinfo->Al != 0)
688
- WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
689
- /* Select MCU decoding routine */
690
- entropy->pub.decode_mcu = decode_mcu;
691
- }
692
-
693
- for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
694
- compptr = cinfo->cur_comp_info[ci];
695
- /* Allocate & initialize requested statistics areas */
696
- if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
697
- tbl = compptr->dc_tbl_no;
698
- if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
699
- ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
700
- if (entropy->dc_stats[tbl] == NULL)
701
- entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
702
- ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
703
- MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
704
- /* Initialize DC predictions to 0 */
705
- entropy->last_dc_val[ci] = 0;
706
- entropy->dc_context[ci] = 0;
707
- }
708
- if (cinfo->progressive_mode == 0 || cinfo->Ss) {
709
- tbl = compptr->ac_tbl_no;
710
- if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
711
- ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
712
- if (entropy->ac_stats[tbl] == NULL)
713
- entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
714
- ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
715
- MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
716
- }
717
- }
718
-
719
- /* Initialize arithmetic decoding variables */
720
- entropy->c = 0;
721
- entropy->a = 0;
722
- entropy->ct = -16; /* force reading 2 initial bytes to fill C */
723
-
724
- /* Initialize restart counter */
725
- entropy->restarts_to_go = cinfo->restart_interval;
726
- }
727
-
728
-
729
- /*
730
- * Module initialization routine for arithmetic entropy decoding.
731
- */
732
-
733
- GLOBAL(void)
734
- jinit_arith_decoder (j_decompress_ptr cinfo)
735
- {
736
- arith_entropy_ptr entropy;
737
- int i;
738
-
739
- entropy = (arith_entropy_ptr)
740
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
741
- SIZEOF(arith_entropy_decoder));
742
- cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
743
- entropy->pub.start_pass = start_pass;
744
-
745
- /* Mark tables unallocated */
746
- for (i = 0; i < NUM_ARITH_TBLS; i++) {
747
- entropy->dc_stats[i] = NULL;
748
- entropy->ac_stats[i] = NULL;
749
- }
750
-
751
- if (cinfo->progressive_mode) {
752
- /* Create progression status table */
753
- int *coef_bit_ptr, ci;
754
- cinfo->coef_bits = (int (*)[DCTSIZE2])
755
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
756
- cinfo->num_components*DCTSIZE2*SIZEOF(int));
757
- coef_bit_ptr = & cinfo->coef_bits[0][0];
758
- for (ci = 0; ci < cinfo->num_components; ci++)
759
- for (i = 0; i < DCTSIZE2; i++)
760
- *coef_bit_ptr++ = -1;
761
- }
762
- }