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,400 @@
1
+ /*
2
+ * jdmerge.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 code for merged upsampling/color conversion.
9
+ *
10
+ * This file combines functions from jdsample.c and jdcolor.c;
11
+ * read those files first to understand what's going on.
12
+ *
13
+ * When the chroma components are to be upsampled by simple replication
14
+ * (ie, box filtering), we can save some work in color conversion by
15
+ * calculating all the output pixels corresponding to a pair of chroma
16
+ * samples at one time. In the conversion equations
17
+ * R = Y + K1 * Cr
18
+ * G = Y + K2 * Cb + K3 * Cr
19
+ * B = Y + K4 * Cb
20
+ * only the Y term varies among the group of pixels corresponding to a pair
21
+ * of chroma samples, so the rest of the terms can be calculated just once.
22
+ * At typical sampling ratios, this eliminates half or three-quarters of the
23
+ * multiplications needed for color conversion.
24
+ *
25
+ * This file currently provides implementations for the following cases:
26
+ * YCbCr => RGB color conversion only.
27
+ * Sampling ratios of 2h1v or 2h2v.
28
+ * No scaling needed at upsample time.
29
+ * Corner-aligned (non-CCIR601) sampling alignment.
30
+ * Other special cases could be added, but in most applications these are
31
+ * the only common cases. (For uncommon cases we fall back on the more
32
+ * general code in jdsample.c and jdcolor.c.)
33
+ */
34
+
35
+ #define JPEG_INTERNALS
36
+ #include "jinclude.h"
37
+ #include "jpeglib.h"
38
+
39
+ #ifdef UPSAMPLE_MERGING_SUPPORTED
40
+
41
+
42
+ /* Private subobject */
43
+
44
+ typedef struct {
45
+ struct jpeg_upsampler pub; /* public fields */
46
+
47
+ /* Pointer to routine to do actual upsampling/conversion of one row group */
48
+ JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
49
+ JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
50
+ JSAMPARRAY output_buf));
51
+
52
+ /* Private state for YCC->RGB conversion */
53
+ int * Cr_r_tab; /* => table for Cr to R conversion */
54
+ int * Cb_b_tab; /* => table for Cb to B conversion */
55
+ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
56
+ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
57
+
58
+ /* For 2:1 vertical sampling, we produce two output rows at a time.
59
+ * We need a "spare" row buffer to hold the second output row if the
60
+ * application provides just a one-row buffer; we also use the spare
61
+ * to discard the dummy last row if the image height is odd.
62
+ */
63
+ JSAMPROW spare_row;
64
+ boolean spare_full; /* T if spare buffer is occupied */
65
+
66
+ JDIMENSION out_row_width; /* samples per output row */
67
+ JDIMENSION rows_to_go; /* counts rows remaining in image */
68
+ } my_upsampler;
69
+
70
+ typedef my_upsampler * my_upsample_ptr;
71
+
72
+ #define SCALEBITS 16 /* speediest right-shift on some machines */
73
+ #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
74
+ #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
75
+
76
+
77
+ /*
78
+ * Initialize tables for YCC->RGB colorspace conversion.
79
+ * This is taken directly from jdcolor.c; see that file for more info.
80
+ */
81
+
82
+ LOCAL(void)
83
+ build_ycc_rgb_table (j_decompress_ptr cinfo)
84
+ {
85
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
86
+ int i;
87
+ INT32 x;
88
+ SHIFT_TEMPS
89
+
90
+ upsample->Cr_r_tab = (int *)
91
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
92
+ (MAXJSAMPLE+1) * SIZEOF(int));
93
+ upsample->Cb_b_tab = (int *)
94
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
95
+ (MAXJSAMPLE+1) * SIZEOF(int));
96
+ upsample->Cr_g_tab = (INT32 *)
97
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
98
+ (MAXJSAMPLE+1) * SIZEOF(INT32));
99
+ upsample->Cb_g_tab = (INT32 *)
100
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
101
+ (MAXJSAMPLE+1) * SIZEOF(INT32));
102
+
103
+ for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
104
+ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
105
+ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
106
+ /* Cr=>R value is nearest int to 1.40200 * x */
107
+ upsample->Cr_r_tab[i] = (int)
108
+ RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
109
+ /* Cb=>B value is nearest int to 1.77200 * x */
110
+ upsample->Cb_b_tab[i] = (int)
111
+ RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
112
+ /* Cr=>G value is scaled-up -0.71414 * x */
113
+ upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
114
+ /* Cb=>G value is scaled-up -0.34414 * x */
115
+ /* We also add in ONE_HALF so that need not do it in inner loop */
116
+ upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
117
+ }
118
+ }
119
+
120
+
121
+ /*
122
+ * Initialize for an upsampling pass.
123
+ */
124
+
125
+ METHODDEF(void)
126
+ start_pass_merged_upsample (j_decompress_ptr cinfo)
127
+ {
128
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
129
+
130
+ /* Mark the spare buffer empty */
131
+ upsample->spare_full = FALSE;
132
+ /* Initialize total-height counter for detecting bottom of image */
133
+ upsample->rows_to_go = cinfo->output_height;
134
+ }
135
+
136
+
137
+ /*
138
+ * Control routine to do upsampling (and color conversion).
139
+ *
140
+ * The control routine just handles the row buffering considerations.
141
+ */
142
+
143
+ METHODDEF(void)
144
+ merged_2v_upsample (j_decompress_ptr cinfo,
145
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
146
+ JDIMENSION in_row_groups_avail,
147
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
148
+ JDIMENSION out_rows_avail)
149
+ /* 2:1 vertical sampling case: may need a spare row. */
150
+ {
151
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
152
+ JSAMPROW work_ptrs[2];
153
+ JDIMENSION num_rows; /* number of rows returned to caller */
154
+
155
+ if (upsample->spare_full) {
156
+ /* If we have a spare row saved from a previous cycle, just return it. */
157
+ jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
158
+ 1, upsample->out_row_width);
159
+ num_rows = 1;
160
+ upsample->spare_full = FALSE;
161
+ } else {
162
+ /* Figure number of rows to return to caller. */
163
+ num_rows = 2;
164
+ /* Not more than the distance to the end of the image. */
165
+ if (num_rows > upsample->rows_to_go)
166
+ num_rows = upsample->rows_to_go;
167
+ /* And not more than what the client can accept: */
168
+ out_rows_avail -= *out_row_ctr;
169
+ if (num_rows > out_rows_avail)
170
+ num_rows = out_rows_avail;
171
+ /* Create output pointer array for upsampler. */
172
+ work_ptrs[0] = output_buf[*out_row_ctr];
173
+ if (num_rows > 1) {
174
+ work_ptrs[1] = output_buf[*out_row_ctr + 1];
175
+ } else {
176
+ work_ptrs[1] = upsample->spare_row;
177
+ upsample->spare_full = TRUE;
178
+ }
179
+ /* Now do the upsampling. */
180
+ (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
181
+ }
182
+
183
+ /* Adjust counts */
184
+ *out_row_ctr += num_rows;
185
+ upsample->rows_to_go -= num_rows;
186
+ /* When the buffer is emptied, declare this input row group consumed */
187
+ if (! upsample->spare_full)
188
+ (*in_row_group_ctr)++;
189
+ }
190
+
191
+
192
+ METHODDEF(void)
193
+ merged_1v_upsample (j_decompress_ptr cinfo,
194
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
195
+ JDIMENSION in_row_groups_avail,
196
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
197
+ JDIMENSION out_rows_avail)
198
+ /* 1:1 vertical sampling case: much easier, never need a spare row. */
199
+ {
200
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
201
+
202
+ /* Just do the upsampling. */
203
+ (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
204
+ output_buf + *out_row_ctr);
205
+ /* Adjust counts */
206
+ (*out_row_ctr)++;
207
+ (*in_row_group_ctr)++;
208
+ }
209
+
210
+
211
+ /*
212
+ * These are the routines invoked by the control routines to do
213
+ * the actual upsampling/conversion. One row group is processed per call.
214
+ *
215
+ * Note: since we may be writing directly into application-supplied buffers,
216
+ * we have to be honest about the output width; we can't assume the buffer
217
+ * has been rounded up to an even width.
218
+ */
219
+
220
+
221
+ /*
222
+ * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
223
+ */
224
+
225
+ METHODDEF(void)
226
+ h2v1_merged_upsample (j_decompress_ptr cinfo,
227
+ JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
228
+ JSAMPARRAY output_buf)
229
+ {
230
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
231
+ register int y, cred, cgreen, cblue;
232
+ int cb, cr;
233
+ register JSAMPROW outptr;
234
+ JSAMPROW inptr0, inptr1, inptr2;
235
+ JDIMENSION col;
236
+ /* copy these pointers into registers if possible */
237
+ register JSAMPLE * range_limit = cinfo->sample_range_limit;
238
+ int * Crrtab = upsample->Cr_r_tab;
239
+ int * Cbbtab = upsample->Cb_b_tab;
240
+ INT32 * Crgtab = upsample->Cr_g_tab;
241
+ INT32 * Cbgtab = upsample->Cb_g_tab;
242
+ SHIFT_TEMPS
243
+
244
+ inptr0 = input_buf[0][in_row_group_ctr];
245
+ inptr1 = input_buf[1][in_row_group_ctr];
246
+ inptr2 = input_buf[2][in_row_group_ctr];
247
+ outptr = output_buf[0];
248
+ /* Loop for each pair of output pixels */
249
+ for (col = cinfo->output_width >> 1; col > 0; col--) {
250
+ /* Do the chroma part of the calculation */
251
+ cb = GETJSAMPLE(*inptr1++);
252
+ cr = GETJSAMPLE(*inptr2++);
253
+ cred = Crrtab[cr];
254
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
255
+ cblue = Cbbtab[cb];
256
+ /* Fetch 2 Y values and emit 2 pixels */
257
+ y = GETJSAMPLE(*inptr0++);
258
+ outptr[RGB_RED] = range_limit[y + cred];
259
+ outptr[RGB_GREEN] = range_limit[y + cgreen];
260
+ outptr[RGB_BLUE] = range_limit[y + cblue];
261
+ outptr += RGB_PIXELSIZE;
262
+ y = GETJSAMPLE(*inptr0++);
263
+ outptr[RGB_RED] = range_limit[y + cred];
264
+ outptr[RGB_GREEN] = range_limit[y + cgreen];
265
+ outptr[RGB_BLUE] = range_limit[y + cblue];
266
+ outptr += RGB_PIXELSIZE;
267
+ }
268
+ /* If image width is odd, do the last output column separately */
269
+ if (cinfo->output_width & 1) {
270
+ cb = GETJSAMPLE(*inptr1);
271
+ cr = GETJSAMPLE(*inptr2);
272
+ cred = Crrtab[cr];
273
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
274
+ cblue = Cbbtab[cb];
275
+ y = GETJSAMPLE(*inptr0);
276
+ outptr[RGB_RED] = range_limit[y + cred];
277
+ outptr[RGB_GREEN] = range_limit[y + cgreen];
278
+ outptr[RGB_BLUE] = range_limit[y + cblue];
279
+ }
280
+ }
281
+
282
+
283
+ /*
284
+ * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
285
+ */
286
+
287
+ METHODDEF(void)
288
+ h2v2_merged_upsample (j_decompress_ptr cinfo,
289
+ JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
290
+ JSAMPARRAY output_buf)
291
+ {
292
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
293
+ register int y, cred, cgreen, cblue;
294
+ int cb, cr;
295
+ register JSAMPROW outptr0, outptr1;
296
+ JSAMPROW inptr00, inptr01, inptr1, inptr2;
297
+ JDIMENSION col;
298
+ /* copy these pointers into registers if possible */
299
+ register JSAMPLE * range_limit = cinfo->sample_range_limit;
300
+ int * Crrtab = upsample->Cr_r_tab;
301
+ int * Cbbtab = upsample->Cb_b_tab;
302
+ INT32 * Crgtab = upsample->Cr_g_tab;
303
+ INT32 * Cbgtab = upsample->Cb_g_tab;
304
+ SHIFT_TEMPS
305
+
306
+ inptr00 = input_buf[0][in_row_group_ctr*2];
307
+ inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
308
+ inptr1 = input_buf[1][in_row_group_ctr];
309
+ inptr2 = input_buf[2][in_row_group_ctr];
310
+ outptr0 = output_buf[0];
311
+ outptr1 = output_buf[1];
312
+ /* Loop for each group of output pixels */
313
+ for (col = cinfo->output_width >> 1; col > 0; col--) {
314
+ /* Do the chroma part of the calculation */
315
+ cb = GETJSAMPLE(*inptr1++);
316
+ cr = GETJSAMPLE(*inptr2++);
317
+ cred = Crrtab[cr];
318
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
319
+ cblue = Cbbtab[cb];
320
+ /* Fetch 4 Y values and emit 4 pixels */
321
+ y = GETJSAMPLE(*inptr00++);
322
+ outptr0[RGB_RED] = range_limit[y + cred];
323
+ outptr0[RGB_GREEN] = range_limit[y + cgreen];
324
+ outptr0[RGB_BLUE] = range_limit[y + cblue];
325
+ outptr0 += RGB_PIXELSIZE;
326
+ y = GETJSAMPLE(*inptr00++);
327
+ outptr0[RGB_RED] = range_limit[y + cred];
328
+ outptr0[RGB_GREEN] = range_limit[y + cgreen];
329
+ outptr0[RGB_BLUE] = range_limit[y + cblue];
330
+ outptr0 += RGB_PIXELSIZE;
331
+ y = GETJSAMPLE(*inptr01++);
332
+ outptr1[RGB_RED] = range_limit[y + cred];
333
+ outptr1[RGB_GREEN] = range_limit[y + cgreen];
334
+ outptr1[RGB_BLUE] = range_limit[y + cblue];
335
+ outptr1 += RGB_PIXELSIZE;
336
+ y = GETJSAMPLE(*inptr01++);
337
+ outptr1[RGB_RED] = range_limit[y + cred];
338
+ outptr1[RGB_GREEN] = range_limit[y + cgreen];
339
+ outptr1[RGB_BLUE] = range_limit[y + cblue];
340
+ outptr1 += RGB_PIXELSIZE;
341
+ }
342
+ /* If image width is odd, do the last output column separately */
343
+ if (cinfo->output_width & 1) {
344
+ cb = GETJSAMPLE(*inptr1);
345
+ cr = GETJSAMPLE(*inptr2);
346
+ cred = Crrtab[cr];
347
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
348
+ cblue = Cbbtab[cb];
349
+ y = GETJSAMPLE(*inptr00);
350
+ outptr0[RGB_RED] = range_limit[y + cred];
351
+ outptr0[RGB_GREEN] = range_limit[y + cgreen];
352
+ outptr0[RGB_BLUE] = range_limit[y + cblue];
353
+ y = GETJSAMPLE(*inptr01);
354
+ outptr1[RGB_RED] = range_limit[y + cred];
355
+ outptr1[RGB_GREEN] = range_limit[y + cgreen];
356
+ outptr1[RGB_BLUE] = range_limit[y + cblue];
357
+ }
358
+ }
359
+
360
+
361
+ /*
362
+ * Module initialization routine for merged upsampling/color conversion.
363
+ *
364
+ * NB: this is called under the conditions determined by use_merged_upsample()
365
+ * in jdmaster.c. That routine MUST correspond to the actual capabilities
366
+ * of this module; no safety checks are made here.
367
+ */
368
+
369
+ GLOBAL(void)
370
+ jinit_merged_upsampler (j_decompress_ptr cinfo)
371
+ {
372
+ my_upsample_ptr upsample;
373
+
374
+ upsample = (my_upsample_ptr)
375
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
376
+ SIZEOF(my_upsampler));
377
+ cinfo->upsample = (struct jpeg_upsampler *) upsample;
378
+ upsample->pub.start_pass = start_pass_merged_upsample;
379
+ upsample->pub.need_context_rows = FALSE;
380
+
381
+ upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
382
+
383
+ if (cinfo->max_v_samp_factor == 2) {
384
+ upsample->pub.upsample = merged_2v_upsample;
385
+ upsample->upmethod = h2v2_merged_upsample;
386
+ /* Allocate a spare row buffer */
387
+ upsample->spare_row = (JSAMPROW)
388
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
389
+ (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
390
+ } else {
391
+ upsample->pub.upsample = merged_1v_upsample;
392
+ upsample->upmethod = h2v1_merged_upsample;
393
+ /* No spare row needed */
394
+ upsample->spare_row = NULL;
395
+ }
396
+
397
+ build_ycc_rgb_table(cinfo);
398
+ }
399
+
400
+ #endif /* UPSAMPLE_MERGING_SUPPORTED */
@@ -0,0 +1,290 @@
1
+ /*
2
+ * jdpostct.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 the decompression postprocessing controller.
9
+ * This controller manages the upsampling, color conversion, and color
10
+ * quantization/reduction steps; specifically, it controls the buffering
11
+ * between upsample/color conversion and color quantization/reduction.
12
+ *
13
+ * If no color quantization/reduction is required, then this module has no
14
+ * work to do, and it just hands off to the upsample/color conversion code.
15
+ * An integrated upsample/convert/quantize process would replace this module
16
+ * entirely.
17
+ */
18
+
19
+ #define JPEG_INTERNALS
20
+ #include "jinclude.h"
21
+ #include "jpeglib.h"
22
+
23
+
24
+ /* Private buffer controller object */
25
+
26
+ typedef struct {
27
+ struct jpeg_d_post_controller pub; /* public fields */
28
+
29
+ /* Color quantization source buffer: this holds output data from
30
+ * the upsample/color conversion step to be passed to the quantizer.
31
+ * For two-pass color quantization, we need a full-image buffer;
32
+ * for one-pass operation, a strip buffer is sufficient.
33
+ */
34
+ jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
35
+ JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
36
+ JDIMENSION strip_height; /* buffer size in rows */
37
+ /* for two-pass mode only: */
38
+ JDIMENSION starting_row; /* row # of first row in current strip */
39
+ JDIMENSION next_row; /* index of next row to fill/empty in strip */
40
+ } my_post_controller;
41
+
42
+ typedef my_post_controller * my_post_ptr;
43
+
44
+
45
+ /* Forward declarations */
46
+ METHODDEF(void) post_process_1pass
47
+ JPP((j_decompress_ptr cinfo,
48
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
49
+ JDIMENSION in_row_groups_avail,
50
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
51
+ JDIMENSION out_rows_avail));
52
+ #ifdef QUANT_2PASS_SUPPORTED
53
+ METHODDEF(void) post_process_prepass
54
+ JPP((j_decompress_ptr cinfo,
55
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
56
+ JDIMENSION in_row_groups_avail,
57
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
58
+ JDIMENSION out_rows_avail));
59
+ METHODDEF(void) post_process_2pass
60
+ JPP((j_decompress_ptr cinfo,
61
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
62
+ JDIMENSION in_row_groups_avail,
63
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
64
+ JDIMENSION out_rows_avail));
65
+ #endif
66
+
67
+
68
+ /*
69
+ * Initialize for a processing pass.
70
+ */
71
+
72
+ METHODDEF(void)
73
+ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
74
+ {
75
+ my_post_ptr post = (my_post_ptr) cinfo->post;
76
+
77
+ switch (pass_mode) {
78
+ case JBUF_PASS_THRU:
79
+ if (cinfo->quantize_colors) {
80
+ /* Single-pass processing with color quantization. */
81
+ post->pub.post_process_data = post_process_1pass;
82
+ /* We could be doing buffered-image output before starting a 2-pass
83
+ * color quantization; in that case, jinit_d_post_controller did not
84
+ * allocate a strip buffer. Use the virtual-array buffer as workspace.
85
+ */
86
+ if (post->buffer == NULL) {
87
+ post->buffer = (*cinfo->mem->access_virt_sarray)
88
+ ((j_common_ptr) cinfo, post->whole_image,
89
+ (JDIMENSION) 0, post->strip_height, TRUE);
90
+ }
91
+ } else {
92
+ /* For single-pass processing without color quantization,
93
+ * I have no work to do; just call the upsampler directly.
94
+ */
95
+ post->pub.post_process_data = cinfo->upsample->upsample;
96
+ }
97
+ break;
98
+ #ifdef QUANT_2PASS_SUPPORTED
99
+ case JBUF_SAVE_AND_PASS:
100
+ /* First pass of 2-pass quantization */
101
+ if (post->whole_image == NULL)
102
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
103
+ post->pub.post_process_data = post_process_prepass;
104
+ break;
105
+ case JBUF_CRANK_DEST:
106
+ /* Second pass of 2-pass quantization */
107
+ if (post->whole_image == NULL)
108
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
109
+ post->pub.post_process_data = post_process_2pass;
110
+ break;
111
+ #endif /* QUANT_2PASS_SUPPORTED */
112
+ default:
113
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
114
+ break;
115
+ }
116
+ post->starting_row = post->next_row = 0;
117
+ }
118
+
119
+
120
+ /*
121
+ * Process some data in the one-pass (strip buffer) case.
122
+ * This is used for color precision reduction as well as one-pass quantization.
123
+ */
124
+
125
+ METHODDEF(void)
126
+ post_process_1pass (j_decompress_ptr cinfo,
127
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
128
+ JDIMENSION in_row_groups_avail,
129
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
130
+ JDIMENSION out_rows_avail)
131
+ {
132
+ my_post_ptr post = (my_post_ptr) cinfo->post;
133
+ JDIMENSION num_rows, max_rows;
134
+
135
+ /* Fill the buffer, but not more than what we can dump out in one go. */
136
+ /* Note we rely on the upsampler to detect bottom of image. */
137
+ max_rows = out_rows_avail - *out_row_ctr;
138
+ if (max_rows > post->strip_height)
139
+ max_rows = post->strip_height;
140
+ num_rows = 0;
141
+ (*cinfo->upsample->upsample) (cinfo,
142
+ input_buf, in_row_group_ctr, in_row_groups_avail,
143
+ post->buffer, &num_rows, max_rows);
144
+ /* Quantize and emit data. */
145
+ (*cinfo->cquantize->color_quantize) (cinfo,
146
+ post->buffer, output_buf + *out_row_ctr, (int) num_rows);
147
+ *out_row_ctr += num_rows;
148
+ }
149
+
150
+
151
+ #ifdef QUANT_2PASS_SUPPORTED
152
+
153
+ /*
154
+ * Process some data in the first pass of 2-pass quantization.
155
+ */
156
+
157
+ METHODDEF(void)
158
+ post_process_prepass (j_decompress_ptr cinfo,
159
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
160
+ JDIMENSION in_row_groups_avail,
161
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
162
+ JDIMENSION out_rows_avail)
163
+ {
164
+ my_post_ptr post = (my_post_ptr) cinfo->post;
165
+ JDIMENSION old_next_row, num_rows;
166
+
167
+ /* Reposition virtual buffer if at start of strip. */
168
+ if (post->next_row == 0) {
169
+ post->buffer = (*cinfo->mem->access_virt_sarray)
170
+ ((j_common_ptr) cinfo, post->whole_image,
171
+ post->starting_row, post->strip_height, TRUE);
172
+ }
173
+
174
+ /* Upsample some data (up to a strip height's worth). */
175
+ old_next_row = post->next_row;
176
+ (*cinfo->upsample->upsample) (cinfo,
177
+ input_buf, in_row_group_ctr, in_row_groups_avail,
178
+ post->buffer, &post->next_row, post->strip_height);
179
+
180
+ /* Allow quantizer to scan new data. No data is emitted, */
181
+ /* but we advance out_row_ctr so outer loop can tell when we're done. */
182
+ if (post->next_row > old_next_row) {
183
+ num_rows = post->next_row - old_next_row;
184
+ (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
185
+ (JSAMPARRAY) NULL, (int) num_rows);
186
+ *out_row_ctr += num_rows;
187
+ }
188
+
189
+ /* Advance if we filled the strip. */
190
+ if (post->next_row >= post->strip_height) {
191
+ post->starting_row += post->strip_height;
192
+ post->next_row = 0;
193
+ }
194
+ }
195
+
196
+
197
+ /*
198
+ * Process some data in the second pass of 2-pass quantization.
199
+ */
200
+
201
+ METHODDEF(void)
202
+ post_process_2pass (j_decompress_ptr cinfo,
203
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
204
+ JDIMENSION in_row_groups_avail,
205
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
206
+ JDIMENSION out_rows_avail)
207
+ {
208
+ my_post_ptr post = (my_post_ptr) cinfo->post;
209
+ JDIMENSION num_rows, max_rows;
210
+
211
+ /* Reposition virtual buffer if at start of strip. */
212
+ if (post->next_row == 0) {
213
+ post->buffer = (*cinfo->mem->access_virt_sarray)
214
+ ((j_common_ptr) cinfo, post->whole_image,
215
+ post->starting_row, post->strip_height, FALSE);
216
+ }
217
+
218
+ /* Determine number of rows to emit. */
219
+ num_rows = post->strip_height - post->next_row; /* available in strip */
220
+ max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
221
+ if (num_rows > max_rows)
222
+ num_rows = max_rows;
223
+ /* We have to check bottom of image here, can't depend on upsampler. */
224
+ max_rows = cinfo->output_height - post->starting_row;
225
+ if (num_rows > max_rows)
226
+ num_rows = max_rows;
227
+
228
+ /* Quantize and emit data. */
229
+ (*cinfo->cquantize->color_quantize) (cinfo,
230
+ post->buffer + post->next_row, output_buf + *out_row_ctr,
231
+ (int) num_rows);
232
+ *out_row_ctr += num_rows;
233
+
234
+ /* Advance if we filled the strip. */
235
+ post->next_row += num_rows;
236
+ if (post->next_row >= post->strip_height) {
237
+ post->starting_row += post->strip_height;
238
+ post->next_row = 0;
239
+ }
240
+ }
241
+
242
+ #endif /* QUANT_2PASS_SUPPORTED */
243
+
244
+
245
+ /*
246
+ * Initialize postprocessing controller.
247
+ */
248
+
249
+ GLOBAL(void)
250
+ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
251
+ {
252
+ my_post_ptr post;
253
+
254
+ post = (my_post_ptr)
255
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
256
+ SIZEOF(my_post_controller));
257
+ cinfo->post = (struct jpeg_d_post_controller *) post;
258
+ post->pub.start_pass = start_pass_dpost;
259
+ post->whole_image = NULL; /* flag for no virtual arrays */
260
+ post->buffer = NULL; /* flag for no strip buffer */
261
+
262
+ /* Create the quantization buffer, if needed */
263
+ if (cinfo->quantize_colors) {
264
+ /* The buffer strip height is max_v_samp_factor, which is typically
265
+ * an efficient number of rows for upsampling to return.
266
+ * (In the presence of output rescaling, we might want to be smarter?)
267
+ */
268
+ post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
269
+ if (need_full_buffer) {
270
+ /* Two-pass color quantization: need full-image storage. */
271
+ /* We round up the number of rows to a multiple of the strip height. */
272
+ #ifdef QUANT_2PASS_SUPPORTED
273
+ post->whole_image = (*cinfo->mem->request_virt_sarray)
274
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
275
+ cinfo->output_width * cinfo->out_color_components,
276
+ (JDIMENSION) jround_up((long) cinfo->output_height,
277
+ (long) post->strip_height),
278
+ post->strip_height);
279
+ #else
280
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
281
+ #endif /* QUANT_2PASS_SUPPORTED */
282
+ } else {
283
+ /* One-pass color quantization: just make a strip buffer. */
284
+ post->buffer = (*cinfo->mem->alloc_sarray)
285
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
286
+ cinfo->output_width * cinfo->out_color_components,
287
+ post->strip_height);
288
+ }
289
+ }
290
+ }