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,855 @@
1
+ /*
2
+ * djpeg.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1991-1997, Thomas G. Lane.
6
+ * Modified 2013-2019 by Guido Vollbeding.
7
+ * libjpeg-turbo Modifications:
8
+ * Copyright (C) 2010-2011, 2013-2017, 2019-2020, 2022, D. R. Commander.
9
+ * Copyright (C) 2015, Google, Inc.
10
+ * For conditions of distribution and use, see the accompanying README.ijg
11
+ * file.
12
+ *
13
+ * This file contains a command-line user interface for the JPEG decompressor.
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
+ * djpeg [options] inputfile outputfile
19
+ * djpeg [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
+ * djpeg [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
+ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
36
+ #include "jversion.h" /* for version message */
37
+ #include "jconfigint.h"
38
+
39
+ #include <ctype.h> /* to declare isprint() */
40
+
41
+
42
+ /* Create the add-on message string table. */
43
+
44
+ #define JMESSAGE(code, string) string,
45
+
46
+ static const char * const cdjpeg_message_table[] = {
47
+ #include "cderror.h"
48
+ NULL
49
+ };
50
+
51
+
52
+ /*
53
+ * This list defines the known output image formats
54
+ * (not all of which need be supported by a given version).
55
+ * You can change the default output format by defining DEFAULT_FMT;
56
+ * indeed, you had better do so if you undefine PPM_SUPPORTED.
57
+ */
58
+
59
+ typedef enum {
60
+ FMT_BMP, /* BMP format (Windows flavor) */
61
+ FMT_GIF, /* GIF format (LZW-compressed) */
62
+ FMT_GIF0, /* GIF format (uncompressed) */
63
+ FMT_OS2, /* BMP format (OS/2 flavor) */
64
+ FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
65
+ FMT_TARGA, /* Targa format */
66
+ FMT_TIFF /* TIFF format */
67
+ } IMAGE_FORMATS;
68
+
69
+ #ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
70
+ #define DEFAULT_FMT FMT_PPM
71
+ #endif
72
+
73
+ static IMAGE_FORMATS requested_fmt;
74
+
75
+
76
+ /*
77
+ * Argument-parsing code.
78
+ * The switch parser is designed to be useful with DOS-style command line
79
+ * syntax, ie, intermixed switches and file names, where only the switches
80
+ * to the left of a given file name affect processing of that file.
81
+ * The main program in this file doesn't actually use this capability...
82
+ */
83
+
84
+
85
+ static const char *progname; /* program name for error messages */
86
+ static char *icc_filename; /* for -icc switch */
87
+ JDIMENSION max_scans; /* for -maxscans switch */
88
+ static char *outfilename; /* for -outfile switch */
89
+ boolean memsrc; /* for -memsrc switch */
90
+ boolean report; /* for -report switch */
91
+ boolean skip, crop;
92
+ JDIMENSION skip_start, skip_end;
93
+ JDIMENSION crop_x, crop_y, crop_width, crop_height;
94
+ boolean strict; /* for -strict switch */
95
+ #define INPUT_BUF_SIZE 4096
96
+
97
+
98
+ LOCAL(void)
99
+ usage(void)
100
+ /* complain about bad command line */
101
+ {
102
+ fprintf(stderr, "usage: %s [switches] ", progname);
103
+ #ifdef TWO_FILE_COMMANDLINE
104
+ fprintf(stderr, "inputfile outputfile\n");
105
+ #else
106
+ fprintf(stderr, "[inputfile]\n");
107
+ #endif
108
+
109
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
110
+ fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
111
+ fprintf(stderr, " -fast Fast, low-quality processing\n");
112
+ fprintf(stderr, " -grayscale Force grayscale output\n");
113
+ fprintf(stderr, " -rgb Force RGB output\n");
114
+ fprintf(stderr, " -rgb565 Force RGB565 output\n");
115
+ #ifdef IDCT_SCALING_SUPPORTED
116
+ fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
117
+ #endif
118
+ #ifdef BMP_SUPPORTED
119
+ fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
120
+ (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
121
+ #endif
122
+ #ifdef GIF_SUPPORTED
123
+ fprintf(stderr, " -gif Select GIF output format (LZW-compressed)%s\n",
124
+ (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
125
+ fprintf(stderr, " -gif0 Select GIF output format (uncompressed)%s\n",
126
+ (DEFAULT_FMT == FMT_GIF0 ? " (default)" : ""));
127
+ #endif
128
+ #ifdef BMP_SUPPORTED
129
+ fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
130
+ (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
131
+ #endif
132
+ #ifdef PPM_SUPPORTED
133
+ fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
134
+ (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
135
+ #endif
136
+ #ifdef TARGA_SUPPORTED
137
+ fprintf(stderr, " -targa Select Targa output format%s\n",
138
+ (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
139
+ #endif
140
+ fprintf(stderr, "Switches for advanced users:\n");
141
+ #ifdef DCT_ISLOW_SUPPORTED
142
+ fprintf(stderr, " -dct int Use accurate integer DCT method%s\n",
143
+ (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
144
+ #endif
145
+ #ifdef DCT_IFAST_SUPPORTED
146
+ fprintf(stderr, " -dct fast Use less accurate integer DCT method [legacy feature]%s\n",
147
+ (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
148
+ #endif
149
+ #ifdef DCT_FLOAT_SUPPORTED
150
+ fprintf(stderr, " -dct float Use floating-point DCT method [legacy feature]%s\n",
151
+ (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
152
+ #endif
153
+ fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
154
+ fprintf(stderr, " -dither none Don't use dithering in quantization\n");
155
+ fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n");
156
+ fprintf(stderr, " -icc FILE Extract ICC profile to FILE\n");
157
+ #ifdef QUANT_2PASS_SUPPORTED
158
+ fprintf(stderr, " -map FILE Map to colors used in named image file\n");
159
+ #endif
160
+ fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n");
161
+ #ifdef QUANT_1PASS_SUPPORTED
162
+ fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n");
163
+ #endif
164
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
165
+ fprintf(stderr, " -maxscans N Maximum number of scans to allow in input file\n");
166
+ fprintf(stderr, " -outfile name Specify name for output file\n");
167
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
168
+ fprintf(stderr, " -memsrc Load input file into memory before decompressing\n");
169
+ #endif
170
+ fprintf(stderr, " -report Report decompression progress\n");
171
+ fprintf(stderr, " -skip Y0,Y1 Decompress all rows except those between Y0 and Y1 (inclusive)\n");
172
+ fprintf(stderr, " -crop WxH+X+Y Decompress only a rectangular subregion of the image\n");
173
+ fprintf(stderr, " [requires PBMPLUS (PPM/PGM), GIF, or Targa output format]\n");
174
+ fprintf(stderr, " -strict Treat all warnings as fatal\n");
175
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
176
+ fprintf(stderr, " -version Print version information and exit\n");
177
+ exit(EXIT_FAILURE);
178
+ }
179
+
180
+
181
+ LOCAL(int)
182
+ parse_switches(j_decompress_ptr cinfo, int argc, char **argv,
183
+ int last_file_arg_seen, boolean for_real)
184
+ /* Parse optional switches.
185
+ * Returns argv[] index of first file-name argument (== argc if none).
186
+ * Any file names with indexes <= last_file_arg_seen are ignored;
187
+ * they have presumably been processed in a previous iteration.
188
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
189
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
190
+ * processing.
191
+ */
192
+ {
193
+ int argn;
194
+ char *arg;
195
+
196
+ /* Set up default JPEG parameters. */
197
+ requested_fmt = DEFAULT_FMT; /* set default output file format */
198
+ icc_filename = NULL;
199
+ max_scans = 0;
200
+ outfilename = NULL;
201
+ memsrc = FALSE;
202
+ report = FALSE;
203
+ skip = FALSE;
204
+ crop = FALSE;
205
+ strict = FALSE;
206
+ cinfo->err->trace_level = 0;
207
+
208
+ /* Scan command line options, adjust parameters */
209
+
210
+ for (argn = 1; argn < argc; argn++) {
211
+ arg = argv[argn];
212
+ if (*arg != '-') {
213
+ /* Not a switch, must be a file name argument */
214
+ if (argn <= last_file_arg_seen) {
215
+ outfilename = NULL; /* -outfile applies to just one input file */
216
+ continue; /* ignore this name if previously processed */
217
+ }
218
+ break; /* else done parsing switches */
219
+ }
220
+ arg++; /* advance past switch marker character */
221
+
222
+ if (keymatch(arg, "bmp", 1)) {
223
+ /* BMP output format (Windows flavor). */
224
+ requested_fmt = FMT_BMP;
225
+
226
+ } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
227
+ keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
228
+ /* Do color quantization. */
229
+ int val;
230
+
231
+ if (++argn >= argc) /* advance to next argument */
232
+ usage();
233
+ if (sscanf(argv[argn], "%d", &val) != 1)
234
+ usage();
235
+ cinfo->desired_number_of_colors = val;
236
+ cinfo->quantize_colors = TRUE;
237
+
238
+ } else if (keymatch(arg, "dct", 2)) {
239
+ /* Select IDCT algorithm. */
240
+ if (++argn >= argc) /* advance to next argument */
241
+ usage();
242
+ if (keymatch(argv[argn], "int", 1)) {
243
+ cinfo->dct_method = JDCT_ISLOW;
244
+ } else if (keymatch(argv[argn], "fast", 2)) {
245
+ cinfo->dct_method = JDCT_IFAST;
246
+ } else if (keymatch(argv[argn], "float", 2)) {
247
+ cinfo->dct_method = JDCT_FLOAT;
248
+ } else
249
+ usage();
250
+
251
+ } else if (keymatch(arg, "dither", 2)) {
252
+ /* Select dithering algorithm. */
253
+ if (++argn >= argc) /* advance to next argument */
254
+ usage();
255
+ if (keymatch(argv[argn], "fs", 2)) {
256
+ cinfo->dither_mode = JDITHER_FS;
257
+ } else if (keymatch(argv[argn], "none", 2)) {
258
+ cinfo->dither_mode = JDITHER_NONE;
259
+ } else if (keymatch(argv[argn], "ordered", 2)) {
260
+ cinfo->dither_mode = JDITHER_ORDERED;
261
+ } else
262
+ usage();
263
+
264
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
265
+ /* Enable debug printouts. */
266
+ /* On first -d, print version identification */
267
+ static boolean printed_version = FALSE;
268
+
269
+ if (!printed_version) {
270
+ fprintf(stderr, "%s version %s (build %s)\n",
271
+ PACKAGE_NAME, VERSION, BUILD);
272
+ fprintf(stderr, "%s\n\n", JCOPYRIGHT);
273
+ fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
274
+ JVERSION);
275
+ printed_version = TRUE;
276
+ }
277
+ cinfo->err->trace_level++;
278
+
279
+ } else if (keymatch(arg, "version", 4)) {
280
+ fprintf(stderr, "%s version %s (build %s)\n",
281
+ PACKAGE_NAME, VERSION, BUILD);
282
+ exit(EXIT_SUCCESS);
283
+
284
+ } else if (keymatch(arg, "fast", 1)) {
285
+ /* Select recommended processing options for quick-and-dirty output. */
286
+ cinfo->two_pass_quantize = FALSE;
287
+ cinfo->dither_mode = JDITHER_ORDERED;
288
+ if (!cinfo->quantize_colors) /* don't override an earlier -colors */
289
+ cinfo->desired_number_of_colors = 216;
290
+ cinfo->dct_method = JDCT_FASTEST;
291
+ cinfo->do_fancy_upsampling = FALSE;
292
+
293
+ } else if (keymatch(arg, "gif", 1)) {
294
+ /* GIF output format (LZW-compressed). */
295
+ requested_fmt = FMT_GIF;
296
+
297
+ } else if (keymatch(arg, "gif0", 4)) {
298
+ /* GIF output format (uncompressed). */
299
+ requested_fmt = FMT_GIF0;
300
+
301
+ } else if (keymatch(arg, "grayscale", 2) ||
302
+ keymatch(arg, "greyscale", 2)) {
303
+ /* Force monochrome output. */
304
+ cinfo->out_color_space = JCS_GRAYSCALE;
305
+
306
+ } else if (keymatch(arg, "rgb", 2)) {
307
+ /* Force RGB output. */
308
+ cinfo->out_color_space = JCS_RGB;
309
+
310
+ } else if (keymatch(arg, "rgb565", 2)) {
311
+ /* Force RGB565 output. */
312
+ cinfo->out_color_space = JCS_RGB565;
313
+
314
+ } else if (keymatch(arg, "icc", 1)) {
315
+ /* Set ICC filename. */
316
+ if (++argn >= argc) /* advance to next argument */
317
+ usage();
318
+ icc_filename = argv[argn];
319
+ #ifdef SAVE_MARKERS_SUPPORTED
320
+ jpeg_save_markers(cinfo, JPEG_APP0 + 2, 0xFFFF);
321
+ #endif
322
+
323
+ } else if (keymatch(arg, "map", 3)) {
324
+ /* Quantize to a color map taken from an input file. */
325
+ if (++argn >= argc) /* advance to next argument */
326
+ usage();
327
+ if (for_real) { /* too expensive to do twice! */
328
+ #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
329
+ FILE *mapfile;
330
+
331
+ if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
332
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
333
+ exit(EXIT_FAILURE);
334
+ }
335
+ read_color_map(cinfo, mapfile);
336
+ fclose(mapfile);
337
+ cinfo->quantize_colors = TRUE;
338
+ #else
339
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
340
+ #endif
341
+ }
342
+
343
+ } else if (keymatch(arg, "maxmemory", 3)) {
344
+ /* Maximum memory in Kb (or Mb with 'm'). */
345
+ long lval;
346
+ char ch = 'x';
347
+
348
+ if (++argn >= argc) /* advance to next argument */
349
+ usage();
350
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
351
+ usage();
352
+ if (ch == 'm' || ch == 'M')
353
+ lval *= 1000L;
354
+ cinfo->mem->max_memory_to_use = lval * 1000L;
355
+
356
+ } else if (keymatch(arg, "maxscans", 4)) {
357
+ if (++argn >= argc) /* advance to next argument */
358
+ usage();
359
+ if (sscanf(argv[argn], "%u", &max_scans) != 1)
360
+ usage();
361
+
362
+ } else if (keymatch(arg, "nosmooth", 3)) {
363
+ /* Suppress fancy upsampling */
364
+ cinfo->do_fancy_upsampling = FALSE;
365
+
366
+ } else if (keymatch(arg, "onepass", 3)) {
367
+ /* Use fast one-pass quantization. */
368
+ cinfo->two_pass_quantize = FALSE;
369
+
370
+ } else if (keymatch(arg, "os2", 3)) {
371
+ /* BMP output format (OS/2 flavor). */
372
+ requested_fmt = FMT_OS2;
373
+
374
+ } else if (keymatch(arg, "outfile", 4)) {
375
+ /* Set output file name. */
376
+ if (++argn >= argc) /* advance to next argument */
377
+ usage();
378
+ outfilename = argv[argn]; /* save it away for later use */
379
+
380
+ } else if (keymatch(arg, "memsrc", 2)) {
381
+ /* Use in-memory source manager */
382
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
383
+ memsrc = TRUE;
384
+ #else
385
+ fprintf(stderr, "%s: sorry, in-memory source manager was not compiled in\n",
386
+ progname);
387
+ exit(EXIT_FAILURE);
388
+ #endif
389
+
390
+ } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
391
+ /* PPM/PGM output format. */
392
+ requested_fmt = FMT_PPM;
393
+
394
+ } else if (keymatch(arg, "report", 2)) {
395
+ report = TRUE;
396
+
397
+ } else if (keymatch(arg, "scale", 2)) {
398
+ /* Scale the output image by a fraction M/N. */
399
+ if (++argn >= argc) /* advance to next argument */
400
+ usage();
401
+ if (sscanf(argv[argn], "%u/%u",
402
+ &cinfo->scale_num, &cinfo->scale_denom) != 2)
403
+ usage();
404
+
405
+ } else if (keymatch(arg, "skip", 2)) {
406
+ if (++argn >= argc)
407
+ usage();
408
+ if (sscanf(argv[argn], "%u,%u", &skip_start, &skip_end) != 2 ||
409
+ skip_start > skip_end)
410
+ usage();
411
+ skip = TRUE;
412
+
413
+ } else if (keymatch(arg, "crop", 2)) {
414
+ char c;
415
+ if (++argn >= argc)
416
+ usage();
417
+ if (sscanf(argv[argn], "%u%c%u+%u+%u", &crop_width, &c, &crop_height,
418
+ &crop_x, &crop_y) != 5 ||
419
+ (c != 'X' && c != 'x') || crop_width < 1 || crop_height < 1)
420
+ usage();
421
+ crop = TRUE;
422
+
423
+ } else if (keymatch(arg, "strict", 2)) {
424
+ strict = TRUE;
425
+
426
+ } else if (keymatch(arg, "targa", 1)) {
427
+ /* Targa output format. */
428
+ requested_fmt = FMT_TARGA;
429
+
430
+ } else {
431
+ usage(); /* bogus switch */
432
+ }
433
+ }
434
+
435
+ return argn; /* return index of next arg (file name) */
436
+ }
437
+
438
+
439
+ /*
440
+ * Marker processor for COM and interesting APPn markers.
441
+ * This replaces the library's built-in processor, which just skips the marker.
442
+ * We want to print out the marker as text, to the extent possible.
443
+ * Note this code relies on a non-suspending data source.
444
+ */
445
+
446
+ LOCAL(unsigned int)
447
+ jpeg_getc(j_decompress_ptr cinfo)
448
+ /* Read next byte */
449
+ {
450
+ struct jpeg_source_mgr *datasrc = cinfo->src;
451
+
452
+ if (datasrc->bytes_in_buffer == 0) {
453
+ if (!(*datasrc->fill_input_buffer) (cinfo))
454
+ ERREXIT(cinfo, JERR_CANT_SUSPEND);
455
+ }
456
+ datasrc->bytes_in_buffer--;
457
+ return *datasrc->next_input_byte++;
458
+ }
459
+
460
+
461
+ METHODDEF(boolean)
462
+ print_text_marker(j_decompress_ptr cinfo)
463
+ {
464
+ boolean traceit = (cinfo->err->trace_level >= 1);
465
+ long length;
466
+ unsigned int ch;
467
+ unsigned int lastch = 0;
468
+
469
+ length = jpeg_getc(cinfo) << 8;
470
+ length += jpeg_getc(cinfo);
471
+ length -= 2; /* discount the length word itself */
472
+
473
+ if (traceit) {
474
+ if (cinfo->unread_marker == JPEG_COM)
475
+ fprintf(stderr, "Comment, length %ld:\n", (long)length);
476
+ else /* assume it is an APPn otherwise */
477
+ fprintf(stderr, "APP%d, length %ld:\n",
478
+ cinfo->unread_marker - JPEG_APP0, (long)length);
479
+ }
480
+
481
+ while (--length >= 0) {
482
+ ch = jpeg_getc(cinfo);
483
+ if (traceit) {
484
+ /* Emit the character in a readable form.
485
+ * Nonprintables are converted to \nnn form,
486
+ * while \ is converted to \\.
487
+ * Newlines in CR, CR/LF, or LF form will be printed as one newline.
488
+ */
489
+ if (ch == '\r') {
490
+ fprintf(stderr, "\n");
491
+ } else if (ch == '\n') {
492
+ if (lastch != '\r')
493
+ fprintf(stderr, "\n");
494
+ } else if (ch == '\\') {
495
+ fprintf(stderr, "\\\\");
496
+ } else if (isprint(ch)) {
497
+ putc(ch, stderr);
498
+ } else {
499
+ fprintf(stderr, "\\%03o", ch);
500
+ }
501
+ lastch = ch;
502
+ }
503
+ }
504
+
505
+ if (traceit)
506
+ fprintf(stderr, "\n");
507
+
508
+ return TRUE;
509
+ }
510
+
511
+
512
+ METHODDEF(void)
513
+ my_emit_message(j_common_ptr cinfo, int msg_level)
514
+ {
515
+ if (msg_level < 0) {
516
+ /* Treat warning as fatal */
517
+ cinfo->err->error_exit(cinfo);
518
+ } else {
519
+ if (cinfo->err->trace_level >= msg_level)
520
+ cinfo->err->output_message(cinfo);
521
+ }
522
+ }
523
+
524
+
525
+ /*
526
+ * The main program.
527
+ */
528
+
529
+ int
530
+ main(int argc, char **argv)
531
+ {
532
+ struct jpeg_decompress_struct cinfo;
533
+ struct jpeg_error_mgr jerr;
534
+ struct cdjpeg_progress_mgr progress;
535
+ int file_index;
536
+ djpeg_dest_ptr dest_mgr = NULL;
537
+ FILE *input_file;
538
+ FILE *output_file;
539
+ unsigned char *inbuffer = NULL;
540
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
541
+ unsigned long insize = 0;
542
+ #endif
543
+ JDIMENSION num_scanlines;
544
+
545
+ progname = argv[0];
546
+ if (progname == NULL || progname[0] == 0)
547
+ progname = "djpeg"; /* in case C library doesn't provide it */
548
+
549
+ /* Initialize the JPEG decompression object with default error handling. */
550
+ cinfo.err = jpeg_std_error(&jerr);
551
+ jpeg_create_decompress(&cinfo);
552
+ /* Add some application-specific error messages (from cderror.h) */
553
+ jerr.addon_message_table = cdjpeg_message_table;
554
+ jerr.first_addon_message = JMSG_FIRSTADDONCODE;
555
+ jerr.last_addon_message = JMSG_LASTADDONCODE;
556
+
557
+ /* Insert custom marker processor for COM and APP12.
558
+ * APP12 is used by some digital camera makers for textual info,
559
+ * so we provide the ability to display it as text.
560
+ * If you like, additional APPn marker types can be selected for display,
561
+ * but don't try to override APP0 or APP14 this way (see libjpeg.txt).
562
+ */
563
+ jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
564
+ jpeg_set_marker_processor(&cinfo, JPEG_APP0 + 12, print_text_marker);
565
+
566
+ /* Scan command line to find file names. */
567
+ /* It is convenient to use just one switch-parsing routine, but the switch
568
+ * values read here are ignored; we will rescan the switches after opening
569
+ * the input file.
570
+ * (Exception: tracing level set here controls verbosity for COM markers
571
+ * found during jpeg_read_header...)
572
+ */
573
+
574
+ file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
575
+
576
+ if (strict)
577
+ jerr.emit_message = my_emit_message;
578
+
579
+ #ifdef TWO_FILE_COMMANDLINE
580
+ /* Must have either -outfile switch or explicit output file name */
581
+ if (outfilename == NULL) {
582
+ if (file_index != argc - 2) {
583
+ fprintf(stderr, "%s: must name one input and one output file\n",
584
+ progname);
585
+ usage();
586
+ }
587
+ outfilename = argv[file_index + 1];
588
+ } else {
589
+ if (file_index != argc - 1) {
590
+ fprintf(stderr, "%s: must name one input and one output file\n",
591
+ progname);
592
+ usage();
593
+ }
594
+ }
595
+ #else
596
+ /* Unix style: expect zero or one file name */
597
+ if (file_index < argc - 1) {
598
+ fprintf(stderr, "%s: only one input file\n", progname);
599
+ usage();
600
+ }
601
+ #endif /* TWO_FILE_COMMANDLINE */
602
+
603
+ /* Open the input file. */
604
+ if (file_index < argc) {
605
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
606
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
607
+ exit(EXIT_FAILURE);
608
+ }
609
+ } else {
610
+ /* default input file is stdin */
611
+ input_file = read_stdin();
612
+ }
613
+
614
+ /* Open the output file. */
615
+ if (outfilename != NULL) {
616
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
617
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
618
+ exit(EXIT_FAILURE);
619
+ }
620
+ } else {
621
+ /* default output file is stdout */
622
+ output_file = write_stdout();
623
+ }
624
+
625
+ if (report || max_scans != 0) {
626
+ start_progress_monitor((j_common_ptr)&cinfo, &progress);
627
+ progress.report = report;
628
+ progress.max_scans = max_scans;
629
+ }
630
+
631
+ /* Specify data source for decompression */
632
+ #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
633
+ if (memsrc) {
634
+ size_t nbytes;
635
+ do {
636
+ inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE);
637
+ if (inbuffer == NULL) {
638
+ fprintf(stderr, "%s: memory allocation failure\n", progname);
639
+ exit(EXIT_FAILURE);
640
+ }
641
+ nbytes = fread(&inbuffer[insize], 1, INPUT_BUF_SIZE, input_file);
642
+ if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) {
643
+ if (file_index < argc)
644
+ fprintf(stderr, "%s: can't read from %s\n", progname,
645
+ argv[file_index]);
646
+ else
647
+ fprintf(stderr, "%s: can't read from stdin\n", progname);
648
+ }
649
+ insize += (unsigned long)nbytes;
650
+ } while (nbytes == INPUT_BUF_SIZE);
651
+ fprintf(stderr, "Compressed size: %lu bytes\n", insize);
652
+ jpeg_mem_src(&cinfo, inbuffer, insize);
653
+ } else
654
+ #endif
655
+ jpeg_stdio_src(&cinfo, input_file);
656
+
657
+ /* Read file header, set default decompression parameters */
658
+ (void)jpeg_read_header(&cinfo, TRUE);
659
+
660
+ /* Adjust default decompression parameters by re-parsing the options */
661
+ file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
662
+
663
+ /* Initialize the output module now to let it override any crucial
664
+ * option settings (for instance, GIF wants to force color quantization).
665
+ */
666
+ switch (requested_fmt) {
667
+ #ifdef BMP_SUPPORTED
668
+ case FMT_BMP:
669
+ dest_mgr = jinit_write_bmp(&cinfo, FALSE, TRUE);
670
+ break;
671
+ case FMT_OS2:
672
+ dest_mgr = jinit_write_bmp(&cinfo, TRUE, TRUE);
673
+ break;
674
+ #endif
675
+ #ifdef GIF_SUPPORTED
676
+ case FMT_GIF:
677
+ dest_mgr = jinit_write_gif(&cinfo, TRUE);
678
+ break;
679
+ case FMT_GIF0:
680
+ dest_mgr = jinit_write_gif(&cinfo, FALSE);
681
+ break;
682
+ #endif
683
+ #ifdef PPM_SUPPORTED
684
+ case FMT_PPM:
685
+ dest_mgr = jinit_write_ppm(&cinfo);
686
+ break;
687
+ #endif
688
+ #ifdef TARGA_SUPPORTED
689
+ case FMT_TARGA:
690
+ dest_mgr = jinit_write_targa(&cinfo);
691
+ break;
692
+ #endif
693
+ default:
694
+ ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
695
+ break;
696
+ }
697
+ dest_mgr->output_file = output_file;
698
+
699
+ /* Start decompressor */
700
+ (void)jpeg_start_decompress(&cinfo);
701
+
702
+ /* Skip rows */
703
+ if (skip) {
704
+ JDIMENSION tmp;
705
+
706
+ /* Check for valid skip_end. We cannot check this value until after
707
+ * jpeg_start_decompress() is called. Note that we have already verified
708
+ * that skip_start <= skip_end.
709
+ */
710
+ if (skip_end > cinfo.output_height - 1) {
711
+ fprintf(stderr, "%s: skip region exceeds image height %u\n", progname,
712
+ cinfo.output_height);
713
+ exit(EXIT_FAILURE);
714
+ }
715
+
716
+ /* Write output file header. This is a hack to ensure that the destination
717
+ * manager creates an output image of the proper size.
718
+ */
719
+ tmp = cinfo.output_height;
720
+ cinfo.output_height -= (skip_end - skip_start + 1);
721
+ (*dest_mgr->start_output) (&cinfo, dest_mgr);
722
+ cinfo.output_height = tmp;
723
+
724
+ /* Process data */
725
+ while (cinfo.output_scanline < skip_start) {
726
+ num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
727
+ dest_mgr->buffer_height);
728
+ (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
729
+ }
730
+ if ((tmp = jpeg_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
731
+ skip_end - skip_start + 1) {
732
+ fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
733
+ progname, tmp, skip_end - skip_start + 1);
734
+ exit(EXIT_FAILURE);
735
+ }
736
+ while (cinfo.output_scanline < cinfo.output_height) {
737
+ num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
738
+ dest_mgr->buffer_height);
739
+ (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
740
+ }
741
+
742
+ /* Decompress a subregion */
743
+ } else if (crop) {
744
+ JDIMENSION tmp;
745
+
746
+ /* Check for valid crop dimensions. We cannot check these values until
747
+ * after jpeg_start_decompress() is called.
748
+ */
749
+ if (crop_x + crop_width > cinfo.output_width ||
750
+ crop_y + crop_height > cinfo.output_height) {
751
+ fprintf(stderr, "%s: crop dimensions exceed image dimensions %u x %u\n",
752
+ progname, cinfo.output_width, cinfo.output_height);
753
+ exit(EXIT_FAILURE);
754
+ }
755
+
756
+ jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
757
+ if (dest_mgr->calc_buffer_dimensions)
758
+ (*dest_mgr->calc_buffer_dimensions) (&cinfo, dest_mgr);
759
+ else
760
+ ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
761
+
762
+ /* Write output file header. This is a hack to ensure that the destination
763
+ * manager creates an output image of the proper size.
764
+ */
765
+ tmp = cinfo.output_height;
766
+ cinfo.output_height = crop_height;
767
+ (*dest_mgr->start_output) (&cinfo, dest_mgr);
768
+ cinfo.output_height = tmp;
769
+
770
+ /* Process data */
771
+ if ((tmp = jpeg_skip_scanlines(&cinfo, crop_y)) != crop_y) {
772
+ fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
773
+ progname, tmp, crop_y);
774
+ exit(EXIT_FAILURE);
775
+ }
776
+ while (cinfo.output_scanline < crop_y + crop_height) {
777
+ num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
778
+ dest_mgr->buffer_height);
779
+ (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
780
+ }
781
+ if ((tmp =
782
+ jpeg_skip_scanlines(&cinfo,
783
+ cinfo.output_height - crop_y - crop_height)) !=
784
+ cinfo.output_height - crop_y - crop_height) {
785
+ fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
786
+ progname, tmp, cinfo.output_height - crop_y - crop_height);
787
+ exit(EXIT_FAILURE);
788
+ }
789
+
790
+ /* Normal full-image decompress */
791
+ } else {
792
+ /* Write output file header */
793
+ (*dest_mgr->start_output) (&cinfo, dest_mgr);
794
+
795
+ /* Process data */
796
+ while (cinfo.output_scanline < cinfo.output_height) {
797
+ num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
798
+ dest_mgr->buffer_height);
799
+ (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
800
+ }
801
+ }
802
+
803
+ /* Hack: count final pass as done in case finish_output does an extra pass.
804
+ * The library won't have updated completed_passes.
805
+ */
806
+ if (report || max_scans != 0)
807
+ progress.pub.completed_passes = progress.pub.total_passes;
808
+
809
+ if (icc_filename != NULL) {
810
+ FILE *icc_file;
811
+ JOCTET *icc_profile;
812
+ unsigned int icc_len;
813
+
814
+ if ((icc_file = fopen(icc_filename, WRITE_BINARY)) == NULL) {
815
+ fprintf(stderr, "%s: can't open %s\n", progname, icc_filename);
816
+ exit(EXIT_FAILURE);
817
+ }
818
+ if (jpeg_read_icc_profile(&cinfo, &icc_profile, &icc_len)) {
819
+ if (fwrite(icc_profile, icc_len, 1, icc_file) < 1) {
820
+ fprintf(stderr, "%s: can't read ICC profile from %s\n", progname,
821
+ icc_filename);
822
+ free(icc_profile);
823
+ fclose(icc_file);
824
+ exit(EXIT_FAILURE);
825
+ }
826
+ free(icc_profile);
827
+ fclose(icc_file);
828
+ } else if (cinfo.err->msg_code != JWRN_BOGUS_ICC)
829
+ fprintf(stderr, "%s: no ICC profile data in JPEG file\n", progname);
830
+ }
831
+
832
+ /* Finish decompression and release memory.
833
+ * I must do it in this order because output module has allocated memory
834
+ * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
835
+ */
836
+ (*dest_mgr->finish_output) (&cinfo, dest_mgr);
837
+ (void)jpeg_finish_decompress(&cinfo);
838
+ jpeg_destroy_decompress(&cinfo);
839
+
840
+ /* Close files, if we opened them */
841
+ if (input_file != stdin)
842
+ fclose(input_file);
843
+ if (output_file != stdout)
844
+ fclose(output_file);
845
+
846
+ if (report || max_scans != 0)
847
+ end_progress_monitor((j_common_ptr)&cinfo);
848
+
849
+ if (memsrc)
850
+ free(inbuffer);
851
+
852
+ /* All done. */
853
+ exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
854
+ return 0; /* suppress no-return-value warnings */
855
+ }