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,827 @@
1
+ /*
2
+ * jpegtran.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1995-2019, Thomas G. Lane, Guido Vollbeding.
6
+ * libjpeg-turbo Modifications:
7
+ * Copyright (C) 2010, 2014, 2017, 2019-2022, D. R. Commander.
8
+ * mozjpeg Modifications:
9
+ * Copyright (C) 2014, Mozilla Corporation.
10
+ * For conditions of distribution and use, see the accompanying README file.
11
+ *
12
+ * This file contains a command-line user interface for JPEG transcoding.
13
+ * It is very similar to cjpeg.c, and partly to djpeg.c, but provides
14
+ * lossless transcoding between different JPEG file formats. It also
15
+ * provides some lossless and sort-of-lossless transformations of JPEG data.
16
+ */
17
+
18
+ #ifdef _MSC_VER
19
+ #define _CRT_SECURE_NO_DEPRECATE
20
+ #endif
21
+
22
+ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
23
+ #include "transupp.h" /* Support routines for jpegtran */
24
+ #include "jversion.h" /* for version message */
25
+ #include "jconfigint.h"
26
+
27
+
28
+ /*
29
+ * Argument-parsing code.
30
+ * The switch parser is designed to be useful with DOS-style command line
31
+ * syntax, ie, intermixed switches and file names, where only the switches
32
+ * to the left of a given file name affect processing of that file.
33
+ * The main program in this file doesn't actually use this capability...
34
+ */
35
+
36
+
37
+ static const char *progname; /* program name for error messages */
38
+ static char *icc_filename; /* for -icc switch */
39
+ JDIMENSION max_scans; /* for -maxscans switch */
40
+ static char *outfilename; /* for -outfile switch */
41
+ static char *dropfilename; /* for -drop switch */
42
+ boolean report; /* for -report switch */
43
+ boolean strict; /* for -strict switch */
44
+ static boolean prefer_smallest; /* use smallest of input or result file (if no image-changing options supplied) */
45
+ static JCOPY_OPTION copyoption; /* -copy switch */
46
+ static jpeg_transform_info transformoption; /* image transformation options */
47
+ boolean memsrc = FALSE; /* for -memsrc switch */
48
+ #define INPUT_BUF_SIZE 4096
49
+
50
+
51
+ LOCAL(void)
52
+ usage(void)
53
+ /* complain about bad command line */
54
+ {
55
+ fprintf(stderr, "usage: %s [switches] ", progname);
56
+ #ifdef TWO_FILE_COMMANDLINE
57
+ fprintf(stderr, "inputfile outputfile\n");
58
+ #else
59
+ fprintf(stderr, "[inputfile]\n");
60
+ #endif
61
+
62
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
63
+ fprintf(stderr, " -copy none Copy no extra markers from source file\n");
64
+ fprintf(stderr, " -copy comments Copy only comment markers (default)\n");
65
+ fprintf(stderr, " -copy icc Copy only ICC profile markers\n");
66
+ fprintf(stderr, " -copy all Copy all extra markers\n");
67
+ #ifdef ENTROPY_OPT_SUPPORTED
68
+ fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression, enabled by default)\n");
69
+ #endif
70
+ #ifdef C_PROGRESSIVE_SUPPORTED
71
+ fprintf(stderr, " -progressive Create progressive JPEG file (enabled by default)\n");
72
+ #endif
73
+ fprintf(stderr, " -revert Revert to standard defaults (instead of mozjpeg defaults)\n");
74
+ fprintf(stderr, " -fastcrush Disable progressive scan optimization\n");
75
+ fprintf(stderr, "Switches for modifying the image:\n");
76
+ #if TRANSFORMS_SUPPORTED
77
+ fprintf(stderr, " -crop WxH+X+Y Crop to a rectangular region\n");
78
+ fprintf(stderr, " -drop +X+Y filename Drop (insert) another image\n");
79
+ fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n");
80
+ fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n");
81
+ fprintf(stderr, " -perfect Fail if there is non-transformable edge blocks\n");
82
+ fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n");
83
+ #endif
84
+ #if TRANSFORMS_SUPPORTED
85
+ fprintf(stderr, " -transpose Transpose image\n");
86
+ fprintf(stderr, " -transverse Transverse transpose image\n");
87
+ fprintf(stderr, " -trim Drop non-transformable edge blocks\n");
88
+ fprintf(stderr, " with -drop: Requantize drop file to match source file\n");
89
+ fprintf(stderr, " -wipe WxH+X+Y Wipe (gray out) a rectangular region\n");
90
+ #endif
91
+ fprintf(stderr, "Switches for advanced users:\n");
92
+ #ifdef C_ARITH_CODING_SUPPORTED
93
+ fprintf(stderr, " -arithmetic Use arithmetic coding\n");
94
+ #endif
95
+ fprintf(stderr, " -icc FILE Embed ICC profile contained in FILE\n");
96
+ fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
97
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
98
+ fprintf(stderr, " -maxscans N Maximum number of scans to allow in input file\n");
99
+ fprintf(stderr, " -outfile name Specify name for output file\n");
100
+ fprintf(stderr, " -report Report transformation progress\n");
101
+ fprintf(stderr, " -strict Treat all warnings as fatal\n");
102
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
103
+ fprintf(stderr, " -version Print version information and exit\n");
104
+ fprintf(stderr, "Switches for wizards:\n");
105
+ #ifdef C_MULTISCAN_FILES_SUPPORTED
106
+ fprintf(stderr, " -scans FILE Create multi-scan JPEG per script FILE\n");
107
+ #endif
108
+ exit(EXIT_FAILURE);
109
+ }
110
+
111
+
112
+ LOCAL(void)
113
+ select_transform(JXFORM_CODE transform)
114
+ /* Silly little routine to detect multiple transform options,
115
+ * which we can't handle.
116
+ */
117
+ {
118
+ #if TRANSFORMS_SUPPORTED
119
+ if (transformoption.transform == JXFORM_NONE ||
120
+ transformoption.transform == transform) {
121
+ transformoption.transform = transform;
122
+ } else {
123
+ fprintf(stderr, "%s: can only do one image transformation at a time\n",
124
+ progname);
125
+ usage();
126
+ }
127
+ #else
128
+ fprintf(stderr, "%s: sorry, image transformation was not compiled\n",
129
+ progname);
130
+ exit(EXIT_FAILURE);
131
+ #endif
132
+ }
133
+
134
+
135
+ LOCAL(int)
136
+ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
137
+ int last_file_arg_seen, boolean for_real)
138
+ /* Parse optional switches.
139
+ * Returns argv[] index of first file-name argument (== argc if none).
140
+ * Any file names with indexes <= last_file_arg_seen are ignored;
141
+ * they have presumably been processed in a previous iteration.
142
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
143
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
144
+ * processing.
145
+ */
146
+ {
147
+ int argn;
148
+ char *arg;
149
+ boolean simple_progressive;
150
+ char *scansarg = NULL; /* saves -scans parm if any */
151
+
152
+ /* Set up default JPEG parameters. */
153
+ #ifdef C_PROGRESSIVE_SUPPORTED
154
+ simple_progressive = cinfo->num_scans == 0 ? FALSE : TRUE;
155
+ #else
156
+ simple_progressive = FALSE;
157
+ #endif
158
+ icc_filename = NULL;
159
+ max_scans = 0;
160
+ outfilename = NULL;
161
+ report = FALSE;
162
+ strict = FALSE;
163
+ copyoption = JCOPYOPT_DEFAULT;
164
+ transformoption.transform = JXFORM_NONE;
165
+ transformoption.perfect = FALSE;
166
+ transformoption.trim = FALSE;
167
+ transformoption.force_grayscale = FALSE;
168
+ transformoption.crop = FALSE;
169
+ transformoption.slow_hflip = FALSE;
170
+ cinfo->err->trace_level = 0;
171
+ prefer_smallest = TRUE;
172
+
173
+ /* Scan command line options, adjust parameters */
174
+
175
+ for (argn = 1; argn < argc; argn++) {
176
+ arg = argv[argn];
177
+ if (*arg != '-') {
178
+ /* Not a switch, must be a file name argument */
179
+ if (argn <= last_file_arg_seen) {
180
+ outfilename = NULL; /* -outfile applies to just one input file */
181
+ continue; /* ignore this name if previously processed */
182
+ }
183
+ break; /* else done parsing switches */
184
+ }
185
+ arg++; /* advance past switch marker character */
186
+
187
+ if (keymatch(arg, "arithmetic", 1)) {
188
+ /* Use arithmetic coding. */
189
+ #ifdef C_ARITH_CODING_SUPPORTED
190
+ cinfo->arith_code = TRUE;
191
+
192
+ /* No table optimization required for AC */
193
+ cinfo->optimize_coding = FALSE;
194
+ prefer_smallest = FALSE;
195
+ #else
196
+ fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
197
+ progname);
198
+ exit(EXIT_FAILURE);
199
+ #endif
200
+
201
+ } else if (keymatch(arg, "copy", 2)) {
202
+ /* Select which extra markers to copy. */
203
+ if (++argn >= argc) /* advance to next argument */
204
+ usage();
205
+ if (keymatch(argv[argn], "none", 1)) {
206
+ copyoption = JCOPYOPT_NONE;
207
+ } else if (keymatch(argv[argn], "comments", 1)) {
208
+ copyoption = JCOPYOPT_COMMENTS;
209
+ } else if (keymatch(argv[argn], "icc", 1)) {
210
+ copyoption = JCOPYOPT_ICC;
211
+ } else if (keymatch(argv[argn], "all", 1)) {
212
+ copyoption = JCOPYOPT_ALL;
213
+ } else
214
+ usage();
215
+
216
+ } else if (keymatch(arg, "crop", 2)) {
217
+ /* Perform lossless cropping. */
218
+ #if TRANSFORMS_SUPPORTED
219
+ if (++argn >= argc) /* advance to next argument */
220
+ usage();
221
+ if (transformoption.crop /* reject multiple crop/drop/wipe requests */ ||
222
+ !jtransform_parse_crop_spec(&transformoption, argv[argn])) {
223
+ fprintf(stderr, "%s: bogus -crop argument '%s'\n",
224
+ progname, argv[argn]);
225
+ exit(EXIT_FAILURE);
226
+ }
227
+ prefer_smallest = FALSE;
228
+ #else
229
+ select_transform(JXFORM_NONE); /* force an error */
230
+ #endif
231
+
232
+ } else if (keymatch(arg, "drop", 2)) {
233
+ #if TRANSFORMS_SUPPORTED
234
+ if (++argn >= argc) /* advance to next argument */
235
+ usage();
236
+ if (transformoption.crop /* reject multiple crop/drop/wipe requests */ ||
237
+ !jtransform_parse_crop_spec(&transformoption, argv[argn]) ||
238
+ transformoption.crop_width_set != JCROP_UNSET ||
239
+ transformoption.crop_height_set != JCROP_UNSET) {
240
+ fprintf(stderr, "%s: bogus -drop argument '%s'\n",
241
+ progname, argv[argn]);
242
+ exit(EXIT_FAILURE);
243
+ }
244
+ if (++argn >= argc) /* advance to next argument */
245
+ usage();
246
+ dropfilename = argv[argn];
247
+ select_transform(JXFORM_DROP);
248
+ #else
249
+ select_transform(JXFORM_NONE); /* force an error */
250
+ #endif
251
+
252
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
253
+ /* Enable debug printouts. */
254
+ /* On first -d, print version identification */
255
+ static boolean printed_version = FALSE;
256
+
257
+ if (!printed_version) {
258
+ fprintf(stderr, "%s version %s (build %s)\n",
259
+ PACKAGE_NAME, VERSION, BUILD);
260
+ fprintf(stderr, "%s\n\n", JCOPYRIGHT);
261
+ fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
262
+ JVERSION);
263
+ printed_version = TRUE;
264
+ }
265
+ cinfo->err->trace_level++;
266
+
267
+ } else if (keymatch(arg, "version", 4)) {
268
+ fprintf(stderr, "%s version %s (build %s)\n",
269
+ PACKAGE_NAME, VERSION, BUILD);
270
+ exit(EXIT_SUCCESS);
271
+
272
+ } else if (keymatch(arg, "flip", 1)) {
273
+ /* Mirror left-right or top-bottom. */
274
+ if (++argn >= argc) /* advance to next argument */
275
+ usage();
276
+ if (keymatch(argv[argn], "horizontal", 1))
277
+ select_transform(JXFORM_FLIP_H);
278
+ else if (keymatch(argv[argn], "vertical", 1))
279
+ select_transform(JXFORM_FLIP_V);
280
+ else
281
+ usage();
282
+
283
+ prefer_smallest = FALSE;
284
+
285
+ } else if (keymatch(arg, "fastcrush", 4)) {
286
+ jpeg_c_set_bool_param(cinfo, JBOOLEAN_OPTIMIZE_SCANS, FALSE);
287
+
288
+ } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) {
289
+ /* Force to grayscale. */
290
+ #if TRANSFORMS_SUPPORTED
291
+ transformoption.force_grayscale = TRUE;
292
+ prefer_smallest = FALSE;
293
+ #else
294
+ select_transform(JXFORM_NONE); /* force an error */
295
+ #endif
296
+
297
+ } else if (keymatch(arg, "icc", 1)) {
298
+ /* Set ICC filename. */
299
+ if (++argn >= argc) /* advance to next argument */
300
+ usage();
301
+ icc_filename = argv[argn];
302
+
303
+ } else if (keymatch(arg, "maxmemory", 3)) {
304
+ /* Maximum memory in Kb (or Mb with 'm'). */
305
+ long lval;
306
+ char ch = 'x';
307
+
308
+ if (++argn >= argc) /* advance to next argument */
309
+ usage();
310
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
311
+ usage();
312
+ if (ch == 'm' || ch == 'M')
313
+ lval *= 1000L;
314
+ cinfo->mem->max_memory_to_use = lval * 1000L;
315
+
316
+ } else if (keymatch(arg, "maxscans", 4)) {
317
+ if (++argn >= argc) /* advance to next argument */
318
+ usage();
319
+ if (sscanf(argv[argn], "%u", &max_scans) != 1)
320
+ usage();
321
+
322
+ } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
323
+ /* Enable entropy parm optimization. */
324
+ #ifdef ENTROPY_OPT_SUPPORTED
325
+ cinfo->optimize_coding = TRUE;
326
+ #else
327
+ fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
328
+ progname);
329
+ exit(EXIT_FAILURE);
330
+ #endif
331
+
332
+ } else if (keymatch(arg, "outfile", 4)) {
333
+ /* Set output file name. */
334
+ if (++argn >= argc) /* advance to next argument */
335
+ usage();
336
+ outfilename = argv[argn]; /* save it away for later use */
337
+
338
+ } else if (keymatch(arg, "perfect", 2)) {
339
+ /* Fail if there is any partial edge MCUs that the transform can't
340
+ * handle. */
341
+ transformoption.perfect = TRUE;
342
+
343
+ } else if (keymatch(arg, "progressive", 2)) {
344
+ /* Select simple progressive mode. */
345
+ #ifdef C_PROGRESSIVE_SUPPORTED
346
+ simple_progressive = TRUE;
347
+ prefer_smallest = FALSE;
348
+ /* We must postpone execution until num_components is known. */
349
+ #else
350
+ fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
351
+ progname);
352
+ exit(EXIT_FAILURE);
353
+ #endif
354
+
355
+ } else if (keymatch(arg, "report", 3)) {
356
+ report = TRUE;
357
+
358
+ } else if (keymatch(arg, "restart", 1)) {
359
+ /* Restart interval in MCU rows (or in MCUs with 'b'). */
360
+ long lval;
361
+ char ch = 'x';
362
+
363
+ if (++argn >= argc) /* advance to next argument */
364
+ usage();
365
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
366
+ usage();
367
+ if (lval < 0 || lval > 65535L)
368
+ usage();
369
+ if (ch == 'b' || ch == 'B') {
370
+ cinfo->restart_interval = (unsigned int)lval;
371
+ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
372
+ } else {
373
+ cinfo->restart_in_rows = (int)lval;
374
+ /* restart_interval will be computed during startup */
375
+ }
376
+
377
+ } else if (keymatch(arg, "revert", 3)) {
378
+ /* revert to old JPEG default */
379
+ jpeg_c_set_int_param(cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST);
380
+ prefer_smallest = FALSE;
381
+
382
+ } else if (keymatch(arg, "rotate", 2)) {
383
+ /* Rotate 90, 180, or 270 degrees (measured clockwise). */
384
+ if (++argn >= argc) /* advance to next argument */
385
+ usage();
386
+ if (keymatch(argv[argn], "90", 2))
387
+ select_transform(JXFORM_ROT_90);
388
+ else if (keymatch(argv[argn], "180", 3))
389
+ select_transform(JXFORM_ROT_180);
390
+ else if (keymatch(argv[argn], "270", 3))
391
+ select_transform(JXFORM_ROT_270);
392
+ else
393
+ usage();
394
+
395
+ prefer_smallest = FALSE;
396
+
397
+ } else if (keymatch(arg, "scans", 1)) {
398
+ /* Set scan script. */
399
+ #ifdef C_MULTISCAN_FILES_SUPPORTED
400
+ if (++argn >= argc) /* advance to next argument */
401
+ usage();
402
+ prefer_smallest = FALSE;
403
+ scansarg = argv[argn];
404
+ /* We must postpone reading the file in case -progressive appears. */
405
+ #else
406
+ fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
407
+ progname);
408
+ exit(EXIT_FAILURE);
409
+ #endif
410
+
411
+ } else if (keymatch(arg, "strict", 2)) {
412
+ strict = TRUE;
413
+
414
+ } else if (keymatch(arg, "transpose", 1)) {
415
+ /* Transpose (across UL-to-LR axis). */
416
+ select_transform(JXFORM_TRANSPOSE);
417
+ prefer_smallest = FALSE;
418
+
419
+ } else if (keymatch(arg, "transverse", 6)) {
420
+ /* Transverse transpose (across UR-to-LL axis). */
421
+ select_transform(JXFORM_TRANSVERSE);
422
+ prefer_smallest = FALSE;
423
+
424
+ } else if (keymatch(arg, "trim", 3)) {
425
+ /* Trim off any partial edge MCUs that the transform can't handle. */
426
+ transformoption.trim = TRUE;
427
+ prefer_smallest = FALSE;
428
+
429
+ } else if (keymatch(arg, "wipe", 1)) {
430
+ #if TRANSFORMS_SUPPORTED
431
+ if (++argn >= argc) /* advance to next argument */
432
+ usage();
433
+ if (transformoption.crop /* reject multiple crop/drop/wipe requests */ ||
434
+ !jtransform_parse_crop_spec(&transformoption, argv[argn])) {
435
+ fprintf(stderr, "%s: bogus -wipe argument '%s'\n",
436
+ progname, argv[argn]);
437
+ exit(EXIT_FAILURE);
438
+ }
439
+ select_transform(JXFORM_WIPE);
440
+ #else
441
+ select_transform(JXFORM_NONE); /* force an error */
442
+ #endif
443
+
444
+ } else {
445
+ usage(); /* bogus switch */
446
+ }
447
+ }
448
+
449
+ /* Post-switch-scanning cleanup */
450
+
451
+ if (for_real) {
452
+
453
+ #ifdef C_PROGRESSIVE_SUPPORTED
454
+ if (simple_progressive) /* process -progressive; -scans can override */
455
+ jpeg_simple_progression(cinfo);
456
+ #endif
457
+
458
+ #ifdef C_MULTISCAN_FILES_SUPPORTED
459
+ if (scansarg != NULL) /* process -scans if it was present */
460
+ if (!read_scan_script(cinfo, scansarg))
461
+ usage();
462
+ #endif
463
+ }
464
+
465
+ return argn; /* return index of next arg (file name) */
466
+ }
467
+
468
+
469
+ METHODDEF(void)
470
+ my_emit_message(j_common_ptr cinfo, int msg_level)
471
+ {
472
+ if (msg_level < 0) {
473
+ /* Treat warning as fatal */
474
+ cinfo->err->error_exit(cinfo);
475
+ } else {
476
+ if (cinfo->err->trace_level >= msg_level)
477
+ cinfo->err->output_message(cinfo);
478
+ }
479
+ }
480
+
481
+
482
+ /*
483
+ * The main program.
484
+ */
485
+
486
+ int
487
+ main(int argc, char **argv)
488
+ {
489
+ struct jpeg_decompress_struct srcinfo;
490
+ #if TRANSFORMS_SUPPORTED
491
+ struct jpeg_decompress_struct dropinfo;
492
+ struct jpeg_error_mgr jdroperr;
493
+ FILE *drop_file;
494
+ #endif
495
+ struct jpeg_compress_struct dstinfo;
496
+ struct jpeg_error_mgr jsrcerr, jdsterr;
497
+ struct cdjpeg_progress_mgr src_progress, dst_progress;
498
+ jvirt_barray_ptr *src_coef_arrays;
499
+ jvirt_barray_ptr *dst_coef_arrays;
500
+ int file_index;
501
+ /* We assume all-in-memory processing and can therefore use only a
502
+ * single file pointer for sequential input and output operation.
503
+ */
504
+ FILE *fp;
505
+ unsigned char *inbuffer = NULL;
506
+ unsigned long insize = 0;
507
+ unsigned char *outbuffer = NULL;
508
+ unsigned long outsize = 0;
509
+ FILE *icc_file;
510
+ JOCTET *icc_profile = NULL;
511
+ long icc_len = 0;
512
+
513
+ progname = argv[0];
514
+ if (progname == NULL || progname[0] == 0)
515
+ progname = "jpegtran"; /* in case C library doesn't provide it */
516
+
517
+ /* Initialize the JPEG decompression object with default error handling. */
518
+ srcinfo.err = jpeg_std_error(&jsrcerr);
519
+ jpeg_create_decompress(&srcinfo);
520
+ /* Initialize the JPEG compression object with default error handling. */
521
+ dstinfo.err = jpeg_std_error(&jdsterr);
522
+ jpeg_create_compress(&dstinfo);
523
+
524
+ /* Scan command line to find file names.
525
+ * It is convenient to use just one switch-parsing routine, but the switch
526
+ * values read here are mostly ignored; we will rescan the switches after
527
+ * opening the input file. Also note that most of the switches affect the
528
+ * destination JPEG object, so we parse into that and then copy over what
529
+ * needs to affect the source too.
530
+ */
531
+
532
+ file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
533
+ jsrcerr.trace_level = jdsterr.trace_level;
534
+ srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;
535
+
536
+ if (strict)
537
+ jsrcerr.emit_message = my_emit_message;
538
+
539
+ #ifdef TWO_FILE_COMMANDLINE
540
+ /* Must have either -outfile switch or explicit output file name */
541
+ if (outfilename == NULL) {
542
+ if (file_index != argc - 2) {
543
+ fprintf(stderr, "%s: must name one input and one output file\n",
544
+ progname);
545
+ usage();
546
+ }
547
+ outfilename = argv[file_index + 1];
548
+ } else {
549
+ if (file_index != argc - 1) {
550
+ fprintf(stderr, "%s: must name one input and one output file\n",
551
+ progname);
552
+ usage();
553
+ }
554
+ }
555
+ #else
556
+ /* Unix style: expect zero or one file name */
557
+ if (file_index < argc - 1) {
558
+ fprintf(stderr, "%s: only one input file\n", progname);
559
+ usage();
560
+ }
561
+ #endif /* TWO_FILE_COMMANDLINE */
562
+
563
+ /* Open the input file. */
564
+ if (file_index < argc) {
565
+ if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) {
566
+ fprintf(stderr, "%s: can't open %s for reading\n", progname,
567
+ argv[file_index]);
568
+ exit(EXIT_FAILURE);
569
+ }
570
+ } else {
571
+ /* default input file is stdin */
572
+ fp = read_stdin();
573
+ }
574
+
575
+ if (icc_filename != NULL) {
576
+ if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {
577
+ fprintf(stderr, "%s: can't open %s\n", progname, icc_filename);
578
+ exit(EXIT_FAILURE);
579
+ }
580
+ if (fseek(icc_file, 0, SEEK_END) < 0 ||
581
+ (icc_len = ftell(icc_file)) < 1 ||
582
+ fseek(icc_file, 0, SEEK_SET) < 0) {
583
+ fprintf(stderr, "%s: can't determine size of %s\n", progname,
584
+ icc_filename);
585
+ exit(EXIT_FAILURE);
586
+ }
587
+ if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) {
588
+ fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname);
589
+ fclose(icc_file);
590
+ exit(EXIT_FAILURE);
591
+ }
592
+ if (fread(icc_profile, icc_len, 1, icc_file) < 1) {
593
+ fprintf(stderr, "%s: can't read ICC profile from %s\n", progname,
594
+ icc_filename);
595
+ free(icc_profile);
596
+ fclose(icc_file);
597
+ exit(EXIT_FAILURE);
598
+ }
599
+ fclose(icc_file);
600
+ if (copyoption == JCOPYOPT_ALL)
601
+ copyoption = JCOPYOPT_ALL_EXCEPT_ICC;
602
+ if (copyoption == JCOPYOPT_ICC)
603
+ copyoption = JCOPYOPT_NONE;
604
+ }
605
+
606
+ if (report) {
607
+ start_progress_monitor((j_common_ptr)&dstinfo, &dst_progress);
608
+ dst_progress.report = report;
609
+ }
610
+ if (report || max_scans != 0) {
611
+ start_progress_monitor((j_common_ptr)&srcinfo, &src_progress);
612
+ src_progress.report = report;
613
+ src_progress.max_scans = max_scans;
614
+ }
615
+ #if TRANSFORMS_SUPPORTED
616
+ /* Open the drop file. */
617
+ if (dropfilename != NULL) {
618
+ if ((drop_file = fopen(dropfilename, READ_BINARY)) == NULL) {
619
+ fprintf(stderr, "%s: can't open %s for reading\n", progname,
620
+ dropfilename);
621
+ exit(EXIT_FAILURE);
622
+ }
623
+ dropinfo.err = jpeg_std_error(&jdroperr);
624
+ jpeg_create_decompress(&dropinfo);
625
+ jpeg_stdio_src(&dropinfo, drop_file);
626
+ } else {
627
+ drop_file = NULL;
628
+ }
629
+ #endif
630
+
631
+ /* Specify data source for decompression */
632
+ if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&
633
+ jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)
634
+ == JCP_MAX_COMPRESSION)
635
+ memsrc = TRUE; /* needed to revert to original */
636
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
637
+ if (memsrc) {
638
+ size_t nbytes;
639
+ do {
640
+ inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE);
641
+ if (inbuffer == NULL) {
642
+ fprintf(stderr, "%s: memory allocation failure\n", progname);
643
+ exit(EXIT_FAILURE);
644
+ }
645
+ nbytes = fread(&inbuffer[insize], 1, INPUT_BUF_SIZE, fp);
646
+ if (nbytes < INPUT_BUF_SIZE && ferror(fp)) {
647
+ if (file_index < argc)
648
+ fprintf(stderr, "%s: can't read from %s\n", progname,
649
+ argv[file_index]);
650
+ else
651
+ fprintf(stderr, "%s: can't read from stdin\n", progname);
652
+ }
653
+ insize += (unsigned long)nbytes;
654
+ } while (nbytes == INPUT_BUF_SIZE);
655
+ jpeg_mem_src(&srcinfo, inbuffer, insize);
656
+ } else
657
+ #endif
658
+ jpeg_stdio_src(&srcinfo, fp);
659
+
660
+ /* Enable saving of extra markers that we want to copy */
661
+ jcopy_markers_setup(&srcinfo, copyoption);
662
+
663
+ /* Read file header */
664
+ (void)jpeg_read_header(&srcinfo, TRUE);
665
+
666
+ #if TRANSFORMS_SUPPORTED
667
+ if (dropfilename != NULL) {
668
+ (void)jpeg_read_header(&dropinfo, TRUE);
669
+ transformoption.crop_width = dropinfo.image_width;
670
+ transformoption.crop_width_set = JCROP_POS;
671
+ transformoption.crop_height = dropinfo.image_height;
672
+ transformoption.crop_height_set = JCROP_POS;
673
+ transformoption.drop_ptr = &dropinfo;
674
+ }
675
+ #endif
676
+
677
+ /* Any space needed by a transform option must be requested before
678
+ * jpeg_read_coefficients so that memory allocation will be done right.
679
+ */
680
+ #if TRANSFORMS_SUPPORTED
681
+ /* Fail right away if -perfect is given and transformation is not perfect.
682
+ */
683
+ if (!jtransform_request_workspace(&srcinfo, &transformoption)) {
684
+ fprintf(stderr, "%s: transformation is not perfect\n", progname);
685
+ exit(EXIT_FAILURE);
686
+ }
687
+ #endif
688
+
689
+ /* Read source file as DCT coefficients */
690
+ src_coef_arrays = jpeg_read_coefficients(&srcinfo);
691
+
692
+ #if TRANSFORMS_SUPPORTED
693
+ if (dropfilename != NULL) {
694
+ transformoption.drop_coef_arrays = jpeg_read_coefficients(&dropinfo);
695
+ }
696
+ #endif
697
+
698
+ /* Initialize destination compression parameters from source values */
699
+ jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
700
+
701
+ /* Adjust destination parameters if required by transform options;
702
+ * also find out which set of coefficient arrays will hold the output.
703
+ */
704
+ #if TRANSFORMS_SUPPORTED
705
+ dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
706
+ src_coef_arrays,
707
+ &transformoption);
708
+ #else
709
+ dst_coef_arrays = src_coef_arrays;
710
+ #endif
711
+
712
+ /* Close input file, if we opened it.
713
+ * Note: we assume that jpeg_read_coefficients consumed all input
714
+ * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will
715
+ * only consume more while (!cinfo->inputctl->eoi_reached).
716
+ * We cannot call jpeg_finish_decompress here since we still need the
717
+ * virtual arrays allocated from the source object for processing.
718
+ */
719
+ if (fp != stdin)
720
+ fclose(fp);
721
+
722
+ /* Open the output file. */
723
+ if (outfilename != NULL) {
724
+ if ((fp = fopen(outfilename, WRITE_BINARY)) == NULL) {
725
+ fprintf(stderr, "%s: can't open %s for writing\n", progname,
726
+ outfilename);
727
+ exit(EXIT_FAILURE);
728
+ }
729
+ } else {
730
+ /* default output file is stdout */
731
+ fp = write_stdout();
732
+ }
733
+
734
+ /* Adjust default compression parameters by re-parsing the options */
735
+ file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE);
736
+
737
+ /* Specify data destination for compression */
738
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
739
+ if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&
740
+ jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)
741
+ == JCP_MAX_COMPRESSION)
742
+ jpeg_mem_dest(&dstinfo, &outbuffer, &outsize);
743
+ else
744
+ #endif
745
+ jpeg_stdio_dest(&dstinfo, fp);
746
+
747
+ /* Start compressor (note no image data is actually written here) */
748
+ jpeg_write_coefficients(&dstinfo, dst_coef_arrays);
749
+
750
+ /* Copy to the output file any extra markers that we want to preserve */
751
+ jcopy_markers_execute(&srcinfo, &dstinfo, copyoption);
752
+
753
+ if (icc_profile != NULL)
754
+ jpeg_write_icc_profile(&dstinfo, icc_profile, (unsigned int)icc_len);
755
+
756
+ /* Execute image transformation, if any */
757
+ #if TRANSFORMS_SUPPORTED
758
+ jtransform_execute_transformation(&srcinfo, &dstinfo, src_coef_arrays,
759
+ &transformoption);
760
+ #endif
761
+
762
+ /* Finish compression and release memory */
763
+ jpeg_finish_compress(&dstinfo);
764
+
765
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
766
+ if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&
767
+ jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)
768
+ == JCP_MAX_COMPRESSION) {
769
+ size_t nbytes;
770
+
771
+ unsigned char *buffer = outbuffer;
772
+ unsigned long size = outsize;
773
+ if (prefer_smallest && insize < size) {
774
+ size = insize;
775
+ buffer = inbuffer;
776
+ }
777
+
778
+ nbytes = fwrite(buffer, 1, size, fp);
779
+ if (nbytes < size && ferror(fp)) {
780
+ if (file_index < argc)
781
+ fprintf(stderr, "%s: can't write to %s\n", progname,
782
+ argv[file_index]);
783
+ else
784
+ fprintf(stderr, "%s: can't write to stdout\n", progname);
785
+ }
786
+ }
787
+ #endif
788
+
789
+ jpeg_destroy_compress(&dstinfo);
790
+ (void)jpeg_finish_decompress(&srcinfo);
791
+ jpeg_destroy_decompress(&srcinfo);
792
+
793
+ #if TRANSFORMS_SUPPORTED
794
+ if (dropfilename != NULL) {
795
+ (void)jpeg_finish_decompress(&dropinfo);
796
+ jpeg_destroy_decompress(&dropinfo);
797
+ }
798
+ #endif
799
+
800
+ /* Close output file, if we opened it */
801
+ if (fp != stdout)
802
+ fclose(fp);
803
+ #if TRANSFORMS_SUPPORTED
804
+ if (drop_file != NULL)
805
+ fclose(drop_file);
806
+ #endif
807
+
808
+ if (report)
809
+ end_progress_monitor((j_common_ptr)&dstinfo);
810
+ if (report || max_scans != 0)
811
+ end_progress_monitor((j_common_ptr)&srcinfo);
812
+
813
+ free(inbuffer);
814
+ free(outbuffer);
815
+
816
+ free(icc_profile);
817
+
818
+ /* All done. */
819
+ #if TRANSFORMS_SUPPORTED
820
+ if (dropfilename != NULL)
821
+ exit(jsrcerr.num_warnings + jdroperr.num_warnings +
822
+ jdsterr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
823
+ #endif
824
+ exit(jsrcerr.num_warnings + jdsterr.num_warnings ?
825
+ EXIT_WARNING : EXIT_SUCCESS);
826
+ return 0; /* suppress no-return-value warnings */
827
+ }