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,781 @@
1
+ /*
2
+ * rdppm.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1991-1997, Thomas G. Lane.
6
+ * Modified 2009 by Bill Allombert, Guido Vollbeding.
7
+ * libjpeg-turbo Modifications:
8
+ * Copyright (C) 2015-2017, 2020-2023, D. R. Commander.
9
+ * For conditions of distribution and use, see the accompanying README.ijg
10
+ * file.
11
+ *
12
+ * This file contains routines to read input images in PPM/PGM format.
13
+ * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
14
+ * The PBMPLUS library is NOT required to compile this software
15
+ * (but it is highly useful as a set of PPM image manipulation programs).
16
+ *
17
+ * These routines may need modification for non-Unix environments or
18
+ * specialized applications. As they stand, they assume input from
19
+ * an ordinary stdio stream. They further assume that reading begins
20
+ * at the start of the file; start_input may need work if the
21
+ * user interface has already read some data (e.g., to determine that
22
+ * the file is indeed PPM format).
23
+ */
24
+
25
+ #include "cmyk.h"
26
+ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
27
+
28
+ #ifdef PPM_SUPPORTED
29
+
30
+
31
+ /* Portions of this code are based on the PBMPLUS library, which is:
32
+ **
33
+ ** Copyright (C) 1988 by Jef Poskanzer.
34
+ **
35
+ ** Permission to use, copy, modify, and distribute this software and its
36
+ ** documentation for any purpose and without fee is hereby granted, provided
37
+ ** that the above copyright notice appear in all copies and that both that
38
+ ** copyright notice and this permission notice appear in supporting
39
+ ** documentation. This software is provided "as is" without express or
40
+ ** implied warranty.
41
+ */
42
+
43
+
44
+ /* Macros to deal with unsigned chars as efficiently as compiler allows */
45
+
46
+ typedef unsigned char U_CHAR;
47
+ #define UCH(x) ((int)(x))
48
+
49
+
50
+ #define ReadOK(file, buffer, len) \
51
+ (fread(buffer, 1, len, file) == ((size_t)(len)))
52
+
53
+ static int alpha_index[JPEG_NUMCS] = {
54
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
55
+ };
56
+
57
+
58
+ /* Private version of data source object */
59
+
60
+ typedef struct {
61
+ struct cjpeg_source_struct pub; /* public fields */
62
+
63
+ /* Usually these two pointers point to the same place: */
64
+ U_CHAR *iobuffer; /* fread's I/O buffer */
65
+ JSAMPROW pixrow; /* compressor input buffer */
66
+ size_t buffer_width; /* width of I/O buffer */
67
+ JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
68
+ unsigned int maxval;
69
+ } ppm_source_struct;
70
+
71
+ typedef ppm_source_struct *ppm_source_ptr;
72
+
73
+
74
+ LOCAL(int)
75
+ pbm_getc(FILE *infile)
76
+ /* Read next char, skipping over any comments */
77
+ /* A comment/newline sequence is returned as a newline */
78
+ {
79
+ register int ch;
80
+
81
+ ch = getc(infile);
82
+ if (ch == '#') {
83
+ do {
84
+ ch = getc(infile);
85
+ } while (ch != '\n' && ch != EOF);
86
+ }
87
+ return ch;
88
+ }
89
+
90
+
91
+ LOCAL(unsigned int)
92
+ read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
93
+ /* Read an unsigned decimal integer from the PPM file */
94
+ /* Swallows one trailing character after the integer */
95
+ /* Note that on a 16-bit-int machine, only values up to 64k can be read. */
96
+ /* This should not be a problem in practice. */
97
+ {
98
+ register int ch;
99
+ register unsigned int val;
100
+
101
+ /* Skip any leading whitespace */
102
+ do {
103
+ ch = pbm_getc(infile);
104
+ if (ch == EOF)
105
+ ERREXIT(cinfo, JERR_INPUT_EOF);
106
+ } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
107
+
108
+ if (ch < '0' || ch > '9')
109
+ ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
110
+
111
+ val = ch - '0';
112
+ while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
113
+ val *= 10;
114
+ val += ch - '0';
115
+ if (val > maxval)
116
+ ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
117
+ }
118
+
119
+ return val;
120
+ }
121
+
122
+
123
+ /*
124
+ * Read one row of pixels.
125
+ *
126
+ * We provide several different versions depending on input file format.
127
+ * In all cases, input is scaled to the size of JSAMPLE.
128
+ *
129
+ * A really fast path is provided for reading byte/sample raw files with
130
+ * maxval = MAXJSAMPLE, which is the normal case for 8-bit data.
131
+ */
132
+
133
+
134
+ METHODDEF(JDIMENSION)
135
+ get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
136
+ /* This version is for reading text-format PGM files with any maxval */
137
+ {
138
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
139
+ FILE *infile = source->pub.input_file;
140
+ register JSAMPROW ptr;
141
+ register JSAMPLE *rescale = source->rescale;
142
+ JDIMENSION col;
143
+ unsigned int maxval = source->maxval;
144
+
145
+ ptr = source->pub.buffer[0];
146
+ for (col = cinfo->image_width; col > 0; col--) {
147
+ *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
148
+ }
149
+ return 1;
150
+ }
151
+
152
+
153
+ #define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
154
+ for (col = cinfo->image_width; col > 0; col--) { \
155
+ ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
156
+ alpha_set_op \
157
+ ptr += ps; \
158
+ } \
159
+ }
160
+
161
+ METHODDEF(JDIMENSION)
162
+ get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
163
+ /* This version is for reading text-format PGM files with any maxval and
164
+ converting to extended RGB */
165
+ {
166
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
167
+ FILE *infile = source->pub.input_file;
168
+ register JSAMPROW ptr;
169
+ register JSAMPLE *rescale = source->rescale;
170
+ JDIMENSION col;
171
+ unsigned int maxval = source->maxval;
172
+ register int rindex = rgb_red[cinfo->in_color_space];
173
+ register int gindex = rgb_green[cinfo->in_color_space];
174
+ register int bindex = rgb_blue[cinfo->in_color_space];
175
+ register int aindex = alpha_index[cinfo->in_color_space];
176
+ register int ps = rgb_pixelsize[cinfo->in_color_space];
177
+
178
+ ptr = source->pub.buffer[0];
179
+ if (maxval == MAXJSAMPLE) {
180
+ if (aindex >= 0)
181
+ GRAY_RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
182
+ ptr[aindex] = MAXJSAMPLE;)
183
+ else
184
+ GRAY_RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
185
+ } else {
186
+ if (aindex >= 0)
187
+ GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
188
+ ptr[aindex] = MAXJSAMPLE;)
189
+ else
190
+ GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
191
+ }
192
+ return 1;
193
+ }
194
+
195
+
196
+ METHODDEF(JDIMENSION)
197
+ get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
198
+ /* This version is for reading text-format PGM files with any maxval and
199
+ converting to CMYK */
200
+ {
201
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
202
+ FILE *infile = source->pub.input_file;
203
+ register JSAMPROW ptr;
204
+ register JSAMPLE *rescale = source->rescale;
205
+ JDIMENSION col;
206
+ unsigned int maxval = source->maxval;
207
+
208
+ ptr = source->pub.buffer[0];
209
+ if (maxval == MAXJSAMPLE) {
210
+ for (col = cinfo->image_width; col > 0; col--) {
211
+ JSAMPLE gray = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
212
+ rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
213
+ ptr += 4;
214
+ }
215
+ } else {
216
+ for (col = cinfo->image_width; col > 0; col--) {
217
+ JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
218
+ rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
219
+ ptr += 4;
220
+ }
221
+ }
222
+ return 1;
223
+ }
224
+
225
+
226
+ #define RGB_READ_LOOP(read_op, alpha_set_op) { \
227
+ for (col = cinfo->image_width; col > 0; col--) { \
228
+ ptr[rindex] = read_op; \
229
+ ptr[gindex] = read_op; \
230
+ ptr[bindex] = read_op; \
231
+ alpha_set_op \
232
+ ptr += ps; \
233
+ } \
234
+ }
235
+
236
+ METHODDEF(JDIMENSION)
237
+ get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
238
+ /* This version is for reading text-format PPM files with any maxval */
239
+ {
240
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
241
+ FILE *infile = source->pub.input_file;
242
+ register JSAMPROW ptr;
243
+ register JSAMPLE *rescale = source->rescale;
244
+ JDIMENSION col;
245
+ unsigned int maxval = source->maxval;
246
+ register int rindex = rgb_red[cinfo->in_color_space];
247
+ register int gindex = rgb_green[cinfo->in_color_space];
248
+ register int bindex = rgb_blue[cinfo->in_color_space];
249
+ register int aindex = alpha_index[cinfo->in_color_space];
250
+ register int ps = rgb_pixelsize[cinfo->in_color_space];
251
+
252
+ ptr = source->pub.buffer[0];
253
+ if (maxval == MAXJSAMPLE) {
254
+ if (aindex >= 0)
255
+ RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
256
+ ptr[aindex] = MAXJSAMPLE;)
257
+ else
258
+ RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
259
+ } else {
260
+ if (aindex >= 0)
261
+ RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
262
+ ptr[aindex] = MAXJSAMPLE;)
263
+ else
264
+ RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
265
+ }
266
+ return 1;
267
+ }
268
+
269
+
270
+ METHODDEF(JDIMENSION)
271
+ get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
272
+ /* This version is for reading text-format PPM files with any maxval and
273
+ converting to CMYK */
274
+ {
275
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
276
+ FILE *infile = source->pub.input_file;
277
+ register JSAMPROW ptr;
278
+ register JSAMPLE *rescale = source->rescale;
279
+ JDIMENSION col;
280
+ unsigned int maxval = source->maxval;
281
+
282
+ ptr = source->pub.buffer[0];
283
+ if (maxval == MAXJSAMPLE) {
284
+ for (col = cinfo->image_width; col > 0; col--) {
285
+ JSAMPLE r = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
286
+ JSAMPLE g = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
287
+ JSAMPLE b = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
+ rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
289
+ ptr += 4;
290
+ }
291
+ } else {
292
+ for (col = cinfo->image_width; col > 0; col--) {
293
+ JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
294
+ JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
295
+ JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
+ rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
297
+ ptr += 4;
298
+ }
299
+ }
300
+ return 1;
301
+ }
302
+
303
+
304
+ METHODDEF(JDIMENSION)
305
+ get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
306
+ /* This version is for reading raw-byte-format PGM files with any maxval */
307
+ {
308
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
309
+ register JSAMPROW ptr;
310
+ register U_CHAR *bufferptr;
311
+ register JSAMPLE *rescale = source->rescale;
312
+ JDIMENSION col;
313
+
314
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
315
+ ERREXIT(cinfo, JERR_INPUT_EOF);
316
+ ptr = source->pub.buffer[0];
317
+ bufferptr = source->iobuffer;
318
+ for (col = cinfo->image_width; col > 0; col--) {
319
+ *ptr++ = rescale[UCH(*bufferptr++)];
320
+ }
321
+ return 1;
322
+ }
323
+
324
+
325
+ METHODDEF(JDIMENSION)
326
+ get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
327
+ /* This version is for reading raw-byte-format PGM files with any maxval
328
+ and converting to extended RGB */
329
+ {
330
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
331
+ register JSAMPROW ptr;
332
+ register U_CHAR *bufferptr;
333
+ register JSAMPLE *rescale = source->rescale;
334
+ JDIMENSION col;
335
+ unsigned int maxval = source->maxval;
336
+ register int rindex = rgb_red[cinfo->in_color_space];
337
+ register int gindex = rgb_green[cinfo->in_color_space];
338
+ register int bindex = rgb_blue[cinfo->in_color_space];
339
+ register int aindex = alpha_index[cinfo->in_color_space];
340
+ register int ps = rgb_pixelsize[cinfo->in_color_space];
341
+
342
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
343
+ ERREXIT(cinfo, JERR_INPUT_EOF);
344
+ ptr = source->pub.buffer[0];
345
+ bufferptr = source->iobuffer;
346
+ if (maxval == MAXJSAMPLE) {
347
+ if (aindex >= 0)
348
+ GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = MAXJSAMPLE;)
349
+ else
350
+ GRAY_RGB_READ_LOOP(*bufferptr++, {})
351
+ } else {
352
+ if (aindex >= 0)
353
+ GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = MAXJSAMPLE;)
354
+ else
355
+ GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
356
+ }
357
+ return 1;
358
+ }
359
+
360
+
361
+ METHODDEF(JDIMENSION)
362
+ get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
363
+ /* This version is for reading raw-byte-format PGM files with any maxval
364
+ and converting to CMYK */
365
+ {
366
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
367
+ register JSAMPROW ptr;
368
+ register U_CHAR *bufferptr;
369
+ register JSAMPLE *rescale = source->rescale;
370
+ JDIMENSION col;
371
+ unsigned int maxval = source->maxval;
372
+
373
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
374
+ ERREXIT(cinfo, JERR_INPUT_EOF);
375
+ ptr = source->pub.buffer[0];
376
+ bufferptr = source->iobuffer;
377
+ if (maxval == MAXJSAMPLE) {
378
+ for (col = cinfo->image_width; col > 0; col--) {
379
+ JSAMPLE gray = *bufferptr++;
380
+ rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
381
+ ptr += 4;
382
+ }
383
+ } else {
384
+ for (col = cinfo->image_width; col > 0; col--) {
385
+ JSAMPLE gray = rescale[UCH(*bufferptr++)];
386
+ rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
387
+ ptr += 4;
388
+ }
389
+ }
390
+ return 1;
391
+ }
392
+
393
+
394
+ METHODDEF(JDIMENSION)
395
+ get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
396
+ /* This version is for reading raw-byte-format PPM files with any maxval */
397
+ {
398
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
+ register JSAMPROW ptr;
400
+ register U_CHAR *bufferptr;
401
+ register JSAMPLE *rescale = source->rescale;
402
+ JDIMENSION col;
403
+ unsigned int maxval = source->maxval;
404
+ register int rindex = rgb_red[cinfo->in_color_space];
405
+ register int gindex = rgb_green[cinfo->in_color_space];
406
+ register int bindex = rgb_blue[cinfo->in_color_space];
407
+ register int aindex = alpha_index[cinfo->in_color_space];
408
+ register int ps = rgb_pixelsize[cinfo->in_color_space];
409
+
410
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
+ ERREXIT(cinfo, JERR_INPUT_EOF);
412
+ ptr = source->pub.buffer[0];
413
+ bufferptr = source->iobuffer;
414
+ if (maxval == MAXJSAMPLE) {
415
+ if (aindex >= 0)
416
+ RGB_READ_LOOP(*bufferptr++, ptr[aindex] = MAXJSAMPLE;)
417
+ else
418
+ RGB_READ_LOOP(*bufferptr++, {})
419
+ } else {
420
+ if (aindex >= 0)
421
+ RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = MAXJSAMPLE;)
422
+ else
423
+ RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
424
+ }
425
+ return 1;
426
+ }
427
+
428
+
429
+ METHODDEF(JDIMENSION)
430
+ get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
431
+ /* This version is for reading raw-byte-format PPM files with any maxval and
432
+ converting to CMYK */
433
+ {
434
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
435
+ register JSAMPROW ptr;
436
+ register U_CHAR *bufferptr;
437
+ register JSAMPLE *rescale = source->rescale;
438
+ JDIMENSION col;
439
+ unsigned int maxval = source->maxval;
440
+
441
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
442
+ ERREXIT(cinfo, JERR_INPUT_EOF);
443
+ ptr = source->pub.buffer[0];
444
+ bufferptr = source->iobuffer;
445
+ if (maxval == MAXJSAMPLE) {
446
+ for (col = cinfo->image_width; col > 0; col--) {
447
+ JSAMPLE r = *bufferptr++;
448
+ JSAMPLE g = *bufferptr++;
449
+ JSAMPLE b = *bufferptr++;
450
+ rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
451
+ ptr += 4;
452
+ }
453
+ } else {
454
+ for (col = cinfo->image_width; col > 0; col--) {
455
+ JSAMPLE r = rescale[UCH(*bufferptr++)];
456
+ JSAMPLE g = rescale[UCH(*bufferptr++)];
457
+ JSAMPLE b = rescale[UCH(*bufferptr++)];
458
+ rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
459
+ ptr += 4;
460
+ }
461
+ }
462
+ return 1;
463
+ }
464
+
465
+
466
+ METHODDEF(JDIMENSION)
467
+ get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
468
+ /* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE.
469
+ * In this case we just read right into the JSAMPLE buffer!
470
+ * Note that same code works for PPM and PGM files.
471
+ */
472
+ {
473
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
474
+
475
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
476
+ ERREXIT(cinfo, JERR_INPUT_EOF);
477
+ return 1;
478
+ }
479
+
480
+
481
+ METHODDEF(JDIMENSION)
482
+ get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
483
+ /* This version is for reading raw-word-format PGM files with any maxval */
484
+ {
485
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
486
+ register JSAMPROW ptr;
487
+ register U_CHAR *bufferptr;
488
+ register JSAMPLE *rescale = source->rescale;
489
+ JDIMENSION col;
490
+ unsigned int maxval = source->maxval;
491
+
492
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
493
+ ERREXIT(cinfo, JERR_INPUT_EOF);
494
+ ptr = source->pub.buffer[0];
495
+ bufferptr = source->iobuffer;
496
+ for (col = cinfo->image_width; col > 0; col--) {
497
+ register unsigned int temp;
498
+ temp = UCH(*bufferptr++) << 8;
499
+ temp |= UCH(*bufferptr++);
500
+ if (temp > maxval)
501
+ ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
502
+ *ptr++ = rescale[temp];
503
+ }
504
+ return 1;
505
+ }
506
+
507
+
508
+ METHODDEF(JDIMENSION)
509
+ get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
510
+ /* This version is for reading raw-word-format PPM files with any maxval */
511
+ {
512
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
513
+ register JSAMPROW ptr;
514
+ register U_CHAR *bufferptr;
515
+ register JSAMPLE *rescale = source->rescale;
516
+ JDIMENSION col;
517
+ unsigned int maxval = source->maxval;
518
+ register int rindex = rgb_red[cinfo->in_color_space];
519
+ register int gindex = rgb_green[cinfo->in_color_space];
520
+ register int bindex = rgb_blue[cinfo->in_color_space];
521
+ register int aindex = alpha_index[cinfo->in_color_space];
522
+ register int ps = rgb_pixelsize[cinfo->in_color_space];
523
+
524
+ if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
525
+ ERREXIT(cinfo, JERR_INPUT_EOF);
526
+ ptr = source->pub.buffer[0];
527
+ bufferptr = source->iobuffer;
528
+ for (col = cinfo->image_width; col > 0; col--) {
529
+ register unsigned int temp;
530
+ temp = UCH(*bufferptr++) << 8;
531
+ temp |= UCH(*bufferptr++);
532
+ if (temp > maxval)
533
+ ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
534
+ ptr[rindex] = rescale[temp];
535
+ temp = UCH(*bufferptr++) << 8;
536
+ temp |= UCH(*bufferptr++);
537
+ if (temp > maxval)
538
+ ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
539
+ ptr[gindex] = rescale[temp];
540
+ temp = UCH(*bufferptr++) << 8;
541
+ temp |= UCH(*bufferptr++);
542
+ if (temp > maxval)
543
+ ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
544
+ ptr[bindex] = rescale[temp];
545
+ if (aindex >= 0)
546
+ ptr[aindex] = MAXJSAMPLE;
547
+ ptr += ps;
548
+ }
549
+ return 1;
550
+ }
551
+
552
+
553
+ /*
554
+ * Read the file header; return image size and component count.
555
+ */
556
+
557
+ METHODDEF(void)
558
+ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
559
+ {
560
+ ppm_source_ptr source = (ppm_source_ptr)sinfo;
561
+ int c;
562
+ unsigned int w, h, maxval;
563
+ boolean need_iobuffer, use_raw_buffer, need_rescale;
564
+
565
+ if (getc(source->pub.input_file) != 'P')
566
+ ERREXIT(cinfo, JERR_PPM_NOT);
567
+
568
+ c = getc(source->pub.input_file); /* subformat discriminator character */
569
+
570
+ /* detect unsupported variants (ie, PBM) before trying to read header */
571
+ switch (c) {
572
+ case '2': /* it's a text-format PGM file */
573
+ case '3': /* it's a text-format PPM file */
574
+ case '5': /* it's a raw-format PGM file */
575
+ case '6': /* it's a raw-format PPM file */
576
+ break;
577
+ default:
578
+ ERREXIT(cinfo, JERR_PPM_NOT);
579
+ break;
580
+ }
581
+
582
+ /* fetch the remaining header info */
583
+ w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
584
+ h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
585
+ maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
586
+
587
+ if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
588
+ ERREXIT(cinfo, JERR_PPM_NOT);
589
+ #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
590
+ if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
591
+ ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
592
+ #endif
593
+
594
+ cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
595
+ cinfo->image_width = (JDIMENSION)w;
596
+ cinfo->image_height = (JDIMENSION)h;
597
+ source->maxval = maxval;
598
+
599
+ /* initialize flags to most common settings */
600
+ need_iobuffer = TRUE; /* do we need an I/O buffer? */
601
+ use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */
602
+ need_rescale = TRUE; /* do we need a rescale array? */
603
+
604
+ switch (c) {
605
+ case '2': /* it's a text-format PGM file */
606
+ if (cinfo->in_color_space == JCS_UNKNOWN ||
607
+ cinfo->in_color_space == JCS_RGB)
608
+ cinfo->in_color_space = JCS_GRAYSCALE;
609
+ TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
610
+ if (cinfo->in_color_space == JCS_GRAYSCALE)
611
+ source->pub.get_pixel_rows = get_text_gray_row;
612
+ else if (IsExtRGB(cinfo->in_color_space))
613
+ source->pub.get_pixel_rows = get_text_gray_rgb_row;
614
+ else if (cinfo->in_color_space == JCS_CMYK)
615
+ source->pub.get_pixel_rows = get_text_gray_cmyk_row;
616
+ else
617
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
618
+ need_iobuffer = FALSE;
619
+ break;
620
+
621
+ case '3': /* it's a text-format PPM file */
622
+ if (cinfo->in_color_space == JCS_UNKNOWN)
623
+ cinfo->in_color_space = JCS_EXT_RGB;
624
+ TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);
625
+ if (IsExtRGB(cinfo->in_color_space))
626
+ source->pub.get_pixel_rows = get_text_rgb_row;
627
+ else if (cinfo->in_color_space == JCS_CMYK)
628
+ source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
629
+ else
630
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
631
+ need_iobuffer = FALSE;
632
+ break;
633
+
634
+ case '5': /* it's a raw-format PGM file */
635
+ if (cinfo->in_color_space == JCS_UNKNOWN ||
636
+ cinfo->in_color_space == JCS_RGB)
637
+ cinfo->in_color_space = JCS_GRAYSCALE;
638
+ TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
639
+ if (maxval > 255) {
640
+ if (cinfo->in_color_space == JCS_GRAYSCALE)
641
+ source->pub.get_pixel_rows = get_word_gray_row;
642
+ else
643
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
644
+ } else if (maxval == MAXJSAMPLE && sizeof(JSAMPLE) == sizeof(U_CHAR) &&
645
+ cinfo->in_color_space == JCS_GRAYSCALE) {
646
+ source->pub.get_pixel_rows = get_raw_row;
647
+ use_raw_buffer = TRUE;
648
+ need_rescale = FALSE;
649
+ } else {
650
+ if (cinfo->in_color_space == JCS_GRAYSCALE)
651
+ source->pub.get_pixel_rows = get_scaled_gray_row;
652
+ else if (IsExtRGB(cinfo->in_color_space))
653
+ source->pub.get_pixel_rows = get_gray_rgb_row;
654
+ else if (cinfo->in_color_space == JCS_CMYK)
655
+ source->pub.get_pixel_rows = get_gray_cmyk_row;
656
+ else
657
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
658
+ }
659
+ break;
660
+
661
+ case '6': /* it's a raw-format PPM file */
662
+ if (cinfo->in_color_space == JCS_UNKNOWN)
663
+ cinfo->in_color_space = JCS_EXT_RGB;
664
+ TRACEMS2(cinfo, 1, JTRC_PPM, w, h);
665
+ if (maxval > 255) {
666
+ if (IsExtRGB(cinfo->in_color_space))
667
+ source->pub.get_pixel_rows = get_word_rgb_row;
668
+ else
669
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
670
+ } else if (maxval == MAXJSAMPLE && sizeof(JSAMPLE) == sizeof(U_CHAR) &&
671
+ #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
672
+ (cinfo->in_color_space == JCS_EXT_RGB ||
673
+ cinfo->in_color_space == JCS_RGB)) {
674
+ #else
675
+ cinfo->in_color_space == JCS_EXT_RGB) {
676
+ #endif
677
+ source->pub.get_pixel_rows = get_raw_row;
678
+ use_raw_buffer = TRUE;
679
+ need_rescale = FALSE;
680
+ } else {
681
+ if (IsExtRGB(cinfo->in_color_space))
682
+ source->pub.get_pixel_rows = get_rgb_row;
683
+ else if (cinfo->in_color_space == JCS_CMYK)
684
+ source->pub.get_pixel_rows = get_rgb_cmyk_row;
685
+ else
686
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
687
+ }
688
+ break;
689
+ }
690
+
691
+ if (IsExtRGB(cinfo->in_color_space))
692
+ cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
693
+ else if (cinfo->in_color_space == JCS_GRAYSCALE)
694
+ cinfo->input_components = 1;
695
+ else if (cinfo->in_color_space == JCS_CMYK)
696
+ cinfo->input_components = 4;
697
+
698
+ /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
699
+ if (need_iobuffer) {
700
+ if (c == '6')
701
+ source->buffer_width = (size_t)w * 3 *
702
+ ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
703
+ else
704
+ source->buffer_width = (size_t)w *
705
+ ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
706
+ source->iobuffer = (U_CHAR *)
707
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
708
+ source->buffer_width);
709
+ }
710
+
711
+ /* Create compressor input buffer. */
712
+ if (use_raw_buffer) {
713
+ /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
714
+ /* Synthesize a JSAMPARRAY pointer structure */
715
+ source->pixrow = (JSAMPROW)source->iobuffer;
716
+ source->pub.buffer = &source->pixrow;
717
+ source->pub.buffer_height = 1;
718
+ } else {
719
+ /* Need to translate anyway, so make a separate sample buffer. */
720
+ source->pub.buffer = (*cinfo->mem->alloc_sarray)
721
+ ((j_common_ptr)cinfo, JPOOL_IMAGE,
722
+ (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
723
+ source->pub.buffer_height = 1;
724
+ }
725
+
726
+ /* Compute the rescaling array if required. */
727
+ if (need_rescale) {
728
+ long val, half_maxval;
729
+
730
+ /* On 16-bit-int machines we have to be careful of maxval = 65535 */
731
+ source->rescale = (JSAMPLE *)
732
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
733
+ (size_t)(((long)MAX(maxval, 255) + 1L) *
734
+ sizeof(JSAMPLE)));
735
+ memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
736
+ sizeof(JSAMPLE)));
737
+ half_maxval = maxval / 2;
738
+ for (val = 0; val <= (long)maxval; val++) {
739
+ /* The multiplication here must be done in 32 bits to avoid overflow */
740
+ source->rescale[val] = (JSAMPLE)((val * MAXJSAMPLE + half_maxval) /
741
+ maxval);
742
+ }
743
+ }
744
+ }
745
+
746
+
747
+ /*
748
+ * Finish up at the end of the file.
749
+ */
750
+
751
+ METHODDEF(void)
752
+ finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
753
+ {
754
+ /* no work */
755
+ }
756
+
757
+
758
+ /*
759
+ * The module selection routine for PPM format input.
760
+ */
761
+
762
+ GLOBAL(cjpeg_source_ptr)
763
+ jinit_read_ppm(j_compress_ptr cinfo)
764
+ {
765
+ ppm_source_ptr source;
766
+
767
+ /* Create module interface object */
768
+ source = (ppm_source_ptr)
769
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
770
+ sizeof(ppm_source_struct));
771
+ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
772
+ source->pub.start_input = start_input_ppm;
773
+ source->pub.finish_input = finish_input_ppm;
774
+ #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
775
+ source->pub.max_pixels = 0;
776
+ #endif
777
+
778
+ return (cjpeg_source_ptr)source;
779
+ }
780
+
781
+ #endif /* PPM_SUPPORTED */