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,1784 @@
1
+ /*
2
+ * Copyright (C)2009-2015, 2017, 2020-2021, 2023 D. R. Commander.
3
+ * All Rights Reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * - Redistributions of source code must retain the above copyright notice,
9
+ * this list of conditions and the following disclaimer.
10
+ * - Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the documentation
12
+ * and/or other materials provided with the distribution.
13
+ * - Neither the name of the libjpeg-turbo Project nor the names of its
14
+ * contributors may be used to endorse or promote products derived from this
15
+ * software without specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
18
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ * POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #ifndef __TURBOJPEG_H__
31
+ #define __TURBOJPEG_H__
32
+
33
+ #if defined(_WIN32) && defined(DLLDEFINE)
34
+ #define DLLEXPORT __declspec(dllexport)
35
+ #else
36
+ #define DLLEXPORT
37
+ #endif
38
+ #define DLLCALL
39
+
40
+
41
+ /**
42
+ * @addtogroup TurboJPEG
43
+ * TurboJPEG API. This API provides an interface for generating, decoding, and
44
+ * transforming planar YUV and JPEG images in memory.
45
+ *
46
+ * @anchor YUVnotes
47
+ * YUV Image Format Notes
48
+ * ----------------------
49
+ * Technically, the JPEG format uses the YCbCr colorspace (which is technically
50
+ * not a colorspace but a color transform), but per the convention of the
51
+ * digital video community, the TurboJPEG API uses "YUV" to refer to an image
52
+ * format consisting of Y, Cb, and Cr image planes.
53
+ *
54
+ * Each plane is simply a 2D array of bytes, each byte representing the value
55
+ * of one of the components (Y, Cb, or Cr) at a particular location in the
56
+ * image. The width and height of each plane are determined by the image
57
+ * width, height, and level of chrominance subsampling. The luminance plane
58
+ * width is the image width padded to the nearest multiple of the horizontal
59
+ * subsampling factor (1 in the case of 4:4:4, grayscale, or 4:4:0; 2 in the
60
+ * case of 4:2:2 or 4:2:0; 4 in the case of 4:1:1.) Similarly, the luminance
61
+ * plane height is the image height padded to the nearest multiple of the
62
+ * vertical subsampling factor (1 in the case of 4:4:4, 4:2:2, grayscale, or
63
+ * 4:1:1; 2 in the case of 4:2:0 or 4:4:0.) This is irrespective of any
64
+ * additional padding that may be specified as an argument to the various YUV
65
+ * functions. The chrominance plane width is equal to the luminance plane
66
+ * width divided by the horizontal subsampling factor, and the chrominance
67
+ * plane height is equal to the luminance plane height divided by the vertical
68
+ * subsampling factor.
69
+ *
70
+ * For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is
71
+ * used, then the luminance plane would be 36 x 35 bytes, and each of the
72
+ * chrominance planes would be 18 x 35 bytes. If you specify a row alignment
73
+ * of 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes,
74
+ * and each of the chrominance planes would be 20 x 35 bytes.
75
+ *
76
+ * @{
77
+ */
78
+
79
+
80
+ /**
81
+ * The number of chrominance subsampling options
82
+ */
83
+ #define TJ_NUMSAMP 6
84
+
85
+ /**
86
+ * Chrominance subsampling options.
87
+ * When pixels are converted from RGB to YCbCr (see #TJCS_YCbCr) or from CMYK
88
+ * to YCCK (see #TJCS_YCCK) as part of the JPEG compression process, some of
89
+ * the Cb and Cr (chrominance) components can be discarded or averaged together
90
+ * to produce a smaller image with little perceptible loss of image clarity.
91
+ * (The human eye is more sensitive to small changes in brightness than to
92
+ * small changes in color.) This is called "chrominance subsampling".
93
+ */
94
+ enum TJSAMP {
95
+ /**
96
+ * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or
97
+ * YUV image will contain one chrominance component for every pixel in the
98
+ * source image.
99
+ */
100
+ TJSAMP_444 = 0,
101
+ /**
102
+ * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one
103
+ * chrominance component for every 2x1 block of pixels in the source image.
104
+ */
105
+ TJSAMP_422,
106
+ /**
107
+ * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one
108
+ * chrominance component for every 2x2 block of pixels in the source image.
109
+ */
110
+ TJSAMP_420,
111
+ /**
112
+ * Grayscale. The JPEG or YUV image will contain no chrominance components.
113
+ */
114
+ TJSAMP_GRAY,
115
+ /**
116
+ * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one
117
+ * chrominance component for every 1x2 block of pixels in the source image.
118
+ *
119
+ * @note 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.
120
+ */
121
+ TJSAMP_440,
122
+ /**
123
+ * 4:1:1 chrominance subsampling. The JPEG or YUV image will contain one
124
+ * chrominance component for every 4x1 block of pixels in the source image.
125
+ * JPEG images compressed with 4:1:1 subsampling will be almost exactly the
126
+ * same size as those compressed with 4:2:0 subsampling, and in the
127
+ * aggregate, both subsampling methods produce approximately the same
128
+ * perceptual quality. However, 4:1:1 is better able to reproduce sharp
129
+ * horizontal features.
130
+ *
131
+ * @note 4:1:1 subsampling is not fully accelerated in libjpeg-turbo.
132
+ */
133
+ TJSAMP_411
134
+ };
135
+
136
+ /**
137
+ * MCU block width (in pixels) for a given level of chrominance subsampling.
138
+ * MCU block sizes:
139
+ * - 8x8 for no subsampling or grayscale
140
+ * - 16x8 for 4:2:2
141
+ * - 8x16 for 4:4:0
142
+ * - 16x16 for 4:2:0
143
+ * - 32x8 for 4:1:1
144
+ */
145
+ static const int tjMCUWidth[TJ_NUMSAMP] = { 8, 16, 16, 8, 8, 32 };
146
+
147
+ /**
148
+ * MCU block height (in pixels) for a given level of chrominance subsampling.
149
+ * MCU block sizes:
150
+ * - 8x8 for no subsampling or grayscale
151
+ * - 16x8 for 4:2:2
152
+ * - 8x16 for 4:4:0
153
+ * - 16x16 for 4:2:0
154
+ * - 32x8 for 4:1:1
155
+ */
156
+ static const int tjMCUHeight[TJ_NUMSAMP] = { 8, 8, 16, 8, 16, 8 };
157
+
158
+
159
+ /**
160
+ * The number of pixel formats
161
+ */
162
+ #define TJ_NUMPF 12
163
+
164
+ /**
165
+ * Pixel formats
166
+ */
167
+ enum TJPF {
168
+ /**
169
+ * RGB pixel format. The red, green, and blue components in the image are
170
+ * stored in 3-byte pixels in the order R, G, B from lowest to highest byte
171
+ * address within each pixel.
172
+ */
173
+ TJPF_RGB = 0,
174
+ /**
175
+ * BGR pixel format. The red, green, and blue components in the image are
176
+ * stored in 3-byte pixels in the order B, G, R from lowest to highest byte
177
+ * address within each pixel.
178
+ */
179
+ TJPF_BGR,
180
+ /**
181
+ * RGBX pixel format. The red, green, and blue components in the image are
182
+ * stored in 4-byte pixels in the order R, G, B from lowest to highest byte
183
+ * address within each pixel. The X component is ignored when compressing
184
+ * and undefined when decompressing.
185
+ */
186
+ TJPF_RGBX,
187
+ /**
188
+ * BGRX pixel format. The red, green, and blue components in the image are
189
+ * stored in 4-byte pixels in the order B, G, R from lowest to highest byte
190
+ * address within each pixel. The X component is ignored when compressing
191
+ * and undefined when decompressing.
192
+ */
193
+ TJPF_BGRX,
194
+ /**
195
+ * XBGR pixel format. The red, green, and blue components in the image are
196
+ * stored in 4-byte pixels in the order R, G, B from highest to lowest byte
197
+ * address within each pixel. The X component is ignored when compressing
198
+ * and undefined when decompressing.
199
+ */
200
+ TJPF_XBGR,
201
+ /**
202
+ * XRGB pixel format. The red, green, and blue components in the image are
203
+ * stored in 4-byte pixels in the order B, G, R from highest to lowest byte
204
+ * address within each pixel. The X component is ignored when compressing
205
+ * and undefined when decompressing.
206
+ */
207
+ TJPF_XRGB,
208
+ /**
209
+ * Grayscale pixel format. Each 1-byte pixel represents a luminance
210
+ * (brightness) level from 0 to 255.
211
+ */
212
+ TJPF_GRAY,
213
+ /**
214
+ * RGBA pixel format. This is the same as @ref TJPF_RGBX, except that when
215
+ * decompressing, the X component is guaranteed to be 0xFF, which can be
216
+ * interpreted as an opaque alpha channel.
217
+ */
218
+ TJPF_RGBA,
219
+ /**
220
+ * BGRA pixel format. This is the same as @ref TJPF_BGRX, except that when
221
+ * decompressing, the X component is guaranteed to be 0xFF, which can be
222
+ * interpreted as an opaque alpha channel.
223
+ */
224
+ TJPF_BGRA,
225
+ /**
226
+ * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when
227
+ * decompressing, the X component is guaranteed to be 0xFF, which can be
228
+ * interpreted as an opaque alpha channel.
229
+ */
230
+ TJPF_ABGR,
231
+ /**
232
+ * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when
233
+ * decompressing, the X component is guaranteed to be 0xFF, which can be
234
+ * interpreted as an opaque alpha channel.
235
+ */
236
+ TJPF_ARGB,
237
+ /**
238
+ * CMYK pixel format. Unlike RGB, which is an additive color model used
239
+ * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive
240
+ * color model used primarily for printing. In the CMYK color model, the
241
+ * value of each color component typically corresponds to an amount of cyan,
242
+ * magenta, yellow, or black ink that is applied to a white background. In
243
+ * order to convert between CMYK and RGB, it is necessary to use a color
244
+ * management system (CMS.) A CMS will attempt to map colors within the
245
+ * printer's gamut to perceptually similar colors in the display's gamut and
246
+ * vice versa, but the mapping is typically not 1:1 or reversible, nor can it
247
+ * be defined with a simple formula. Thus, such a conversion is out of scope
248
+ * for a codec library. However, the TurboJPEG API allows for compressing
249
+ * packed-pixel CMYK images into YCCK JPEG images (see #TJCS_YCCK) and
250
+ * decompressing YCCK JPEG images into packed-pixel CMYK images.
251
+ */
252
+ TJPF_CMYK,
253
+ /**
254
+ * Unknown pixel format. Currently this is only used by #tjLoadImage().
255
+ */
256
+ TJPF_UNKNOWN = -1
257
+ };
258
+
259
+ /**
260
+ * Red offset (in bytes) for a given pixel format. This specifies the number
261
+ * of bytes that the red component is offset from the start of the pixel. For
262
+ * instance, if a pixel of format TJPF_BGRX is stored in
263
+ * `unsigned char pixel[]`, then the red component will be
264
+ *`pixel[tjRedOffset[TJPF_BGRX]]`. This will be -1 if the pixel format does
265
+ * not have a red component.
266
+ */
267
+ static const int tjRedOffset[TJ_NUMPF] = {
268
+ 0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
269
+ };
270
+ /**
271
+ * Green offset (in bytes) for a given pixel format. This specifies the number
272
+ * of bytes that the green component is offset from the start of the pixel.
273
+ * For instance, if a pixel of format TJPF_BGRX is stored in
274
+ * `unsigned char pixel[]`, then the green component will be
275
+ * `pixel[tjGreenOffset[TJPF_BGRX]]`. This will be -1 if the pixel format does
276
+ * not have a green component.
277
+ */
278
+ static const int tjGreenOffset[TJ_NUMPF] = {
279
+ 1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
280
+ };
281
+ /**
282
+ * Blue offset (in bytes) for a given pixel format. This specifies the number
283
+ * of bytes that the blue component is offset from the start of the pixel. For
284
+ * instance, if a pixel of format TJPF_BGRX is stored in
285
+ * `unsigned char pixel[]`, then the blue component will be
286
+ * `pixel[tjBlueOffset[TJPF_BGRX]]`. This will be -1 if the pixel format does
287
+ * not have a blue component.
288
+ */
289
+ static const int tjBlueOffset[TJ_NUMPF] = {
290
+ 2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
291
+ };
292
+ /**
293
+ * Alpha offset (in bytes) for a given pixel format. This specifies the number
294
+ * of bytes that the alpha component is offset from the start of the pixel.
295
+ * For instance, if a pixel of format TJPF_BGRA is stored in
296
+ * `unsigned char pixel[]`, then the alpha component will be
297
+ * `pixel[tjAlphaOffset[TJPF_BGRA]]`. This will be -1 if the pixel format does
298
+ * not have an alpha component.
299
+ */
300
+ static const int tjAlphaOffset[TJ_NUMPF] = {
301
+ -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
302
+ };
303
+ /**
304
+ * Pixel size (in bytes) for a given pixel format
305
+ */
306
+ static const int tjPixelSize[TJ_NUMPF] = {
307
+ 3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
308
+ };
309
+
310
+
311
+ /**
312
+ * The number of JPEG colorspaces
313
+ */
314
+ #define TJ_NUMCS 5
315
+
316
+ /**
317
+ * JPEG colorspaces
318
+ */
319
+ enum TJCS {
320
+ /**
321
+ * RGB colorspace. When compressing the JPEG image, the R, G, and B
322
+ * components in the source image are reordered into image planes, but no
323
+ * colorspace conversion or subsampling is performed. RGB JPEG images can be
324
+ * decompressed to packed-pixel images with any of the extended RGB or
325
+ * grayscale pixel formats, but they cannot be decompressed to planar YUV
326
+ * images.
327
+ */
328
+ TJCS_RGB = 0,
329
+ /**
330
+ * YCbCr colorspace. YCbCr is not an absolute colorspace but rather a
331
+ * mathematical transformation of RGB designed solely for storage and
332
+ * transmission. YCbCr images must be converted to RGB before they can
333
+ * actually be displayed. In the YCbCr colorspace, the Y (luminance)
334
+ * component represents the black & white portion of the original image, and
335
+ * the Cb and Cr (chrominance) components represent the color portion of the
336
+ * original image. Originally, the analog equivalent of this transformation
337
+ * allowed the same signal to drive both black & white and color televisions,
338
+ * but JPEG images use YCbCr primarily because it allows the color data to be
339
+ * optionally subsampled for the purposes of reducing network or disk usage.
340
+ * YCbCr is the most common JPEG colorspace, and YCbCr JPEG images can be
341
+ * compressed from and decompressed to packed-pixel images with any of the
342
+ * extended RGB or grayscale pixel formats. YCbCr JPEG images can also be
343
+ * compressed from and decompressed to planar YUV images.
344
+ */
345
+ TJCS_YCbCr,
346
+ /**
347
+ * Grayscale colorspace. The JPEG image retains only the luminance data (Y
348
+ * component), and any color data from the source image is discarded.
349
+ * Grayscale JPEG images can be compressed from and decompressed to
350
+ * packed-pixel images with any of the extended RGB or grayscale pixel
351
+ * formats, or they can be compressed from and decompressed to planar YUV
352
+ * images.
353
+ */
354
+ TJCS_GRAY,
355
+ /**
356
+ * CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K
357
+ * components in the source image are reordered into image planes, but no
358
+ * colorspace conversion or subsampling is performed. CMYK JPEG images can
359
+ * only be decompressed to packed-pixel images with the CMYK pixel format.
360
+ */
361
+ TJCS_CMYK,
362
+ /**
363
+ * YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but
364
+ * rather a mathematical transformation of CMYK designed solely for storage
365
+ * and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be
366
+ * reversibly transformed into YCCK, and as with YCbCr, the chrominance
367
+ * components in the YCCK pixels can be subsampled without incurring major
368
+ * perceptual loss. YCCK JPEG images can only be compressed from and
369
+ * decompressed to packed-pixel images with the CMYK pixel format.
370
+ */
371
+ TJCS_YCCK
372
+ };
373
+
374
+
375
+ /**
376
+ * Rows in the packed-pixel source/destination image are stored in bottom-up
377
+ * (Windows, OpenGL) order rather than in top-down (X11) order.
378
+ */
379
+ #define TJFLAG_BOTTOMUP 2
380
+ /**
381
+ * When decompressing an image that was compressed using chrominance
382
+ * subsampling, use the fastest chrominance upsampling algorithm available.
383
+ * The default is to use smooth upsampling, which creates a smooth transition
384
+ * between neighboring chrominance components in order to reduce upsampling
385
+ * artifacts in the decompressed image.
386
+ */
387
+ #define TJFLAG_FASTUPSAMPLE 256
388
+ /**
389
+ * Disable JPEG buffer (re)allocation. If passed to one of the JPEG
390
+ * compression or transform functions, this flag will cause those functions to
391
+ * generate an error if the JPEG destination buffer is invalid or too small,
392
+ * rather than attempt to allocate or reallocate that buffer.
393
+ */
394
+ #define TJFLAG_NOREALLOC 1024
395
+ /**
396
+ * Use the fastest DCT/IDCT algorithm available. The default if this flag is
397
+ * not specified is implementation-specific. For example, the implementation
398
+ * of the TurboJPEG API in libjpeg-turbo uses the fast algorithm by default
399
+ * when compressing, because this has been shown to have only a very slight
400
+ * effect on accuracy, but it uses the accurate algorithm when decompressing,
401
+ * because this has been shown to have a larger effect.
402
+ */
403
+ #define TJFLAG_FASTDCT 2048
404
+ /**
405
+ * Use the most accurate DCT/IDCT algorithm available. The default if this
406
+ * flag is not specified is implementation-specific. For example, the
407
+ * implementation of the TurboJPEG API in libjpeg-turbo uses the fast algorithm
408
+ * by default when compressing, because this has been shown to have only a very
409
+ * slight effect on accuracy, but it uses the accurate algorithm when
410
+ * decompressing, because this has been shown to have a larger effect.
411
+ */
412
+ #define TJFLAG_ACCURATEDCT 4096
413
+ /**
414
+ * Immediately discontinue the current compression/decompression/transform
415
+ * operation if a warning (non-fatal error) occurs. The default behavior is to
416
+ * allow the operation to complete unless a fatal error is encountered.
417
+ */
418
+ #define TJFLAG_STOPONWARNING 8192
419
+ /**
420
+ * Use progressive entropy coding in JPEG images generated by the compression
421
+ * and transform functions. Progressive entropy coding will generally improve
422
+ * compression relative to baseline entropy coding (the default), but it will
423
+ * reduce compression and decompression performance considerably.
424
+ */
425
+ #define TJFLAG_PROGRESSIVE 16384
426
+ /**
427
+ * Limit the number of progressive JPEG scans that the decompression and
428
+ * transform functions will process. If a progressive JPEG image contains an
429
+ * unreasonably large number of scans, then this flag will cause the
430
+ * decompression and transform functions to return an error. The primary
431
+ * purpose of this is to allow security-critical applications to guard against
432
+ * an exploit of the progressive JPEG format described in
433
+ * <a href="https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf" target="_blank">this report</a>.
434
+ */
435
+ #define TJFLAG_LIMITSCANS 32768
436
+
437
+
438
+ /**
439
+ * The number of error codes
440
+ */
441
+ #define TJ_NUMERR 2
442
+
443
+ /**
444
+ * Error codes
445
+ */
446
+ enum TJERR {
447
+ /**
448
+ * The error was non-fatal and recoverable, but the destination image may
449
+ * still be corrupt.
450
+ */
451
+ TJERR_WARNING = 0,
452
+ /**
453
+ * The error was fatal and non-recoverable.
454
+ */
455
+ TJERR_FATAL
456
+ };
457
+
458
+
459
+ /**
460
+ * The number of transform operations
461
+ */
462
+ #define TJ_NUMXOP 8
463
+
464
+ /**
465
+ * Transform operations for #tjTransform()
466
+ */
467
+ enum TJXOP {
468
+ /**
469
+ * Do not transform the position of the image pixels
470
+ */
471
+ TJXOP_NONE = 0,
472
+ /**
473
+ * Flip (mirror) image horizontally. This transform is imperfect if there
474
+ * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.)
475
+ */
476
+ TJXOP_HFLIP,
477
+ /**
478
+ * Flip (mirror) image vertically. This transform is imperfect if there are
479
+ * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.)
480
+ */
481
+ TJXOP_VFLIP,
482
+ /**
483
+ * Transpose image (flip/mirror along upper left to lower right axis.) This
484
+ * transform is always perfect.
485
+ */
486
+ TJXOP_TRANSPOSE,
487
+ /**
488
+ * Transverse transpose image (flip/mirror along upper right to lower left
489
+ * axis.) This transform is imperfect if there are any partial MCU blocks in
490
+ * the image (see #TJXOPT_PERFECT.)
491
+ */
492
+ TJXOP_TRANSVERSE,
493
+ /**
494
+ * Rotate image clockwise by 90 degrees. This transform is imperfect if
495
+ * there are any partial MCU blocks on the bottom edge (see
496
+ * #TJXOPT_PERFECT.)
497
+ */
498
+ TJXOP_ROT90,
499
+ /**
500
+ * Rotate image 180 degrees. This transform is imperfect if there are any
501
+ * partial MCU blocks in the image (see #TJXOPT_PERFECT.)
502
+ */
503
+ TJXOP_ROT180,
504
+ /**
505
+ * Rotate image counter-clockwise by 90 degrees. This transform is imperfect
506
+ * if there are any partial MCU blocks on the right edge (see
507
+ * #TJXOPT_PERFECT.)
508
+ */
509
+ TJXOP_ROT270
510
+ };
511
+
512
+
513
+ /**
514
+ * This option will cause #tjTransform() to return an error if the transform is
515
+ * not perfect. Lossless transforms operate on MCU blocks, whose size depends
516
+ * on the level of chrominance subsampling used (see #tjMCUWidth and
517
+ * #tjMCUHeight.) If the image's width or height is not evenly divisible by
518
+ * the MCU block size, then there will be partial MCU blocks on the right
519
+ * and/or bottom edges. It is not possible to move these partial MCU blocks to
520
+ * the top or left of the image, so any transform that would require that is
521
+ * "imperfect." If this option is not specified, then any partial MCU blocks
522
+ * that cannot be transformed will be left in place, which will create
523
+ * odd-looking strips on the right or bottom edge of the image.
524
+ */
525
+ #define TJXOPT_PERFECT 1
526
+ /**
527
+ * This option will cause #tjTransform() to discard any partial MCU blocks that
528
+ * cannot be transformed.
529
+ */
530
+ #define TJXOPT_TRIM 2
531
+ /**
532
+ * This option will enable lossless cropping. See #tjTransform() for more
533
+ * information.
534
+ */
535
+ #define TJXOPT_CROP 4
536
+ /**
537
+ * This option will discard the color data in the source image and produce a
538
+ * grayscale destination image.
539
+ */
540
+ #define TJXOPT_GRAY 8
541
+ /**
542
+ * This option will prevent #tjTransform() from outputting a JPEG image for
543
+ * this particular transform. (This can be used in conjunction with a custom
544
+ * filter to capture the transformed DCT coefficients without transcoding
545
+ * them.)
546
+ */
547
+ #define TJXOPT_NOOUTPUT 16
548
+ /**
549
+ * This option will enable progressive entropy coding in the JPEG image
550
+ * generated by this particular transform. Progressive entropy coding will
551
+ * generally improve compression relative to baseline entropy coding (the
552
+ * default), but it will reduce decompression performance considerably.
553
+ */
554
+ #define TJXOPT_PROGRESSIVE 32
555
+ /**
556
+ * This option will prevent #tjTransform() from copying any extra markers
557
+ * (including EXIF and ICC profile data) from the source image to the
558
+ * destination image.
559
+ */
560
+ #define TJXOPT_COPYNONE 64
561
+
562
+
563
+ /**
564
+ * Scaling factor
565
+ */
566
+ typedef struct {
567
+ /**
568
+ * Numerator
569
+ */
570
+ int num;
571
+ /**
572
+ * Denominator
573
+ */
574
+ int denom;
575
+ } tjscalingfactor;
576
+
577
+ /**
578
+ * Cropping region
579
+ */
580
+ typedef struct {
581
+ /**
582
+ * The left boundary of the cropping region. This must be evenly divisible
583
+ * by the MCU block width (see #tjMCUWidth.)
584
+ */
585
+ int x;
586
+ /**
587
+ * The upper boundary of the cropping region. This must be evenly divisible
588
+ * by the MCU block height (see #tjMCUHeight.)
589
+ */
590
+ int y;
591
+ /**
592
+ * The width of the cropping region. Setting this to 0 is the equivalent of
593
+ * setting it to the width of the source JPEG image - x.
594
+ */
595
+ int w;
596
+ /**
597
+ * The height of the cropping region. Setting this to 0 is the equivalent of
598
+ * setting it to the height of the source JPEG image - y.
599
+ */
600
+ int h;
601
+ } tjregion;
602
+
603
+ /**
604
+ * Lossless transform
605
+ */
606
+ typedef struct tjtransform {
607
+ /**
608
+ * Cropping region
609
+ */
610
+ tjregion r;
611
+ /**
612
+ * One of the @ref TJXOP "transform operations"
613
+ */
614
+ int op;
615
+ /**
616
+ * The bitwise OR of one of more of the @ref TJXOPT_COPYNONE
617
+ * "transform options"
618
+ */
619
+ int options;
620
+ /**
621
+ * Arbitrary data that can be accessed within the body of the callback
622
+ * function
623
+ */
624
+ void *data;
625
+ /**
626
+ * A callback function that can be used to modify the DCT coefficients after
627
+ * they are losslessly transformed but before they are transcoded to a new
628
+ * JPEG image. This allows for custom filters or other transformations to be
629
+ * applied in the frequency domain.
630
+ *
631
+ * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE:
632
+ * this pointer is not guaranteed to be valid once the callback returns, so
633
+ * applications wishing to hand off the DCT coefficients to another function
634
+ * or library should make a copy of them within the body of the callback.)
635
+ *
636
+ * @param arrayRegion #tjregion structure containing the width and height of
637
+ * the array pointed to by `coeffs` as well as its offset relative to the
638
+ * component plane. TurboJPEG implementations may choose to split each
639
+ * component plane into multiple DCT coefficient arrays and call the callback
640
+ * function once for each array.
641
+ *
642
+ * @param planeRegion #tjregion structure containing the width and height of
643
+ * the component plane to which `coeffs` belongs
644
+ *
645
+ * @param componentID ID number of the component plane to which `coeffs`
646
+ * belongs. (Y, Cb, and Cr have, respectively, ID's of 0, 1, and 2 in
647
+ * typical JPEG images.)
648
+ *
649
+ * @param transformID ID number of the transformed image to which `coeffs`
650
+ * belongs. This is the same as the index of the transform in the
651
+ * `transforms` array that was passed to #tjTransform().
652
+ *
653
+ * @param transform a pointer to a #tjtransform structure that specifies the
654
+ * parameters and/or cropping region for this transform
655
+ *
656
+ * @return 0 if the callback was successful, or -1 if an error occurred.
657
+ */
658
+ int (*customFilter) (short *coeffs, tjregion arrayRegion,
659
+ tjregion planeRegion, int componentID, int transformID,
660
+ struct tjtransform *transform);
661
+ } tjtransform;
662
+
663
+ /**
664
+ * TurboJPEG instance handle
665
+ */
666
+ typedef void *tjhandle;
667
+
668
+
669
+ /**
670
+ * Pad the given width to the nearest multiple of 4
671
+ */
672
+ #define TJPAD(width) (((width) + 3) & (~3))
673
+
674
+ /**
675
+ * Compute the scaled value of `dimension` using the given scaling factor.
676
+ * This macro performs the integer equivalent of `ceil(dimension *
677
+ * scalingFactor)`.
678
+ */
679
+ #define TJSCALED(dimension, scalingFactor) \
680
+ (((dimension) * scalingFactor.num + scalingFactor.denom - 1) / \
681
+ scalingFactor.denom)
682
+
683
+
684
+ #ifdef __cplusplus
685
+ extern "C" {
686
+ #endif
687
+
688
+
689
+ /**
690
+ * Create a TurboJPEG compressor instance.
691
+ *
692
+ * @return a handle to the newly-created instance, or NULL if an error occurred
693
+ * (see #tjGetErrorStr2().)
694
+ */
695
+ DLLEXPORT tjhandle tjInitCompress(void);
696
+
697
+
698
+ /**
699
+ * Compress a packed-pixel RGB, grayscale, or CMYK image into a JPEG image.
700
+ *
701
+ * @param handle a handle to a TurboJPEG compressor or transformer instance
702
+ *
703
+ * @param srcBuf pointer to a buffer containing a packed-pixel RGB, grayscale,
704
+ * or CMYK source image to be compressed
705
+ *
706
+ * @param width width (in pixels) of the source image
707
+ *
708
+ * @param pitch bytes per row in the source image. Normally this should be
709
+ * <tt>width * #tjPixelSize[pixelFormat]</tt>, if the image is unpadded, or
710
+ * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each row of the image
711
+ * is padded to the nearest multiple of 4 bytes, as is the case for Windows
712
+ * bitmaps. You can also be clever and use this parameter to skip rows, etc.
713
+ * Setting this parameter to 0 is the equivalent of setting it to
714
+ * <tt>width * #tjPixelSize[pixelFormat]</tt>.
715
+ *
716
+ * @param height height (in pixels) of the source image
717
+ *
718
+ * @param pixelFormat pixel format of the source image (see @ref TJPF
719
+ * "Pixel formats".)
720
+ *
721
+ * @param jpegBuf address of a pointer to a byte buffer that will receive the
722
+ * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
723
+ * accommodate the size of the JPEG image. Thus, you can choose to:
724
+ * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
725
+ * let TurboJPEG grow the buffer as needed,
726
+ * -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you,
727
+ * or
728
+ * -# pre-allocate the buffer to a "worst case" size determined by calling
729
+ * #tjBufSize(). This should ensure that the buffer never has to be
730
+ * re-allocated. (Setting #TJFLAG_NOREALLOC guarantees that it won't be.)
731
+ * .
732
+ * If you choose option 1, then `*jpegSize` should be set to the size of your
733
+ * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
734
+ * you should always check `*jpegBuf` upon return from this function, as it may
735
+ * have changed.
736
+ *
737
+ * @param jpegSize pointer to an unsigned long variable that holds the size of
738
+ * the JPEG buffer. If `*jpegBuf` points to a pre-allocated buffer, then
739
+ * `*jpegSize` should be set to the size of the buffer. Upon return,
740
+ * `*jpegSize` will contain the size of the JPEG image (in bytes.) If
741
+ * `*jpegBuf` points to a JPEG buffer that is being reused from a previous call
742
+ * to one of the JPEG compression functions, then `*jpegSize` is ignored.
743
+ *
744
+ * @param jpegSubsamp the level of chrominance subsampling to be used when
745
+ * generating the JPEG image (see @ref TJSAMP
746
+ * "Chrominance subsampling options".)
747
+ *
748
+ * @param jpegQual the image quality of the generated JPEG image (1 = worst,
749
+ * 100 = best)
750
+ *
751
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
752
+ * "flags"
753
+ *
754
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
755
+ * and #tjGetErrorCode().)
756
+ */
757
+ DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf,
758
+ int width, int pitch, int height, int pixelFormat,
759
+ unsigned char **jpegBuf, unsigned long *jpegSize,
760
+ int jpegSubsamp, int jpegQual, int flags);
761
+
762
+
763
+ /**
764
+ * Compress a unified planar YUV image into a JPEG image.
765
+ *
766
+ * @param handle a handle to a TurboJPEG compressor or transformer instance
767
+ *
768
+ * @param srcBuf pointer to a buffer containing a unified planar YUV source
769
+ * image to be compressed. The size of this buffer should match the value
770
+ * returned by #tjBufSizeYUV2() for the given image width, height, row
771
+ * alignment, and level of chrominance subsampling. The Y, U (Cb), and V (Cr)
772
+ * image planes should be stored sequentially in the buffer. (Refer to
773
+ * @ref YUVnotes "YUV Image Format Notes".)
774
+ *
775
+ * @param width width (in pixels) of the source image. If the width is not an
776
+ * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
777
+ * buffer copy will be performed.
778
+ *
779
+ * @param align row alignment (in bytes) of the source image (must be a power
780
+ * of 2.) Setting this parameter to n indicates that each row in each plane of
781
+ * the source image is padded to the nearest multiple of n bytes
782
+ * (1 = unpadded.)
783
+ *
784
+ * @param height height (in pixels) of the source image. If the height is not
785
+ * an even multiple of the MCU block height (see #tjMCUHeight), then an
786
+ * intermediate buffer copy will be performed.
787
+ *
788
+ * @param subsamp the level of chrominance subsampling used in the source image
789
+ * (see @ref TJSAMP "Chrominance subsampling options".)
790
+ *
791
+ * @param jpegBuf address of a pointer to a byte buffer that will receive the
792
+ * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
793
+ * accommodate the size of the JPEG image. Thus, you can choose to:
794
+ * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
795
+ * let TurboJPEG grow the buffer as needed,
796
+ * -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you,
797
+ * or
798
+ * -# pre-allocate the buffer to a "worst case" size determined by calling
799
+ * #tjBufSize(). This should ensure that the buffer never has to be
800
+ * re-allocated. (Setting #TJFLAG_NOREALLOC guarantees that it won't be.)
801
+ * .
802
+ * If you choose option 1, then `*jpegSize` should be set to the size of your
803
+ * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
804
+ * you should always check `*jpegBuf` upon return from this function, as it may
805
+ * have changed.
806
+ *
807
+ * @param jpegSize pointer to an unsigned long variable that holds the size of
808
+ * the JPEG buffer. If `*jpegBuf` points to a pre-allocated buffer, then
809
+ * `*jpegSize` should be set to the size of the buffer. Upon return,
810
+ * `*jpegSize` will contain the size of the JPEG image (in bytes.) If
811
+ * `*jpegBuf` points to a JPEG buffer that is being reused from a previous call
812
+ * to one of the JPEG compression functions, then `*jpegSize` is ignored.
813
+ *
814
+ * @param jpegQual the image quality of the generated JPEG image (1 = worst,
815
+ * 100 = best)
816
+ *
817
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
818
+ * "flags"
819
+ *
820
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
821
+ * and #tjGetErrorCode().)
822
+ */
823
+ DLLEXPORT int tjCompressFromYUV(tjhandle handle, const unsigned char *srcBuf,
824
+ int width, int align, int height, int subsamp,
825
+ unsigned char **jpegBuf,
826
+ unsigned long *jpegSize, int jpegQual,
827
+ int flags);
828
+
829
+
830
+ /**
831
+ * Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image.
832
+ *
833
+ * @param handle a handle to a TurboJPEG compressor or transformer instance
834
+ *
835
+ * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
836
+ * (or just a Y plane, if compressing a grayscale image) that contain a YUV
837
+ * source image to be compressed. These planes can be contiguous or
838
+ * non-contiguous in memory. The size of each plane should match the value
839
+ * returned by #tjPlaneSizeYUV() for the given image width, height, strides,
840
+ * and level of chrominance subsampling. Refer to @ref YUVnotes
841
+ * "YUV Image Format Notes" for more details.
842
+ *
843
+ * @param width width (in pixels) of the source image. If the width is not an
844
+ * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
845
+ * buffer copy will be performed.
846
+ *
847
+ * @param strides an array of integers, each specifying the number of bytes per
848
+ * row in the corresponding plane of the YUV source image. Setting the stride
849
+ * for any plane to 0 is the same as setting it to the plane width (see
850
+ * @ref YUVnotes "YUV Image Format Notes".) If `strides` is NULL, then the
851
+ * strides for all planes will be set to their respective plane widths. You
852
+ * can adjust the strides in order to specify an arbitrary amount of row
853
+ * padding in each plane or to create a JPEG image from a subregion of a larger
854
+ * planar YUV image.
855
+ *
856
+ * @param height height (in pixels) of the source image. If the height is not
857
+ * an even multiple of the MCU block height (see #tjMCUHeight), then an
858
+ * intermediate buffer copy will be performed.
859
+ *
860
+ * @param subsamp the level of chrominance subsampling used in the source image
861
+ * (see @ref TJSAMP "Chrominance subsampling options".)
862
+ *
863
+ * @param jpegBuf address of a pointer to a byte buffer that will receive the
864
+ * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
865
+ * accommodate the size of the JPEG image. Thus, you can choose to:
866
+ * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
867
+ * let TurboJPEG grow the buffer as needed,
868
+ * -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you,
869
+ * or
870
+ * -# pre-allocate the buffer to a "worst case" size determined by calling
871
+ * #tjBufSize(). This should ensure that the buffer never has to be
872
+ * re-allocated. (Setting #TJFLAG_NOREALLOC guarantees that it won't be.)
873
+ * .
874
+ * If you choose option 1, then `*jpegSize` should be set to the size of your
875
+ * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
876
+ * you should always check `*jpegBuf` upon return from this function, as it may
877
+ * have changed.
878
+ *
879
+ * @param jpegSize pointer to an unsigned long variable that holds the size of
880
+ * the JPEG buffer. If `*jpegBuf` points to a pre-allocated buffer, then
881
+ * `*jpegSize` should be set to the size of the buffer. Upon return,
882
+ * `*jpegSize` will contain the size of the JPEG image (in bytes.) If
883
+ * `*jpegBuf` points to a JPEG buffer that is being reused from a previous call
884
+ * to one of the JPEG compression functions, then `*jpegSize` is ignored.
885
+ *
886
+ * @param jpegQual the image quality of the generated JPEG image (1 = worst,
887
+ * 100 = best)
888
+ *
889
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
890
+ * "flags"
891
+ *
892
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
893
+ * and #tjGetErrorCode().)
894
+ */
895
+ DLLEXPORT int tjCompressFromYUVPlanes(tjhandle handle,
896
+ const unsigned char **srcPlanes,
897
+ int width, const int *strides,
898
+ int height, int subsamp,
899
+ unsigned char **jpegBuf,
900
+ unsigned long *jpegSize, int jpegQual,
901
+ int flags);
902
+
903
+
904
+ /**
905
+ * The maximum size of the buffer (in bytes) required to hold a JPEG image with
906
+ * the given parameters. The number of bytes returned by this function is
907
+ * larger than the size of the uncompressed source image. The reason for this
908
+ * is that the JPEG format uses 16-bit coefficients, so it is possible for a
909
+ * very high-quality source image with very high-frequency content to expand
910
+ * rather than compress when converted to the JPEG format. Such images
911
+ * represent very rare corner cases, but since there is no way to predict the
912
+ * size of a JPEG image prior to compression, the corner cases have to be
913
+ * handled.
914
+ *
915
+ * @param width width (in pixels) of the image
916
+ *
917
+ * @param height height (in pixels) of the image
918
+ *
919
+ * @param jpegSubsamp the level of chrominance subsampling to be used when
920
+ * generating the JPEG image (see @ref TJSAMP
921
+ * "Chrominance subsampling options".)
922
+ *
923
+ * @return the maximum size of the buffer (in bytes) required to hold the
924
+ * image, or -1 if the arguments are out of bounds.
925
+ */
926
+ DLLEXPORT unsigned long tjBufSize(int width, int height, int jpegSubsamp);
927
+
928
+
929
+ /**
930
+ * The size of the buffer (in bytes) required to hold a unified planar YUV
931
+ * image with the given parameters.
932
+ *
933
+ * @param width width (in pixels) of the image
934
+ *
935
+ * @param align row alignment (in bytes) of the image (must be a power of 2.)
936
+ * Setting this parameter to n specifies that each row in each plane of the
937
+ * image will be padded to the nearest multiple of n bytes (1 = unpadded.)
938
+ *
939
+ * @param height height (in pixels) of the image
940
+ *
941
+ * @param subsamp level of chrominance subsampling in the image (see
942
+ * @ref TJSAMP "Chrominance subsampling options".)
943
+ *
944
+ * @return the size of the buffer (in bytes) required to hold the image, or -1
945
+ * if the arguments are out of bounds.
946
+ */
947
+ DLLEXPORT unsigned long tjBufSizeYUV2(int width, int align, int height,
948
+ int subsamp);
949
+
950
+
951
+ /**
952
+ * The size of the buffer (in bytes) required to hold a YUV image plane with
953
+ * the given parameters.
954
+ *
955
+ * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
956
+ *
957
+ * @param width width (in pixels) of the YUV image. NOTE: this is the width of
958
+ * the whole image, not the plane width.
959
+ *
960
+ * @param stride bytes per row in the image plane. Setting this to 0 is the
961
+ * equivalent of setting it to the plane width.
962
+ *
963
+ * @param height height (in pixels) of the YUV image. NOTE: this is the height
964
+ * of the whole image, not the plane height.
965
+ *
966
+ * @param subsamp level of chrominance subsampling in the image (see
967
+ * @ref TJSAMP "Chrominance subsampling options".)
968
+ *
969
+ * @return the size of the buffer (in bytes) required to hold the YUV image
970
+ * plane, or -1 if the arguments are out of bounds.
971
+ */
972
+ DLLEXPORT unsigned long tjPlaneSizeYUV(int componentID, int width, int stride,
973
+ int height, int subsamp);
974
+
975
+
976
+ /**
977
+ * The plane width of a YUV image plane with the given parameters. Refer to
978
+ * @ref YUVnotes "YUV Image Format Notes" for a description of plane width.
979
+ *
980
+ * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
981
+ *
982
+ * @param width width (in pixels) of the YUV image
983
+ *
984
+ * @param subsamp level of chrominance subsampling in the image (see
985
+ * @ref TJSAMP "Chrominance subsampling options".)
986
+ *
987
+ * @return the plane width of a YUV image plane with the given parameters, or
988
+ * -1 if the arguments are out of bounds.
989
+ */
990
+ DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp);
991
+
992
+
993
+ /**
994
+ * The plane height of a YUV image plane with the given parameters. Refer to
995
+ * @ref YUVnotes "YUV Image Format Notes" for a description of plane height.
996
+ *
997
+ * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
998
+ *
999
+ * @param height height (in pixels) of the YUV image
1000
+ *
1001
+ * @param subsamp level of chrominance subsampling in the image (see
1002
+ * @ref TJSAMP "Chrominance subsampling options".)
1003
+ *
1004
+ * @return the plane height of a YUV image plane with the given parameters, or
1005
+ * -1 if the arguments are out of bounds.
1006
+ */
1007
+ DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp);
1008
+
1009
+
1010
+ /**
1011
+ * Encode a packed-pixel RGB or grayscale image into a unified planar YUV
1012
+ * image. This function performs color conversion (which is accelerated in the
1013
+ * libjpeg-turbo implementation) but does not execute any of the other steps in
1014
+ * the JPEG compression process.
1015
+ *
1016
+ * @param handle a handle to a TurboJPEG compressor or transformer instance
1017
+ *
1018
+ * @param srcBuf pointer to a buffer containing a packed-pixel RGB or grayscale
1019
+ * source image to be encoded
1020
+ *
1021
+ * @param width width (in pixels) of the source image
1022
+ *
1023
+ * @param pitch bytes per row in the source image. Normally this should be
1024
+ * <tt>width * #tjPixelSize[pixelFormat]</tt>, if the image is unpadded, or
1025
+ * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each row of the image
1026
+ * is padded to the nearest multiple of 4 bytes, as is the case for Windows
1027
+ * bitmaps. You can also be clever and use this parameter to skip rows, etc.
1028
+ * Setting this parameter to 0 is the equivalent of setting it to
1029
+ * <tt>width * #tjPixelSize[pixelFormat]</tt>.
1030
+ *
1031
+ * @param height height (in pixels) of the source image
1032
+ *
1033
+ * @param pixelFormat pixel format of the source image (see @ref TJPF
1034
+ * "Pixel formats".)
1035
+ *
1036
+ * @param dstBuf pointer to a buffer that will receive the unified planar YUV
1037
+ * image. Use #tjBufSizeYUV2() to determine the appropriate size for this
1038
+ * buffer based on the image width, height, row alignment, and level of
1039
+ * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes will be
1040
+ * stored sequentially in the buffer. (Refer to @ref YUVnotes
1041
+ * "YUV Image Format Notes".)
1042
+ *
1043
+ * @param align row alignment (in bytes) of the YUV image (must be a power of
1044
+ * 2.) Setting this parameter to n will cause each row in each plane of the
1045
+ * YUV image to be padded to the nearest multiple of n bytes (1 = unpadded.)
1046
+ * To generate images suitable for X Video, `align` should be set to 4.
1047
+ *
1048
+ * @param subsamp the level of chrominance subsampling to be used when
1049
+ * generating the YUV image (see @ref TJSAMP
1050
+ * "Chrominance subsampling options".) To generate images suitable for X
1051
+ * Video, `subsamp` should be set to @ref TJSAMP_420. This produces an image
1052
+ * compatible with the I420 (AKA "YUV420P") format.
1053
+ *
1054
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1055
+ * "flags"
1056
+ *
1057
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1058
+ * and #tjGetErrorCode().)
1059
+ */
1060
+ DLLEXPORT int tjEncodeYUV3(tjhandle handle, const unsigned char *srcBuf,
1061
+ int width, int pitch, int height, int pixelFormat,
1062
+ unsigned char *dstBuf, int align, int subsamp,
1063
+ int flags);
1064
+
1065
+
1066
+ /**
1067
+ * Encode a packed-pixel RGB or grayscale image into separate Y, U (Cb), and
1068
+ * V (Cr) image planes. This function performs color conversion (which is
1069
+ * accelerated in the libjpeg-turbo implementation) but does not execute any of
1070
+ * the other steps in the JPEG compression process.
1071
+ *
1072
+ * @param handle a handle to a TurboJPEG compressor or transformer instance
1073
+ *
1074
+ * @param srcBuf pointer to a buffer containing a packed-pixel RGB or grayscale
1075
+ * source image to be encoded
1076
+ *
1077
+ * @param width width (in pixels) of the source image
1078
+ *
1079
+ * @param pitch bytes per row in the source image. Normally this should be
1080
+ * <tt>width * #tjPixelSize[pixelFormat]</tt>, if the image is unpadded, or
1081
+ * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each row of the image
1082
+ * is padded to the nearest multiple of 4 bytes, as is the case for Windows
1083
+ * bitmaps. You can also be clever and use this parameter to skip rows, etc.
1084
+ * Setting this parameter to 0 is the equivalent of setting it to
1085
+ * <tt>width * #tjPixelSize[pixelFormat]</tt>.
1086
+ *
1087
+ * @param height height (in pixels) of the source image
1088
+ *
1089
+ * @param pixelFormat pixel format of the source image (see @ref TJPF
1090
+ * "Pixel formats".)
1091
+ *
1092
+ * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
1093
+ * (or just a Y plane, if generating a grayscale image) that will receive the
1094
+ * encoded image. These planes can be contiguous or non-contiguous in memory.
1095
+ * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based
1096
+ * on the image width, height, strides, and level of chrominance subsampling.
1097
+ * Refer to @ref YUVnotes "YUV Image Format Notes" for more details.
1098
+ *
1099
+ * @param strides an array of integers, each specifying the number of bytes per
1100
+ * row in the corresponding plane of the YUV image. Setting the stride for any
1101
+ * plane to 0 is the same as setting it to the plane width (see @ref YUVnotes
1102
+ * "YUV Image Format Notes".) If `strides` is NULL, then the strides for all
1103
+ * planes will be set to their respective plane widths. You can adjust the
1104
+ * strides in order to add an arbitrary amount of row padding to each plane or
1105
+ * to encode an RGB or grayscale image into a subregion of a larger planar YUV
1106
+ * image.
1107
+ *
1108
+ * @param subsamp the level of chrominance subsampling to be used when
1109
+ * generating the YUV image (see @ref TJSAMP
1110
+ * "Chrominance subsampling options".) To generate images suitable for X
1111
+ * Video, `subsamp` should be set to @ref TJSAMP_420. This produces an image
1112
+ * compatible with the I420 (AKA "YUV420P") format.
1113
+ *
1114
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1115
+ * "flags"
1116
+ *
1117
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1118
+ * and #tjGetErrorCode().)
1119
+ */
1120
+ DLLEXPORT int tjEncodeYUVPlanes(tjhandle handle, const unsigned char *srcBuf,
1121
+ int width, int pitch, int height,
1122
+ int pixelFormat, unsigned char **dstPlanes,
1123
+ int *strides, int subsamp, int flags);
1124
+
1125
+
1126
+ /**
1127
+ * Create a TurboJPEG decompressor instance.
1128
+ *
1129
+ * @return a handle to the newly-created instance, or NULL if an error occurred
1130
+ * (see #tjGetErrorStr2().)
1131
+ */
1132
+ DLLEXPORT tjhandle tjInitDecompress(void);
1133
+
1134
+
1135
+ /**
1136
+ * Retrieve information about a JPEG image without decompressing it, or prime
1137
+ * the decompressor with quantization and Huffman tables.
1138
+ *
1139
+ * @param handle a handle to a TurboJPEG decompressor or transformer instance
1140
+ *
1141
+ * @param jpegBuf pointer to a byte buffer containing a JPEG image or an
1142
+ * "abbreviated table specification" (AKA "tables-only") datastream. Passing a
1143
+ * tables-only datastream to this function primes the decompressor with
1144
+ * quantization and Huffman tables that can be used when decompressing
1145
+ * subsequent "abbreviated image" datastreams. This is useful, for instance,
1146
+ * when decompressing video streams in which all frames share the same
1147
+ * quantization and Huffman tables.
1148
+ *
1149
+ * @param jpegSize size of the JPEG image or tables-only datastream (in bytes)
1150
+ *
1151
+ * @param width pointer to an integer variable that will receive the width (in
1152
+ * pixels) of the JPEG image. If `jpegBuf` points to a tables-only datastream,
1153
+ * then `width` is ignored.
1154
+ *
1155
+ * @param height pointer to an integer variable that will receive the height
1156
+ * (in pixels) of the JPEG image. If `jpegBuf` points to a tables-only
1157
+ * datastream, then `height` is ignored.
1158
+ *
1159
+ * @param jpegSubsamp pointer to an integer variable that will receive the
1160
+ * level of chrominance subsampling used when the JPEG image was compressed
1161
+ * (see @ref TJSAMP "Chrominance subsampling options".) If `jpegBuf` points to
1162
+ * a tables-only datastream, then `jpegSubsamp` is ignored.
1163
+ *
1164
+ * @param jpegColorspace pointer to an integer variable that will receive one
1165
+ * of the JPEG colorspace constants, indicating the colorspace of the JPEG
1166
+ * image (see @ref TJCS "JPEG colorspaces".) If `jpegBuf` points to a
1167
+ * tables-only datastream, then `jpegColorspace` is ignored.
1168
+ *
1169
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1170
+ * and #tjGetErrorCode().)
1171
+ */
1172
+ DLLEXPORT int tjDecompressHeader3(tjhandle handle,
1173
+ const unsigned char *jpegBuf,
1174
+ unsigned long jpegSize, int *width,
1175
+ int *height, int *jpegSubsamp,
1176
+ int *jpegColorspace);
1177
+
1178
+
1179
+ /**
1180
+ * Returns a list of fractional scaling factors that the JPEG decompressor
1181
+ * supports.
1182
+ *
1183
+ * @param numScalingFactors pointer to an integer variable that will receive
1184
+ * the number of elements in the list
1185
+ *
1186
+ * @return a pointer to a list of fractional scaling factors, or NULL if an
1187
+ * error is encountered (see #tjGetErrorStr2().)
1188
+ */
1189
+ DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numScalingFactors);
1190
+
1191
+
1192
+ /**
1193
+ * Decompress a JPEG image into a packed-pixel RGB, grayscale, or CMYK image.
1194
+ *
1195
+ * @param handle a handle to a TurboJPEG decompressor or transformer instance
1196
+ *
1197
+ * @param jpegBuf pointer to a byte buffer containing the JPEG image to
1198
+ * decompress
1199
+ *
1200
+ * @param jpegSize size of the JPEG image (in bytes)
1201
+ *
1202
+ * @param dstBuf pointer to a buffer that will receive the packed-pixel
1203
+ * decompressed image. This buffer should normally be `pitch * scaledHeight`
1204
+ * bytes in size, where `scaledHeight` can be determined by calling #TJSCALED()
1205
+ * with the JPEG image height and one of the scaling factors returned by
1206
+ * #tjGetScalingFactors(). The `dstBuf` pointer may also be used to decompress
1207
+ * into a specific region of a larger buffer.
1208
+ *
1209
+ * @param width desired width (in pixels) of the destination image. If this is
1210
+ * different than the width of the JPEG image being decompressed, then
1211
+ * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1212
+ * possible image that will fit within the desired width. If `width` is set to
1213
+ * 0, then only the height will be considered when determining the scaled image
1214
+ * size.
1215
+ *
1216
+ * @param pitch bytes per row in the destination image. Normally this should
1217
+ * be set to <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt>, if the
1218
+ * destination image should be unpadded, or
1219
+ * <tt>#TJPAD(scaledWidth * #tjPixelSize[pixelFormat])</tt> if each row of the
1220
+ * destination image should be padded to the nearest multiple of 4 bytes, as is
1221
+ * the case for Windows bitmaps. (NOTE: `scaledWidth` can be determined by
1222
+ * calling #TJSCALED() with the JPEG image width and one of the scaling factors
1223
+ * returned by #tjGetScalingFactors().) You can also be clever and use the
1224
+ * pitch parameter to skip rows, etc. Setting this parameter to 0 is the
1225
+ * equivalent of setting it to
1226
+ * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt>.
1227
+ *
1228
+ * @param height desired height (in pixels) of the destination image. If this
1229
+ * is different than the height of the JPEG image being decompressed, then
1230
+ * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1231
+ * possible image that will fit within the desired height. If `height` is set
1232
+ * to 0, then only the width will be considered when determining the scaled
1233
+ * image size.
1234
+ *
1235
+ * @param pixelFormat pixel format of the destination image (see @ref
1236
+ * TJPF "Pixel formats".)
1237
+ *
1238
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1239
+ * "flags"
1240
+ *
1241
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1242
+ * and #tjGetErrorCode().)
1243
+ */
1244
+ DLLEXPORT int tjDecompress2(tjhandle handle, const unsigned char *jpegBuf,
1245
+ unsigned long jpegSize, unsigned char *dstBuf,
1246
+ int width, int pitch, int height, int pixelFormat,
1247
+ int flags);
1248
+
1249
+
1250
+ /**
1251
+ * Decompress a JPEG image into a unified planar YUV image. This function
1252
+ * performs JPEG decompression but leaves out the color conversion step, so a
1253
+ * planar YUV image is generated instead of a packed-pixel image.
1254
+ *
1255
+ * @param handle a handle to a TurboJPEG decompressor or transformer instance
1256
+ *
1257
+ * @param jpegBuf pointer to a byte buffer containing the JPEG image to
1258
+ * decompress
1259
+ *
1260
+ * @param jpegSize size of the JPEG image (in bytes)
1261
+ *
1262
+ * @param dstBuf pointer to a buffer that will receive the unified planar YUV
1263
+ * decompressed image. Use #tjBufSizeYUV2() to determine the appropriate size
1264
+ * for this buffer based on the scaled image width, scaled image height, row
1265
+ * alignment, and level of chrominance subsampling. The Y, U (Cb), and V (Cr)
1266
+ * image planes will be stored sequentially in the buffer. (Refer to
1267
+ * @ref YUVnotes "YUV Image Format Notes".)
1268
+ *
1269
+ * @param width desired width (in pixels) of the YUV image. If this is
1270
+ * different than the width of the JPEG image being decompressed, then
1271
+ * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1272
+ * possible image that will fit within the desired width. If `width` is set to
1273
+ * 0, then only the height will be considered when determining the scaled image
1274
+ * size. If the scaled width is not an even multiple of the MCU block width
1275
+ * (see #tjMCUWidth), then an intermediate buffer copy will be performed.
1276
+ *
1277
+ * @param align row alignment (in bytes) of the YUV image (must be a power of
1278
+ * 2.) Setting this parameter to n will cause each row in each plane of the
1279
+ * YUV image to be padded to the nearest multiple of n bytes (1 = unpadded.)
1280
+ * To generate images suitable for X Video, `align` should be set to 4.
1281
+ *
1282
+ * @param height desired height (in pixels) of the YUV image. If this is
1283
+ * different than the height of the JPEG image being decompressed, then
1284
+ * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1285
+ * possible image that will fit within the desired height. If `height` is set
1286
+ * to 0, then only the width will be considered when determining the scaled
1287
+ * image size. If the scaled height is not an even multiple of the MCU block
1288
+ * height (see #tjMCUHeight), then an intermediate buffer copy will be
1289
+ * performed.
1290
+ *
1291
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1292
+ * "flags"
1293
+ *
1294
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1295
+ * and #tjGetErrorCode().)
1296
+ */
1297
+ DLLEXPORT int tjDecompressToYUV2(tjhandle handle, const unsigned char *jpegBuf,
1298
+ unsigned long jpegSize, unsigned char *dstBuf,
1299
+ int width, int align, int height, int flags);
1300
+
1301
+
1302
+ /**
1303
+ * Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image
1304
+ * planes. This function performs JPEG decompression but leaves out the color
1305
+ * conversion step, so a planar YUV image is generated instead of a
1306
+ * packed-pixel image.
1307
+ *
1308
+ * @param handle a handle to a TurboJPEG decompressor or transformer instance
1309
+ *
1310
+ * @param jpegBuf pointer to a byte buffer containing the JPEG image to
1311
+ * decompress
1312
+ *
1313
+ * @param jpegSize size of the JPEG image (in bytes)
1314
+ *
1315
+ * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
1316
+ * (or just a Y plane, if decompressing a grayscale image) that will receive
1317
+ * the decompressed image. These planes can be contiguous or non-contiguous in
1318
+ * memory. Use #tjPlaneSizeYUV() to determine the appropriate size for each
1319
+ * plane based on the scaled image width, scaled image height, strides, and
1320
+ * level of chrominance subsampling. Refer to @ref YUVnotes
1321
+ * "YUV Image Format Notes" for more details.
1322
+ *
1323
+ * @param width desired width (in pixels) of the YUV image. If this is
1324
+ * different than the width of the JPEG image being decompressed, then
1325
+ * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1326
+ * possible image that will fit within the desired width. If `width` is set to
1327
+ * 0, then only the height will be considered when determining the scaled image
1328
+ * size. If the scaled width is not an even multiple of the MCU block width
1329
+ * (see #tjMCUWidth), then an intermediate buffer copy will be performed.
1330
+ *
1331
+ * @param strides an array of integers, each specifying the number of bytes per
1332
+ * row in the corresponding plane of the YUV image. Setting the stride for any
1333
+ * plane to 0 is the same as setting it to the scaled plane width (see
1334
+ * @ref YUVnotes "YUV Image Format Notes".) If `strides` is NULL, then the
1335
+ * strides for all planes will be set to their respective scaled plane widths.
1336
+ * You can adjust the strides in order to add an arbitrary amount of row
1337
+ * padding to each plane or to decompress the JPEG image into a subregion of a
1338
+ * larger planar YUV image.
1339
+ *
1340
+ * @param height desired height (in pixels) of the YUV image. If this is
1341
+ * different than the height of the JPEG image being decompressed, then
1342
+ * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1343
+ * possible image that will fit within the desired height. If `height` is set
1344
+ * to 0, then only the width will be considered when determining the scaled
1345
+ * image size. If the scaled height is not an even multiple of the MCU block
1346
+ * height (see #tjMCUHeight), then an intermediate buffer copy will be
1347
+ * performed.
1348
+ *
1349
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1350
+ * "flags"
1351
+ *
1352
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1353
+ * and #tjGetErrorCode().)
1354
+ */
1355
+ DLLEXPORT int tjDecompressToYUVPlanes(tjhandle handle,
1356
+ const unsigned char *jpegBuf,
1357
+ unsigned long jpegSize,
1358
+ unsigned char **dstPlanes, int width,
1359
+ int *strides, int height, int flags);
1360
+
1361
+
1362
+ /**
1363
+ * Decode a unified planar YUV image into a packed-pixel RGB or grayscale
1364
+ * image. This function performs color conversion (which is accelerated in the
1365
+ * libjpeg-turbo implementation) but does not execute any of the other steps in
1366
+ * the JPEG decompression process.
1367
+ *
1368
+ * @param handle a handle to a TurboJPEG decompressor or transformer instance
1369
+ *
1370
+ * @param srcBuf pointer to a buffer containing a unified planar YUV source
1371
+ * image to be decoded. The size of this buffer should match the value
1372
+ * returned by #tjBufSizeYUV2() for the given image width, height, row
1373
+ * alignment, and level of chrominance subsampling. The Y, U (Cb), and V (Cr)
1374
+ * image planes should be stored sequentially in the source buffer. (Refer to
1375
+ * @ref YUVnotes "YUV Image Format Notes".)
1376
+ *
1377
+ * @param align row alignment (in bytes) of the YUV source image (must be a
1378
+ * power of 2.) Setting this parameter to n indicates that each row in each
1379
+ * plane of the YUV source image is padded to the nearest multiple of n bytes
1380
+ * (1 = unpadded.)
1381
+ *
1382
+ * @param subsamp the level of chrominance subsampling used in the YUV source
1383
+ * image (see @ref TJSAMP "Chrominance subsampling options".)
1384
+ *
1385
+ * @param dstBuf pointer to a buffer that will receive the packed-pixel decoded
1386
+ * image. This buffer should normally be `pitch * height` bytes in size, but
1387
+ * the `dstBuf` pointer can also be used to decode into a specific region of a
1388
+ * larger buffer.
1389
+ *
1390
+ * @param width width (in pixels) of the source and destination images
1391
+ *
1392
+ * @param pitch bytes per row in the destination image. Normally this should
1393
+ * be set to <tt>width * #tjPixelSize[pixelFormat]</tt>, if the destination
1394
+ * image should be unpadded, or
1395
+ * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each row of the
1396
+ * destination image should be padded to the nearest multiple of 4 bytes, as is
1397
+ * the case for Windows bitmaps. You can also be clever and use the pitch
1398
+ * parameter to skip rows, etc. Setting this parameter to 0 is the equivalent
1399
+ * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
1400
+ *
1401
+ * @param height height (in pixels) of the source and destination images
1402
+ *
1403
+ * @param pixelFormat pixel format of the destination image (see @ref TJPF
1404
+ * "Pixel formats".)
1405
+ *
1406
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1407
+ * "flags"
1408
+ *
1409
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1410
+ * and #tjGetErrorCode().)
1411
+ */
1412
+ DLLEXPORT int tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
1413
+ int align, int subsamp, unsigned char *dstBuf,
1414
+ int width, int pitch, int height, int pixelFormat,
1415
+ int flags);
1416
+
1417
+
1418
+ /**
1419
+ * Decode a set of Y, U (Cb), and V (Cr) image planes into a packed-pixel RGB
1420
+ * or grayscale image. This function performs color conversion (which is
1421
+ * accelerated in the libjpeg-turbo implementation) but does not execute any of
1422
+ * the other steps in the JPEG decompression process.
1423
+ *
1424
+ * @param handle a handle to a TurboJPEG decompressor or transformer instance
1425
+ *
1426
+ * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
1427
+ * (or just a Y plane, if decoding a grayscale image) that contain a YUV image
1428
+ * to be decoded. These planes can be contiguous or non-contiguous in memory.
1429
+ * The size of each plane should match the value returned by #tjPlaneSizeYUV()
1430
+ * for the given image width, height, strides, and level of chrominance
1431
+ * subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" for more
1432
+ * details.
1433
+ *
1434
+ * @param strides an array of integers, each specifying the number of bytes per
1435
+ * row in the corresponding plane of the YUV source image. Setting the stride
1436
+ * for any plane to 0 is the same as setting it to the plane width (see
1437
+ * @ref YUVnotes "YUV Image Format Notes".) If `strides` is NULL, then the
1438
+ * strides for all planes will be set to their respective plane widths. You
1439
+ * can adjust the strides in order to specify an arbitrary amount of row
1440
+ * padding in each plane or to decode a subregion of a larger planar YUV image.
1441
+ *
1442
+ * @param subsamp the level of chrominance subsampling used in the YUV source
1443
+ * image (see @ref TJSAMP "Chrominance subsampling options".)
1444
+ *
1445
+ * @param dstBuf pointer to a buffer that will receive the packed-pixel decoded
1446
+ * image. This buffer should normally be `pitch * height` bytes in size, but
1447
+ * the `dstBuf` pointer can also be used to decode into a specific region of a
1448
+ * larger buffer.
1449
+ *
1450
+ * @param width width (in pixels) of the source and destination images
1451
+ *
1452
+ * @param pitch bytes per row in the destination image. Normally this should
1453
+ * be set to <tt>width * #tjPixelSize[pixelFormat]</tt>, if the destination
1454
+ * image should be unpadded, or
1455
+ * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each row of the
1456
+ * destination image should be padded to the nearest multiple of 4 bytes, as is
1457
+ * the case for Windows bitmaps. You can also be clever and use the pitch
1458
+ * parameter to skip rows, etc. Setting this parameter to 0 is the equivalent
1459
+ * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
1460
+ *
1461
+ * @param height height (in pixels) of the source and destination images
1462
+ *
1463
+ * @param pixelFormat pixel format of the destination image (see @ref TJPF
1464
+ * "Pixel formats".)
1465
+ *
1466
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1467
+ * "flags"
1468
+ *
1469
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1470
+ * and #tjGetErrorCode().)
1471
+ */
1472
+ DLLEXPORT int tjDecodeYUVPlanes(tjhandle handle,
1473
+ const unsigned char **srcPlanes,
1474
+ const int *strides, int subsamp,
1475
+ unsigned char *dstBuf, int width, int pitch,
1476
+ int height, int pixelFormat, int flags);
1477
+
1478
+
1479
+ /**
1480
+ * Create a new TurboJPEG transformer instance.
1481
+ *
1482
+ * @return a handle to the newly-created instance, or NULL if an error
1483
+ * occurred (see #tjGetErrorStr2().)
1484
+ */
1485
+ DLLEXPORT tjhandle tjInitTransform(void);
1486
+
1487
+
1488
+ /**
1489
+ * Losslessly transform a JPEG image into another JPEG image. Lossless
1490
+ * transforms work by moving the raw DCT coefficients from one JPEG image
1491
+ * structure to another without altering the values of the coefficients. While
1492
+ * this is typically faster than decompressing the image, transforming it, and
1493
+ * re-compressing it, lossless transforms are not free. Each lossless
1494
+ * transform requires reading and performing Huffman decoding on all of the
1495
+ * coefficients in the source image, regardless of the size of the destination
1496
+ * image. Thus, this function provides a means of generating multiple
1497
+ * transformed images from the same source or applying multiple transformations
1498
+ * simultaneously, in order to eliminate the need to read the source
1499
+ * coefficients multiple times.
1500
+ *
1501
+ * @param handle a handle to a TurboJPEG transformer instance
1502
+ *
1503
+ * @param jpegBuf pointer to a byte buffer containing the JPEG source image to
1504
+ * transform
1505
+ *
1506
+ * @param jpegSize size of the JPEG source image (in bytes)
1507
+ *
1508
+ * @param n the number of transformed JPEG images to generate
1509
+ *
1510
+ * @param dstBufs pointer to an array of n byte buffers. `dstBufs[i]` will
1511
+ * receive a JPEG image that has been transformed using the parameters in
1512
+ * `transforms[i]`. TurboJPEG has the ability to reallocate the JPEG
1513
+ * destination buffer to accommodate the size of the transformed JPEG image.
1514
+ * Thus, you can choose to:
1515
+ * -# pre-allocate the JPEG destination buffer with an arbitrary size using
1516
+ * #tjAlloc() and let TurboJPEG grow the buffer as needed,
1517
+ * -# set `dstBufs[i]` to NULL to tell TurboJPEG to allocate the buffer for
1518
+ * you, or
1519
+ * -# pre-allocate the buffer to a "worst case" size determined by calling
1520
+ * #tjBufSize() with the transformed or cropped width and height and the level
1521
+ * of subsampling used in the source image. Under normal circumstances, this
1522
+ * should ensure that the buffer never has to be re-allocated. (Setting
1523
+ * #TJFLAG_NOREALLOC guarantees that it won't be.) Note, however, that there
1524
+ * are some rare cases (such as transforming images with a large amount of
1525
+ * embedded EXIF or ICC profile data) in which the transformed JPEG image will
1526
+ * be larger than the worst-case size, and #TJFLAG_NOREALLOC cannot be used in
1527
+ * those cases.
1528
+ * .
1529
+ * If you choose option 1, then `dstSizes[i]` should be set to the size of your
1530
+ * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
1531
+ * you should always check `dstBufs[i]` upon return from this function, as it
1532
+ * may have changed.
1533
+ *
1534
+ * @param dstSizes pointer to an array of n unsigned long variables that will
1535
+ * receive the actual sizes (in bytes) of each transformed JPEG image. If
1536
+ * `dstBufs[i]` points to a pre-allocated buffer, then `dstSizes[i]` should be
1537
+ * set to the size of the buffer. Upon return, `dstSizes[i]` will contain the
1538
+ * size of the transformed JPEG image (in bytes.)
1539
+ *
1540
+ * @param transforms pointer to an array of n #tjtransform structures, each of
1541
+ * which specifies the transform parameters and/or cropping region for the
1542
+ * corresponding transformed JPEG image.
1543
+ *
1544
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
1545
+ * "flags"
1546
+ *
1547
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
1548
+ * and #tjGetErrorCode().)
1549
+ */
1550
+ DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf,
1551
+ unsigned long jpegSize, int n,
1552
+ unsigned char **dstBufs, unsigned long *dstSizes,
1553
+ tjtransform *transforms, int flags);
1554
+
1555
+
1556
+ /**
1557
+ * Destroy a TurboJPEG compressor, decompressor, or transformer instance.
1558
+ *
1559
+ * @param handle a handle to a TurboJPEG compressor, decompressor or
1560
+ * transformer instance
1561
+ *
1562
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
1563
+ */
1564
+ DLLEXPORT int tjDestroy(tjhandle handle);
1565
+
1566
+
1567
+ /**
1568
+ * Allocate a byte buffer for use with TurboJPEG. You should always use this
1569
+ * function to allocate the JPEG destination buffer(s) for the compression and
1570
+ * transform functions unless you are disabling automatic buffer (re)allocation
1571
+ * (by setting #TJFLAG_NOREALLOC.)
1572
+ *
1573
+ * @param bytes the number of bytes to allocate
1574
+ *
1575
+ * @return a pointer to a newly-allocated buffer with the specified number of
1576
+ * bytes.
1577
+ *
1578
+ * @sa tjFree()
1579
+ */
1580
+ DLLEXPORT unsigned char *tjAlloc(int bytes);
1581
+
1582
+
1583
+ /**
1584
+ * Load a packed-pixel image from disk into memory.
1585
+ *
1586
+ * @param filename name of a file containing a packed-pixel image in Windows
1587
+ * BMP or PBMPLUS (PPM/PGM) format
1588
+ *
1589
+ * @param width pointer to an integer variable that will receive the width (in
1590
+ * pixels) of the packed-pixel image
1591
+ *
1592
+ * @param align row alignment of the packed-pixel buffer to be returned (must
1593
+ * be a power of 2.) Setting this parameter to n will cause all rows in the
1594
+ * buffer to be padded to the nearest multiple of n bytes (1 = unpadded.)
1595
+ *
1596
+ * @param height pointer to an integer variable that will receive the height
1597
+ * (in pixels) of the packed-pixel image
1598
+ *
1599
+ * @param pixelFormat pointer to an integer variable that specifies or will
1600
+ * receive the pixel format of the packed-pixel buffer. The behavior of
1601
+ * #tjLoadImage() will vary depending on the value of `*pixelFormat` passed to
1602
+ * the function:
1603
+ * - @ref TJPF_UNKNOWN : The packed-pixel buffer returned by this function will
1604
+ * use the most optimal pixel format for the file type, and `*pixelFormat` will
1605
+ * contain the ID of that pixel format upon successful return from this
1606
+ * function.
1607
+ * - @ref TJPF_GRAY : Only PGM files and 8-bit-per-pixel BMP files with a
1608
+ * grayscale colormap can be loaded.
1609
+ * - @ref TJPF_CMYK : The RGB or grayscale pixels stored in the file will be
1610
+ * converted using a quick & dirty algorithm that is suitable only for testing
1611
+ * purposes. (Proper conversion between CMYK and other formats requires a
1612
+ * color management system.)
1613
+ * - Other @ref TJPF "pixel formats" : The packed-pixel buffer will use the
1614
+ * specified pixel format, and pixel format conversion will be performed if
1615
+ * necessary.
1616
+ *
1617
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1618
+ * "flags".
1619
+ *
1620
+ * @return a pointer to a newly-allocated buffer containing the packed-pixel
1621
+ * image, converted to the chosen pixel format and with the chosen row
1622
+ * alignment, or NULL if an error occurred (see #tjGetErrorStr2().) This
1623
+ * buffer should be freed using #tjFree().
1624
+ */
1625
+ DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width,
1626
+ int align, int *height, int *pixelFormat,
1627
+ int flags);
1628
+
1629
+
1630
+ /**
1631
+ * Save a packed-pixel image from memory to disk.
1632
+ *
1633
+ * @param filename name of a file to which to save the packed-pixel image. The
1634
+ * image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, depending
1635
+ * on the file extension.
1636
+ *
1637
+ * @param buffer pointer to a buffer containing a packed-pixel RGB, grayscale,
1638
+ * or CMYK image to be saved
1639
+ *
1640
+ * @param width width (in pixels) of the packed-pixel image
1641
+ *
1642
+ * @param pitch bytes per row in the packed-pixel image. Setting this
1643
+ * parameter to 0 is the equivalent of setting it to
1644
+ * <tt>width * #tjPixelSize[pixelFormat]</tt>.
1645
+ *
1646
+ * @param height height (in pixels) of the packed-pixel image
1647
+ *
1648
+ * @param pixelFormat pixel format of the packed-pixel image (see @ref TJPF
1649
+ * "Pixel formats".) If this parameter is set to @ref TJPF_GRAY, then the
1650
+ * image will be stored in PGM or 8-bit-per-pixel (indexed color) BMP format.
1651
+ * Otherwise, the image will be stored in PPM or 24-bit-per-pixel BMP format.
1652
+ * If this parameter is set to @ref TJPF_CMYK, then the CMYK pixels will be
1653
+ * converted to RGB using a quick & dirty algorithm that is suitable only for
1654
+ * testing purposes. (Proper conversion between CMYK and other formats
1655
+ * requires a color management system.)
1656
+ *
1657
+ * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1658
+ * "flags".
1659
+ *
1660
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
1661
+ */
1662
+ DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer,
1663
+ int width, int pitch, int height, int pixelFormat,
1664
+ int flags);
1665
+
1666
+
1667
+ /**
1668
+ * Free a byte buffer previously allocated by TurboJPEG. You should always use
1669
+ * this function to free JPEG destination buffer(s) that were automatically
1670
+ * (re)allocated by the compression and transform functions or that were
1671
+ * manually allocated using #tjAlloc().
1672
+ *
1673
+ * @param buffer address of the buffer to free. If the address is NULL, then
1674
+ * this function has no effect.
1675
+ *
1676
+ * @sa tjAlloc()
1677
+ */
1678
+ DLLEXPORT void tjFree(unsigned char *buffer);
1679
+
1680
+
1681
+ /**
1682
+ * Returns a descriptive error message explaining why the last command failed.
1683
+ *
1684
+ * @param handle a handle to a TurboJPEG compressor, decompressor, or
1685
+ * transformer instance, or NULL if the error was generated by a global
1686
+ * function (but note that retrieving the error message for a global function
1687
+ * is thread-safe only on platforms that support thread-local storage.)
1688
+ *
1689
+ * @return a descriptive error message explaining why the last command failed.
1690
+ */
1691
+ DLLEXPORT char *tjGetErrorStr2(tjhandle handle);
1692
+
1693
+
1694
+ /**
1695
+ * Returns a code indicating the severity of the last error. See
1696
+ * @ref TJERR "Error codes".
1697
+ *
1698
+ * @param handle a handle to a TurboJPEG compressor, decompressor or
1699
+ * transformer instance
1700
+ *
1701
+ * @return a code indicating the severity of the last error. See
1702
+ * @ref TJERR "Error codes".
1703
+ */
1704
+ DLLEXPORT int tjGetErrorCode(tjhandle handle);
1705
+
1706
+
1707
+ /* Backward compatibility functions and macros (nothing to see here) */
1708
+
1709
+ /* TurboJPEG 1.0+ */
1710
+
1711
+ #define NUMSUBOPT TJ_NUMSAMP
1712
+ #define TJ_444 TJSAMP_444
1713
+ #define TJ_422 TJSAMP_422
1714
+ #define TJ_420 TJSAMP_420
1715
+ #define TJ_411 TJSAMP_420
1716
+ #define TJ_GRAYSCALE TJSAMP_GRAY
1717
+
1718
+ #define TJ_BGR 1
1719
+ #define TJ_BOTTOMUP TJFLAG_BOTTOMUP
1720
+ #define TJ_FORCEMMX TJFLAG_FORCEMMX
1721
+ #define TJ_FORCESSE TJFLAG_FORCESSE
1722
+ #define TJ_FORCESSE2 TJFLAG_FORCESSE2
1723
+ #define TJ_ALPHAFIRST 64
1724
+ #define TJ_FORCESSE3 TJFLAG_FORCESSE3
1725
+ #define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE
1726
+
1727
+ DLLEXPORT unsigned long TJBUFSIZE(int width, int height);
1728
+
1729
+ DLLEXPORT int tjCompress(tjhandle handle, unsigned char *srcBuf, int width,
1730
+ int pitch, int height, int pixelSize,
1731
+ unsigned char *dstBuf, unsigned long *compressedSize,
1732
+ int jpegSubsamp, int jpegQual, int flags);
1733
+
1734
+ DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf,
1735
+ unsigned long jpegSize, unsigned char *dstBuf,
1736
+ int width, int pitch, int height, int pixelSize,
1737
+ int flags);
1738
+
1739
+ DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf,
1740
+ unsigned long jpegSize, int *width,
1741
+ int *height);
1742
+
1743
+ DLLEXPORT char *tjGetErrorStr(void);
1744
+
1745
+ /* TurboJPEG 1.1+ */
1746
+
1747
+ #define TJ_YUV 512
1748
+
1749
+ DLLEXPORT unsigned long TJBUFSIZEYUV(int width, int height, int jpegSubsamp);
1750
+
1751
+ DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf,
1752
+ unsigned long jpegSize, int *width,
1753
+ int *height, int *jpegSubsamp);
1754
+
1755
+ DLLEXPORT int tjDecompressToYUV(tjhandle handle, unsigned char *jpegBuf,
1756
+ unsigned long jpegSize, unsigned char *dstBuf,
1757
+ int flags);
1758
+
1759
+ DLLEXPORT int tjEncodeYUV(tjhandle handle, unsigned char *srcBuf, int width,
1760
+ int pitch, int height, int pixelSize,
1761
+ unsigned char *dstBuf, int subsamp, int flags);
1762
+
1763
+ /* TurboJPEG 1.2+ */
1764
+
1765
+ #define TJFLAG_FORCEMMX 8
1766
+ #define TJFLAG_FORCESSE 16
1767
+ #define TJFLAG_FORCESSE2 32
1768
+ #define TJFLAG_FORCESSE3 128
1769
+
1770
+ DLLEXPORT unsigned long tjBufSizeYUV(int width, int height, int subsamp);
1771
+
1772
+ DLLEXPORT int tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, int width,
1773
+ int pitch, int height, int pixelFormat,
1774
+ unsigned char *dstBuf, int subsamp, int flags);
1775
+
1776
+ /**
1777
+ * @}
1778
+ */
1779
+
1780
+ #ifdef __cplusplus
1781
+ }
1782
+ #endif
1783
+
1784
+ #endif