image_pack 0.2.0

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 (319) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +18 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +140 -0
  5. data/THIRD_PARTY_NOTICES.md +8 -0
  6. data/ext/image_pack/extconf.rb +515 -0
  7. data/ext/image_pack/image_pack.c +1618 -0
  8. data/ext/image_pack/vendor/.vendored +1 -0
  9. data/ext/image_pack/vendor/mozjpeg/BUILDING.txt +902 -0
  10. data/ext/image_pack/vendor/mozjpeg/CMakeLists.txt +1593 -0
  11. data/ext/image_pack/vendor/mozjpeg/LICENSE.md +132 -0
  12. data/ext/image_pack/vendor/mozjpeg/README-mozilla.txt +194 -0
  13. data/ext/image_pack/vendor/mozjpeg/README-turbo.txt +346 -0
  14. data/ext/image_pack/vendor/mozjpeg/README.ijg +258 -0
  15. data/ext/image_pack/vendor/mozjpeg/README.md +29 -0
  16. data/ext/image_pack/vendor/mozjpeg/cderror.h +128 -0
  17. data/ext/image_pack/vendor/mozjpeg/cdjpeg.c +156 -0
  18. data/ext/image_pack/vendor/mozjpeg/cdjpeg.h +171 -0
  19. data/ext/image_pack/vendor/mozjpeg/cjpeg.c +961 -0
  20. data/ext/image_pack/vendor/mozjpeg/cmyk.h +60 -0
  21. data/ext/image_pack/vendor/mozjpeg/coderules.txt +78 -0
  22. data/ext/image_pack/vendor/mozjpeg/croptest.in +95 -0
  23. data/ext/image_pack/vendor/mozjpeg/djpeg.c +855 -0
  24. data/ext/image_pack/vendor/mozjpeg/example.txt +464 -0
  25. data/ext/image_pack/vendor/mozjpeg/jaricom.c +157 -0
  26. data/ext/image_pack/vendor/mozjpeg/jcapimin.c +307 -0
  27. data/ext/image_pack/vendor/mozjpeg/jcapistd.c +168 -0
  28. data/ext/image_pack/vendor/mozjpeg/jcarith.c +972 -0
  29. data/ext/image_pack/vendor/mozjpeg/jccoefct.c +609 -0
  30. data/ext/image_pack/vendor/mozjpeg/jccolext.c +144 -0
  31. data/ext/image_pack/vendor/mozjpeg/jccolor.c +721 -0
  32. data/ext/image_pack/vendor/mozjpeg/jcdctmgr.c +1776 -0
  33. data/ext/image_pack/vendor/mozjpeg/jcext.c +219 -0
  34. data/ext/image_pack/vendor/mozjpeg/jchuff.c +1146 -0
  35. data/ext/image_pack/vendor/mozjpeg/jchuff.h +57 -0
  36. data/ext/image_pack/vendor/mozjpeg/jcicc.c +105 -0
  37. data/ext/image_pack/vendor/mozjpeg/jcinit.c +82 -0
  38. data/ext/image_pack/vendor/mozjpeg/jcmainct.c +162 -0
  39. data/ext/image_pack/vendor/mozjpeg/jcmarker.c +844 -0
  40. data/ext/image_pack/vendor/mozjpeg/jcmaster.c +958 -0
  41. data/ext/image_pack/vendor/mozjpeg/jcmaster.h +56 -0
  42. data/ext/image_pack/vendor/mozjpeg/jcomapi.c +109 -0
  43. data/ext/image_pack/vendor/mozjpeg/jconfig.h.in +37 -0
  44. data/ext/image_pack/vendor/mozjpeg/jconfig.txt +93 -0
  45. data/ext/image_pack/vendor/mozjpeg/jconfigint.h.in +44 -0
  46. data/ext/image_pack/vendor/mozjpeg/jcparam.c +991 -0
  47. data/ext/image_pack/vendor/mozjpeg/jcphuff.c +1123 -0
  48. data/ext/image_pack/vendor/mozjpeg/jcprepct.c +351 -0
  49. data/ext/image_pack/vendor/mozjpeg/jcsample.c +522 -0
  50. data/ext/image_pack/vendor/mozjpeg/jcstest.c +126 -0
  51. data/ext/image_pack/vendor/mozjpeg/jctrans.c +408 -0
  52. data/ext/image_pack/vendor/mozjpeg/jdapimin.c +407 -0
  53. data/ext/image_pack/vendor/mozjpeg/jdapistd.c +691 -0
  54. data/ext/image_pack/vendor/mozjpeg/jdarith.c +782 -0
  55. data/ext/image_pack/vendor/mozjpeg/jdatadst-tj.c +198 -0
  56. data/ext/image_pack/vendor/mozjpeg/jdatadst.c +299 -0
  57. data/ext/image_pack/vendor/mozjpeg/jdatasrc-tj.c +194 -0
  58. data/ext/image_pack/vendor/mozjpeg/jdatasrc.c +295 -0
  59. data/ext/image_pack/vendor/mozjpeg/jdcoefct.c +881 -0
  60. data/ext/image_pack/vendor/mozjpeg/jdcoefct.h +83 -0
  61. data/ext/image_pack/vendor/mozjpeg/jdcol565.c +384 -0
  62. data/ext/image_pack/vendor/mozjpeg/jdcolext.c +141 -0
  63. data/ext/image_pack/vendor/mozjpeg/jdcolor.c +881 -0
  64. data/ext/image_pack/vendor/mozjpeg/jdct.h +208 -0
  65. data/ext/image_pack/vendor/mozjpeg/jddctmgr.c +367 -0
  66. data/ext/image_pack/vendor/mozjpeg/jdhuff.c +834 -0
  67. data/ext/image_pack/vendor/mozjpeg/jdhuff.h +247 -0
  68. data/ext/image_pack/vendor/mozjpeg/jdicc.c +167 -0
  69. data/ext/image_pack/vendor/mozjpeg/jdinput.c +408 -0
  70. data/ext/image_pack/vendor/mozjpeg/jdmainct.c +460 -0
  71. data/ext/image_pack/vendor/mozjpeg/jdmainct.h +71 -0
  72. data/ext/image_pack/vendor/mozjpeg/jdmarker.c +1374 -0
  73. data/ext/image_pack/vendor/mozjpeg/jdmaster.c +727 -0
  74. data/ext/image_pack/vendor/mozjpeg/jdmaster.h +33 -0
  75. data/ext/image_pack/vendor/mozjpeg/jdmerge.c +587 -0
  76. data/ext/image_pack/vendor/mozjpeg/jdmerge.h +47 -0
  77. data/ext/image_pack/vendor/mozjpeg/jdmrg565.c +354 -0
  78. data/ext/image_pack/vendor/mozjpeg/jdmrgext.c +184 -0
  79. data/ext/image_pack/vendor/mozjpeg/jdphuff.c +679 -0
  80. data/ext/image_pack/vendor/mozjpeg/jdpostct.c +294 -0
  81. data/ext/image_pack/vendor/mozjpeg/jdsample.c +524 -0
  82. data/ext/image_pack/vendor/mozjpeg/jdsample.h +50 -0
  83. data/ext/image_pack/vendor/mozjpeg/jdtrans.c +156 -0
  84. data/ext/image_pack/vendor/mozjpeg/jerror.c +251 -0
  85. data/ext/image_pack/vendor/mozjpeg/jerror.h +335 -0
  86. data/ext/image_pack/vendor/mozjpeg/jfdctflt.c +169 -0
  87. data/ext/image_pack/vendor/mozjpeg/jfdctfst.c +227 -0
  88. data/ext/image_pack/vendor/mozjpeg/jfdctint.c +288 -0
  89. data/ext/image_pack/vendor/mozjpeg/jidctflt.c +240 -0
  90. data/ext/image_pack/vendor/mozjpeg/jidctfst.c +371 -0
  91. data/ext/image_pack/vendor/mozjpeg/jidctint.c +2627 -0
  92. data/ext/image_pack/vendor/mozjpeg/jidctred.c +409 -0
  93. data/ext/image_pack/vendor/mozjpeg/jinclude.h +147 -0
  94. data/ext/image_pack/vendor/mozjpeg/jmemmgr.c +1180 -0
  95. data/ext/image_pack/vendor/mozjpeg/jmemnobs.c +110 -0
  96. data/ext/image_pack/vendor/mozjpeg/jmemsys.h +178 -0
  97. data/ext/image_pack/vendor/mozjpeg/jmorecfg.h +382 -0
  98. data/ext/image_pack/vendor/mozjpeg/jpeg_nbits_table.h +4098 -0
  99. data/ext/image_pack/vendor/mozjpeg/jpegcomp.h +32 -0
  100. data/ext/image_pack/vendor/mozjpeg/jpegint.h +453 -0
  101. data/ext/image_pack/vendor/mozjpeg/jpeglib.h +1211 -0
  102. data/ext/image_pack/vendor/mozjpeg/jpegtran.c +827 -0
  103. data/ext/image_pack/vendor/mozjpeg/jpegyuv.c +172 -0
  104. data/ext/image_pack/vendor/mozjpeg/jquant1.c +856 -0
  105. data/ext/image_pack/vendor/mozjpeg/jquant2.c +1286 -0
  106. data/ext/image_pack/vendor/mozjpeg/jsimd.h +123 -0
  107. data/ext/image_pack/vendor/mozjpeg/jsimd_none.c +431 -0
  108. data/ext/image_pack/vendor/mozjpeg/jsimddct.h +70 -0
  109. data/ext/image_pack/vendor/mozjpeg/jstdhuff.c +144 -0
  110. data/ext/image_pack/vendor/mozjpeg/jutils.c +133 -0
  111. data/ext/image_pack/vendor/mozjpeg/jversion.h.in +56 -0
  112. data/ext/image_pack/vendor/mozjpeg/libjpeg.map.in +11 -0
  113. data/ext/image_pack/vendor/mozjpeg/libjpeg.txt +3150 -0
  114. data/ext/image_pack/vendor/mozjpeg/rdbmp.c +690 -0
  115. data/ext/image_pack/vendor/mozjpeg/rdcolmap.c +253 -0
  116. data/ext/image_pack/vendor/mozjpeg/rdgif.c +720 -0
  117. data/ext/image_pack/vendor/mozjpeg/rdjpeg.c +160 -0
  118. data/ext/image_pack/vendor/mozjpeg/rdjpgcom.c +494 -0
  119. data/ext/image_pack/vendor/mozjpeg/rdpng.c +194 -0
  120. data/ext/image_pack/vendor/mozjpeg/rdppm.c +781 -0
  121. data/ext/image_pack/vendor/mozjpeg/rdswitch.c +642 -0
  122. data/ext/image_pack/vendor/mozjpeg/rdtarga.c +508 -0
  123. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jccolext-neon.c +148 -0
  124. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jchuff-neon.c +334 -0
  125. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jsimd.c +976 -0
  126. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jsimd_neon.S +1200 -0
  127. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch64/jccolext-neon.c +316 -0
  128. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch64/jchuff-neon.c +411 -0
  129. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch64/jsimd.c +1053 -0
  130. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch64/jsimd_neon.S +2254 -0
  131. data/ext/image_pack/vendor/mozjpeg/simd/arm/align.h +28 -0
  132. data/ext/image_pack/vendor/mozjpeg/simd/arm/jccolor-neon.c +160 -0
  133. data/ext/image_pack/vendor/mozjpeg/simd/arm/jcgray-neon.c +120 -0
  134. data/ext/image_pack/vendor/mozjpeg/simd/arm/jcgryext-neon.c +106 -0
  135. data/ext/image_pack/vendor/mozjpeg/simd/arm/jchuff.h +131 -0
  136. data/ext/image_pack/vendor/mozjpeg/simd/arm/jcphuff-neon.c +623 -0
  137. data/ext/image_pack/vendor/mozjpeg/simd/arm/jcsample-neon.c +192 -0
  138. data/ext/image_pack/vendor/mozjpeg/simd/arm/jdcolext-neon.c +374 -0
  139. data/ext/image_pack/vendor/mozjpeg/simd/arm/jdcolor-neon.c +141 -0
  140. data/ext/image_pack/vendor/mozjpeg/simd/arm/jdmerge-neon.c +144 -0
  141. data/ext/image_pack/vendor/mozjpeg/simd/arm/jdmrgext-neon.c +723 -0
  142. data/ext/image_pack/vendor/mozjpeg/simd/arm/jdsample-neon.c +569 -0
  143. data/ext/image_pack/vendor/mozjpeg/simd/arm/jfdctfst-neon.c +214 -0
  144. data/ext/image_pack/vendor/mozjpeg/simd/arm/jfdctint-neon.c +376 -0
  145. data/ext/image_pack/vendor/mozjpeg/simd/arm/jidctfst-neon.c +472 -0
  146. data/ext/image_pack/vendor/mozjpeg/simd/arm/jidctint-neon.c +801 -0
  147. data/ext/image_pack/vendor/mozjpeg/simd/arm/jidctred-neon.c +486 -0
  148. data/ext/image_pack/vendor/mozjpeg/simd/arm/jquanti-neon.c +193 -0
  149. data/ext/image_pack/vendor/mozjpeg/simd/arm/neon-compat.h +26 -0
  150. data/ext/image_pack/vendor/mozjpeg/simd/arm/neon-compat.h.in +37 -0
  151. data/ext/image_pack/vendor/mozjpeg/simd/i386/jccolext-avx2.asm +578 -0
  152. data/ext/image_pack/vendor/mozjpeg/simd/i386/jccolext-mmx.asm +476 -0
  153. data/ext/image_pack/vendor/mozjpeg/simd/i386/jccolext-sse2.asm +503 -0
  154. data/ext/image_pack/vendor/mozjpeg/simd/i386/jccolor-avx2.asm +121 -0
  155. data/ext/image_pack/vendor/mozjpeg/simd/i386/jccolor-mmx.asm +121 -0
  156. data/ext/image_pack/vendor/mozjpeg/simd/i386/jccolor-sse2.asm +120 -0
  157. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcgray-avx2.asm +113 -0
  158. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcgray-mmx.asm +113 -0
  159. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcgray-sse2.asm +112 -0
  160. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcgryext-avx2.asm +457 -0
  161. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcgryext-mmx.asm +355 -0
  162. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcgryext-sse2.asm +382 -0
  163. data/ext/image_pack/vendor/mozjpeg/simd/i386/jchuff-sse2.asm +761 -0
  164. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcphuff-sse2.asm +662 -0
  165. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcsample-avx2.asm +388 -0
  166. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcsample-mmx.asm +324 -0
  167. data/ext/image_pack/vendor/mozjpeg/simd/i386/jcsample-sse2.asm +351 -0
  168. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdcolext-avx2.asm +515 -0
  169. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdcolext-mmx.asm +404 -0
  170. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdcolext-sse2.asm +458 -0
  171. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdcolor-avx2.asm +118 -0
  172. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdcolor-mmx.asm +117 -0
  173. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdcolor-sse2.asm +117 -0
  174. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdmerge-avx2.asm +136 -0
  175. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdmerge-mmx.asm +123 -0
  176. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdmerge-sse2.asm +135 -0
  177. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdmrgext-avx2.asm +575 -0
  178. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdmrgext-mmx.asm +460 -0
  179. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdmrgext-sse2.asm +517 -0
  180. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdsample-avx2.asm +760 -0
  181. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdsample-mmx.asm +731 -0
  182. data/ext/image_pack/vendor/mozjpeg/simd/i386/jdsample-sse2.asm +724 -0
  183. data/ext/image_pack/vendor/mozjpeg/simd/i386/jfdctflt-3dn.asm +318 -0
  184. data/ext/image_pack/vendor/mozjpeg/simd/i386/jfdctflt-sse.asm +369 -0
  185. data/ext/image_pack/vendor/mozjpeg/simd/i386/jfdctfst-mmx.asm +395 -0
  186. data/ext/image_pack/vendor/mozjpeg/simd/i386/jfdctfst-sse2.asm +403 -0
  187. data/ext/image_pack/vendor/mozjpeg/simd/i386/jfdctint-avx2.asm +331 -0
  188. data/ext/image_pack/vendor/mozjpeg/simd/i386/jfdctint-mmx.asm +620 -0
  189. data/ext/image_pack/vendor/mozjpeg/simd/i386/jfdctint-sse2.asm +633 -0
  190. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctflt-3dn.asm +451 -0
  191. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctflt-sse.asm +571 -0
  192. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctflt-sse2.asm +497 -0
  193. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctfst-mmx.asm +499 -0
  194. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctfst-sse2.asm +501 -0
  195. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctint-avx2.asm +453 -0
  196. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctint-mmx.asm +851 -0
  197. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctint-sse2.asm +858 -0
  198. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctred-mmx.asm +704 -0
  199. data/ext/image_pack/vendor/mozjpeg/simd/i386/jidctred-sse2.asm +592 -0
  200. data/ext/image_pack/vendor/mozjpeg/simd/i386/jquant-3dn.asm +230 -0
  201. data/ext/image_pack/vendor/mozjpeg/simd/i386/jquant-mmx.asm +276 -0
  202. data/ext/image_pack/vendor/mozjpeg/simd/i386/jquant-sse.asm +208 -0
  203. data/ext/image_pack/vendor/mozjpeg/simd/i386/jquantf-sse2.asm +168 -0
  204. data/ext/image_pack/vendor/mozjpeg/simd/i386/jquanti-avx2.asm +188 -0
  205. data/ext/image_pack/vendor/mozjpeg/simd/i386/jquanti-sse2.asm +201 -0
  206. data/ext/image_pack/vendor/mozjpeg/simd/i386/jsimd.c +1312 -0
  207. data/ext/image_pack/vendor/mozjpeg/simd/i386/jsimdcpu.asm +135 -0
  208. data/ext/image_pack/vendor/mozjpeg/simd/jsimd.h +1258 -0
  209. data/ext/image_pack/vendor/mozjpeg/simd/mips/jsimd.c +1143 -0
  210. data/ext/image_pack/vendor/mozjpeg/simd/mips/jsimd_dspr2.S +4543 -0
  211. data/ext/image_pack/vendor/mozjpeg/simd/mips/jsimd_dspr2_asm.h +292 -0
  212. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jccolext-mmi.c +455 -0
  213. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jccolor-mmi.c +148 -0
  214. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcgray-mmi.c +132 -0
  215. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcgryext-mmi.c +374 -0
  216. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcsample-mmi.c +98 -0
  217. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcsample.h +28 -0
  218. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdcolext-mmi.c +415 -0
  219. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdcolor-mmi.c +139 -0
  220. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdmerge-mmi.c +149 -0
  221. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdmrgext-mmi.c +615 -0
  222. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdsample-mmi.c +304 -0
  223. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jfdctfst-mmi.c +255 -0
  224. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jfdctint-mmi.c +398 -0
  225. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jidctfst-mmi.c +395 -0
  226. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jidctint-mmi.c +571 -0
  227. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jquanti-mmi.c +124 -0
  228. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jsimd.c +866 -0
  229. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jsimd_mmi.h +69 -0
  230. data/ext/image_pack/vendor/mozjpeg/simd/mips64/loongson-mmintrin.h +1334 -0
  231. data/ext/image_pack/vendor/mozjpeg/simd/nasm/jcolsamp.inc +135 -0
  232. data/ext/image_pack/vendor/mozjpeg/simd/nasm/jdct.inc +31 -0
  233. data/ext/image_pack/vendor/mozjpeg/simd/nasm/jsimdcfg.inc +93 -0
  234. data/ext/image_pack/vendor/mozjpeg/simd/nasm/jsimdcfg.inc.h +133 -0
  235. data/ext/image_pack/vendor/mozjpeg/simd/nasm/jsimdext.inc +520 -0
  236. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jccolext-altivec.c +269 -0
  237. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jccolor-altivec.c +116 -0
  238. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcgray-altivec.c +111 -0
  239. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcgryext-altivec.c +228 -0
  240. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcsample-altivec.c +159 -0
  241. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcsample.h +28 -0
  242. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdcolext-altivec.c +276 -0
  243. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdcolor-altivec.c +106 -0
  244. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdmerge-altivec.c +130 -0
  245. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdmrgext-altivec.c +329 -0
  246. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdsample-altivec.c +400 -0
  247. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jfdctfst-altivec.c +154 -0
  248. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jfdctint-altivec.c +258 -0
  249. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jidctfst-altivec.c +255 -0
  250. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jidctint-altivec.c +357 -0
  251. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jquanti-altivec.c +250 -0
  252. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jsimd.c +884 -0
  253. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jsimd_altivec.h +98 -0
  254. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jccolext-avx2.asm +559 -0
  255. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jccolext-sse2.asm +484 -0
  256. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jccolor-avx2.asm +121 -0
  257. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jccolor-sse2.asm +120 -0
  258. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jcgray-avx2.asm +113 -0
  259. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jcgray-sse2.asm +112 -0
  260. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jcgryext-avx2.asm +438 -0
  261. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jcgryext-sse2.asm +363 -0
  262. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jchuff-sse2.asm +583 -0
  263. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jcphuff-sse2.asm +639 -0
  264. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jcsample-avx2.asm +367 -0
  265. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jcsample-sse2.asm +330 -0
  266. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdcolext-avx2.asm +496 -0
  267. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdcolext-sse2.asm +439 -0
  268. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdcolor-avx2.asm +118 -0
  269. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdcolor-sse2.asm +117 -0
  270. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdmerge-avx2.asm +136 -0
  271. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdmerge-sse2.asm +135 -0
  272. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdmrgext-avx2.asm +596 -0
  273. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdmrgext-sse2.asm +538 -0
  274. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdsample-avx2.asm +696 -0
  275. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jdsample-sse2.asm +665 -0
  276. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jfdctflt-sse.asm +355 -0
  277. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jfdctfst-sse2.asm +389 -0
  278. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jfdctint-avx2.asm +320 -0
  279. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jfdctint-sse2.asm +619 -0
  280. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jidctflt-sse2.asm +482 -0
  281. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jidctfst-sse2.asm +491 -0
  282. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jidctint-avx2.asm +418 -0
  283. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jidctint-sse2.asm +847 -0
  284. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jidctred-sse2.asm +574 -0
  285. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jquantf-sse2.asm +155 -0
  286. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jquanti-avx2.asm +163 -0
  287. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jquanti-sse2.asm +188 -0
  288. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jsimd.c +1110 -0
  289. data/ext/image_pack/vendor/mozjpeg/simd/x86_64/jsimdcpu.asm +86 -0
  290. data/ext/image_pack/vendor/mozjpeg/strtest.c +170 -0
  291. data/ext/image_pack/vendor/mozjpeg/structure.txt +900 -0
  292. data/ext/image_pack/vendor/mozjpeg/tjbench.c +1044 -0
  293. data/ext/image_pack/vendor/mozjpeg/tjbenchtest.in +256 -0
  294. data/ext/image_pack/vendor/mozjpeg/tjbenchtest.java.in +215 -0
  295. data/ext/image_pack/vendor/mozjpeg/tjexample.c +406 -0
  296. data/ext/image_pack/vendor/mozjpeg/tjexampletest.in +149 -0
  297. data/ext/image_pack/vendor/mozjpeg/tjexampletest.java.in +151 -0
  298. data/ext/image_pack/vendor/mozjpeg/tjunittest.c +961 -0
  299. data/ext/image_pack/vendor/mozjpeg/tjutil.c +70 -0
  300. data/ext/image_pack/vendor/mozjpeg/tjutil.h +53 -0
  301. data/ext/image_pack/vendor/mozjpeg/transupp.c +2373 -0
  302. data/ext/image_pack/vendor/mozjpeg/transupp.h +243 -0
  303. data/ext/image_pack/vendor/mozjpeg/turbojpeg-jni.c +1259 -0
  304. data/ext/image_pack/vendor/mozjpeg/turbojpeg.c +2320 -0
  305. data/ext/image_pack/vendor/mozjpeg/turbojpeg.h +1784 -0
  306. data/ext/image_pack/vendor/mozjpeg/usage.txt +679 -0
  307. data/ext/image_pack/vendor/mozjpeg/wizard.txt +220 -0
  308. data/ext/image_pack/vendor/mozjpeg/wrbmp.c +552 -0
  309. data/ext/image_pack/vendor/mozjpeg/wrgif.c +580 -0
  310. data/ext/image_pack/vendor/mozjpeg/wrjpgcom.c +577 -0
  311. data/ext/image_pack/vendor/mozjpeg/wrppm.c +366 -0
  312. data/ext/image_pack/vendor/mozjpeg/wrtarga.c +258 -0
  313. data/ext/image_pack/vendor/mozjpeg/yuvjpeg.c +268 -0
  314. data/lib/image_pack/backend.rb +8 -0
  315. data/lib/image_pack/configuration.rb +23 -0
  316. data/lib/image_pack/errors.rb +13 -0
  317. data/lib/image_pack/version.rb +5 -0
  318. data/lib/image_pack.rb +208 -0
  319. metadata +433 -0
@@ -0,0 +1,991 @@
1
+ /*
2
+ * jcparam.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1991-1998, Thomas G. Lane.
6
+ * Modified 2003-2008 by Guido Vollbeding.
7
+ * libjpeg-turbo Modifications:
8
+ * Copyright (C) 2009-2011, 2018, D. R. Commander.
9
+ * mozjpeg Modifications:
10
+ * Copyright (C) 2014, Mozilla Corporation.
11
+ * For conditions of distribution and use, see the accompanying README file.
12
+ *
13
+ * This file contains optional default-setting code for the JPEG compressor.
14
+ * Applications do not have to use this file, but those that don't use it
15
+ * must know a lot more about the innards of the JPEG code.
16
+ */
17
+
18
+ #define JPEG_INTERNALS
19
+ #include "jinclude.h"
20
+ #include "jpeglib.h"
21
+ #include "jstdhuff.c"
22
+
23
+
24
+ /*
25
+ * Quantization table setup routines
26
+ */
27
+
28
+ GLOBAL(void)
29
+ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
30
+ const unsigned int *basic_table, int scale_factor,
31
+ boolean force_baseline)
32
+ /* Define a quantization table equal to the basic_table times
33
+ * a scale factor (given as a percentage).
34
+ * If force_baseline is TRUE, the computed quantization table entries
35
+ * are limited to 1..255 for JPEG baseline compatibility.
36
+ */
37
+ {
38
+ JQUANT_TBL **qtblptr;
39
+ int i;
40
+ long temp;
41
+
42
+ /* Safety check to ensure start_compress not called yet. */
43
+ if (cinfo->global_state != CSTATE_START)
44
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
45
+
46
+ if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
47
+ ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
48
+
49
+ qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
50
+
51
+ if (*qtblptr == NULL)
52
+ *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
53
+
54
+ for (i = 0; i < DCTSIZE2; i++) {
55
+ temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
56
+ /* limit the values to the valid range */
57
+ if (temp <= 0L) temp = 1L;
58
+ if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
59
+ if (force_baseline && temp > 255L)
60
+ temp = 255L; /* limit to baseline range if requested */
61
+ (*qtblptr)->quantval[i] = (UINT16) temp;
62
+ }
63
+
64
+ /* Initialize sent_table FALSE so table will be written to JPEG file. */
65
+ (*qtblptr)->sent_table = FALSE;
66
+ }
67
+
68
+
69
+ /* These are the sample quantization tables given in Annex K (Clause K.1) of
70
+ * Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
71
+ * The spec says that the values given produce "good" quality, and
72
+ * when divided by 2, "very good" quality.
73
+ */
74
+ static const unsigned int std_luminance_quant_tbl[9][DCTSIZE2] = {
75
+ {
76
+ /* JPEG Annex K
77
+ */
78
+ 16, 11, 10, 16, 24, 40, 51, 61,
79
+ 12, 12, 14, 19, 26, 58, 60, 55,
80
+ 14, 13, 16, 24, 40, 57, 69, 56,
81
+ 14, 17, 22, 29, 51, 87, 80, 62,
82
+ 18, 22, 37, 56, 68, 109, 103, 77,
83
+ 24, 35, 55, 64, 81, 104, 113, 92,
84
+ 49, 64, 78, 87, 103, 121, 120, 101,
85
+ 72, 92, 95, 98, 112, 100, 103, 99
86
+ },
87
+ {
88
+ /* flat
89
+ */
90
+ 16, 16, 16, 16, 16, 16, 16, 16,
91
+ 16, 16, 16, 16, 16, 16, 16, 16,
92
+ 16, 16, 16, 16, 16, 16, 16, 16,
93
+ 16, 16, 16, 16, 16, 16, 16, 16,
94
+ 16, 16, 16, 16, 16, 16, 16, 16,
95
+ 16, 16, 16, 16, 16, 16, 16, 16,
96
+ 16, 16, 16, 16, 16, 16, 16, 16,
97
+ 16, 16, 16, 16, 16, 16, 16, 16
98
+ },
99
+ {
100
+ 12, 17, 20, 21, 30, 34, 56, 63,
101
+ 18, 20, 20, 26, 28, 51, 61, 55,
102
+ 19, 20, 21, 26, 33, 58, 69, 55,
103
+ 26, 26, 26, 30, 46, 87, 86, 66,
104
+ 31, 33, 36, 40, 46, 96, 100, 73,
105
+ 40, 35, 46, 62, 81, 100, 111, 91,
106
+ 46, 66, 76, 86, 102, 121, 120, 101,
107
+ 68, 90, 90, 96, 113, 102, 105, 103
108
+ },
109
+ {
110
+ /* From http://www.imagemagick.org/discourse-server/viewtopic.php?f=22&t=20333&p=98008#p98008
111
+ */
112
+ 16, 16, 16, 18, 25, 37, 56, 85,
113
+ 16, 17, 20, 27, 34, 40, 53, 75,
114
+ 16, 20, 24, 31, 43, 62, 91, 135,
115
+ 18, 27, 31, 40, 53, 74, 106, 156,
116
+ 25, 34, 43, 53, 69, 94, 131, 189,
117
+ 37, 40, 62, 74, 94, 124, 169, 238,
118
+ 56, 53, 91, 106, 131, 169, 226, 311,
119
+ 85, 75, 135, 156, 189, 238, 311, 418
120
+ },
121
+ {
122
+ 9, 10, 12, 14, 27, 32, 51, 62,
123
+ 11, 12, 14, 19, 27, 44, 59, 73,
124
+ 12, 14, 18, 25, 42, 59, 79, 78,
125
+ 17, 18, 25, 42, 61, 92, 87, 92,
126
+ 23, 28, 42, 75, 79, 112, 112, 99,
127
+ 40, 42, 59, 84, 88, 124, 132, 111,
128
+ 42, 64, 78, 95, 105, 126, 125, 99,
129
+ 70, 75, 100, 102, 116, 100, 107, 98
130
+ },
131
+ {
132
+ /* Relevance of human vision to JPEG-DCT compression (1992) Klein, Silverstein and Carney.
133
+ */
134
+ 10, 12, 14, 19, 26, 38, 57, 86,
135
+ 12, 18, 21, 28, 35, 41, 54, 76,
136
+ 14, 21, 25, 32, 44, 63, 92, 136,
137
+ 19, 28, 32, 41, 54, 75, 107, 157,
138
+ 26, 35, 44, 54, 70, 95, 132, 190,
139
+ 38, 41, 63, 75, 95, 125, 170, 239,
140
+ 57, 54, 92, 107, 132, 170, 227, 312,
141
+ 86, 76, 136, 157, 190, 239, 312, 419
142
+ },
143
+ {
144
+ /* DCTune perceptual optimization of compressed dental X-Rays (1997) Watson, Taylor, Borthwick
145
+ */
146
+ 7, 8, 10, 14, 23, 44, 95, 241,
147
+ 8, 8, 11, 15, 25, 47, 102, 255,
148
+ 10, 11, 13, 19, 31, 58, 127, 255,
149
+ 14, 15, 19, 27, 44, 83, 181, 255,
150
+ 23, 25, 31, 44, 72, 136, 255, 255,
151
+ 44, 47, 58, 83, 136, 255, 255, 255,
152
+ 95, 102, 127, 181, 255, 255, 255, 255,
153
+ 241, 255, 255, 255, 255, 255, 255, 255
154
+ },
155
+ {
156
+ /* A visual detection model for DCT coefficient quantization (12/9/93) Ahumada, Watson, Peterson
157
+ */
158
+ 15, 11, 11, 12, 15, 19, 25, 32,
159
+ 11, 13, 10, 10, 12, 15, 19, 24,
160
+ 11, 10, 14, 14, 16, 18, 22, 27,
161
+ 12, 10, 14, 18, 21, 24, 28, 33,
162
+ 15, 12, 16, 21, 26, 31, 36, 42,
163
+ 19, 15, 18, 24, 31, 38, 45, 53,
164
+ 25, 19, 22, 28, 36, 45, 55, 65,
165
+ 32, 24, 27, 33, 42, 53, 65, 77
166
+ },
167
+ {
168
+ /* An improved detection model for DCT coefficient quantization (1993) Peterson, Ahumada and Watson
169
+ */
170
+ 14, 10, 11, 14, 19, 25, 34, 45,
171
+ 10, 11, 11, 12, 15, 20, 26, 33,
172
+ 11, 11, 15, 18, 21, 25, 31, 38,
173
+ 14, 12, 18, 24, 28, 33, 39, 47,
174
+ 19, 15, 21, 28, 36, 43, 51, 59,
175
+ 25, 20, 25, 33, 43, 54, 64, 74,
176
+ 34, 26, 31, 39, 51, 64, 77, 91,
177
+ 45, 33, 38, 47, 59, 74, 91, 108
178
+ }
179
+ };
180
+
181
+ static const unsigned int std_chrominance_quant_tbl[9][DCTSIZE2] = {
182
+ {
183
+ /* JPEG Annex K
184
+ */
185
+ 17, 18, 24, 47, 99, 99, 99, 99,
186
+ 18, 21, 26, 66, 99, 99, 99, 99,
187
+ 24, 26, 56, 99, 99, 99, 99, 99,
188
+ 47, 66, 99, 99, 99, 99, 99, 99,
189
+ 99, 99, 99, 99, 99, 99, 99, 99,
190
+ 99, 99, 99, 99, 99, 99, 99, 99,
191
+ 99, 99, 99, 99, 99, 99, 99, 99,
192
+ 99, 99, 99, 99, 99, 99, 99, 99
193
+ },
194
+ {
195
+ /* flat
196
+ */
197
+ 16, 16, 16, 16, 16, 16, 16, 16,
198
+ 16, 16, 16, 16, 16, 16, 16, 16,
199
+ 16, 16, 16, 16, 16, 16, 16, 16,
200
+ 16, 16, 16, 16, 16, 16, 16, 16,
201
+ 16, 16, 16, 16, 16, 16, 16, 16,
202
+ 16, 16, 16, 16, 16, 16, 16, 16,
203
+ 16, 16, 16, 16, 16, 16, 16, 16,
204
+ 16, 16, 16, 16, 16, 16, 16, 16
205
+ },
206
+ {
207
+ 8, 12, 15, 15, 86, 96, 96, 98,
208
+ 13, 13, 15, 26, 90, 96, 99, 98,
209
+ 12, 15, 18, 96, 99, 99, 99, 99,
210
+ 17, 16, 90, 96, 99, 99, 99, 99,
211
+ 96, 96, 99, 99, 99, 99, 99, 99,
212
+ 99, 99, 99, 99, 99, 99, 99, 99,
213
+ 99, 99, 99, 99, 99, 99, 99, 99,
214
+ 99, 99, 99, 99, 99, 99, 99, 99
215
+ },
216
+ {
217
+ /* From http://www.imagemagick.org/discourse-server/viewtopic.php?f=22&t=20333&p=98008#p98008
218
+ */
219
+ 16, 16, 16, 18, 25, 37, 56, 85,
220
+ 16, 17, 20, 27, 34, 40, 53, 75,
221
+ 16, 20, 24, 31, 43, 62, 91, 135,
222
+ 18, 27, 31, 40, 53, 74, 106, 156,
223
+ 25, 34, 43, 53, 69, 94, 131, 189,
224
+ 37, 40, 62, 74, 94, 124, 169, 238,
225
+ 56, 53, 91, 106, 131, 169, 226, 311,
226
+ 85, 75, 135, 156, 189, 238, 311, 418
227
+ },
228
+ {
229
+ 9, 10, 17, 19, 62, 89, 91, 97,
230
+ 12, 13, 18, 29, 84, 91, 88, 98,
231
+ 14, 19, 29, 93, 95, 95, 98, 97,
232
+ 20, 26, 84, 88, 95, 95, 98, 94,
233
+ 26, 86, 91, 93, 97, 99, 98, 99,
234
+ 99, 100, 98, 99, 99, 99, 99, 99,
235
+ 99, 99, 99, 99, 99, 99, 99, 99,
236
+ 97, 97, 99, 99, 99, 99, 97, 99
237
+ },
238
+ {
239
+ /* Relevance of human vision to JPEG-DCT compression (1992) Klein, Silverstein and Carney.
240
+ * Copied from luma
241
+ */
242
+ 10, 12, 14, 19, 26, 38, 57, 86,
243
+ 12, 18, 21, 28, 35, 41, 54, 76,
244
+ 14, 21, 25, 32, 44, 63, 92, 136,
245
+ 19, 28, 32, 41, 54, 75, 107, 157,
246
+ 26, 35, 44, 54, 70, 95, 132, 190,
247
+ 38, 41, 63, 75, 95, 125, 170, 239,
248
+ 57, 54, 92, 107, 132, 170, 227, 312,
249
+ 86, 76, 136, 157, 190, 239, 312, 419
250
+ },
251
+ {
252
+ /* DCTune perceptual optimization of compressed dental X-Rays (1997) Watson, Taylor, Borthwick
253
+ * Copied from luma
254
+ */
255
+ 7, 8, 10, 14, 23, 44, 95, 241,
256
+ 8, 8, 11, 15, 25, 47, 102, 255,
257
+ 10, 11, 13, 19, 31, 58, 127, 255,
258
+ 14, 15, 19, 27, 44, 83, 181, 255,
259
+ 23, 25, 31, 44, 72, 136, 255, 255,
260
+ 44, 47, 58, 83, 136, 255, 255, 255,
261
+ 95, 102, 127, 181, 255, 255, 255, 255,
262
+ 241, 255, 255, 255, 255, 255, 255, 255
263
+ },
264
+ {
265
+ /* A visual detection model for DCT coefficient quantization (12/9/93) Ahumada, Watson, Peterson
266
+ * Copied from luma
267
+ */
268
+ 15, 11, 11, 12, 15, 19, 25, 32,
269
+ 11, 13, 10, 10, 12, 15, 19, 24,
270
+ 11, 10, 14, 14, 16, 18, 22, 27,
271
+ 12, 10, 14, 18, 21, 24, 28, 33,
272
+ 15, 12, 16, 21, 26, 31, 36, 42,
273
+ 19, 15, 18, 24, 31, 38, 45, 53,
274
+ 25, 19, 22, 28, 36, 45, 55, 65,
275
+ 32, 24, 27, 33, 42, 53, 65, 77
276
+ },
277
+ {
278
+ /* An improved detection model for DCT coefficient quantization (1993) Peterson, Ahumada and Watson
279
+ * Copied from luma
280
+ */
281
+ 14, 10, 11, 14, 19, 25, 34, 45,
282
+ 10, 11, 11, 12, 15, 20, 26, 33,
283
+ 11, 11, 15, 18, 21, 25, 31, 38,
284
+ 14, 12, 18, 24, 28, 33, 39, 47,
285
+ 19, 15, 21, 28, 36, 43, 51, 59,
286
+ 25, 20, 25, 33, 43, 54, 64, 74,
287
+ 34, 26, 31, 39, 51, 64, 77, 91,
288
+ 45, 33, 38, 47, 59, 74, 91, 108
289
+ }
290
+ };
291
+
292
+ #if JPEG_LIB_VERSION >= 70
293
+ GLOBAL(void)
294
+ jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
295
+ /* Set or change the 'quality' (quantization) setting, using default tables
296
+ * and straight percentage-scaling quality scales.
297
+ * This entry point allows different scalings for luminance and chrominance.
298
+ */
299
+ {
300
+ /* Set up two quantization tables using the specified scaling */
301
+ jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl[cinfo->master->quant_tbl_master_idx],
302
+ cinfo->q_scale_factor[0], force_baseline);
303
+ jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl[cinfo->master->quant_tbl_master_idx],
304
+ cinfo->q_scale_factor[1], force_baseline);
305
+ }
306
+ #endif
307
+
308
+
309
+ GLOBAL(void)
310
+ jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
311
+ boolean force_baseline)
312
+ /* Set or change the 'quality' (quantization) setting, using default tables
313
+ * and a straight percentage-scaling quality scale. In most cases it's better
314
+ * to use jpeg_set_quality (below); this entry point is provided for
315
+ * applications that insist on a linear percentage scaling.
316
+ */
317
+ {
318
+ /* Set up two quantization tables using the specified scaling */
319
+ jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl[cinfo->master->quant_tbl_master_idx],
320
+ scale_factor, force_baseline);
321
+ jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl[cinfo->master->quant_tbl_master_idx],
322
+ scale_factor, force_baseline);
323
+ }
324
+
325
+
326
+ GLOBAL(int)
327
+ jpeg_quality_scaling (int quality)
328
+ {
329
+ return jpeg_float_quality_scaling(quality);
330
+ }
331
+
332
+ GLOBAL(float)
333
+ jpeg_float_quality_scaling(float quality)
334
+ /* Convert a user-specified quality rating to a percentage scaling factor
335
+ * for an underlying quantization table, using our recommended scaling curve.
336
+ * The input 'quality' factor should be 0 (terrible) to 100 (very good).
337
+ */
338
+ {
339
+ /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */
340
+ if (quality <= 0.f) quality = 1.f;
341
+ if (quality > 100.f) quality = 100.f;
342
+
343
+ /* The basic table is used as-is (scaling 100) for a quality of 50.
344
+ * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
345
+ * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table
346
+ * to make all the table entries 1 (hence, minimum quantization loss).
347
+ * Qualities 1..50 are converted to scaling percentage 5000/Q.
348
+ */
349
+ if (quality < 50.f)
350
+ quality = 5000.f / quality;
351
+ else
352
+ quality = 200.f - quality*2.f;
353
+
354
+ return quality;
355
+ }
356
+
357
+
358
+ GLOBAL(void)
359
+ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
360
+ /* Set or change the 'quality' (quantization) setting, using default tables.
361
+ * This is the standard quality-adjusting entry point for typical user
362
+ * interfaces; only those who want detailed control over quantization tables
363
+ * would use the preceding three routines directly.
364
+ */
365
+ {
366
+ /* Convert user 0-100 rating to percentage scaling */
367
+ quality = jpeg_quality_scaling(quality);
368
+
369
+ /* Set up standard quality tables */
370
+ jpeg_set_linear_quality(cinfo, quality, force_baseline);
371
+ }
372
+
373
+
374
+ /*
375
+ * Default parameter setup for compression.
376
+ *
377
+ * Applications that don't choose to use this routine must do their
378
+ * own setup of all these parameters. Alternately, you can call this
379
+ * to establish defaults and then alter parameters selectively. This
380
+ * is the recommended approach since, if we add any new parameters,
381
+ * your code will still work (they'll be set to reasonable defaults).
382
+ */
383
+
384
+ GLOBAL(void)
385
+ jpeg_set_defaults (j_compress_ptr cinfo)
386
+ {
387
+ int i;
388
+
389
+ /* Safety check to ensure start_compress not called yet. */
390
+ if (cinfo->global_state != CSTATE_START)
391
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
392
+
393
+ /* Allocate comp_info array large enough for maximum component count.
394
+ * Array is made permanent in case application wants to compress
395
+ * multiple images at same param settings.
396
+ */
397
+ if (cinfo->comp_info == NULL)
398
+ cinfo->comp_info = (jpeg_component_info *)
399
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
400
+ MAX_COMPONENTS * sizeof(jpeg_component_info));
401
+
402
+ /* Initialize everything not dependent on the color space */
403
+
404
+ #if JPEG_LIB_VERSION >= 70
405
+ cinfo->scale_num = 1; /* 1:1 scaling */
406
+ cinfo->scale_denom = 1;
407
+ #endif
408
+ cinfo->data_precision = BITS_IN_JSAMPLE;
409
+ /* Set up two quantization tables using default quality of 75 */
410
+ jpeg_set_quality(cinfo, 75, TRUE);
411
+ /* Set up two Huffman tables */
412
+ std_huff_tables((j_common_ptr) cinfo);
413
+
414
+ /* Initialize default arithmetic coding conditioning */
415
+ for (i = 0; i < NUM_ARITH_TBLS; i++) {
416
+ cinfo->arith_dc_L[i] = 0;
417
+ cinfo->arith_dc_U[i] = 1;
418
+ cinfo->arith_ac_K[i] = 5;
419
+ }
420
+
421
+ /* Default is no multiple-scan output */
422
+ cinfo->scan_info = NULL;
423
+ cinfo->num_scans = 0;
424
+
425
+ /* Expect normal source image, not raw downsampled data */
426
+ cinfo->raw_data_in = FALSE;
427
+
428
+ /* Use Huffman coding, not arithmetic coding, by default */
429
+ cinfo->arith_code = FALSE;
430
+
431
+ #ifdef ENTROPY_OPT_SUPPORTED
432
+ if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION)
433
+ /* By default, do extra passes to optimize entropy coding */
434
+ cinfo->optimize_coding = TRUE;
435
+ else
436
+ /* By default, don't do extra passes to optimize entropy coding */
437
+ cinfo->optimize_coding = FALSE;
438
+ #else
439
+ /* By default, don't do extra passes to optimize entropy coding */
440
+ cinfo->optimize_coding = FALSE;
441
+ #endif
442
+
443
+ /* The standard Huffman tables are only valid for 8-bit data precision.
444
+ * If the precision is higher, force optimization on so that usable
445
+ * tables will be computed. This test can be removed if default tables
446
+ * are supplied that are valid for the desired precision.
447
+ */
448
+ if (cinfo->data_precision > 8)
449
+ cinfo->optimize_coding = TRUE;
450
+
451
+ /* By default, use the simpler non-cosited sampling alignment */
452
+ cinfo->CCIR601_sampling = FALSE;
453
+
454
+ #if JPEG_LIB_VERSION >= 70
455
+ /* By default, apply fancy downsampling */
456
+ cinfo->do_fancy_downsampling = TRUE;
457
+ #endif
458
+
459
+ cinfo->master->overshoot_deringing =
460
+ cinfo->master->compress_profile == JCP_MAX_COMPRESSION;
461
+
462
+ /* No input smoothing */
463
+ cinfo->smoothing_factor = 0;
464
+
465
+ /* DCT algorithm preference */
466
+ cinfo->dct_method = JDCT_DEFAULT;
467
+
468
+ /* No restart markers */
469
+ cinfo->restart_interval = 0;
470
+ cinfo->restart_in_rows = 0;
471
+
472
+ /* Fill in default JFIF marker parameters. Note that whether the marker
473
+ * will actually be written is determined by jpeg_set_colorspace.
474
+ *
475
+ * By default, the library emits JFIF version code 1.01.
476
+ * An application that wants to emit JFIF 1.02 extension markers should set
477
+ * JFIF_minor_version to 2. We could probably get away with just defaulting
478
+ * to 1.02, but there may still be some decoders in use that will complain
479
+ * about that; saying 1.01 should minimize compatibility problems.
480
+ */
481
+ cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
482
+ cinfo->JFIF_minor_version = 1;
483
+ cinfo->density_unit = 0; /* Pixel size is unknown by default */
484
+ cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
485
+ cinfo->Y_density = 1;
486
+
487
+ /* Choose JPEG colorspace based on input space, set defaults accordingly */
488
+
489
+ jpeg_default_colorspace(cinfo);
490
+
491
+ cinfo->master->dc_scan_opt_mode = 0;
492
+
493
+ #ifdef C_PROGRESSIVE_SUPPORTED
494
+ if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
495
+ cinfo->master->optimize_scans = TRUE;
496
+ jpeg_simple_progression(cinfo);
497
+ } else
498
+ cinfo->master->optimize_scans = FALSE;
499
+ #endif
500
+
501
+ cinfo->master->trellis_quant =
502
+ cinfo->master->compress_profile == JCP_MAX_COMPRESSION;
503
+ cinfo->master->lambda_log_scale1 = 14.75;
504
+ cinfo->master->lambda_log_scale2 = 16.5;
505
+ cinfo->master->quant_tbl_master_idx =
506
+ cinfo->master->compress_profile == JCP_MAX_COMPRESSION ? 3 : 0;
507
+
508
+ cinfo->master->use_lambda_weight_tbl = TRUE;
509
+ cinfo->master->use_scans_in_trellis = FALSE;
510
+ cinfo->master->trellis_freq_split = 8;
511
+ cinfo->master->trellis_num_loops = 1;
512
+ cinfo->master->trellis_q_opt = FALSE;
513
+ cinfo->master->trellis_quant_dc = TRUE;
514
+ cinfo->master->trellis_delta_dc_weight = 0.0;
515
+ }
516
+
517
+
518
+ /*
519
+ * Select an appropriate JPEG colorspace for in_color_space.
520
+ */
521
+
522
+ GLOBAL(void)
523
+ jpeg_default_colorspace (j_compress_ptr cinfo)
524
+ {
525
+ switch (cinfo->in_color_space) {
526
+ case JCS_GRAYSCALE:
527
+ jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
528
+ break;
529
+ case JCS_RGB:
530
+ case JCS_EXT_RGB:
531
+ case JCS_EXT_RGBX:
532
+ case JCS_EXT_BGR:
533
+ case JCS_EXT_BGRX:
534
+ case JCS_EXT_XBGR:
535
+ case JCS_EXT_XRGB:
536
+ case JCS_EXT_RGBA:
537
+ case JCS_EXT_BGRA:
538
+ case JCS_EXT_ABGR:
539
+ case JCS_EXT_ARGB:
540
+ jpeg_set_colorspace(cinfo, JCS_YCbCr);
541
+ break;
542
+ case JCS_YCbCr:
543
+ jpeg_set_colorspace(cinfo, JCS_YCbCr);
544
+ break;
545
+ case JCS_CMYK:
546
+ jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
547
+ break;
548
+ case JCS_YCCK:
549
+ jpeg_set_colorspace(cinfo, JCS_YCCK);
550
+ break;
551
+ case JCS_UNKNOWN:
552
+ jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
553
+ break;
554
+ default:
555
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
556
+ }
557
+ }
558
+
559
+
560
+ /*
561
+ * Set the JPEG colorspace, and choose colorspace-dependent default values.
562
+ */
563
+
564
+ GLOBAL(void)
565
+ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
566
+ {
567
+ jpeg_component_info *compptr;
568
+ int ci;
569
+
570
+ #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
571
+ (compptr = &cinfo->comp_info[index], \
572
+ compptr->component_id = (id), \
573
+ compptr->h_samp_factor = (hsamp), \
574
+ compptr->v_samp_factor = (vsamp), \
575
+ compptr->quant_tbl_no = (quant), \
576
+ compptr->dc_tbl_no = (dctbl), \
577
+ compptr->ac_tbl_no = (actbl) )
578
+
579
+ /* Safety check to ensure start_compress not called yet. */
580
+ if (cinfo->global_state != CSTATE_START)
581
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
582
+
583
+ /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
584
+ * tables 1 for chrominance components.
585
+ */
586
+
587
+ cinfo->jpeg_color_space = colorspace;
588
+
589
+ cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
590
+ cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
591
+
592
+ switch (colorspace) {
593
+ case JCS_GRAYSCALE:
594
+ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
595
+ cinfo->num_components = 1;
596
+ /* JFIF specifies component ID 1 */
597
+ SET_COMP(0, 1, 1,1, 0, 0,0);
598
+ break;
599
+ case JCS_RGB:
600
+ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
601
+ cinfo->num_components = 3;
602
+ SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
603
+ SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
604
+ SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
605
+ break;
606
+ case JCS_YCbCr:
607
+ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
608
+ cinfo->num_components = 3;
609
+ /* JFIF specifies component IDs 1,2,3 */
610
+ /* We default to 2x2 subsamples of chrominance */
611
+ SET_COMP(0, 1, 2,2, 0, 0,0);
612
+ SET_COMP(1, 2, 1,1, 1, 1,1);
613
+ SET_COMP(2, 3, 1,1, 1, 1,1);
614
+ break;
615
+ case JCS_CMYK:
616
+ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
617
+ cinfo->num_components = 4;
618
+ SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
619
+ SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
620
+ SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
621
+ SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
622
+ break;
623
+ case JCS_YCCK:
624
+ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
625
+ cinfo->num_components = 4;
626
+ SET_COMP(0, 1, 2,2, 0, 0,0);
627
+ SET_COMP(1, 2, 1,1, 1, 1,1);
628
+ SET_COMP(2, 3, 1,1, 1, 1,1);
629
+ SET_COMP(3, 4, 2,2, 0, 0,0);
630
+ break;
631
+ case JCS_UNKNOWN:
632
+ cinfo->num_components = cinfo->input_components;
633
+ if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
634
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
635
+ MAX_COMPONENTS);
636
+ for (ci = 0; ci < cinfo->num_components; ci++) {
637
+ SET_COMP(ci, ci, 1,1, 0, 0,0);
638
+ }
639
+ break;
640
+ default:
641
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
642
+ }
643
+ }
644
+
645
+
646
+ #ifdef C_PROGRESSIVE_SUPPORTED
647
+
648
+ LOCAL(jpeg_scan_info *)
649
+ fill_a_scan(jpeg_scan_info *scanptr, int ci, int Ss, int Se, int Ah, int Al)
650
+ /* Support routine: generate one scan for specified component */
651
+ {
652
+ scanptr->comps_in_scan = 1;
653
+ scanptr->component_index[0] = ci;
654
+ scanptr->Ss = Ss;
655
+ scanptr->Se = Se;
656
+ scanptr->Ah = Ah;
657
+ scanptr->Al = Al;
658
+ scanptr++;
659
+ return scanptr;
660
+ }
661
+
662
+ LOCAL(jpeg_scan_info *)
663
+ fill_a_scan_pair (jpeg_scan_info * scanptr, int ci,
664
+ int Ss, int Se, int Ah, int Al)
665
+ /* Support routine: generate one scan for pair of components */
666
+ {
667
+ scanptr->comps_in_scan = 2;
668
+ scanptr->component_index[0] = ci;
669
+ scanptr->component_index[1] = ci + 1;
670
+ scanptr->Ss = Ss;
671
+ scanptr->Se = Se;
672
+ scanptr->Ah = Ah;
673
+ scanptr->Al = Al;
674
+ scanptr++;
675
+ return scanptr;
676
+ }
677
+
678
+ LOCAL(jpeg_scan_info *)
679
+ fill_scans (jpeg_scan_info *scanptr, int ncomps,
680
+ int Ss, int Se, int Ah, int Al)
681
+ /* Support routine: generate one scan for each component */
682
+ {
683
+ int ci;
684
+
685
+ for (ci = 0; ci < ncomps; ci++) {
686
+ scanptr->comps_in_scan = 1;
687
+ scanptr->component_index[0] = ci;
688
+ scanptr->Ss = Ss;
689
+ scanptr->Se = Se;
690
+ scanptr->Ah = Ah;
691
+ scanptr->Al = Al;
692
+ scanptr++;
693
+ }
694
+ return scanptr;
695
+ }
696
+
697
+ LOCAL(jpeg_scan_info *)
698
+ fill_dc_scans (jpeg_scan_info *scanptr, int ncomps, int Ah, int Al)
699
+ /* Support routine: generate interleaved DC scan if possible, else N scans */
700
+ {
701
+ int ci;
702
+
703
+ if (ncomps <= MAX_COMPS_IN_SCAN) {
704
+ /* Single interleaved DC scan */
705
+ scanptr->comps_in_scan = ncomps;
706
+ for (ci = 0; ci < ncomps; ci++)
707
+ scanptr->component_index[ci] = ci;
708
+ scanptr->Ss = scanptr->Se = 0;
709
+ scanptr->Ah = Ah;
710
+ scanptr->Al = Al;
711
+ scanptr++;
712
+ } else {
713
+ /* Noninterleaved DC scan for each component */
714
+ scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
715
+ }
716
+ return scanptr;
717
+ }
718
+
719
+
720
+ /*
721
+ * List of scans to be tested
722
+ * cinfo->num_components and cinfo->jpeg_color_space must be correct.
723
+ */
724
+
725
+ LOCAL(boolean)
726
+ jpeg_search_progression (j_compress_ptr cinfo)
727
+ {
728
+ int ncomps = cinfo->num_components;
729
+ int nscans;
730
+ jpeg_scan_info * scanptr;
731
+ int Al;
732
+ int frequency_split[] = { 2, 8, 5, 12, 18 };
733
+ int i;
734
+
735
+ /* Safety check to ensure start_compress not called yet. */
736
+ if (cinfo->global_state != CSTATE_START)
737
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
738
+
739
+ /* Figure space needed for script. Calculation must match code below! */
740
+ if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
741
+ /* Custom script for YCbCr color images. */
742
+ nscans = 64;
743
+ } else if (ncomps == 1) {
744
+ nscans = 23;
745
+ } else {
746
+ cinfo->master->num_scans_luma = 0;
747
+ return FALSE;
748
+ }
749
+
750
+ /* Allocate space for script.
751
+ * We need to put it in the permanent pool in case the application performs
752
+ * multiple compressions without changing the settings. To avoid a memory
753
+ * leak if jpeg_simple_progression is called repeatedly for the same JPEG
754
+ * object, we try to re-use previously allocated space, and we allocate
755
+ * enough space to handle YCbCr even if initially asked for grayscale.
756
+ */
757
+ if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
758
+ cinfo->script_space_size = MAX(nscans, 64);
759
+ cinfo->script_space = (jpeg_scan_info *)
760
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
761
+ cinfo->script_space_size * sizeof(jpeg_scan_info));
762
+ }
763
+ scanptr = cinfo->script_space;
764
+ cinfo->scan_info = scanptr;
765
+ cinfo->num_scans = nscans;
766
+
767
+ cinfo->master->Al_max_luma = 3;
768
+ cinfo->master->num_scans_luma_dc = 1;
769
+ cinfo->master->num_frequency_splits = 5;
770
+ cinfo->master->num_scans_luma =
771
+ cinfo->master->num_scans_luma_dc + (3 * cinfo->master->Al_max_luma + 2) +
772
+ (2 * cinfo->master->num_frequency_splits + 1);
773
+
774
+ /* 23 scans for luma */
775
+ /* 1 scan for DC */
776
+ /* 11 scans to determine successive approximation */
777
+ /* 11 scans to determine frequency approximation */
778
+ /* after 12 scans need to update following 11 */
779
+ /* after 23 scans need to determine which to keep */
780
+ /* last 4 done conditionally */
781
+
782
+ /* luma DC by itself */
783
+ if (cinfo->master->dc_scan_opt_mode == 0)
784
+ scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
785
+ else
786
+ scanptr = fill_dc_scans(scanptr, 1, 0, 0);
787
+
788
+ scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 0);
789
+ scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, 0);
790
+
791
+ for (Al = 0; Al < cinfo->master->Al_max_luma; Al++) {
792
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, Al+1, Al);
793
+ scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, Al+1);
794
+ scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, Al+1);
795
+ }
796
+
797
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, 0, 0);
798
+
799
+ for (i = 0; i < cinfo->master->num_frequency_splits; i++) {
800
+ scanptr = fill_a_scan(scanptr, 0, 1, frequency_split[i], 0, 0);
801
+ scanptr = fill_a_scan(scanptr, 0, frequency_split[i]+1, 63, 0, 0);
802
+ }
803
+
804
+ if (ncomps == 1) {
805
+ cinfo->master->Al_max_chroma = 0;
806
+ cinfo->master->num_scans_chroma_dc = 0;
807
+ } else {
808
+ cinfo->master->Al_max_chroma = 2;
809
+ cinfo->master->num_scans_chroma_dc = 3;
810
+ /* 41 scans for chroma */
811
+
812
+ /* chroma DC combined */
813
+ scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
814
+ /* chroma DC separate */
815
+ scanptr = fill_a_scan(scanptr, 1, 0, 0, 0, 0);
816
+ scanptr = fill_a_scan(scanptr, 2, 0, 0, 0, 0);
817
+
818
+ scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, 0);
819
+ scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, 0);
820
+ scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, 0);
821
+ scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0);
822
+
823
+ for (Al = 0; Al < cinfo->master->Al_max_chroma; Al++) {
824
+ scanptr = fill_a_scan(scanptr, 1, 1, 63, Al+1, Al);
825
+ scanptr = fill_a_scan(scanptr, 2, 1, 63, Al+1, Al);
826
+ scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, Al+1);
827
+ scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, Al+1);
828
+ scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, Al+1);
829
+ scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, Al+1);
830
+ }
831
+
832
+ scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 0);
833
+ scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 0);
834
+
835
+ for (i = 0; i < cinfo->master->num_frequency_splits; i++) {
836
+ scanptr = fill_a_scan(scanptr, 1, 1, frequency_split[i], 0, 0);
837
+ scanptr = fill_a_scan(scanptr, 1, frequency_split[i]+1, 63, 0, 0);
838
+ scanptr = fill_a_scan(scanptr, 2, 1, frequency_split[i], 0, 0);
839
+ scanptr = fill_a_scan(scanptr, 2, frequency_split[i]+1, 63, 0, 0);
840
+ }
841
+ }
842
+
843
+ return TRUE;
844
+ }
845
+
846
+ /*
847
+ * Create a recommended progressive-JPEG script.
848
+ * cinfo->num_components and cinfo->jpeg_color_space must be correct.
849
+ */
850
+
851
+ GLOBAL(void)
852
+ jpeg_simple_progression (j_compress_ptr cinfo)
853
+ {
854
+ int ncomps;
855
+ int nscans;
856
+ jpeg_scan_info *scanptr;
857
+
858
+ if (cinfo->master->optimize_scans) {
859
+ if (jpeg_search_progression(cinfo) == TRUE)
860
+ return;
861
+ }
862
+
863
+ /* Safety check to ensure start_compress not called yet. */
864
+ if (cinfo->global_state != CSTATE_START)
865
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
866
+
867
+ /* Figure space needed for script. Calculation must match code below! */
868
+ ncomps = cinfo->num_components;
869
+ if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
870
+ /* Custom script for YCbCr color images. */
871
+ if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
872
+ if (cinfo->master->dc_scan_opt_mode == 0) {
873
+ nscans = 9; /* 1 DC scan for all components */
874
+ } else if (cinfo->master->dc_scan_opt_mode == 1) {
875
+ nscans = 11; /* 1 DC scan for each component */
876
+ } else {
877
+ nscans = 10; /* 1 DC scan for luminance and 1 DC scan for chroma */
878
+ }
879
+ } else {
880
+ nscans = 10; /* 2 DC scans and 8 AC scans */
881
+ }
882
+ } else {
883
+ /* All-purpose script for other color spaces. */
884
+ if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
885
+ if (ncomps > MAX_COMPS_IN_SCAN)
886
+ nscans = 5 * ncomps; /* 2 DC + 4 AC scans per component */
887
+ else
888
+ nscans = 1 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
889
+ } else {
890
+ if (ncomps > MAX_COMPS_IN_SCAN)
891
+ nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
892
+ else
893
+ nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
894
+ }
895
+ }
896
+
897
+ /* Allocate space for script.
898
+ * We need to put it in the permanent pool in case the application performs
899
+ * multiple compressions without changing the settings. To avoid a memory
900
+ * leak if jpeg_simple_progression is called repeatedly for the same JPEG
901
+ * object, we try to re-use previously allocated space, and we allocate
902
+ * enough space to handle YCbCr even if initially asked for grayscale.
903
+ */
904
+ if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
905
+ cinfo->script_space_size = MAX(nscans, 10);
906
+ cinfo->script_space = (jpeg_scan_info *)
907
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
908
+ cinfo->script_space_size * sizeof(jpeg_scan_info));
909
+ }
910
+ scanptr = cinfo->script_space;
911
+ cinfo->scan_info = scanptr;
912
+ cinfo->num_scans = nscans;
913
+
914
+ if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
915
+ /* Custom script for YCbCr color images. */
916
+ if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
917
+ /* scan defined in jpeg_scan_rgb.txt in jpgcrush */
918
+ /* Initial DC scan */
919
+ if (cinfo->master->dc_scan_opt_mode == 0) {
920
+ /* 1 DC scan for all components */
921
+ scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
922
+ } else if (cinfo->master->dc_scan_opt_mode == 1) {
923
+ /* 1 DC scan for each component */
924
+ scanptr = fill_a_scan(scanptr, 0, 0, 0, 0, 0);
925
+ scanptr = fill_a_scan(scanptr, 1, 0, 0, 0, 0);
926
+ scanptr = fill_a_scan(scanptr, 2, 0, 0, 0, 0);
927
+ } else {
928
+ /* 1 DC scan for luminance and 1 DC scan for chroma */
929
+ scanptr = fill_dc_scans(scanptr, 1, 0, 0);
930
+ scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
931
+ }
932
+ /* Low frequency AC scans */
933
+ scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 2);
934
+ scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, 0);
935
+ scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, 0);
936
+ /* Complete spectral selection for luma AC */
937
+ scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, 2);
938
+ /* Finish luma AC successive approximation */
939
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
940
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
941
+ /* Complete spectral selection for chroma AC */
942
+ scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, 0);
943
+ scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0);
944
+ } else {
945
+ /* Initial DC scan */
946
+ scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
947
+ /* Initial AC scan: get some luma data out in a hurry */
948
+ scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
949
+ /* Chroma data is too small to be worth expending many scans on */
950
+ scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
951
+ scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
952
+ /* Complete spectral selection for luma AC */
953
+ scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
954
+ /* Refine next bit of luma AC */
955
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
956
+ /* Finish DC successive approximation */
957
+ scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
958
+ /* Finish AC successive approximation */
959
+ scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
960
+ scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
961
+ /* Luma bottom bit comes last since it's usually largest scan */
962
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
963
+ }
964
+ } else {
965
+ /* All-purpose script for other color spaces. */
966
+ if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
967
+ /* scan defined in jpeg_scan_bw.txt in jpgcrush */
968
+ /* DC component, no successive approximation */
969
+ scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
970
+ /* Successive approximation first pass */
971
+ scanptr = fill_scans(scanptr, ncomps, 1, 8, 0, 2);
972
+ scanptr = fill_scans(scanptr, ncomps, 9, 63, 0, 2);
973
+ /* Successive approximation second pass */
974
+ scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
975
+ /* Successive approximation final pass */
976
+ scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
977
+ } else {
978
+ /* Successive approximation first pass */
979
+ scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
980
+ scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
981
+ scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
982
+ /* Successive approximation second pass */
983
+ scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
984
+ /* Successive approximation final pass */
985
+ scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
986
+ scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
987
+ }
988
+ }
989
+ }
990
+
991
+ #endif /* C_PROGRESSIVE_SUPPORTED */