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,358 @@
1
+ /*
2
+ * jcprepct.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 compression preprocessing controller.
9
+ * This controller manages the color conversion, downsampling,
10
+ * and edge expansion steps.
11
+ *
12
+ * Most of the complexity here is associated with buffering input rows
13
+ * as required by the downsampler. See the comments at the head of
14
+ * jcsample.c for the downsampler's needs.
15
+ */
16
+
17
+ #define JPEG_INTERNALS
18
+ #include "jinclude.h"
19
+ #include "jpeglib.h"
20
+
21
+
22
+ /* At present, jcsample.c can request context rows only for smoothing.
23
+ * In the future, we might also need context rows for CCIR601 sampling
24
+ * or other more-complex downsampling procedures. The code to support
25
+ * context rows should be compiled only if needed.
26
+ */
27
+ #ifdef INPUT_SMOOTHING_SUPPORTED
28
+ #define CONTEXT_ROWS_SUPPORTED
29
+ #endif
30
+
31
+
32
+ /*
33
+ * For the simple (no-context-row) case, we just need to buffer one
34
+ * row group's worth of pixels for the downsampling step. At the bottom of
35
+ * the image, we pad to a full row group by replicating the last pixel row.
36
+ * The downsampler's last output row is then replicated if needed to pad
37
+ * out to a full iMCU row.
38
+ *
39
+ * When providing context rows, we must buffer three row groups' worth of
40
+ * pixels. Three row groups are physically allocated, but the row pointer
41
+ * arrays are made five row groups high, with the extra pointers above and
42
+ * below "wrapping around" to point to the last and first real row groups.
43
+ * This allows the downsampler to access the proper context rows.
44
+ * At the top and bottom of the image, we create dummy context rows by
45
+ * copying the first or last real pixel row. This copying could be avoided
46
+ * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the
47
+ * trouble on the compression side.
48
+ */
49
+
50
+
51
+ /* Private buffer controller object */
52
+
53
+ typedef struct {
54
+ struct jpeg_c_prep_controller pub; /* public fields */
55
+
56
+ /* Downsampling input buffer. This buffer holds color-converted data
57
+ * until we have enough to do a downsample step.
58
+ */
59
+ JSAMPARRAY color_buf[MAX_COMPONENTS];
60
+
61
+ JDIMENSION rows_to_go; /* counts rows remaining in source image */
62
+ int next_buf_row; /* index of next row to store in color_buf */
63
+
64
+ #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
65
+ int this_row_group; /* starting row index of group to process */
66
+ int next_buf_stop; /* downsample when we reach this index */
67
+ #endif
68
+ } my_prep_controller;
69
+
70
+ typedef my_prep_controller * my_prep_ptr;
71
+
72
+
73
+ /*
74
+ * Initialize for a processing pass.
75
+ */
76
+
77
+ METHODDEF(void)
78
+ start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
79
+ {
80
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
81
+
82
+ if (pass_mode != JBUF_PASS_THRU)
83
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
84
+
85
+ /* Initialize total-height counter for detecting bottom of image */
86
+ prep->rows_to_go = cinfo->image_height;
87
+ /* Mark the conversion buffer empty */
88
+ prep->next_buf_row = 0;
89
+ #ifdef CONTEXT_ROWS_SUPPORTED
90
+ /* Preset additional state variables for context mode.
91
+ * These aren't used in non-context mode, so we needn't test which mode.
92
+ */
93
+ prep->this_row_group = 0;
94
+ /* Set next_buf_stop to stop after two row groups have been read in. */
95
+ prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
96
+ #endif
97
+ }
98
+
99
+
100
+ /*
101
+ * Expand an image vertically from height input_rows to height output_rows,
102
+ * by duplicating the bottom row.
103
+ */
104
+
105
+ LOCAL(void)
106
+ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
107
+ int input_rows, int output_rows)
108
+ {
109
+ register int row;
110
+
111
+ for (row = input_rows; row < output_rows; row++) {
112
+ jcopy_sample_rows(image_data, input_rows-1, image_data, row,
113
+ 1, num_cols);
114
+ }
115
+ }
116
+
117
+
118
+ /*
119
+ * Process some data in the simple no-context case.
120
+ *
121
+ * Preprocessor output data is counted in "row groups". A row group
122
+ * is defined to be v_samp_factor sample rows of each component.
123
+ * Downsampling will produce this much data from each max_v_samp_factor
124
+ * input rows.
125
+ */
126
+
127
+ METHODDEF(void)
128
+ pre_process_data (j_compress_ptr cinfo,
129
+ JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
130
+ JDIMENSION in_rows_avail,
131
+ JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
132
+ JDIMENSION out_row_groups_avail)
133
+ {
134
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
135
+ int numrows, ci;
136
+ JDIMENSION inrows;
137
+ jpeg_component_info * compptr;
138
+
139
+ while (*in_row_ctr < in_rows_avail &&
140
+ *out_row_group_ctr < out_row_groups_avail) {
141
+ /* Do color conversion to fill the conversion buffer. */
142
+ inrows = in_rows_avail - *in_row_ctr;
143
+ numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
144
+ numrows = (int) MIN((JDIMENSION) numrows, inrows);
145
+ (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
146
+ prep->color_buf,
147
+ (JDIMENSION) prep->next_buf_row,
148
+ numrows);
149
+ *in_row_ctr += numrows;
150
+ prep->next_buf_row += numrows;
151
+ prep->rows_to_go -= numrows;
152
+ /* If at bottom of image, pad to fill the conversion buffer. */
153
+ if (prep->rows_to_go == 0 &&
154
+ prep->next_buf_row < cinfo->max_v_samp_factor) {
155
+ for (ci = 0; ci < cinfo->num_components; ci++) {
156
+ expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
157
+ prep->next_buf_row, cinfo->max_v_samp_factor);
158
+ }
159
+ prep->next_buf_row = cinfo->max_v_samp_factor;
160
+ }
161
+ /* If we've filled the conversion buffer, empty it. */
162
+ if (prep->next_buf_row == cinfo->max_v_samp_factor) {
163
+ (*cinfo->downsample->downsample) (cinfo,
164
+ prep->color_buf, (JDIMENSION) 0,
165
+ output_buf, *out_row_group_ctr);
166
+ prep->next_buf_row = 0;
167
+ (*out_row_group_ctr)++;
168
+ }
169
+ /* If at bottom of image, pad the output to a full iMCU height.
170
+ * Note we assume the caller is providing a one-iMCU-height output buffer!
171
+ */
172
+ if (prep->rows_to_go == 0 &&
173
+ *out_row_group_ctr < out_row_groups_avail) {
174
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
175
+ ci++, compptr++) {
176
+ numrows = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
177
+ cinfo->min_DCT_v_scaled_size;
178
+ expand_bottom_edge(output_buf[ci],
179
+ compptr->width_in_blocks * compptr->DCT_h_scaled_size,
180
+ (int) (*out_row_group_ctr * numrows),
181
+ (int) (out_row_groups_avail * numrows));
182
+ }
183
+ *out_row_group_ctr = out_row_groups_avail;
184
+ break; /* can exit outer loop without test */
185
+ }
186
+ }
187
+ }
188
+
189
+
190
+ #ifdef CONTEXT_ROWS_SUPPORTED
191
+
192
+ /*
193
+ * Process some data in the context case.
194
+ */
195
+
196
+ METHODDEF(void)
197
+ pre_process_context (j_compress_ptr cinfo,
198
+ JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
199
+ JDIMENSION in_rows_avail,
200
+ JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
201
+ JDIMENSION out_row_groups_avail)
202
+ {
203
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
204
+ int numrows, ci;
205
+ int buf_height = cinfo->max_v_samp_factor * 3;
206
+ JDIMENSION inrows;
207
+
208
+ while (*out_row_group_ctr < out_row_groups_avail) {
209
+ if (*in_row_ctr < in_rows_avail) {
210
+ /* Do color conversion to fill the conversion buffer. */
211
+ inrows = in_rows_avail - *in_row_ctr;
212
+ numrows = prep->next_buf_stop - prep->next_buf_row;
213
+ numrows = (int) MIN((JDIMENSION) numrows, inrows);
214
+ (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
215
+ prep->color_buf,
216
+ (JDIMENSION) prep->next_buf_row,
217
+ numrows);
218
+ /* Pad at top of image, if first time through */
219
+ if (prep->rows_to_go == cinfo->image_height) {
220
+ for (ci = 0; ci < cinfo->num_components; ci++) {
221
+ int row;
222
+ for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
223
+ jcopy_sample_rows(prep->color_buf[ci], 0,
224
+ prep->color_buf[ci], -row,
225
+ 1, cinfo->image_width);
226
+ }
227
+ }
228
+ }
229
+ *in_row_ctr += numrows;
230
+ prep->next_buf_row += numrows;
231
+ prep->rows_to_go -= numrows;
232
+ } else {
233
+ /* Return for more data, unless we are at the bottom of the image. */
234
+ if (prep->rows_to_go != 0)
235
+ break;
236
+ /* When at bottom of image, pad to fill the conversion buffer. */
237
+ if (prep->next_buf_row < prep->next_buf_stop) {
238
+ for (ci = 0; ci < cinfo->num_components; ci++) {
239
+ expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
240
+ prep->next_buf_row, prep->next_buf_stop);
241
+ }
242
+ prep->next_buf_row = prep->next_buf_stop;
243
+ }
244
+ }
245
+ /* If we've gotten enough data, downsample a row group. */
246
+ if (prep->next_buf_row == prep->next_buf_stop) {
247
+ (*cinfo->downsample->downsample) (cinfo,
248
+ prep->color_buf,
249
+ (JDIMENSION) prep->this_row_group,
250
+ output_buf, *out_row_group_ctr);
251
+ (*out_row_group_ctr)++;
252
+ /* Advance pointers with wraparound as necessary. */
253
+ prep->this_row_group += cinfo->max_v_samp_factor;
254
+ if (prep->this_row_group >= buf_height)
255
+ prep->this_row_group = 0;
256
+ if (prep->next_buf_row >= buf_height)
257
+ prep->next_buf_row = 0;
258
+ prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
259
+ }
260
+ }
261
+ }
262
+
263
+
264
+ /*
265
+ * Create the wrapped-around downsampling input buffer needed for context mode.
266
+ */
267
+
268
+ LOCAL(void)
269
+ create_context_buffer (j_compress_ptr cinfo)
270
+ {
271
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
272
+ int rgroup_height = cinfo->max_v_samp_factor;
273
+ int ci, i;
274
+ jpeg_component_info * compptr;
275
+ JSAMPARRAY true_buffer, fake_buffer;
276
+
277
+ /* Grab enough space for fake row pointers for all the components;
278
+ * we need five row groups' worth of pointers for each component.
279
+ */
280
+ fake_buffer = (JSAMPARRAY)
281
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
282
+ (cinfo->num_components * 5 * rgroup_height) *
283
+ SIZEOF(JSAMPROW));
284
+
285
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
286
+ ci++, compptr++) {
287
+ /* Allocate the actual buffer space (3 row groups) for this component.
288
+ * We make the buffer wide enough to allow the downsampler to edge-expand
289
+ * horizontally within the buffer, if it so chooses.
290
+ */
291
+ true_buffer = (*cinfo->mem->alloc_sarray)
292
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
293
+ (JDIMENSION) (((long) compptr->width_in_blocks *
294
+ cinfo->min_DCT_h_scaled_size *
295
+ cinfo->max_h_samp_factor) / compptr->h_samp_factor),
296
+ (JDIMENSION) (3 * rgroup_height));
297
+ /* Copy true buffer row pointers into the middle of the fake row array */
298
+ MEMCOPY(fake_buffer + rgroup_height, true_buffer,
299
+ 3 * rgroup_height * SIZEOF(JSAMPROW));
300
+ /* Fill in the above and below wraparound pointers */
301
+ for (i = 0; i < rgroup_height; i++) {
302
+ fake_buffer[i] = true_buffer[2 * rgroup_height + i];
303
+ fake_buffer[4 * rgroup_height + i] = true_buffer[i];
304
+ }
305
+ prep->color_buf[ci] = fake_buffer + rgroup_height;
306
+ fake_buffer += 5 * rgroup_height; /* point to space for next component */
307
+ }
308
+ }
309
+
310
+ #endif /* CONTEXT_ROWS_SUPPORTED */
311
+
312
+
313
+ /*
314
+ * Initialize preprocessing controller.
315
+ */
316
+
317
+ GLOBAL(void)
318
+ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
319
+ {
320
+ my_prep_ptr prep;
321
+ int ci;
322
+ jpeg_component_info * compptr;
323
+
324
+ if (need_full_buffer) /* safety check */
325
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
326
+
327
+ prep = (my_prep_ptr)
328
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
329
+ SIZEOF(my_prep_controller));
330
+ cinfo->prep = (struct jpeg_c_prep_controller *) prep;
331
+ prep->pub.start_pass = start_pass_prep;
332
+
333
+ /* Allocate the color conversion buffer.
334
+ * We make the buffer wide enough to allow the downsampler to edge-expand
335
+ * horizontally within the buffer, if it so chooses.
336
+ */
337
+ if (cinfo->downsample->need_context_rows) {
338
+ /* Set up to provide context rows */
339
+ #ifdef CONTEXT_ROWS_SUPPORTED
340
+ prep->pub.pre_process_data = pre_process_context;
341
+ create_context_buffer(cinfo);
342
+ #else
343
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
344
+ #endif
345
+ } else {
346
+ /* No context, just make it tall enough for one row group */
347
+ prep->pub.pre_process_data = pre_process_data;
348
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
349
+ ci++, compptr++) {
350
+ prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
351
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
352
+ (JDIMENSION) (((long) compptr->width_in_blocks *
353
+ cinfo->min_DCT_h_scaled_size *
354
+ cinfo->max_h_samp_factor) / compptr->h_samp_factor),
355
+ (JDIMENSION) cinfo->max_v_samp_factor);
356
+ }
357
+ }
358
+ }
@@ -0,0 +1,545 @@
1
+ /*
2
+ * jcsample.c
3
+ *
4
+ * Copyright (C) 1991-1996, Thomas G. Lane.
5
+ * This file is part of the Independent JPEG Group's software.
6
+ * For conditions of distribution and use, see the accompanying README file.
7
+ *
8
+ * This file contains downsampling routines.
9
+ *
10
+ * Downsampling input data is counted in "row groups". A row group
11
+ * is defined to be max_v_samp_factor pixel rows of each component,
12
+ * from which the downsampler produces v_samp_factor sample rows.
13
+ * A single row group is processed in each call to the downsampler module.
14
+ *
15
+ * The downsampler is responsible for edge-expansion of its output data
16
+ * to fill an integral number of DCT blocks horizontally. The source buffer
17
+ * may be modified if it is helpful for this purpose (the source buffer is
18
+ * allocated wide enough to correspond to the desired output width).
19
+ * The caller (the prep controller) is responsible for vertical padding.
20
+ *
21
+ * The downsampler may request "context rows" by setting need_context_rows
22
+ * during startup. In this case, the input arrays will contain at least
23
+ * one row group's worth of pixels above and below the passed-in data;
24
+ * the caller will create dummy rows at image top and bottom by replicating
25
+ * the first or last real pixel row.
26
+ *
27
+ * An excellent reference for image resampling is
28
+ * Digital Image Warping, George Wolberg, 1990.
29
+ * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
30
+ *
31
+ * The downsampling algorithm used here is a simple average of the source
32
+ * pixels covered by the output pixel. The hi-falutin sampling literature
33
+ * refers to this as a "box filter". In general the characteristics of a box
34
+ * filter are not very good, but for the specific cases we normally use (1:1
35
+ * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
36
+ * nearly so bad. If you intend to use other sampling ratios, you'd be well
37
+ * advised to improve this code.
38
+ *
39
+ * A simple input-smoothing capability is provided. This is mainly intended
40
+ * for cleaning up color-dithered GIF input files (if you find it inadequate,
41
+ * we suggest using an external filtering program such as pnmconvol). When
42
+ * enabled, each input pixel P is replaced by a weighted sum of itself and its
43
+ * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF,
44
+ * where SF = (smoothing_factor / 1024).
45
+ * Currently, smoothing is only supported for 2h2v sampling factors.
46
+ */
47
+
48
+ #define JPEG_INTERNALS
49
+ #include "jinclude.h"
50
+ #include "jpeglib.h"
51
+
52
+
53
+ /* Pointer to routine to downsample a single component */
54
+ typedef JMETHOD(void, downsample1_ptr,
55
+ (j_compress_ptr cinfo, jpeg_component_info * compptr,
56
+ JSAMPARRAY input_data, JSAMPARRAY output_data));
57
+
58
+ /* Private subobject */
59
+
60
+ typedef struct {
61
+ struct jpeg_downsampler pub; /* public fields */
62
+
63
+ /* Downsampling method pointers, one per component */
64
+ downsample1_ptr methods[MAX_COMPONENTS];
65
+
66
+ /* Height of an output row group for each component. */
67
+ int rowgroup_height[MAX_COMPONENTS];
68
+
69
+ /* These arrays save pixel expansion factors so that int_downsample need not
70
+ * recompute them each time. They are unused for other downsampling methods.
71
+ */
72
+ UINT8 h_expand[MAX_COMPONENTS];
73
+ UINT8 v_expand[MAX_COMPONENTS];
74
+ } my_downsampler;
75
+
76
+ typedef my_downsampler * my_downsample_ptr;
77
+
78
+
79
+ /*
80
+ * Initialize for a downsampling pass.
81
+ */
82
+
83
+ METHODDEF(void)
84
+ start_pass_downsample (j_compress_ptr cinfo)
85
+ {
86
+ /* no work for now */
87
+ }
88
+
89
+
90
+ /*
91
+ * Expand a component horizontally from width input_cols to width output_cols,
92
+ * by duplicating the rightmost samples.
93
+ */
94
+
95
+ LOCAL(void)
96
+ expand_right_edge (JSAMPARRAY image_data, int num_rows,
97
+ JDIMENSION input_cols, JDIMENSION output_cols)
98
+ {
99
+ register JSAMPROW ptr;
100
+ register JSAMPLE pixval;
101
+ register int count;
102
+ int row;
103
+ int numcols = (int) (output_cols - input_cols);
104
+
105
+ if (numcols > 0) {
106
+ for (row = 0; row < num_rows; row++) {
107
+ ptr = image_data[row] + input_cols;
108
+ pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
109
+ for (count = numcols; count > 0; count--)
110
+ *ptr++ = pixval;
111
+ }
112
+ }
113
+ }
114
+
115
+
116
+ /*
117
+ * Do downsampling for a whole row group (all components).
118
+ *
119
+ * In this version we simply downsample each component independently.
120
+ */
121
+
122
+ METHODDEF(void)
123
+ sep_downsample (j_compress_ptr cinfo,
124
+ JSAMPIMAGE input_buf, JDIMENSION in_row_index,
125
+ JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
126
+ {
127
+ my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
128
+ int ci;
129
+ jpeg_component_info * compptr;
130
+ JSAMPARRAY in_ptr, out_ptr;
131
+
132
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
133
+ ci++, compptr++) {
134
+ in_ptr = input_buf[ci] + in_row_index;
135
+ out_ptr = output_buf[ci] +
136
+ (out_row_group_index * downsample->rowgroup_height[ci]);
137
+ (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
138
+ }
139
+ }
140
+
141
+
142
+ /*
143
+ * Downsample pixel values of a single component.
144
+ * One row group is processed per call.
145
+ * This version handles arbitrary integral sampling ratios, without smoothing.
146
+ * Note that this version is not actually used for customary sampling ratios.
147
+ */
148
+
149
+ METHODDEF(void)
150
+ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
151
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
152
+ {
153
+ my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
154
+ int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
155
+ JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
156
+ JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
157
+ JSAMPROW inptr, outptr;
158
+ INT32 outvalue;
159
+
160
+ h_expand = downsample->h_expand[compptr->component_index];
161
+ v_expand = downsample->v_expand[compptr->component_index];
162
+ numpix = h_expand * v_expand;
163
+ numpix2 = numpix/2;
164
+
165
+ /* Expand input data enough to let all the output samples be generated
166
+ * by the standard loop. Special-casing padded output would be more
167
+ * efficient.
168
+ */
169
+ expand_right_edge(input_data, cinfo->max_v_samp_factor,
170
+ cinfo->image_width, output_cols * h_expand);
171
+
172
+ inrow = outrow = 0;
173
+ while (inrow < cinfo->max_v_samp_factor) {
174
+ outptr = output_data[outrow];
175
+ for (outcol = 0, outcol_h = 0; outcol < output_cols;
176
+ outcol++, outcol_h += h_expand) {
177
+ outvalue = 0;
178
+ for (v = 0; v < v_expand; v++) {
179
+ inptr = input_data[inrow+v] + outcol_h;
180
+ for (h = 0; h < h_expand; h++) {
181
+ outvalue += (INT32) GETJSAMPLE(*inptr++);
182
+ }
183
+ }
184
+ *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
185
+ }
186
+ inrow += v_expand;
187
+ outrow++;
188
+ }
189
+ }
190
+
191
+
192
+ /*
193
+ * Downsample pixel values of a single component.
194
+ * This version handles the special case of a full-size component,
195
+ * without smoothing.
196
+ */
197
+
198
+ METHODDEF(void)
199
+ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
200
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
201
+ {
202
+ /* Copy the data */
203
+ jcopy_sample_rows(input_data, 0, output_data, 0,
204
+ cinfo->max_v_samp_factor, cinfo->image_width);
205
+ /* Edge-expand */
206
+ expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
207
+ compptr->width_in_blocks * compptr->DCT_h_scaled_size);
208
+ }
209
+
210
+
211
+ /*
212
+ * Downsample pixel values of a single component.
213
+ * This version handles the common case of 2:1 horizontal and 1:1 vertical,
214
+ * without smoothing.
215
+ *
216
+ * A note about the "bias" calculations: when rounding fractional values to
217
+ * integer, we do not want to always round 0.5 up to the next integer.
218
+ * If we did that, we'd introduce a noticeable bias towards larger values.
219
+ * Instead, this code is arranged so that 0.5 will be rounded up or down at
220
+ * alternate pixel locations (a simple ordered dither pattern).
221
+ */
222
+
223
+ METHODDEF(void)
224
+ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
225
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
226
+ {
227
+ int inrow;
228
+ JDIMENSION outcol;
229
+ JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
230
+ register JSAMPROW inptr, outptr;
231
+ register int bias;
232
+
233
+ /* Expand input data enough to let all the output samples be generated
234
+ * by the standard loop. Special-casing padded output would be more
235
+ * efficient.
236
+ */
237
+ expand_right_edge(input_data, cinfo->max_v_samp_factor,
238
+ cinfo->image_width, output_cols * 2);
239
+
240
+ for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
241
+ outptr = output_data[inrow];
242
+ inptr = input_data[inrow];
243
+ bias = 0; /* bias = 0,1,0,1,... for successive samples */
244
+ for (outcol = 0; outcol < output_cols; outcol++) {
245
+ *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
246
+ + bias) >> 1);
247
+ bias ^= 1; /* 0=>1, 1=>0 */
248
+ inptr += 2;
249
+ }
250
+ }
251
+ }
252
+
253
+
254
+ /*
255
+ * Downsample pixel values of a single component.
256
+ * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
257
+ * without smoothing.
258
+ */
259
+
260
+ METHODDEF(void)
261
+ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
262
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
263
+ {
264
+ int inrow, outrow;
265
+ JDIMENSION outcol;
266
+ JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
267
+ register JSAMPROW inptr0, inptr1, outptr;
268
+ register int bias;
269
+
270
+ /* Expand input data enough to let all the output samples be generated
271
+ * by the standard loop. Special-casing padded output would be more
272
+ * efficient.
273
+ */
274
+ expand_right_edge(input_data, cinfo->max_v_samp_factor,
275
+ cinfo->image_width, output_cols * 2);
276
+
277
+ inrow = outrow = 0;
278
+ while (inrow < cinfo->max_v_samp_factor) {
279
+ outptr = output_data[outrow];
280
+ inptr0 = input_data[inrow];
281
+ inptr1 = input_data[inrow+1];
282
+ bias = 1; /* bias = 1,2,1,2,... for successive samples */
283
+ for (outcol = 0; outcol < output_cols; outcol++) {
284
+ *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
285
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
286
+ + bias) >> 2);
287
+ bias ^= 3; /* 1=>2, 2=>1 */
288
+ inptr0 += 2; inptr1 += 2;
289
+ }
290
+ inrow += 2;
291
+ outrow++;
292
+ }
293
+ }
294
+
295
+
296
+ #ifdef INPUT_SMOOTHING_SUPPORTED
297
+
298
+ /*
299
+ * Downsample pixel values of a single component.
300
+ * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
301
+ * with smoothing. One row of context is required.
302
+ */
303
+
304
+ METHODDEF(void)
305
+ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
306
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
307
+ {
308
+ int inrow, outrow;
309
+ JDIMENSION colctr;
310
+ JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
311
+ register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
312
+ INT32 membersum, neighsum, memberscale, neighscale;
313
+
314
+ /* Expand input data enough to let all the output samples be generated
315
+ * by the standard loop. Special-casing padded output would be more
316
+ * efficient.
317
+ */
318
+ expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
319
+ cinfo->image_width, output_cols * 2);
320
+
321
+ /* We don't bother to form the individual "smoothed" input pixel values;
322
+ * we can directly compute the output which is the average of the four
323
+ * smoothed values. Each of the four member pixels contributes a fraction
324
+ * (1-8*SF) to its own smoothed image and a fraction SF to each of the three
325
+ * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
326
+ * output. The four corner-adjacent neighbor pixels contribute a fraction
327
+ * SF to just one smoothed pixel, or SF/4 to the final output; while the
328
+ * eight edge-adjacent neighbors contribute SF to each of two smoothed
329
+ * pixels, or SF/2 overall. In order to use integer arithmetic, these
330
+ * factors are scaled by 2^16 = 65536.
331
+ * Also recall that SF = smoothing_factor / 1024.
332
+ */
333
+
334
+ memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
335
+ neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
336
+
337
+ inrow = outrow = 0;
338
+ while (inrow < cinfo->max_v_samp_factor) {
339
+ outptr = output_data[outrow];
340
+ inptr0 = input_data[inrow];
341
+ inptr1 = input_data[inrow+1];
342
+ above_ptr = input_data[inrow-1];
343
+ below_ptr = input_data[inrow+2];
344
+
345
+ /* Special case for first column: pretend column -1 is same as column 0 */
346
+ membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
347
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
348
+ neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
349
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
350
+ GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
351
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
352
+ neighsum += neighsum;
353
+ neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
354
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
355
+ membersum = membersum * memberscale + neighsum * neighscale;
356
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
357
+ inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
358
+
359
+ for (colctr = output_cols - 2; colctr > 0; colctr--) {
360
+ /* sum of pixels directly mapped to this output element */
361
+ membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
362
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
363
+ /* sum of edge-neighbor pixels */
364
+ neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
365
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
366
+ GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
367
+ GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
368
+ /* The edge-neighbors count twice as much as corner-neighbors */
369
+ neighsum += neighsum;
370
+ /* Add in the corner-neighbors */
371
+ neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
372
+ GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
373
+ /* form final output scaled up by 2^16 */
374
+ membersum = membersum * memberscale + neighsum * neighscale;
375
+ /* round, descale and output it */
376
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
377
+ inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
378
+ }
379
+
380
+ /* Special case for last column */
381
+ membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
382
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
383
+ neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
384
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
385
+ GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
386
+ GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
387
+ neighsum += neighsum;
388
+ neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
389
+ GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
390
+ membersum = membersum * memberscale + neighsum * neighscale;
391
+ *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
392
+
393
+ inrow += 2;
394
+ outrow++;
395
+ }
396
+ }
397
+
398
+
399
+ /*
400
+ * Downsample pixel values of a single component.
401
+ * This version handles the special case of a full-size component,
402
+ * with smoothing. One row of context is required.
403
+ */
404
+
405
+ METHODDEF(void)
406
+ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
407
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
408
+ {
409
+ int inrow;
410
+ JDIMENSION colctr;
411
+ JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
412
+ register JSAMPROW inptr, above_ptr, below_ptr, outptr;
413
+ INT32 membersum, neighsum, memberscale, neighscale;
414
+ int colsum, lastcolsum, nextcolsum;
415
+
416
+ /* Expand input data enough to let all the output samples be generated
417
+ * by the standard loop. Special-casing padded output would be more
418
+ * efficient.
419
+ */
420
+ expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
421
+ cinfo->image_width, output_cols);
422
+
423
+ /* Each of the eight neighbor pixels contributes a fraction SF to the
424
+ * smoothed pixel, while the main pixel contributes (1-8*SF). In order
425
+ * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
426
+ * Also recall that SF = smoothing_factor / 1024.
427
+ */
428
+
429
+ memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
430
+ neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
431
+
432
+ for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
433
+ outptr = output_data[inrow];
434
+ inptr = input_data[inrow];
435
+ above_ptr = input_data[inrow-1];
436
+ below_ptr = input_data[inrow+1];
437
+
438
+ /* Special case for first column */
439
+ colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
440
+ GETJSAMPLE(*inptr);
441
+ membersum = GETJSAMPLE(*inptr++);
442
+ nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
443
+ GETJSAMPLE(*inptr);
444
+ neighsum = colsum + (colsum - membersum) + nextcolsum;
445
+ membersum = membersum * memberscale + neighsum * neighscale;
446
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
447
+ lastcolsum = colsum; colsum = nextcolsum;
448
+
449
+ for (colctr = output_cols - 2; colctr > 0; colctr--) {
450
+ membersum = GETJSAMPLE(*inptr++);
451
+ above_ptr++; below_ptr++;
452
+ nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
453
+ GETJSAMPLE(*inptr);
454
+ neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
455
+ membersum = membersum * memberscale + neighsum * neighscale;
456
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
457
+ lastcolsum = colsum; colsum = nextcolsum;
458
+ }
459
+
460
+ /* Special case for last column */
461
+ membersum = GETJSAMPLE(*inptr);
462
+ neighsum = lastcolsum + (colsum - membersum) + colsum;
463
+ membersum = membersum * memberscale + neighsum * neighscale;
464
+ *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
465
+
466
+ }
467
+ }
468
+
469
+ #endif /* INPUT_SMOOTHING_SUPPORTED */
470
+
471
+
472
+ /*
473
+ * Module initialization routine for downsampling.
474
+ * Note that we must select a routine for each component.
475
+ */
476
+
477
+ GLOBAL(void)
478
+ jinit_downsampler (j_compress_ptr cinfo)
479
+ {
480
+ my_downsample_ptr downsample;
481
+ int ci;
482
+ jpeg_component_info * compptr;
483
+ boolean smoothok = TRUE;
484
+ int h_in_group, v_in_group, h_out_group, v_out_group;
485
+
486
+ downsample = (my_downsample_ptr)
487
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
488
+ SIZEOF(my_downsampler));
489
+ cinfo->downsample = (struct jpeg_downsampler *) downsample;
490
+ downsample->pub.start_pass = start_pass_downsample;
491
+ downsample->pub.downsample = sep_downsample;
492
+ downsample->pub.need_context_rows = FALSE;
493
+
494
+ if (cinfo->CCIR601_sampling)
495
+ ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
496
+
497
+ /* Verify we can handle the sampling factors, and set up method pointers */
498
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
499
+ ci++, compptr++) {
500
+ /* Compute size of an "output group" for DCT scaling. This many samples
501
+ * are to be converted from max_h_samp_factor * max_v_samp_factor pixels.
502
+ */
503
+ h_out_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) /
504
+ cinfo->min_DCT_h_scaled_size;
505
+ v_out_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
506
+ cinfo->min_DCT_v_scaled_size;
507
+ h_in_group = cinfo->max_h_samp_factor;
508
+ v_in_group = cinfo->max_v_samp_factor;
509
+ downsample->rowgroup_height[ci] = v_out_group; /* save for use later */
510
+ if (h_in_group == h_out_group && v_in_group == v_out_group) {
511
+ #ifdef INPUT_SMOOTHING_SUPPORTED
512
+ if (cinfo->smoothing_factor) {
513
+ downsample->methods[ci] = fullsize_smooth_downsample;
514
+ downsample->pub.need_context_rows = TRUE;
515
+ } else
516
+ #endif
517
+ downsample->methods[ci] = fullsize_downsample;
518
+ } else if (h_in_group == h_out_group * 2 &&
519
+ v_in_group == v_out_group) {
520
+ smoothok = FALSE;
521
+ downsample->methods[ci] = h2v1_downsample;
522
+ } else if (h_in_group == h_out_group * 2 &&
523
+ v_in_group == v_out_group * 2) {
524
+ #ifdef INPUT_SMOOTHING_SUPPORTED
525
+ if (cinfo->smoothing_factor) {
526
+ downsample->methods[ci] = h2v2_smooth_downsample;
527
+ downsample->pub.need_context_rows = TRUE;
528
+ } else
529
+ #endif
530
+ downsample->methods[ci] = h2v2_downsample;
531
+ } else if ((h_in_group % h_out_group) == 0 &&
532
+ (v_in_group % v_out_group) == 0) {
533
+ smoothok = FALSE;
534
+ downsample->methods[ci] = int_downsample;
535
+ downsample->h_expand[ci] = (UINT8) (h_in_group / h_out_group);
536
+ downsample->v_expand[ci] = (UINT8) (v_in_group / v_out_group);
537
+ } else
538
+ ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
539
+ }
540
+
541
+ #ifdef INPUT_SMOOTHING_SUPPORTED
542
+ if (cinfo->smoothing_factor && !smoothok)
543
+ TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
544
+ #endif
545
+ }