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,961 @@
1
+ /*
2
+ * cjpeg.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-2011 by Guido Vollbeding.
7
+ * libjpeg-turbo Modifications:
8
+ * Copyright (C) 2010, 2013-2014, 2017, 2019-2022, 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 a command-line user interface for the JPEG compressor.
14
+ * It should work on any system with Unix- or MS-DOS-style command lines.
15
+ *
16
+ * Two different command line styles are permitted, depending on the
17
+ * compile-time switch TWO_FILE_COMMANDLINE:
18
+ * cjpeg [options] inputfile outputfile
19
+ * cjpeg [options] [inputfile]
20
+ * In the second style, output is always to standard output, which you'd
21
+ * normally redirect to a file or pipe to some other program. Input is
22
+ * either from a named file or from standard input (typically redirected).
23
+ * The second style is convenient on Unix but is unhelpful on systems that
24
+ * don't support pipes. Also, you MUST use the first style if your system
25
+ * doesn't do binary I/O to stdin/stdout.
26
+ * To simplify script writing, the "-outfile" switch is provided. The syntax
27
+ * cjpeg [options] -outfile outputfile inputfile
28
+ * works regardless of which command line style is used.
29
+ */
30
+
31
+ #ifdef _MSC_VER
32
+ #define _CRT_SECURE_NO_DEPRECATE
33
+ #endif
34
+
35
+ #ifdef CJPEG_FUZZER
36
+ #define JPEG_INTERNALS
37
+ #endif
38
+ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
39
+ #include "jversion.h" /* for version message */
40
+ #include "jconfigint.h"
41
+
42
+
43
+ /* Create the add-on message string table. */
44
+
45
+ #define JMESSAGE(code, string) string,
46
+
47
+ static const char * const cdjpeg_message_table[] = {
48
+ #include "cderror.h"
49
+ NULL
50
+ };
51
+
52
+
53
+ /*
54
+ * This routine determines what format the input file is,
55
+ * and selects the appropriate input-reading module.
56
+ *
57
+ * To determine which family of input formats the file belongs to,
58
+ * we may look only at the first byte of the file, since C does not
59
+ * guarantee that more than one character can be pushed back with ungetc.
60
+ * Looking at additional bytes would require one of these approaches:
61
+ * 1) assume we can fseek() the input file (fails for piped input);
62
+ * 2) assume we can push back more than one character (works in
63
+ * some C implementations, but unportable);
64
+ * 3) provide our own buffering (breaks input readers that want to use
65
+ * stdio directly);
66
+ * or 4) don't put back the data, and modify the input_init methods to assume
67
+ * they start reading after the start of file.
68
+ * #1 is attractive for MS-DOS but is untenable on Unix.
69
+ *
70
+ * The most portable solution for file types that can't be identified by their
71
+ * first byte is to make the user tell us what they are. This is also the
72
+ * only approach for "raw" file types that contain only arbitrary values.
73
+ * We presently apply this method for Targa files. Most of the time Targa
74
+ * files start with 0x00, so we recognize that case. Potentially, however,
75
+ * a Targa file could start with any byte value (byte 0 is the length of the
76
+ * seldom-used ID field), so we provide a switch to force Targa input mode.
77
+ */
78
+
79
+ static boolean is_targa; /* records user -targa switch */
80
+ static boolean is_jpeg;
81
+ static boolean copy_markers;
82
+
83
+ LOCAL(cjpeg_source_ptr)
84
+ select_file_type(j_compress_ptr cinfo, FILE *infile)
85
+ {
86
+ int c;
87
+
88
+ if (is_targa) {
89
+ #ifdef TARGA_SUPPORTED
90
+ return jinit_read_targa(cinfo);
91
+ #else
92
+ ERREXIT(cinfo, JERR_TGA_NOTCOMP);
93
+ #endif
94
+ }
95
+
96
+ if ((c = getc(infile)) == EOF)
97
+ ERREXIT(cinfo, JERR_INPUT_EMPTY);
98
+ if (ungetc(c, infile) == EOF)
99
+ ERREXIT(cinfo, JERR_UNGETC_FAILED);
100
+
101
+ switch (c) {
102
+ #ifdef BMP_SUPPORTED
103
+ case 'B':
104
+ return jinit_read_bmp(cinfo, TRUE);
105
+ #endif
106
+ #ifdef GIF_SUPPORTED
107
+ case 'G':
108
+ return jinit_read_gif(cinfo);
109
+ #endif
110
+ #ifdef PPM_SUPPORTED
111
+ case 'P':
112
+ return jinit_read_ppm(cinfo);
113
+ #endif
114
+ #ifdef PNG_SUPPORTED
115
+ case 0x89:
116
+ copy_markers = TRUE;
117
+ return jinit_read_png(cinfo);
118
+ #endif
119
+ #ifdef TARGA_SUPPORTED
120
+ case 0x00:
121
+ return jinit_read_targa(cinfo);
122
+ #endif
123
+ case 0xff:
124
+ is_jpeg = TRUE;
125
+ copy_markers = TRUE;
126
+ return jinit_read_jpeg(cinfo);
127
+ default:
128
+ ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
129
+ break;
130
+ }
131
+
132
+ return NULL; /* suppress compiler warnings */
133
+ }
134
+
135
+
136
+ /*
137
+ * Argument-parsing code.
138
+ * The switch parser is designed to be useful with DOS-style command line
139
+ * syntax, ie, intermixed switches and file names, where only the switches
140
+ * to the left of a given file name affect processing of that file.
141
+ * The main program in this file doesn't actually use this capability...
142
+ */
143
+
144
+
145
+ static const char *progname; /* program name for error messages */
146
+ static char *icc_filename; /* for -icc switch */
147
+ static char *outfilename; /* for -outfile switch */
148
+ boolean memdst; /* for -memdst switch */
149
+ boolean report; /* for -report switch */
150
+ boolean strict; /* for -strict switch */
151
+
152
+
153
+ #ifdef CJPEG_FUZZER
154
+
155
+ #include <setjmp.h>
156
+
157
+ struct my_error_mgr {
158
+ struct jpeg_error_mgr pub;
159
+ jmp_buf setjmp_buffer;
160
+ };
161
+
162
+ void my_error_exit(j_common_ptr cinfo)
163
+ {
164
+ struct my_error_mgr *myerr = (struct my_error_mgr *)cinfo->err;
165
+
166
+ longjmp(myerr->setjmp_buffer, 1);
167
+ }
168
+
169
+ static void my_emit_message_fuzzer(j_common_ptr cinfo, int msg_level)
170
+ {
171
+ if (msg_level < 0)
172
+ cinfo->err->num_warnings++;
173
+ }
174
+
175
+ #define HANDLE_ERROR() { \
176
+ if (cinfo.global_state > CSTATE_START) { \
177
+ if (memdst && outbuffer) \
178
+ (*cinfo.dest->term_destination) (&cinfo); \
179
+ jpeg_abort_compress(&cinfo); \
180
+ } \
181
+ jpeg_destroy_compress(&cinfo); \
182
+ if (input_file != stdin && input_file != NULL) \
183
+ fclose(input_file); \
184
+ if (memdst) \
185
+ free(outbuffer); \
186
+ return EXIT_FAILURE; \
187
+ }
188
+
189
+ #endif
190
+
191
+
192
+ LOCAL(void)
193
+ usage(void)
194
+ /* complain about bad command line */
195
+ {
196
+ fprintf(stderr, "usage: %s [switches] ", progname);
197
+ #ifdef TWO_FILE_COMMANDLINE
198
+ fprintf(stderr, "inputfile outputfile\n");
199
+ #else
200
+ fprintf(stderr, "[inputfile]\n");
201
+ #endif
202
+
203
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
204
+ fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is most useful range,\n");
205
+ fprintf(stderr, " default is 75)\n");
206
+ fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
207
+ fprintf(stderr, " -rgb Create RGB JPEG file\n");
208
+ #ifdef ENTROPY_OPT_SUPPORTED
209
+ fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression, enabled by default)\n");
210
+ #endif
211
+ #ifdef C_PROGRESSIVE_SUPPORTED
212
+ fprintf(stderr, " -progressive Create progressive JPEG file (enabled by default)\n");
213
+ #endif
214
+ fprintf(stderr, " -baseline Create baseline JPEG file (disable progressive coding)\n");
215
+ #ifdef TARGA_SUPPORTED
216
+ fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
217
+ #endif
218
+ fprintf(stderr, " -revert Revert to standard defaults (instead of mozjpeg defaults)\n");
219
+ fprintf(stderr, " -fastcrush Disable progressive scan optimization\n");
220
+ fprintf(stderr, " -dc-scan-opt DC scan optimization mode\n");
221
+ fprintf(stderr, " - 0 One scan for all components\n");
222
+ fprintf(stderr, " - 1 One scan per component (default)\n");
223
+ fprintf(stderr, " - 2 Optimize between one scan for all components and one scan for 1st component\n");
224
+ fprintf(stderr, " plus one scan for remaining components\n");
225
+ fprintf(stderr, " -notrellis Disable trellis optimization\n");
226
+ fprintf(stderr, " -trellis-dc Enable trellis optimization of DC coefficients (default)\n");
227
+ fprintf(stderr, " -notrellis-dc Disable trellis optimization of DC coefficients\n");
228
+ fprintf(stderr, " -tune-psnr Tune trellis optimization for PSNR\n");
229
+ fprintf(stderr, " -tune-hvs-psnr Tune trellis optimization for PSNR-HVS (default)\n");
230
+ fprintf(stderr, " -tune-ssim Tune trellis optimization for SSIM\n");
231
+ fprintf(stderr, " -tune-ms-ssim Tune trellis optimization for MS-SSIM\n");
232
+ fprintf(stderr, "Switches for advanced users:\n");
233
+ fprintf(stderr, " -noovershoot Disable black-on-white deringing via overshoot\n");
234
+ fprintf(stderr, " -nojfif Do not write JFIF (reduces size by 18 bytes but breaks standards; no known problems in Web browsers)\n");
235
+ #ifdef C_ARITH_CODING_SUPPORTED
236
+ fprintf(stderr, " -arithmetic Use arithmetic coding\n");
237
+ #endif
238
+ #ifdef DCT_ISLOW_SUPPORTED
239
+ fprintf(stderr, " -dct int Use accurate integer DCT method%s\n",
240
+ (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
241
+ #endif
242
+ #ifdef DCT_IFAST_SUPPORTED
243
+ fprintf(stderr, " -dct fast Use less accurate integer DCT method [legacy feature]%s\n",
244
+ (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
245
+ #endif
246
+ #ifdef DCT_FLOAT_SUPPORTED
247
+ fprintf(stderr, " -dct float Use floating-point DCT method [legacy feature]%s\n",
248
+ (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
249
+ #endif
250
+ fprintf(stderr, " -quant-baseline Use 8-bit quantization table entries for baseline JPEG compatibility\n");
251
+ fprintf(stderr, " -quant-table N Use predefined quantization table N:\n");
252
+ fprintf(stderr, " - 0 JPEG Annex K\n");
253
+ fprintf(stderr, " - 1 Flat\n");
254
+ fprintf(stderr, " - 2 Tuned for MS-SSIM on Kodak image set\n");
255
+ fprintf(stderr, " - 3 ImageMagick table by N. Robidoux (default)\n");
256
+ fprintf(stderr, " - 4 Tuned for PSNR-HVS on Kodak image set\n");
257
+ fprintf(stderr, " - 5 Table from paper by Klein, Silverstein and Carney\n");
258
+ fprintf(stderr, " - 6 Table from paper by Watson, Taylor and Borthwick\n");
259
+ fprintf(stderr, " - 7 Table from paper by Ahumada, Watson, Peterson\n");
260
+ fprintf(stderr, " - 8 Table from paper by Peterson, Ahumada and Watson\n");
261
+ fprintf(stderr, " -icc FILE Embed ICC profile contained in FILE\n");
262
+ fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
263
+ #ifdef INPUT_SMOOTHING_SUPPORTED
264
+ fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n");
265
+ #endif
266
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
267
+ fprintf(stderr, " -outfile name Specify name for output file\n");
268
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
269
+ fprintf(stderr, " -memdst Compress to memory instead of file (useful for benchmarking)\n");
270
+ #endif
271
+ fprintf(stderr, " -report Report compression progress\n");
272
+ fprintf(stderr, " -strict Treat all warnings as fatal\n");
273
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
274
+ fprintf(stderr, " -version Print version information and exit\n");
275
+ fprintf(stderr, "Switches for wizards:\n");
276
+ fprintf(stderr, " -qtables FILE Use quantization tables given in FILE\n");
277
+ fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
278
+ fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
279
+ #ifdef C_MULTISCAN_FILES_SUPPORTED
280
+ fprintf(stderr, " -scans FILE Create multi-scan JPEG per script FILE\n");
281
+ #endif
282
+ exit(EXIT_FAILURE);
283
+ }
284
+
285
+
286
+ LOCAL(int)
287
+ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
288
+ int last_file_arg_seen, boolean for_real)
289
+ /* Parse optional switches.
290
+ * Returns argv[] index of first file-name argument (== argc if none).
291
+ * Any file names with indexes <= last_file_arg_seen are ignored;
292
+ * they have presumably been processed in a previous iteration.
293
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
294
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
295
+ * processing.
296
+ */
297
+ {
298
+ int argn;
299
+ char *arg;
300
+ boolean force_baseline;
301
+ boolean simple_progressive;
302
+ char *qualityarg = NULL; /* saves -quality parm if any */
303
+ char *qtablefile = NULL; /* saves -qtables filename if any */
304
+ char *qslotsarg = NULL; /* saves -qslots parm if any */
305
+ char *samplearg = NULL; /* saves -sample parm if any */
306
+ char *scansarg = NULL; /* saves -scans parm if any */
307
+
308
+ /* Set up default JPEG parameters. */
309
+
310
+ force_baseline = FALSE; /* by default, allow 16-bit quantizers */
311
+ #ifdef C_PROGRESSIVE_SUPPORTED
312
+ simple_progressive = cinfo->num_scans == 0 ? FALSE : TRUE;
313
+ #else
314
+ simple_progressive = FALSE;
315
+ #endif
316
+ is_targa = FALSE;
317
+ icc_filename = NULL;
318
+ outfilename = NULL;
319
+ memdst = FALSE;
320
+ report = FALSE;
321
+ strict = FALSE;
322
+ cinfo->err->trace_level = 0;
323
+
324
+ /* Scan command line options, adjust parameters */
325
+
326
+ for (argn = 1; argn < argc; argn++) {
327
+ arg = argv[argn];
328
+ if (*arg != '-') {
329
+ /* Not a switch, must be a file name argument */
330
+ if (argn <= last_file_arg_seen) {
331
+ outfilename = NULL; /* -outfile applies to just one input file */
332
+ continue; /* ignore this name if previously processed */
333
+ }
334
+ break; /* else done parsing switches */
335
+ }
336
+ arg++; /* advance past switch marker character */
337
+
338
+ if (keymatch(arg, "arithmetic", 1)) {
339
+ /* Use arithmetic coding. */
340
+ #ifdef C_ARITH_CODING_SUPPORTED
341
+ cinfo->arith_code = TRUE;
342
+
343
+ /* No table optimization required for AC */
344
+ cinfo->optimize_coding = FALSE;
345
+ #else
346
+ fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
347
+ progname);
348
+ exit(EXIT_FAILURE);
349
+ #endif
350
+
351
+ } else if (keymatch(arg, "baseline", 1)) {
352
+ /* Force baseline-compatible output (8-bit quantizer values). */
353
+ force_baseline = TRUE;
354
+ /* Disable multiple scans */
355
+ simple_progressive = FALSE;
356
+ cinfo->num_scans = 0;
357
+ cinfo->scan_info = NULL;
358
+
359
+ } else if (keymatch(arg, "dct", 2)) {
360
+ /* Select DCT algorithm. */
361
+ if (++argn >= argc) { /* advance to next argument */
362
+ fprintf(stderr, "%s: missing argument for dct\n", progname);
363
+ usage();
364
+ }
365
+ if (keymatch(argv[argn], "int", 1)) {
366
+ cinfo->dct_method = JDCT_ISLOW;
367
+ } else if (keymatch(argv[argn], "fast", 2)) {
368
+ cinfo->dct_method = JDCT_IFAST;
369
+ } else if (keymatch(argv[argn], "float", 2)) {
370
+ cinfo->dct_method = JDCT_FLOAT;
371
+ } else {
372
+ fprintf(stderr, "%s: invalid argument for dct\n", progname);
373
+ usage();
374
+ }
375
+
376
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
377
+ /* Enable debug printouts. */
378
+ /* On first -d, print version identification */
379
+ static boolean printed_version = FALSE;
380
+
381
+ if (!printed_version) {
382
+ fprintf(stderr, "%s version %s (build %s)\n",
383
+ PACKAGE_NAME, VERSION, BUILD);
384
+ fprintf(stderr, "%s\n\n", JCOPYRIGHT);
385
+ fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
386
+ JVERSION);
387
+ printed_version = TRUE;
388
+ }
389
+ cinfo->err->trace_level++;
390
+
391
+ } else if (keymatch(arg, "version", 4)) {
392
+ fprintf(stderr, "%s version %s (build %s)\n",
393
+ PACKAGE_NAME, VERSION, BUILD);
394
+ exit(EXIT_SUCCESS);
395
+
396
+ } else if (keymatch(arg, "fastcrush", 4)) {
397
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_OPTIMIZE_SCANS, FALSE);
398
+
399
+ } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
400
+ /* Force a monochrome JPEG file to be generated. */
401
+ jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
402
+
403
+ } else if (keymatch(arg, "rgb", 3)) {
404
+ /* Force an RGB JPEG file to be generated. */
405
+ jpeg_set_colorspace(cinfo, JCS_RGB);
406
+
407
+ } else if (keymatch(arg, "lambda1", 7)) {
408
+ if (++argn >= argc) /* advance to next argument */
409
+ usage();
410
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1,
411
+ atof(argv[argn]));
412
+
413
+ } else if (keymatch(arg, "lambda2", 7)) {
414
+ if (++argn >= argc) /* advance to next argument */
415
+ usage();
416
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE2,
417
+ atof(argv[argn]));
418
+
419
+ } else if (keymatch(arg, "icc", 1)) {
420
+ /* Set ICC filename. */
421
+ if (++argn >= argc) /* advance to next argument */
422
+ usage();
423
+ icc_filename = argv[argn];
424
+
425
+ } else if (keymatch(arg, "maxmemory", 3)) {
426
+ /* Maximum memory in Kb (or Mb with 'm'). */
427
+ long lval;
428
+ char ch = 'x';
429
+
430
+ if (++argn >= argc) /* advance to next argument */
431
+ usage();
432
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
433
+ usage();
434
+ if (ch == 'm' || ch == 'M')
435
+ lval *= 1000L;
436
+ cinfo->mem->max_memory_to_use = lval * 1000L;
437
+
438
+ } else if (keymatch(arg, "dc-scan-opt", 3)) {
439
+ if (++argn >= argc) { /* advance to next argument */
440
+ fprintf(stderr, "%s: missing argument for dc-scan-opt\n", progname);
441
+ usage();
442
+ }
443
+ jpeg_c_set_int_param(cinfo, JINT_DC_SCAN_OPT_MODE, atoi(argv[argn]));
444
+
445
+ } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
446
+ /* Enable entropy parm optimization. */
447
+ #ifdef ENTROPY_OPT_SUPPORTED
448
+ cinfo->optimize_coding = TRUE;
449
+ #else
450
+ fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n",
451
+ progname);
452
+ exit(EXIT_FAILURE);
453
+ #endif
454
+
455
+ } else if (keymatch(arg, "outfile", 4)) {
456
+ /* Set output file name. */
457
+ if (++argn >= argc) { /* advance to next argument */
458
+ fprintf(stderr, "%s: missing argument for outfile\n", progname);
459
+ usage();
460
+ }
461
+ outfilename = argv[argn]; /* save it away for later use */
462
+
463
+ } else if (keymatch(arg, "progressive", 1)) {
464
+ /* Select simple progressive mode. */
465
+ #ifdef C_PROGRESSIVE_SUPPORTED
466
+ simple_progressive = TRUE;
467
+ /* We must postpone execution until num_components is known. */
468
+ #else
469
+ fprintf(stderr, "%s: sorry, progressive output was not compiled in\n",
470
+ progname);
471
+ exit(EXIT_FAILURE);
472
+ #endif
473
+
474
+ } else if (keymatch(arg, "memdst", 2)) {
475
+ /* Use in-memory destination manager */
476
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
477
+ memdst = TRUE;
478
+ #else
479
+ fprintf(stderr, "%s: sorry, in-memory destination manager was not compiled in\n",
480
+ progname);
481
+ exit(EXIT_FAILURE);
482
+ #endif
483
+
484
+ } else if (keymatch(arg, "quality", 1)) {
485
+ /* Quality ratings (quantization table scaling factors). */
486
+ if (++argn >= argc) { /* advance to next argument */
487
+ fprintf(stderr, "%s: missing argument for quality\n", progname);
488
+ usage();
489
+ }
490
+ qualityarg = argv[argn];
491
+
492
+ } else if (keymatch(arg, "qslots", 2)) {
493
+ /* Quantization table slot numbers. */
494
+ if (++argn >= argc) /* advance to next argument */
495
+ usage();
496
+ qslotsarg = argv[argn];
497
+ /* Must delay setting qslots until after we have processed any
498
+ * colorspace-determining switches, since jpeg_set_colorspace sets
499
+ * default quant table numbers.
500
+ */
501
+
502
+ } else if (keymatch(arg, "qtables", 2)) {
503
+ /* Quantization tables fetched from file. */
504
+ if (++argn >= argc) /* advance to next argument */
505
+ usage();
506
+ qtablefile = argv[argn];
507
+ /* We postpone actually reading the file in case -quality comes later. */
508
+
509
+ } else if (keymatch(arg, "report", 3)) {
510
+ report = TRUE;
511
+ } else if (keymatch(arg, "quant-table", 7)) {
512
+ int val;
513
+ if (++argn >= argc) /* advance to next argument */
514
+ usage();
515
+ val = atoi(argv[argn]);
516
+ jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, val);
517
+ if (jpeg_c_get_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX) != val) {
518
+ fprintf(stderr, "%s: %d is invalid argument for quant-table\n", progname, val);
519
+ usage();
520
+ }
521
+ jpeg_set_quality(cinfo, 75, TRUE);
522
+
523
+ } else if (keymatch(arg, "quant-baseline", 7)) {
524
+ /* Force quantization table to meet baseline requirements */
525
+ force_baseline = TRUE;
526
+
527
+ } else if (keymatch(arg, "restart", 1)) {
528
+ /* Restart interval in MCU rows (or in MCUs with 'b'). */
529
+ long lval;
530
+ char ch = 'x';
531
+
532
+ if (++argn >= argc) /* advance to next argument */
533
+ usage();
534
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
535
+ usage();
536
+ if (lval < 0 || lval > 65535L)
537
+ usage();
538
+ if (ch == 'b' || ch == 'B') {
539
+ cinfo->restart_interval = (unsigned int)lval;
540
+ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
541
+ } else {
542
+ cinfo->restart_in_rows = (int)lval;
543
+ /* restart_interval will be computed during startup */
544
+ }
545
+
546
+ } else if (keymatch(arg, "revert", 3)) {
547
+ /* revert to old JPEG default */
548
+ jpeg_c_set_int_param(cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST);
549
+ jpeg_set_defaults(cinfo);
550
+
551
+ } else if (keymatch(arg, "sample", 2)) {
552
+ /* Set sampling factors. */
553
+ if (++argn >= argc) /* advance to next argument */
554
+ usage();
555
+ samplearg = argv[argn];
556
+ /* Must delay setting sample factors until after we have processed any
557
+ * colorspace-determining switches, since jpeg_set_colorspace sets
558
+ * default sampling factors.
559
+ */
560
+
561
+ } else if (keymatch(arg, "scans", 4)) {
562
+ /* Set scan script. */
563
+ #ifdef C_MULTISCAN_FILES_SUPPORTED
564
+ if (++argn >= argc) /* advance to next argument */
565
+ usage();
566
+ scansarg = argv[argn];
567
+ /* We must postpone reading the file in case -progressive appears. */
568
+ #else
569
+ fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n",
570
+ progname);
571
+ exit(EXIT_FAILURE);
572
+ #endif
573
+
574
+ } else if (keymatch(arg, "smooth", 2)) {
575
+ /* Set input smoothing factor. */
576
+ int val;
577
+
578
+ if (++argn >= argc) /* advance to next argument */
579
+ usage();
580
+ if (sscanf(argv[argn], "%d", &val) != 1)
581
+ usage();
582
+ if (val < 0 || val > 100)
583
+ usage();
584
+ cinfo->smoothing_factor = val;
585
+
586
+ } else if (keymatch(arg, "strict", 2)) {
587
+ strict = TRUE;
588
+
589
+ } else if (keymatch(arg, "targa", 1)) {
590
+ /* Input file is Targa format. */
591
+ is_targa = TRUE;
592
+
593
+ } else if (keymatch(arg, "notrellis-dc", 11)) {
594
+ /* disable trellis quantization */
595
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT_DC, FALSE);
596
+
597
+ } else if (keymatch(arg, "notrellis", 1)) {
598
+ /* disable trellis quantization */
599
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT, FALSE);
600
+
601
+ } else if (keymatch(arg, "trellis-dc-ver-weight", 12)) {
602
+ if (++argn >= argc) { /* advance to next argument */
603
+ fprintf(stderr, "%s: missing argument for trellis-dc-ver-weight\n", progname);
604
+ usage();
605
+ }
606
+ jpeg_c_set_float_param(cinfo, JFLOAT_TRELLIS_DELTA_DC_WEIGHT, atof(argv[argn]));
607
+
608
+ } else if (keymatch(arg, "trellis-dc", 9)) {
609
+ /* enable DC trellis quantization */
610
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT_DC, TRUE);
611
+
612
+ } else if (keymatch(arg, "tune-psnr", 6)) {
613
+ jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 1);
614
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 9.0);
615
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE2, 0.0);
616
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_LAMBDA_WEIGHT_TBL, FALSE);
617
+ jpeg_set_quality(cinfo, 75, TRUE);
618
+
619
+ } else if (keymatch(arg, "tune-ssim", 6)) {
620
+ jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 1);
621
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 11.5);
622
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE2, 12.75);
623
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_LAMBDA_WEIGHT_TBL, FALSE);
624
+ jpeg_set_quality(cinfo, 75, TRUE);
625
+
626
+ } else if (keymatch(arg, "tune-ms-ssim", 6)) {
627
+ jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 3);
628
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 12.0);
629
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE2, 13.0);
630
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_LAMBDA_WEIGHT_TBL, TRUE);
631
+ jpeg_set_quality(cinfo, 75, TRUE);
632
+
633
+ } else if (keymatch(arg, "tune-hvs-psnr", 6)) {
634
+ jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 3);
635
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 14.75);
636
+ jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE2, 16.5);
637
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_LAMBDA_WEIGHT_TBL, TRUE);
638
+ jpeg_set_quality(cinfo, 75, TRUE);
639
+
640
+ } else if (keymatch(arg, "noovershoot", 11)) {
641
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_OVERSHOOT_DERINGING, FALSE);
642
+
643
+ } else if (keymatch(arg, "nojfif", 6)) {
644
+ cinfo->write_JFIF_header = 0;
645
+ } else {
646
+ fprintf(stderr, "%s: unknown option '%s'\n", progname, arg);
647
+ usage(); /* bogus switch */
648
+ }
649
+ }
650
+
651
+ /* Post-switch-scanning cleanup */
652
+
653
+ if (for_real) {
654
+
655
+ /* Set quantization tables for selected quality. */
656
+ /* Some or all may be overridden if -qtables is present. */
657
+ if (qualityarg != NULL) /* process -quality if it was present */
658
+ if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) {
659
+ fprintf(stderr, "%s: can't set quality ratings\n", progname);
660
+ usage();
661
+ }
662
+
663
+ if (qtablefile != NULL) /* process -qtables if it was present */
664
+ if (! read_quant_tables(cinfo, qtablefile, force_baseline)) {
665
+ fprintf(stderr, "%s: can't read qtable file\n", progname);
666
+ usage();
667
+ }
668
+
669
+ if (qslotsarg != NULL) /* process -qslots if it was present */
670
+ if (!set_quant_slots(cinfo, qslotsarg))
671
+ usage();
672
+
673
+ /* set_quality_ratings sets default subsampling, so the explicit
674
+ subsampling must be set after it */
675
+ if (samplearg != NULL) /* process -sample if it was present */
676
+ if (! set_sample_factors(cinfo, samplearg)) {
677
+ fprintf(stderr, "%s: can't set sample factors\n", progname);
678
+ usage();
679
+ }
680
+
681
+ #ifdef C_PROGRESSIVE_SUPPORTED
682
+ if (simple_progressive) /* process -progressive; -scans can override */
683
+ jpeg_simple_progression(cinfo);
684
+ #endif
685
+
686
+ #ifdef C_MULTISCAN_FILES_SUPPORTED
687
+ if (scansarg != NULL) /* process -scans if it was present */
688
+ if (!read_scan_script(cinfo, scansarg))
689
+ usage();
690
+ #endif
691
+ }
692
+
693
+ return argn; /* return index of next arg (file name) */
694
+ }
695
+
696
+
697
+ METHODDEF(void)
698
+ my_emit_message(j_common_ptr cinfo, int msg_level)
699
+ {
700
+ if (msg_level < 0) {
701
+ /* Treat warning as fatal */
702
+ cinfo->err->error_exit(cinfo);
703
+ } else {
704
+ if (cinfo->err->trace_level >= msg_level)
705
+ cinfo->err->output_message(cinfo);
706
+ }
707
+ }
708
+
709
+
710
+ /*
711
+ * The main program.
712
+ */
713
+
714
+ int
715
+ main(int argc, char **argv)
716
+ {
717
+ struct jpeg_compress_struct cinfo;
718
+ #ifdef CJPEG_FUZZER
719
+ struct my_error_mgr myerr;
720
+ struct jpeg_error_mgr &jerr = myerr.pub;
721
+ #else
722
+ struct jpeg_error_mgr jerr;
723
+ #endif
724
+ struct cdjpeg_progress_mgr progress;
725
+ int file_index;
726
+ cjpeg_source_ptr src_mgr;
727
+ FILE *input_file = NULL;
728
+ FILE *icc_file;
729
+ JOCTET *icc_profile = NULL;
730
+ long icc_len = 0;
731
+ FILE *output_file = NULL;
732
+ unsigned char *outbuffer = NULL;
733
+ unsigned long outsize = 0;
734
+ JDIMENSION num_scanlines;
735
+
736
+ progname = argv[0];
737
+ if (progname == NULL || progname[0] == 0)
738
+ progname = "cjpeg"; /* in case C library doesn't provide it */
739
+
740
+ /* Initialize the JPEG compression object with default error handling. */
741
+ cinfo.err = jpeg_std_error(&jerr);
742
+ jpeg_create_compress(&cinfo);
743
+ /* Add some application-specific error messages (from cderror.h) */
744
+ jerr.addon_message_table = cdjpeg_message_table;
745
+ jerr.first_addon_message = JMSG_FIRSTADDONCODE;
746
+ jerr.last_addon_message = JMSG_LASTADDONCODE;
747
+
748
+ /* Initialize JPEG parameters.
749
+ * Much of this may be overridden later.
750
+ * In particular, we don't yet know the input file's color space,
751
+ * but we need to provide some value for jpeg_set_defaults() to work.
752
+ */
753
+
754
+ cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
755
+ jpeg_set_defaults(&cinfo);
756
+
757
+ /* Scan command line to find file names.
758
+ * It is convenient to use just one switch-parsing routine, but the switch
759
+ * values read here are ignored; we will rescan the switches after opening
760
+ * the input file.
761
+ */
762
+
763
+ file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
764
+
765
+ if (strict)
766
+ jerr.emit_message = my_emit_message;
767
+
768
+ #ifdef TWO_FILE_COMMANDLINE
769
+ if (!memdst) {
770
+ /* Must have either -outfile switch or explicit output file name */
771
+ if (outfilename == NULL) {
772
+ if (file_index != argc - 2) {
773
+ fprintf(stderr, "%s: must name one input and one output file\n",
774
+ progname);
775
+ usage();
776
+ }
777
+ outfilename = argv[file_index + 1];
778
+ } else {
779
+ if (file_index != argc - 1) {
780
+ fprintf(stderr, "%s: must name one input and one output file\n",
781
+ progname);
782
+ usage();
783
+ }
784
+ }
785
+ }
786
+ #else
787
+ /* Unix style: expect zero or one file name */
788
+ if (file_index < argc - 1) {
789
+ fprintf(stderr, "%s: only one input file\n", progname);
790
+ usage();
791
+ }
792
+ #endif /* TWO_FILE_COMMANDLINE */
793
+
794
+ /* Open the input file. */
795
+ if (file_index < argc) {
796
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
797
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
798
+ exit(EXIT_FAILURE);
799
+ }
800
+ } else {
801
+ /* default input file is stdin */
802
+ input_file = read_stdin();
803
+ }
804
+
805
+ /* Open the output file. */
806
+ if (outfilename != NULL) {
807
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
808
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
809
+ exit(EXIT_FAILURE);
810
+ }
811
+ } else if (!memdst) {
812
+ /* default output file is stdout */
813
+ output_file = write_stdout();
814
+ }
815
+
816
+ if (icc_filename != NULL) {
817
+ if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {
818
+ fprintf(stderr, "%s: can't open %s\n", progname, icc_filename);
819
+ exit(EXIT_FAILURE);
820
+ }
821
+ if (fseek(icc_file, 0, SEEK_END) < 0 ||
822
+ (icc_len = ftell(icc_file)) < 1 ||
823
+ fseek(icc_file, 0, SEEK_SET) < 0) {
824
+ fprintf(stderr, "%s: can't determine size of %s\n", progname,
825
+ icc_filename);
826
+ exit(EXIT_FAILURE);
827
+ }
828
+ if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) {
829
+ fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname);
830
+ fclose(icc_file);
831
+ exit(EXIT_FAILURE);
832
+ }
833
+ if (fread(icc_profile, icc_len, 1, icc_file) < 1) {
834
+ fprintf(stderr, "%s: can't read ICC profile from %s\n", progname,
835
+ icc_filename);
836
+ free(icc_profile);
837
+ fclose(icc_file);
838
+ exit(EXIT_FAILURE);
839
+ }
840
+ fclose(icc_file);
841
+ }
842
+
843
+ #ifdef CJPEG_FUZZER
844
+ jerr.error_exit = my_error_exit;
845
+ jerr.emit_message = my_emit_message_fuzzer;
846
+ if (setjmp(myerr.setjmp_buffer))
847
+ HANDLE_ERROR()
848
+ #endif
849
+
850
+ if (report) {
851
+ start_progress_monitor((j_common_ptr)&cinfo, &progress);
852
+ progress.report = report;
853
+ }
854
+
855
+ /* Figure out the input file format, and set up to read it. */
856
+ src_mgr = select_file_type(&cinfo, input_file);
857
+ src_mgr->input_file = input_file;
858
+ #ifdef CJPEG_FUZZER
859
+ src_mgr->max_pixels = 1048576;
860
+ #endif
861
+
862
+ /* Read the input file header to obtain file size & colorspace. */
863
+ (*src_mgr->start_input) (&cinfo, src_mgr);
864
+
865
+ /* Now that we know input colorspace, fix colorspace-dependent defaults */
866
+ #if JPEG_RAW_READER
867
+ if (!is_jpeg)
868
+ #endif
869
+ jpeg_default_colorspace(&cinfo);
870
+
871
+ /* Adjust default compression parameters by re-parsing the options */
872
+ file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
873
+
874
+ /* Specify data destination for compression */
875
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
876
+ if (memdst)
877
+ jpeg_mem_dest(&cinfo, &outbuffer, &outsize);
878
+ else
879
+ #endif
880
+ jpeg_stdio_dest(&cinfo, output_file);
881
+
882
+ #ifdef CJPEG_FUZZER
883
+ if (setjmp(myerr.setjmp_buffer))
884
+ HANDLE_ERROR()
885
+ #endif
886
+
887
+ /* Start compressor */
888
+ jpeg_start_compress(&cinfo, TRUE);
889
+
890
+ /* Copy metadata */
891
+ if (copy_markers) {
892
+ jpeg_saved_marker_ptr marker;
893
+
894
+ /* In the current implementation, we don't actually need to examine the
895
+ * option flag here; we just copy everything that got saved.
896
+ * But to avoid confusion, we do not output JFIF and Adobe APP14 markers
897
+ * if the encoder library already wrote one.
898
+ */
899
+ for (marker = src_mgr->marker_list; marker != NULL; marker = marker->next) {
900
+ if (cinfo.write_JFIF_header &&
901
+ marker->marker == JPEG_APP0 &&
902
+ marker->data_length >= 5 &&
903
+ GETJOCTET(marker->data[0]) == 0x4A &&
904
+ GETJOCTET(marker->data[1]) == 0x46 &&
905
+ GETJOCTET(marker->data[2]) == 0x49 &&
906
+ GETJOCTET(marker->data[3]) == 0x46 &&
907
+ GETJOCTET(marker->data[4]) == 0)
908
+ continue; /* reject duplicate JFIF */
909
+ if (cinfo.write_Adobe_marker &&
910
+ marker->marker == JPEG_APP0+14 &&
911
+ marker->data_length >= 5 &&
912
+ GETJOCTET(marker->data[0]) == 0x41 &&
913
+ GETJOCTET(marker->data[1]) == 0x64 &&
914
+ GETJOCTET(marker->data[2]) == 0x6F &&
915
+ GETJOCTET(marker->data[3]) == 0x62 &&
916
+ GETJOCTET(marker->data[4]) == 0x65)
917
+ continue; /* reject duplicate Adobe */
918
+ jpeg_write_marker(&cinfo, marker->marker, marker->data,
919
+ marker->data_length);
920
+ }
921
+ }
922
+ if (icc_profile != NULL)
923
+ jpeg_write_icc_profile(&cinfo, icc_profile, (unsigned int)icc_len);
924
+
925
+ /* Process data */
926
+ while (cinfo.next_scanline < cinfo.image_height) {
927
+ num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
928
+ #if JPEG_RAW_READER
929
+ if (is_jpeg)
930
+ (void) jpeg_write_raw_data(&cinfo, src_mgr->plane_pointer, num_scanlines);
931
+ else
932
+ #endif
933
+ (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
934
+ }
935
+
936
+ /* Finish compression and release memory */
937
+ (*src_mgr->finish_input) (&cinfo, src_mgr);
938
+ jpeg_finish_compress(&cinfo);
939
+ jpeg_destroy_compress(&cinfo);
940
+
941
+ /* Close files, if we opened them */
942
+ if (input_file != stdin)
943
+ fclose(input_file);
944
+ if (output_file != stdout && output_file != NULL)
945
+ fclose(output_file);
946
+
947
+ if (report)
948
+ end_progress_monitor((j_common_ptr)&cinfo);
949
+
950
+ if (memdst) {
951
+ #ifndef CJPEG_FUZZER
952
+ fprintf(stderr, "Compressed size: %lu bytes\n", outsize);
953
+ #endif
954
+ free(outbuffer);
955
+ }
956
+
957
+ free(icc_profile);
958
+
959
+ /* All done. */
960
+ return (jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
961
+ }