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,1044 @@
1
+ /*
2
+ * Copyright (C)2009-2019, 2021-2023 D. R. Commander. All Rights Reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * - Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * - Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * - Neither the name of the libjpeg-turbo Project nor the names of its
13
+ * contributors may be used to endorse or promote products derived from this
14
+ * software without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ * POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ #ifdef _MSC_VER
30
+ #define _CRT_SECURE_NO_DEPRECATE
31
+ #endif
32
+
33
+ #include <stdio.h>
34
+ #include <stdlib.h>
35
+ #include <string.h>
36
+ #include <ctype.h>
37
+ #include <math.h>
38
+ #include <errno.h>
39
+ #include <limits.h>
40
+ #include <cdjpeg.h>
41
+ #include "./tjutil.h"
42
+ #include "./turbojpeg.h"
43
+
44
+
45
+ #define THROW(op, err) { \
46
+ printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err); \
47
+ retval = -1; goto bailout; \
48
+ }
49
+ #define THROW_UNIX(m) THROW(m, strerror(errno))
50
+
51
+ char tjErrorStr[JMSG_LENGTH_MAX] = "\0", tjErrorMsg[JMSG_LENGTH_MAX] = "\0";
52
+ int tjErrorLine = -1, tjErrorCode = -1;
53
+
54
+ #define THROW_TJG(m) { \
55
+ printf("ERROR in line %d while %s:\n%s\n", __LINE__, m, \
56
+ tjGetErrorStr2(NULL)); \
57
+ retval = -1; goto bailout; \
58
+ }
59
+
60
+ #define THROW_TJ(m) { \
61
+ int _tjErrorCode = tjGetErrorCode(handle); \
62
+ char *_tjErrorStr = tjGetErrorStr2(handle); \
63
+ \
64
+ if (!(flags & TJFLAG_STOPONWARNING) && _tjErrorCode == TJERR_WARNING) { \
65
+ if (strncmp(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX) || \
66
+ strncmp(tjErrorMsg, m, JMSG_LENGTH_MAX) || \
67
+ tjErrorCode != _tjErrorCode || tjErrorLine != __LINE__) { \
68
+ strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX); \
69
+ tjErrorStr[JMSG_LENGTH_MAX - 1] = '\0'; \
70
+ strncpy(tjErrorMsg, m, JMSG_LENGTH_MAX); \
71
+ tjErrorMsg[JMSG_LENGTH_MAX - 1] = '\0'; \
72
+ tjErrorCode = _tjErrorCode; \
73
+ tjErrorLine = __LINE__; \
74
+ printf("WARNING in line %d while %s:\n%s\n", __LINE__, m, _tjErrorStr); \
75
+ } \
76
+ } else { \
77
+ printf("%s in line %d while %s:\n%s\n", \
78
+ _tjErrorCode == TJERR_WARNING ? "WARNING" : "ERROR", __LINE__, m, \
79
+ _tjErrorStr); \
80
+ retval = -1; goto bailout; \
81
+ } \
82
+ }
83
+
84
+ int flags = TJFLAG_NOREALLOC, compOnly = 0, decompOnly = 0, doYUV = 0,
85
+ quiet = 0, doTile = 0, pf = TJPF_BGR, yuvAlign = 1, doWrite = 1;
86
+ char *ext = "ppm";
87
+ const char *pixFormatStr[TJ_NUMPF] = {
88
+ "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY", "", "", "", "", "CMYK"
89
+ };
90
+ const char *subNameLong[TJ_NUMSAMP] = {
91
+ "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
92
+ };
93
+ const char *csName[TJ_NUMCS] = {
94
+ "RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
95
+ };
96
+ const char *subName[TJ_NUMSAMP] = {
97
+ "444", "422", "420", "GRAY", "440", "411"
98
+ };
99
+ tjscalingfactor *scalingFactors = NULL, sf = { 1, 1 };
100
+ int nsf = 0, xformOp = TJXOP_NONE, xformOpt = 0;
101
+ int (*customFilter) (short *, tjregion, tjregion, int, int, tjtransform *);
102
+ double benchTime = 5.0, warmup = 1.0;
103
+
104
+
105
+ static char *formatName(int subsamp, int cs, char *buf)
106
+ {
107
+ if (cs == TJCS_YCbCr)
108
+ return (char *)subNameLong[subsamp];
109
+ else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
110
+ SNPRINTF(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
111
+ return buf;
112
+ } else
113
+ return (char *)csName[cs];
114
+ }
115
+
116
+
117
+ static char *sigfig(double val, int figs, char *buf, int len)
118
+ {
119
+ char format[80];
120
+ int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val)));
121
+
122
+ if (digitsAfterDecimal < 1)
123
+ SNPRINTF(format, 80, "%%.0f");
124
+ else
125
+ SNPRINTF(format, 80, "%%.%df", digitsAfterDecimal);
126
+ SNPRINTF(buf, len, format, val);
127
+ return buf;
128
+ }
129
+
130
+
131
+ /* Custom DCT filter which produces a negative of the image */
132
+ static int dummyDCTFilter(short *coeffs, tjregion arrayRegion,
133
+ tjregion planeRegion, int componentIndex,
134
+ int transformIndex, tjtransform *transform)
135
+ {
136
+ int i;
137
+
138
+ for (i = 0; i < arrayRegion.w * arrayRegion.h; i++)
139
+ coeffs[i] = -coeffs[i];
140
+ return 0;
141
+ }
142
+
143
+
144
+ /* Decompression test */
145
+ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
146
+ unsigned long *jpegSize, unsigned char *dstBuf, int w, int h,
147
+ int subsamp, int jpegQual, char *fileName, int tilew,
148
+ int tileh)
149
+ {
150
+ char tempStr[1024], sizeStr[24] = "\0", qualStr[13] = "\0", *ptr;
151
+ FILE *file = NULL;
152
+ tjhandle handle = NULL;
153
+ int row, col, iter = 0, dstBufAlloc = 0, retval = 0;
154
+ double elapsed, elapsedDecode;
155
+ int ps = tjPixelSize[pf];
156
+ int scaledw = TJSCALED(w, sf);
157
+ int scaledh = TJSCALED(h, sf);
158
+ int pitch = scaledw * ps;
159
+ int ntilesw = (w + tilew - 1) / tilew, ntilesh = (h + tileh - 1) / tileh;
160
+ unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
161
+
162
+ if (jpegQual > 0) {
163
+ SNPRINTF(qualStr, 13, "_Q%d", jpegQual);
164
+ qualStr[12] = 0;
165
+ }
166
+
167
+ if ((handle = tjInitDecompress()) == NULL)
168
+ THROW_TJ("executing tjInitDecompress()");
169
+
170
+ if (dstBuf == NULL) {
171
+ if ((unsigned long long)pitch * (unsigned long long)scaledh >
172
+ (unsigned long long)((size_t)-1))
173
+ THROW("allocating destination buffer", "Image is too large");
174
+ if ((dstBuf = (unsigned char *)malloc((size_t)pitch * scaledh)) == NULL)
175
+ THROW_UNIX("allocating destination buffer");
176
+ dstBufAlloc = 1;
177
+ }
178
+ /* Set the destination buffer to gray so we know whether the decompressor
179
+ attempted to write to it */
180
+ memset(dstBuf, 127, (size_t)pitch * scaledh);
181
+
182
+ if (doYUV) {
183
+ int width = doTile ? tilew : scaledw;
184
+ int height = doTile ? tileh : scaledh;
185
+ unsigned long yuvSize = tjBufSizeYUV2(width, yuvAlign, height, subsamp);
186
+
187
+ if (yuvSize == (unsigned long)-1)
188
+ THROW_TJ("allocating YUV buffer");
189
+ if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
190
+ THROW_UNIX("allocating YUV buffer");
191
+ memset(yuvBuf, 127, yuvSize);
192
+ }
193
+
194
+ /* Benchmark */
195
+ iter = -1;
196
+ elapsed = elapsedDecode = 0.;
197
+ while (1) {
198
+ int tile = 0;
199
+ double start = getTime();
200
+
201
+ for (row = 0, dstPtr = dstBuf; row < ntilesh;
202
+ row++, dstPtr += (size_t)pitch * tileh) {
203
+ for (col = 0, dstPtr2 = dstPtr; col < ntilesw;
204
+ col++, tile++, dstPtr2 += ps * tilew) {
205
+ int width = doTile ? min(tilew, w - col * tilew) : scaledw;
206
+ int height = doTile ? min(tileh, h - row * tileh) : scaledh;
207
+
208
+ if (doYUV) {
209
+ double startDecode;
210
+
211
+ if (tjDecompressToYUV2(handle, jpegBuf[tile], jpegSize[tile], yuvBuf,
212
+ width, yuvAlign, height, flags) == -1)
213
+ THROW_TJ("executing tjDecompressToYUV2()");
214
+ startDecode = getTime();
215
+ if (tjDecodeYUV(handle, yuvBuf, yuvAlign, subsamp, dstPtr2, width,
216
+ pitch, height, pf, flags) == -1)
217
+ THROW_TJ("executing tjDecodeYUV()");
218
+ if (iter >= 0) elapsedDecode += getTime() - startDecode;
219
+ } else if (tjDecompress2(handle, jpegBuf[tile], jpegSize[tile],
220
+ dstPtr2, width, pitch, height, pf,
221
+ flags) == -1)
222
+ THROW_TJ("executing tjDecompress2()");
223
+ }
224
+ }
225
+ elapsed += getTime() - start;
226
+ if (iter >= 0) {
227
+ iter++;
228
+ if (elapsed >= benchTime) break;
229
+ } else if (elapsed >= warmup) {
230
+ iter = 0;
231
+ elapsed = elapsedDecode = 0.;
232
+ }
233
+ }
234
+ if (doYUV) elapsed -= elapsedDecode;
235
+
236
+ if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
237
+ handle = NULL;
238
+
239
+ if (quiet) {
240
+ printf("%-6s%s",
241
+ sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
242
+ tempStr, 1024),
243
+ quiet == 2 ? "\n" : " ");
244
+ if (doYUV)
245
+ printf("%s\n",
246
+ sigfig((double)(w * h) / 1000000. * (double)iter / elapsedDecode,
247
+ 4, tempStr, 1024));
248
+ else if (quiet != 2) printf("\n");
249
+ } else {
250
+ printf("%s --> Frame rate: %f fps\n",
251
+ doYUV ? "Decomp to YUV" : "Decompress ", (double)iter / elapsed);
252
+ printf(" Throughput: %f Megapixels/sec\n",
253
+ (double)(w * h) / 1000000. * (double)iter / elapsed);
254
+ if (doYUV) {
255
+ printf("YUV Decode --> Frame rate: %f fps\n",
256
+ (double)iter / elapsedDecode);
257
+ printf(" Throughput: %f Megapixels/sec\n",
258
+ (double)(w * h) / 1000000. * (double)iter / elapsedDecode);
259
+ }
260
+ }
261
+
262
+ if (!doWrite) goto bailout;
263
+
264
+ if (sf.num != 1 || sf.denom != 1)
265
+ SNPRINTF(sizeStr, 24, "%d_%d", sf.num, sf.denom);
266
+ else if (tilew != w || tileh != h)
267
+ SNPRINTF(sizeStr, 24, "%dx%d", tilew, tileh);
268
+ else SNPRINTF(sizeStr, 24, "full");
269
+ if (decompOnly)
270
+ SNPRINTF(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
271
+ else
272
+ SNPRINTF(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
273
+ qualStr, sizeStr, ext);
274
+
275
+ if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
276
+ THROW_TJG("saving output image");
277
+ ptr = strrchr(tempStr, '.');
278
+ SNPRINTF(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
279
+ if (srcBuf && sf.num == 1 && sf.denom == 1) {
280
+ if (!quiet) printf("Compression error written to %s.\n", tempStr);
281
+ if (subsamp == TJSAMP_GRAY) {
282
+ unsigned long index, index2;
283
+
284
+ for (row = 0, index = 0; row < h; row++, index += pitch) {
285
+ for (col = 0, index2 = index; col < w; col++, index2 += ps) {
286
+ unsigned long rindex = index2 + tjRedOffset[pf];
287
+ unsigned long gindex = index2 + tjGreenOffset[pf];
288
+ unsigned long bindex = index2 + tjBlueOffset[pf];
289
+ int y = (int)((double)srcBuf[rindex] * 0.299 +
290
+ (double)srcBuf[gindex] * 0.587 +
291
+ (double)srcBuf[bindex] * 0.114 + 0.5);
292
+
293
+ if (y > 255) y = 255;
294
+ if (y < 0) y = 0;
295
+ dstBuf[rindex] = (unsigned char)abs(dstBuf[rindex] - y);
296
+ dstBuf[gindex] = (unsigned char)abs(dstBuf[gindex] - y);
297
+ dstBuf[bindex] = (unsigned char)abs(dstBuf[bindex] - y);
298
+ }
299
+ }
300
+ } else {
301
+ for (row = 0; row < h; row++)
302
+ for (col = 0; col < w * ps; col++)
303
+ dstBuf[pitch * row + col] =
304
+ (unsigned char)abs(dstBuf[pitch * row + col] -
305
+ srcBuf[pitch * row + col]);
306
+ }
307
+ if (tjSaveImage(tempStr, dstBuf, w, 0, h, pf, flags) == -1)
308
+ THROW_TJG("saving output image");
309
+ }
310
+
311
+ bailout:
312
+ if (file) fclose(file);
313
+ if (handle) tjDestroy(handle);
314
+ if (dstBufAlloc) free(dstBuf);
315
+ free(yuvBuf);
316
+ return retval;
317
+ }
318
+
319
+
320
+ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
321
+ int jpegQual, char *fileName)
322
+ {
323
+ char tempStr[1024], tempStr2[80];
324
+ FILE *file = NULL;
325
+ tjhandle handle = NULL;
326
+ unsigned char **jpegBuf = NULL, *yuvBuf = NULL, *tmpBuf = NULL, *srcPtr,
327
+ *srcPtr2;
328
+ double start, elapsed, elapsedEncode;
329
+ int totalJpegSize = 0, row, col, i, tilew = w, tileh = h, retval = 0;
330
+ int iter;
331
+ unsigned long *jpegSize = NULL, yuvSize = 0;
332
+ int ps = tjPixelSize[pf];
333
+ int ntilesw = 1, ntilesh = 1, pitch = w * ps;
334
+ const char *pfStr = pixFormatStr[pf];
335
+
336
+ if ((unsigned long long)pitch * (unsigned long long)h >
337
+ (unsigned long long)((size_t)-1))
338
+ THROW("allocating temporary image buffer", "Image is too large");
339
+ if ((tmpBuf = (unsigned char *)malloc((size_t)pitch * h)) == NULL)
340
+ THROW_UNIX("allocating temporary image buffer");
341
+
342
+ if (!quiet)
343
+ printf(">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pfStr,
344
+ (flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down",
345
+ subNameLong[subsamp], jpegQual);
346
+
347
+ for (tilew = doTile ? 8 : w, tileh = doTile ? 8 : h; ;
348
+ tilew *= 2, tileh *= 2) {
349
+ if (tilew > w) tilew = w;
350
+ if (tileh > h) tileh = h;
351
+ ntilesw = (w + tilew - 1) / tilew;
352
+ ntilesh = (h + tileh - 1) / tileh;
353
+
354
+ if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
355
+ ntilesw * ntilesh)) == NULL)
356
+ THROW_UNIX("allocating JPEG tile array");
357
+ memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
358
+ if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
359
+ ntilesw * ntilesh)) == NULL)
360
+ THROW_UNIX("allocating JPEG size array");
361
+ memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
362
+
363
+ if ((flags & TJFLAG_NOREALLOC) != 0)
364
+ for (i = 0; i < ntilesw * ntilesh; i++) {
365
+ if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
366
+ THROW("getting buffer size", "Image is too large");
367
+ if ((jpegBuf[i] = (unsigned char *)
368
+ tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
369
+ THROW_UNIX("allocating JPEG tiles");
370
+ }
371
+
372
+ /* Compression test */
373
+ if (quiet == 1)
374
+ printf("%-4s (%s) %-5s %-3d ", pfStr,
375
+ (flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", subNameLong[subsamp],
376
+ jpegQual);
377
+ for (i = 0; i < h; i++)
378
+ memcpy(&tmpBuf[pitch * i], &srcBuf[w * ps * i], w * ps);
379
+ if ((handle = tjInitCompress()) == NULL)
380
+ THROW_TJ("executing tjInitCompress()");
381
+
382
+ if (doYUV) {
383
+ yuvSize = tjBufSizeYUV2(tilew, yuvAlign, tileh, subsamp);
384
+ if (yuvSize == (unsigned long)-1)
385
+ THROW_TJ("allocating YUV buffer");
386
+ if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
387
+ THROW_UNIX("allocating YUV buffer");
388
+ memset(yuvBuf, 127, yuvSize);
389
+ }
390
+
391
+ /* Benchmark */
392
+ iter = -1;
393
+ elapsed = elapsedEncode = 0.;
394
+ while (1) {
395
+ int tile = 0;
396
+
397
+ totalJpegSize = 0;
398
+ start = getTime();
399
+ for (row = 0, srcPtr = srcBuf; row < ntilesh;
400
+ row++, srcPtr += pitch * tileh) {
401
+ for (col = 0, srcPtr2 = srcPtr; col < ntilesw;
402
+ col++, tile++, srcPtr2 += ps * tilew) {
403
+ int width = min(tilew, w - col * tilew);
404
+ int height = min(tileh, h - row * tileh);
405
+
406
+ if (doYUV) {
407
+ double startEncode = getTime();
408
+
409
+ if (tjEncodeYUV3(handle, srcPtr2, width, pitch, height, pf, yuvBuf,
410
+ yuvAlign, subsamp, flags) == -1)
411
+ THROW_TJ("executing tjEncodeYUV3()");
412
+ if (iter >= 0) elapsedEncode += getTime() - startEncode;
413
+ if (tjCompressFromYUV(handle, yuvBuf, width, yuvAlign, height,
414
+ subsamp, &jpegBuf[tile], &jpegSize[tile],
415
+ jpegQual, flags) == -1)
416
+ THROW_TJ("executing tjCompressFromYUV()");
417
+ } else {
418
+ if (tjCompress2(handle, srcPtr2, width, pitch, height, pf,
419
+ &jpegBuf[tile], &jpegSize[tile], subsamp, jpegQual,
420
+ flags) == -1)
421
+ THROW_TJ("executing tjCompress2()");
422
+ }
423
+ totalJpegSize += jpegSize[tile];
424
+ }
425
+ }
426
+ elapsed += getTime() - start;
427
+ if (iter >= 0) {
428
+ iter++;
429
+ if (elapsed >= benchTime) break;
430
+ } else if (elapsed >= warmup) {
431
+ iter = 0;
432
+ elapsed = elapsedEncode = 0.;
433
+ }
434
+ }
435
+ if (doYUV) elapsed -= elapsedEncode;
436
+
437
+ if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
438
+ handle = NULL;
439
+
440
+ if (quiet == 1) printf("%-5d %-5d ", tilew, tileh);
441
+ if (quiet) {
442
+ if (doYUV)
443
+ printf("%-6s%s",
444
+ sigfig((double)(w * h) / 1000000. *
445
+ (double)iter / elapsedEncode, 4, tempStr, 1024),
446
+ quiet == 2 ? "\n" : " ");
447
+ printf("%-6s%s",
448
+ sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
449
+ tempStr, 1024),
450
+ quiet == 2 ? "\n" : " ");
451
+ printf("%-6s%s",
452
+ sigfig((double)(w * h * ps) / (double)totalJpegSize, 4, tempStr2,
453
+ 80),
454
+ quiet == 2 ? "\n" : " ");
455
+ } else {
456
+ printf("\n%s size: %d x %d\n", doTile ? "Tile" : "Image", tilew, tileh);
457
+ if (doYUV) {
458
+ printf("Encode YUV --> Frame rate: %f fps\n",
459
+ (double)iter / elapsedEncode);
460
+ printf(" Output image size: %lu bytes\n", yuvSize);
461
+ printf(" Compression ratio: %f:1\n",
462
+ (double)(w * h * ps) / (double)yuvSize);
463
+ printf(" Throughput: %f Megapixels/sec\n",
464
+ (double)(w * h) / 1000000. * (double)iter / elapsedEncode);
465
+ printf(" Output bit stream: %f Megabits/sec\n",
466
+ (double)yuvSize * 8. / 1000000. * (double)iter / elapsedEncode);
467
+ }
468
+ printf("%s --> Frame rate: %f fps\n",
469
+ doYUV ? "Comp from YUV" : "Compress ",
470
+ (double)iter / elapsed);
471
+ printf(" Output image size: %d bytes\n",
472
+ totalJpegSize);
473
+ printf(" Compression ratio: %f:1\n",
474
+ (double)(w * h * ps) / (double)totalJpegSize);
475
+ printf(" Throughput: %f Megapixels/sec\n",
476
+ (double)(w * h) / 1000000. * (double)iter / elapsed);
477
+ printf(" Output bit stream: %f Megabits/sec\n",
478
+ (double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
479
+ }
480
+ if (tilew == w && tileh == h && doWrite) {
481
+ SNPRINTF(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
482
+ jpegQual);
483
+ if ((file = fopen(tempStr, "wb")) == NULL)
484
+ THROW_UNIX("opening reference image");
485
+ if (fwrite(jpegBuf[0], jpegSize[0], 1, file) != 1)
486
+ THROW_UNIX("writing reference image");
487
+ fclose(file); file = NULL;
488
+ if (!quiet) printf("Reference image written to %s\n", tempStr);
489
+ }
490
+
491
+ /* Decompression test */
492
+ if (!compOnly) {
493
+ if (decomp(srcBuf, jpegBuf, jpegSize, tmpBuf, w, h, subsamp, jpegQual,
494
+ fileName, tilew, tileh) == -1)
495
+ goto bailout;
496
+ } else if (quiet == 1) printf("N/A\n");
497
+
498
+ for (i = 0; i < ntilesw * ntilesh; i++) {
499
+ tjFree(jpegBuf[i]);
500
+ jpegBuf[i] = NULL;
501
+ }
502
+ free(jpegBuf); jpegBuf = NULL;
503
+ free(jpegSize); jpegSize = NULL;
504
+ if (doYUV) {
505
+ free(yuvBuf); yuvBuf = NULL;
506
+ }
507
+
508
+ if (tilew == w && tileh == h) break;
509
+ }
510
+
511
+ bailout:
512
+ if (file) fclose(file);
513
+ if (jpegBuf) {
514
+ for (i = 0; i < ntilesw * ntilesh; i++)
515
+ tjFree(jpegBuf[i]);
516
+ }
517
+ free(jpegBuf);
518
+ free(yuvBuf);
519
+ free(jpegSize);
520
+ free(tmpBuf);
521
+ if (handle) tjDestroy(handle);
522
+ return retval;
523
+ }
524
+
525
+
526
+ static int decompTest(char *fileName)
527
+ {
528
+ FILE *file = NULL;
529
+ tjhandle handle = NULL;
530
+ unsigned char **jpegBuf = NULL, *srcBuf = NULL;
531
+ unsigned long *jpegSize = NULL, srcSize, totalJpegSize;
532
+ tjtransform *t = NULL;
533
+ double start, elapsed;
534
+ int ps = tjPixelSize[pf], tile, row, col, i, iter, retval = 0, decompsrc = 0;
535
+ char *temp = NULL, tempStr[80], tempStr2[80];
536
+ /* Original image */
537
+ int w = 0, h = 0, minTile, tilew, tileh, ntilesw = 1, ntilesh = 1,
538
+ subsamp = -1, cs = -1;
539
+ /* Transformed image */
540
+ int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
541
+
542
+ if ((file = fopen(fileName, "rb")) == NULL)
543
+ THROW_UNIX("opening file");
544
+ if (fseek(file, 0, SEEK_END) < 0 ||
545
+ (srcSize = ftell(file)) == (unsigned long)-1)
546
+ THROW_UNIX("determining file size");
547
+ if ((srcBuf = (unsigned char *)malloc(srcSize)) == NULL)
548
+ THROW_UNIX("allocating memory");
549
+ if (fseek(file, 0, SEEK_SET) < 0)
550
+ THROW_UNIX("setting file position");
551
+ if (fread(srcBuf, srcSize, 1, file) < 1)
552
+ THROW_UNIX("reading JPEG data");
553
+ fclose(file); file = NULL;
554
+
555
+ temp = strrchr(fileName, '.');
556
+ if (temp != NULL) *temp = '\0';
557
+
558
+ if ((handle = tjInitTransform()) == NULL)
559
+ THROW_TJ("executing tjInitTransform()");
560
+ if (tjDecompressHeader3(handle, srcBuf, srcSize, &w, &h, &subsamp,
561
+ &cs) == -1)
562
+ THROW_TJ("executing tjDecompressHeader3()");
563
+ if (w < 1 || h < 1)
564
+ THROW("reading JPEG header", "Invalid image dimensions");
565
+ if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
566
+ pf = TJPF_CMYK; ps = tjPixelSize[pf];
567
+ }
568
+
569
+ if (quiet == 1) {
570
+ printf("All performance values in Mpixels/sec\n\n");
571
+ printf("Pixel JPEG JPEG %s %s Xform Comp Decomp ",
572
+ doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
573
+ if (doYUV) printf("Decode");
574
+ printf("\n");
575
+ printf("Format CS Subsamp Width Height Perf Ratio Perf ");
576
+ if (doYUV) printf("Perf");
577
+ printf("\n\n");
578
+ } else if (!quiet)
579
+ printf(">>>>> JPEG %s --> %s (%s) <<<<<\n",
580
+ formatName(subsamp, cs, tempStr), pixFormatStr[pf],
581
+ (flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down");
582
+
583
+ minTile = max(tjMCUWidth[subsamp], tjMCUHeight[subsamp]);
584
+ for (tilew = doTile ? minTile : w, tileh = doTile ? minTile : h; ;
585
+ tilew *= 2, tileh *= 2) {
586
+ if (tilew > w) tilew = w;
587
+ if (tileh > h) tileh = h;
588
+ ntilesw = (w + tilew - 1) / tilew;
589
+ ntilesh = (h + tileh - 1) / tileh;
590
+
591
+ if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
592
+ ntilesw * ntilesh)) == NULL)
593
+ THROW_UNIX("allocating JPEG tile array");
594
+ memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
595
+ if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
596
+ ntilesw * ntilesh)) == NULL)
597
+ THROW_UNIX("allocating JPEG size array");
598
+ memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
599
+
600
+ if ((flags & TJFLAG_NOREALLOC) != 0 &&
601
+ (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter))
602
+ for (i = 0; i < ntilesw * ntilesh; i++) {
603
+ unsigned long jpegBufSize;
604
+
605
+ if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
606
+ xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270)
607
+ jpegBufSize = tjBufSize(tileh, tilew, subsamp);
608
+ else
609
+ jpegBufSize = tjBufSize(tilew, tileh, subsamp);
610
+ if (jpegBufSize > (unsigned long)INT_MAX)
611
+ THROW("getting buffer size", "Image is too large");
612
+ if ((jpegBuf[i] = (unsigned char *)tjAlloc(jpegBufSize)) == NULL)
613
+ THROW_UNIX("allocating JPEG tiles");
614
+ }
615
+
616
+ tw = w; th = h; ttilew = tilew; ttileh = tileh;
617
+ if (!quiet) {
618
+ printf("\n%s size: %d x %d", doTile ? "Tile" : "Image", ttilew, ttileh);
619
+ if (sf.num != 1 || sf.denom != 1)
620
+ printf(" --> %d x %d", TJSCALED(tw, sf), TJSCALED(th, sf));
621
+ printf("\n");
622
+ } else if (quiet == 1) {
623
+ printf("%-4s (%s) %-5s %-5s ", pixFormatStr[pf],
624
+ (flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", csName[cs],
625
+ subNameLong[subsamp]);
626
+ printf("%-5d %-5d ", tilew, tileh);
627
+ }
628
+
629
+ tsubsamp = subsamp;
630
+ if (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter) {
631
+ if ((t = (tjtransform *)malloc(sizeof(tjtransform) * ntilesw *
632
+ ntilesh)) == NULL)
633
+ THROW_UNIX("allocating image transform array");
634
+
635
+ if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
636
+ xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
637
+ tw = h; th = w; ttilew = tileh; ttileh = tilew;
638
+ }
639
+
640
+ if (xformOpt & TJXOPT_GRAY) tsubsamp = TJSAMP_GRAY;
641
+ if (xformOp == TJXOP_HFLIP || xformOp == TJXOP_ROT180)
642
+ tw = tw - (tw % tjMCUWidth[tsubsamp]);
643
+ if (xformOp == TJXOP_VFLIP || xformOp == TJXOP_ROT180)
644
+ th = th - (th % tjMCUHeight[tsubsamp]);
645
+ if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT90)
646
+ tw = tw - (tw % tjMCUHeight[tsubsamp]);
647
+ if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT270)
648
+ th = th - (th % tjMCUWidth[tsubsamp]);
649
+ tntilesw = (tw + ttilew - 1) / ttilew;
650
+ tntilesh = (th + ttileh - 1) / ttileh;
651
+
652
+ if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
653
+ xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
654
+ if (tsubsamp == TJSAMP_422) tsubsamp = TJSAMP_440;
655
+ else if (tsubsamp == TJSAMP_440) tsubsamp = TJSAMP_422;
656
+ }
657
+
658
+ for (row = 0, tile = 0; row < tntilesh; row++) {
659
+ for (col = 0; col < tntilesw; col++, tile++) {
660
+ t[tile].r.w = min(ttilew, tw - col * ttilew);
661
+ t[tile].r.h = min(ttileh, th - row * ttileh);
662
+ t[tile].r.x = col * ttilew;
663
+ t[tile].r.y = row * ttileh;
664
+ t[tile].op = xformOp;
665
+ t[tile].options = xformOpt | TJXOPT_TRIM;
666
+ t[tile].customFilter = customFilter;
667
+ if (t[tile].options & TJXOPT_NOOUTPUT && jpegBuf[tile]) {
668
+ tjFree(jpegBuf[tile]); jpegBuf[tile] = NULL;
669
+ }
670
+ }
671
+ }
672
+
673
+ iter = -1;
674
+ elapsed = 0.;
675
+ while (1) {
676
+ start = getTime();
677
+ if (tjTransform(handle, srcBuf, srcSize, tntilesw * tntilesh, jpegBuf,
678
+ jpegSize, t, flags) == -1)
679
+ THROW_TJ("executing tjTransform()");
680
+ elapsed += getTime() - start;
681
+ if (iter >= 0) {
682
+ iter++;
683
+ if (elapsed >= benchTime) break;
684
+ } else if (elapsed >= warmup) {
685
+ iter = 0;
686
+ elapsed = 0.;
687
+ }
688
+ }
689
+
690
+ free(t); t = NULL;
691
+
692
+ for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++)
693
+ totalJpegSize += jpegSize[tile];
694
+
695
+ if (quiet) {
696
+ printf("%-6s%s%-6s%s",
697
+ sigfig((double)(w * h) / 1000000. / elapsed, 4, tempStr, 80),
698
+ quiet == 2 ? "\n" : " ",
699
+ sigfig((double)(w * h * ps) / (double)totalJpegSize, 4,
700
+ tempStr2, 80),
701
+ quiet == 2 ? "\n" : " ");
702
+ } else {
703
+ printf("Transform --> Frame rate: %f fps\n",
704
+ 1.0 / elapsed);
705
+ printf(" Output image size: %lu bytes\n",
706
+ totalJpegSize);
707
+ printf(" Compression ratio: %f:1\n",
708
+ (double)(w * h * ps) / (double)totalJpegSize);
709
+ printf(" Throughput: %f Megapixels/sec\n",
710
+ (double)(w * h) / 1000000. / elapsed);
711
+ printf(" Output bit stream: %f Megabits/sec\n",
712
+ (double)totalJpegSize * 8. / 1000000. / elapsed);
713
+ }
714
+ } else {
715
+ if (quiet == 1) printf("N/A N/A ");
716
+ tjFree(jpegBuf[0]);
717
+ jpegBuf[0] = NULL;
718
+ decompsrc = 1;
719
+ }
720
+
721
+ if (w == tilew) ttilew = tw;
722
+ if (h == tileh) ttileh = th;
723
+ if (!(xformOpt & TJXOPT_NOOUTPUT)) {
724
+ if (decomp(NULL, decompsrc ? &srcBuf : jpegBuf,
725
+ decompsrc ? &srcSize : jpegSize, NULL, tw, th, tsubsamp, 0,
726
+ fileName, ttilew, ttileh) == -1)
727
+ goto bailout;
728
+ } else if (quiet == 1) printf("N/A\n");
729
+
730
+ for (i = 0; i < ntilesw * ntilesh; i++) {
731
+ tjFree(jpegBuf[i]);
732
+ jpegBuf[i] = NULL;
733
+ }
734
+ free(jpegBuf); jpegBuf = NULL;
735
+ free(jpegSize); jpegSize = NULL;
736
+
737
+ if (tilew == w && tileh == h) break;
738
+ }
739
+
740
+ bailout:
741
+ if (file) fclose(file);
742
+ if (jpegBuf) {
743
+ for (i = 0; i < ntilesw * ntilesh; i++)
744
+ tjFree(jpegBuf[i]);
745
+ }
746
+ free(jpegBuf);
747
+ free(jpegSize);
748
+ free(srcBuf);
749
+ free(t);
750
+ if (handle) { tjDestroy(handle); handle = NULL; }
751
+ return retval;
752
+ }
753
+
754
+
755
+ static void usage(char *progName)
756
+ {
757
+ int i;
758
+
759
+ printf("USAGE: %s\n", progName);
760
+ printf(" <Inputimage (BMP|PPM)> <Quality> [options]\n\n");
761
+ printf(" %s\n", progName);
762
+ printf(" <Inputimage (JPG)> [options]\n\n");
763
+ printf("Options:\n\n");
764
+ printf("-alloc = Dynamically allocate JPEG buffers\n");
765
+ printf("-bmp = Use Windows Bitmap format for output images [default = PPM]\n");
766
+ printf("-bottomup = Use bottom-up row order for packed-pixel source/destination buffers\n");
767
+ printf("-tile = Compress/transform the input image into separate JPEG tiles of varying\n");
768
+ printf(" sizes (useful for measuring JPEG overhead)\n");
769
+ printf("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =\n");
770
+ printf(" Use the specified pixel format for packed-pixel source/destination buffers\n");
771
+ printf(" [default = BGR]\n");
772
+ printf("-cmyk = Indirectly test YCCK JPEG compression/decompression\n");
773
+ printf(" (use the CMYK pixel format for packed-pixel source/destination buffers)\n");
774
+ printf("-fastupsample = Use the fastest chrominance upsampling algorithm available\n");
775
+ printf("-fastdct = Use the fastest DCT/IDCT algorithm available\n");
776
+ printf("-accuratedct = Use the most accurate DCT/IDCT algorithm available\n");
777
+ printf("-progressive = Use progressive entropy coding in JPEG images generated by\n");
778
+ printf(" compression and transform operations\n");
779
+ printf("-subsamp <s> = When compressing, use the specified level of chrominance\n");
780
+ printf(" subsampling (<s> = 444, 422, 440, 420, 411, or GRAY) [default = test\n");
781
+ printf(" Grayscale, 4:2:0, 4:2:2, and 4:4:4 in sequence]\n");
782
+ printf("-quiet = Output results in tabular rather than verbose format\n");
783
+ printf("-yuv = Compress from/decompress to intermediate planar YUV images\n");
784
+ printf("-yuvpad <p> = The number of bytes by which each row in each plane of an\n");
785
+ printf(" intermediate YUV image is evenly divisible (must be a power of 2)\n");
786
+ printf(" [default = 1]\n");
787
+ printf("-scale M/N = When decompressing, scale the width/height of the JPEG image by a\n");
788
+ printf(" factor of M/N (M/N = ");
789
+ for (i = 0; i < nsf; i++) {
790
+ printf("%d/%d", scalingFactors[i].num, scalingFactors[i].denom);
791
+ if (nsf == 2 && i != nsf - 1) printf(" or ");
792
+ else if (nsf > 2) {
793
+ if (i != nsf - 1) printf(", ");
794
+ if (i == nsf - 2) printf("or ");
795
+ }
796
+ if (i % 8 == 0 && i != 0) printf("\n ");
797
+ }
798
+ printf(")\n");
799
+ printf("-hflip, -vflip, -transpose, -transverse, -rot90, -rot180, -rot270 =\n");
800
+ printf(" Perform the specified lossless transform operation on the input image\n");
801
+ printf(" prior to decompression (these operations are mutually exclusive)\n");
802
+ printf("-grayscale = Transform the input image into a grayscale JPEG image prior to\n");
803
+ printf(" decompression (can be combined with the other transform operations above)\n");
804
+ printf("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)\n");
805
+ printf(" when transforming the input image\n");
806
+ printf("-benchtime <t> = Run each benchmark for at least <t> seconds [default = 5.0]\n");
807
+ printf("-warmup <t> = Run each benchmark for <t> seconds [default = 1.0] prior to\n");
808
+ printf(" starting the timer, in order to prime the caches and thus improve the\n");
809
+ printf(" consistency of the benchmark results\n");
810
+ printf("-componly = Stop after running compression tests. Do not test decompression.\n");
811
+ printf("-nowrite = Do not write reference or output images (improves consistency of\n");
812
+ printf(" benchmark results)\n");
813
+ printf("-limitscans = Refuse to decompress or transform progressive JPEG images that\n");
814
+ printf(" have an unreasonably large number of scans\n");
815
+ printf("-stoponwarning = Immediately discontinue the current\n");
816
+ printf(" compression/decompression/transform operation if a warning (non-fatal\n");
817
+ printf(" error) occurs\n\n");
818
+ printf("NOTE: If the quality is specified as a range (e.g. 90-100), a separate\n");
819
+ printf("test will be performed for all quality values in the range.\n\n");
820
+ exit(1);
821
+ }
822
+
823
+
824
+ int main(int argc, char *argv[])
825
+ {
826
+ unsigned char *srcBuf = NULL;
827
+ int w = 0, h = 0, i, j, minQual = -1, maxQual = -1;
828
+ char *temp;
829
+ int minArg = 2, retval = 0, subsamp = -1;
830
+
831
+ if ((scalingFactors = tjGetScalingFactors(&nsf)) == NULL || nsf == 0)
832
+ THROW("executing tjGetScalingFactors()", tjGetErrorStr());
833
+
834
+ if (argc < minArg) usage(argv[0]);
835
+
836
+ temp = strrchr(argv[1], '.');
837
+ if (temp != NULL) {
838
+ if (!strcasecmp(temp, ".bmp")) ext = "bmp";
839
+ if (!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg"))
840
+ decompOnly = 1;
841
+ }
842
+
843
+ printf("\n");
844
+
845
+ if (!decompOnly) {
846
+ minArg = 3;
847
+ if (argc < minArg) usage(argv[0]);
848
+ if ((minQual = atoi(argv[2])) < 1 || minQual > 100) {
849
+ puts("ERROR: Quality must be between 1 and 100.");
850
+ exit(1);
851
+ }
852
+ if ((temp = strchr(argv[2], '-')) != NULL && strlen(temp) > 1 &&
853
+ sscanf(&temp[1], "%d", &maxQual) == 1 && maxQual > minQual &&
854
+ maxQual >= 1 && maxQual <= 100) {}
855
+ else maxQual = minQual;
856
+ }
857
+
858
+ if (argc > minArg) {
859
+ for (i = minArg; i < argc; i++) {
860
+ if (!strcasecmp(argv[i], "-tile")) {
861
+ doTile = 1; xformOpt |= TJXOPT_CROP;
862
+ } else if (!strcasecmp(argv[i], "-fastupsample")) {
863
+ printf("Using fastest upsampling algorithm\n\n");
864
+ flags |= TJFLAG_FASTUPSAMPLE;
865
+ } else if (!strcasecmp(argv[i], "-fastdct")) {
866
+ printf("Using fastest DCT/IDCT algorithm\n\n");
867
+ flags |= TJFLAG_FASTDCT;
868
+ } else if (!strcasecmp(argv[i], "-accuratedct")) {
869
+ printf("Using most accurate DCT/IDCT algorithm\n\n");
870
+ flags |= TJFLAG_ACCURATEDCT;
871
+ } else if (!strcasecmp(argv[i], "-progressive")) {
872
+ printf("Using progressive entropy coding\n\n");
873
+ flags |= TJFLAG_PROGRESSIVE;
874
+ xformOpt |= TJXOPT_PROGRESSIVE;
875
+ } else if (!strcasecmp(argv[i], "-rgb"))
876
+ pf = TJPF_RGB;
877
+ else if (!strcasecmp(argv[i], "-rgbx"))
878
+ pf = TJPF_RGBX;
879
+ else if (!strcasecmp(argv[i], "-bgr"))
880
+ pf = TJPF_BGR;
881
+ else if (!strcasecmp(argv[i], "-bgrx"))
882
+ pf = TJPF_BGRX;
883
+ else if (!strcasecmp(argv[i], "-xbgr"))
884
+ pf = TJPF_XBGR;
885
+ else if (!strcasecmp(argv[i], "-xrgb"))
886
+ pf = TJPF_XRGB;
887
+ else if (!strcasecmp(argv[i], "-cmyk"))
888
+ pf = TJPF_CMYK;
889
+ else if (!strcasecmp(argv[i], "-bottomup"))
890
+ flags |= TJFLAG_BOTTOMUP;
891
+ else if (!strcasecmp(argv[i], "-quiet"))
892
+ quiet = 1;
893
+ else if (!strcasecmp(argv[i], "-qq"))
894
+ quiet = 2;
895
+ else if (!strcasecmp(argv[i], "-scale") && i < argc - 1) {
896
+ int temp1 = 0, temp2 = 0, match = 0;
897
+
898
+ if (sscanf(argv[++i], "%d/%d", &temp1, &temp2) == 2) {
899
+ for (j = 0; j < nsf; j++) {
900
+ if ((double)temp1 / (double)temp2 ==
901
+ (double)scalingFactors[j].num /
902
+ (double)scalingFactors[j].denom) {
903
+ sf = scalingFactors[j];
904
+ match = 1; break;
905
+ }
906
+ }
907
+ if (!match) usage(argv[0]);
908
+ } else usage(argv[0]);
909
+ } else if (!strcasecmp(argv[i], "-hflip"))
910
+ xformOp = TJXOP_HFLIP;
911
+ else if (!strcasecmp(argv[i], "-vflip"))
912
+ xformOp = TJXOP_VFLIP;
913
+ else if (!strcasecmp(argv[i], "-transpose"))
914
+ xformOp = TJXOP_TRANSPOSE;
915
+ else if (!strcasecmp(argv[i], "-transverse"))
916
+ xformOp = TJXOP_TRANSVERSE;
917
+ else if (!strcasecmp(argv[i], "-rot90"))
918
+ xformOp = TJXOP_ROT90;
919
+ else if (!strcasecmp(argv[i], "-rot180"))
920
+ xformOp = TJXOP_ROT180;
921
+ else if (!strcasecmp(argv[i], "-rot270"))
922
+ xformOp = TJXOP_ROT270;
923
+ else if (!strcasecmp(argv[i], "-grayscale"))
924
+ xformOpt |= TJXOPT_GRAY;
925
+ else if (!strcasecmp(argv[i], "-custom"))
926
+ customFilter = dummyDCTFilter;
927
+ else if (!strcasecmp(argv[i], "-nooutput"))
928
+ xformOpt |= TJXOPT_NOOUTPUT;
929
+ else if (!strcasecmp(argv[i], "-copynone"))
930
+ xformOpt |= TJXOPT_COPYNONE;
931
+ else if (!strcasecmp(argv[i], "-benchtime") && i < argc - 1) {
932
+ double tempd = atof(argv[++i]);
933
+
934
+ if (tempd > 0.0) benchTime = tempd;
935
+ else usage(argv[0]);
936
+ } else if (!strcasecmp(argv[i], "-warmup") && i < argc - 1) {
937
+ double tempd = atof(argv[++i]);
938
+
939
+ if (tempd >= 0.0) warmup = tempd;
940
+ else usage(argv[0]);
941
+ printf("Warmup time = %.1f seconds\n\n", warmup);
942
+ } else if (!strcasecmp(argv[i], "-alloc"))
943
+ flags &= (~TJFLAG_NOREALLOC);
944
+ else if (!strcasecmp(argv[i], "-bmp"))
945
+ ext = "bmp";
946
+ else if (!strcasecmp(argv[i], "-yuv")) {
947
+ printf("Testing planar YUV encoding/decoding\n\n");
948
+ doYUV = 1;
949
+ } else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) {
950
+ int tempi = atoi(argv[++i]);
951
+
952
+ if (tempi >= 1 && (tempi & (tempi - 1)) == 0) yuvAlign = tempi;
953
+ else usage(argv[0]);
954
+ } else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) {
955
+ i++;
956
+ if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY;
957
+ else {
958
+ int tempi = atoi(argv[i]);
959
+
960
+ switch (tempi) {
961
+ case 444: subsamp = TJSAMP_444; break;
962
+ case 422: subsamp = TJSAMP_422; break;
963
+ case 440: subsamp = TJSAMP_440; break;
964
+ case 420: subsamp = TJSAMP_420; break;
965
+ case 411: subsamp = TJSAMP_411; break;
966
+ default: usage(argv[0]);
967
+ }
968
+ }
969
+ } else if (!strcasecmp(argv[i], "-componly"))
970
+ compOnly = 1;
971
+ else if (!strcasecmp(argv[i], "-nowrite"))
972
+ doWrite = 0;
973
+ else if (!strcasecmp(argv[i], "-limitscans"))
974
+ flags |= TJFLAG_LIMITSCANS;
975
+ else if (!strcasecmp(argv[i], "-stoponwarning"))
976
+ flags |= TJFLAG_STOPONWARNING;
977
+ else usage(argv[0]);
978
+ }
979
+ }
980
+
981
+ if ((sf.num != 1 || sf.denom != 1) && doTile) {
982
+ printf("Disabling tiled compression/decompression tests, because those tests do not\n");
983
+ printf("work when scaled decompression is enabled.\n\n");
984
+ doTile = 0; xformOpt &= (~TJXOPT_CROP);
985
+ }
986
+
987
+ if ((flags & TJFLAG_NOREALLOC) == 0 && doTile) {
988
+ printf("Disabling tiled compression/decompression tests, because those tests do not\n");
989
+ printf("work when dynamic JPEG buffer allocation is enabled.\n\n");
990
+ doTile = 0; xformOpt &= (~TJXOPT_CROP);
991
+ }
992
+
993
+ if (!decompOnly) {
994
+ if ((srcBuf = tjLoadImage(argv[1], &w, 1, &h, &pf, flags)) == NULL)
995
+ THROW_TJG("loading input image");
996
+ temp = strrchr(argv[1], '.');
997
+ if (temp != NULL) *temp = '\0';
998
+ }
999
+
1000
+ if (quiet == 1 && !decompOnly) {
1001
+ printf("All performance values in Mpixels/sec\n\n");
1002
+ printf("Pixel JPEG JPEG %s %s ",
1003
+ doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
1004
+ if (doYUV) printf("Encode ");
1005
+ printf("Comp Comp Decomp ");
1006
+ if (doYUV) printf("Decode");
1007
+ printf("\n");
1008
+ printf("Format Subsamp Qual Width Height ");
1009
+ if (doYUV) printf("Perf ");
1010
+ printf("Perf Ratio Perf ");
1011
+ if (doYUV) printf("Perf");
1012
+ printf("\n\n");
1013
+ }
1014
+
1015
+ if (decompOnly) {
1016
+ decompTest(argv[1]);
1017
+ printf("\n");
1018
+ goto bailout;
1019
+ }
1020
+ if (subsamp >= 0 && subsamp < TJ_NUMSAMP) {
1021
+ for (i = maxQual; i >= minQual; i--)
1022
+ fullTest(srcBuf, w, h, subsamp, i, argv[1]);
1023
+ printf("\n");
1024
+ } else {
1025
+ if (pf != TJPF_CMYK) {
1026
+ for (i = maxQual; i >= minQual; i--)
1027
+ fullTest(srcBuf, w, h, TJSAMP_GRAY, i, argv[1]);
1028
+ printf("\n");
1029
+ }
1030
+ for (i = maxQual; i >= minQual; i--)
1031
+ fullTest(srcBuf, w, h, TJSAMP_420, i, argv[1]);
1032
+ printf("\n");
1033
+ for (i = maxQual; i >= minQual; i--)
1034
+ fullTest(srcBuf, w, h, TJSAMP_422, i, argv[1]);
1035
+ printf("\n");
1036
+ for (i = maxQual; i >= minQual; i--)
1037
+ fullTest(srcBuf, w, h, TJSAMP_444, i, argv[1]);
1038
+ printf("\n");
1039
+ }
1040
+
1041
+ bailout:
1042
+ tjFree(srcBuf);
1043
+ return retval;
1044
+ }