epeg 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (504) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/MANIFEST +5 -0
  4. data/TODO +1 -0
  5. data/epeg/.dockerignore +4 -0
  6. data/epeg/.gitignore +5 -0
  7. data/epeg/CMakeLists.txt +30 -0
  8. data/epeg/Dockerfile +23 -0
  9. data/epeg/Epeg.h +90 -0
  10. data/epeg/README.md +42 -0
  11. data/epeg/epeg_main.c +1642 -0
  12. data/epeg/epeg_private.h +85 -0
  13. data/epeg/example/.gitignore +1 -0
  14. data/epeg/example/CMakeLists.txt +20 -0
  15. data/epeg/example/example.jpg +0 -0
  16. data/epeg/example/rotatetest.c +29 -0
  17. data/epeg/example/scaletest.c +48 -0
  18. data/epeg/vendor/libjpeg-turbo-2.0.4/BUILDING.md +828 -0
  19. data/epeg/vendor/libjpeg-turbo-2.0.4/CMakeLists.txt +1420 -0
  20. data/epeg/vendor/libjpeg-turbo-2.0.4/ChangeLog.md +1494 -0
  21. data/epeg/vendor/libjpeg-turbo-2.0.4/LICENSE.md +132 -0
  22. data/epeg/vendor/libjpeg-turbo-2.0.4/README.ijg +277 -0
  23. data/epeg/vendor/libjpeg-turbo-2.0.4/README.md +356 -0
  24. data/epeg/vendor/libjpeg-turbo-2.0.4/cderror.h +137 -0
  25. data/epeg/vendor/libjpeg-turbo-2.0.4/cdjpeg.c +145 -0
  26. data/epeg/vendor/libjpeg-turbo-2.0.4/cdjpeg.h +157 -0
  27. data/epeg/vendor/libjpeg-turbo-2.0.4/change.log +315 -0
  28. data/epeg/vendor/libjpeg-turbo-2.0.4/cjpeg.1 +354 -0
  29. data/epeg/vendor/libjpeg-turbo-2.0.4/cjpeg.c +695 -0
  30. data/epeg/vendor/libjpeg-turbo-2.0.4/cmakescripts/BuildPackages.cmake +182 -0
  31. data/epeg/vendor/libjpeg-turbo-2.0.4/cmakescripts/GNUInstallDirs.cmake +416 -0
  32. data/epeg/vendor/libjpeg-turbo-2.0.4/cmakescripts/cmake_uninstall.cmake.in +24 -0
  33. data/epeg/vendor/libjpeg-turbo-2.0.4/cmakescripts/testclean.cmake +41 -0
  34. data/epeg/vendor/libjpeg-turbo-2.0.4/cmyk.h +61 -0
  35. data/epeg/vendor/libjpeg-turbo-2.0.4/coderules.txt +78 -0
  36. data/epeg/vendor/libjpeg-turbo-2.0.4/djpeg.1 +296 -0
  37. data/epeg/vendor/libjpeg-turbo-2.0.4/djpeg.c +822 -0
  38. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/annotated.html +104 -0
  39. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/bc_s.png +0 -0
  40. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/bdwn.png +0 -0
  41. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/classes.html +106 -0
  42. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/closed.png +0 -0
  43. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/doxygen-extra.css +3 -0
  44. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/doxygen.css +1184 -0
  45. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/doxygen.png +0 -0
  46. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/dynsections.js +97 -0
  47. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2blank.png +0 -0
  48. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2cl.png +0 -0
  49. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2doc.png +0 -0
  50. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2folderclosed.png +0 -0
  51. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2folderopen.png +0 -0
  52. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2lastnode.png +0 -0
  53. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2link.png +0 -0
  54. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2mlastnode.png +0 -0
  55. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2mnode.png +0 -0
  56. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2mo.png +0 -0
  57. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2node.png +0 -0
  58. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2ns.png +0 -0
  59. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2plastnode.png +0 -0
  60. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2pnode.png +0 -0
  61. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2splitbar.png +0 -0
  62. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/ftv2vertline.png +0 -0
  63. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/functions.html +134 -0
  64. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/functions_vars.html +134 -0
  65. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/group___turbo_j_p_e_g.html +2775 -0
  66. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/index.html +90 -0
  67. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/jquery.js +8 -0
  68. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/modules.html +95 -0
  69. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/nav_f.png +0 -0
  70. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/nav_g.png +0 -0
  71. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/nav_h.png +0 -0
  72. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/open.png +0 -0
  73. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_63.html +26 -0
  74. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_63.js +4 -0
  75. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_64.html +26 -0
  76. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_64.js +5 -0
  77. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_68.html +26 -0
  78. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_68.js +4 -0
  79. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_6e.html +26 -0
  80. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_6e.js +4 -0
  81. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_6f.html +26 -0
  82. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_6f.js +5 -0
  83. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_72.html +26 -0
  84. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_72.js +4 -0
  85. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_74.html +26 -0
  86. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_74.js +102 -0
  87. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_77.html +26 -0
  88. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_77.js +4 -0
  89. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_78.html +26 -0
  90. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_78.js +4 -0
  91. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_79.html +26 -0
  92. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/all_79.js +4 -0
  93. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/classes_74.html +26 -0
  94. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/classes_74.js +6 -0
  95. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/close.png +0 -0
  96. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/enums_74.html +26 -0
  97. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/enums_74.js +8 -0
  98. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/enumvalues_74.html +26 -0
  99. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/enumvalues_74.js +37 -0
  100. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/functions_74.html +26 -0
  101. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/functions_74.js +31 -0
  102. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/groups_74.html +26 -0
  103. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/groups_74.js +4 -0
  104. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/mag_sel.png +0 -0
  105. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/nomatches.html +12 -0
  106. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/search.css +271 -0
  107. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/search.js +809 -0
  108. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/search_l.png +0 -0
  109. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/search_m.png +0 -0
  110. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/search_r.png +0 -0
  111. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/typedefs_74.html +26 -0
  112. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/typedefs_74.js +5 -0
  113. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_63.html +26 -0
  114. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_63.js +4 -0
  115. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_64.html +26 -0
  116. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_64.js +5 -0
  117. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_68.html +26 -0
  118. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_68.js +4 -0
  119. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_6e.html +26 -0
  120. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_6e.js +4 -0
  121. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_6f.html +26 -0
  122. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_6f.js +5 -0
  123. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_72.html +26 -0
  124. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_72.js +4 -0
  125. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_74.html +26 -0
  126. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_74.js +10 -0
  127. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_77.html +26 -0
  128. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_77.js +4 -0
  129. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_78.html +26 -0
  130. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_78.js +4 -0
  131. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_79.html +26 -0
  132. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/search/variables_79.js +4 -0
  133. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/structtjregion.html +186 -0
  134. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/structtjscalingfactor.html +148 -0
  135. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/structtjtransform.html +212 -0
  136. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/sync_off.png +0 -0
  137. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/sync_on.png +0 -0
  138. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/tab_a.png +0 -0
  139. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/tab_b.png +0 -0
  140. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/tab_h.png +0 -0
  141. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/tab_s.png +0 -0
  142. data/epeg/vendor/libjpeg-turbo-2.0.4/doc/html/tabs.css +60 -0
  143. data/epeg/vendor/libjpeg-turbo-2.0.4/doxygen-extra.css +3 -0
  144. data/epeg/vendor/libjpeg-turbo-2.0.4/doxygen.config +16 -0
  145. data/epeg/vendor/libjpeg-turbo-2.0.4/example.txt +464 -0
  146. data/epeg/vendor/libjpeg-turbo-2.0.4/jaricom.c +157 -0
  147. data/epeg/vendor/libjpeg-turbo-2.0.4/java/CMakeLists.txt +88 -0
  148. data/epeg/vendor/libjpeg-turbo-2.0.4/java/MANIFEST.MF +2 -0
  149. data/epeg/vendor/libjpeg-turbo-2.0.4/java/README +52 -0
  150. data/epeg/vendor/libjpeg-turbo-2.0.4/java/TJBench.java +1021 -0
  151. data/epeg/vendor/libjpeg-turbo-2.0.4/java/TJExample.java +405 -0
  152. data/epeg/vendor/libjpeg-turbo-2.0.4/java/TJUnitTest.java +960 -0
  153. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/allclasses-frame.html +24 -0
  154. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/allclasses-noframe.html +24 -0
  155. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/constant-values.html +532 -0
  156. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/deprecated-list.html +252 -0
  157. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/help-doc.html +210 -0
  158. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/index-all.html +1029 -0
  159. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/index.html +71 -0
  160. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJ.html +1356 -0
  161. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html +926 -0
  162. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html +241 -0
  163. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html +1255 -0
  164. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJException.html +340 -0
  165. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html +343 -0
  166. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html +751 -0
  167. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html +421 -0
  168. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html +765 -0
  169. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/package-frame.html +31 -0
  170. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/package-summary.html +202 -0
  171. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/org/libjpegturbo/turbojpeg/package-tree.html +160 -0
  172. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/overview-tree.html +164 -0
  173. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/package-list +1 -0
  174. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/resources/background.gif +0 -0
  175. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/resources/tab.gif +0 -0
  176. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/resources/titlebar.gif +0 -0
  177. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/resources/titlebar_end.gif +0 -0
  178. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/script.js +30 -0
  179. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/serialized-form.html +176 -0
  180. data/epeg/vendor/libjpeg-turbo-2.0.4/java/doc/stylesheet.css +474 -0
  181. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJ.java +584 -0
  182. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJCompressor.java +677 -0
  183. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJCustomFilter.java +76 -0
  184. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJDecompressor.java +931 -0
  185. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJException.java +78 -0
  186. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJLoader-unix.java.in +59 -0
  187. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJLoader-win.java.in +35 -0
  188. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJScalingFactor.java +115 -0
  189. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJTransform.java +227 -0
  190. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/TJTransformer.java +163 -0
  191. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org/libjpegturbo/turbojpeg/YUVImage.java +445 -0
  192. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org_libjpegturbo_turbojpeg_TJ.h +129 -0
  193. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org_libjpegturbo_turbojpeg_TJCompressor.h +101 -0
  194. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org_libjpegturbo_turbojpeg_TJDecompressor.h +101 -0
  195. data/epeg/vendor/libjpeg-turbo-2.0.4/java/org_libjpegturbo_turbojpeg_TJTransformer.h +29 -0
  196. data/epeg/vendor/libjpeg-turbo-2.0.4/jcapimin.c +295 -0
  197. data/epeg/vendor/libjpeg-turbo-2.0.4/jcapistd.c +162 -0
  198. data/epeg/vendor/libjpeg-turbo-2.0.4/jcarith.c +932 -0
  199. data/epeg/vendor/libjpeg-turbo-2.0.4/jccoefct.c +449 -0
  200. data/epeg/vendor/libjpeg-turbo-2.0.4/jccolext.c +144 -0
  201. data/epeg/vendor/libjpeg-turbo-2.0.4/jccolor.c +710 -0
  202. data/epeg/vendor/libjpeg-turbo-2.0.4/jcdctmgr.c +721 -0
  203. data/epeg/vendor/libjpeg-turbo-2.0.4/jchuff.c +1096 -0
  204. data/epeg/vendor/libjpeg-turbo-2.0.4/jchuff.h +42 -0
  205. data/epeg/vendor/libjpeg-turbo-2.0.4/jcicc.c +105 -0
  206. data/epeg/vendor/libjpeg-turbo-2.0.4/jcinit.c +77 -0
  207. data/epeg/vendor/libjpeg-turbo-2.0.4/jcmainct.c +162 -0
  208. data/epeg/vendor/libjpeg-turbo-2.0.4/jcmarker.c +664 -0
  209. data/epeg/vendor/libjpeg-turbo-2.0.4/jcmaster.c +640 -0
  210. data/epeg/vendor/libjpeg-turbo-2.0.4/jcomapi.c +109 -0
  211. data/epeg/vendor/libjpeg-turbo-2.0.4/jconfig.h.in +73 -0
  212. data/epeg/vendor/libjpeg-turbo-2.0.4/jconfig.txt +143 -0
  213. data/epeg/vendor/libjpeg-turbo-2.0.4/jconfigint.h.in +31 -0
  214. data/epeg/vendor/libjpeg-turbo-2.0.4/jcparam.c +541 -0
  215. data/epeg/vendor/libjpeg-turbo-2.0.4/jcphuff.c +1105 -0
  216. data/epeg/vendor/libjpeg-turbo-2.0.4/jcprepct.c +351 -0
  217. data/epeg/vendor/libjpeg-turbo-2.0.4/jcsample.c +539 -0
  218. data/epeg/vendor/libjpeg-turbo-2.0.4/jcstest.c +126 -0
  219. data/epeg/vendor/libjpeg-turbo-2.0.4/jctrans.c +400 -0
  220. data/epeg/vendor/libjpeg-turbo-2.0.4/jdapimin.c +407 -0
  221. data/epeg/vendor/libjpeg-turbo-2.0.4/jdapistd.c +639 -0
  222. data/epeg/vendor/libjpeg-turbo-2.0.4/jdarith.c +773 -0
  223. data/epeg/vendor/libjpeg-turbo-2.0.4/jdatadst-tj.c +203 -0
  224. data/epeg/vendor/libjpeg-turbo-2.0.4/jdatadst.c +293 -0
  225. data/epeg/vendor/libjpeg-turbo-2.0.4/jdatasrc-tj.c +194 -0
  226. data/epeg/vendor/libjpeg-turbo-2.0.4/jdatasrc.c +295 -0
  227. data/epeg/vendor/libjpeg-turbo-2.0.4/jdcoefct.c +692 -0
  228. data/epeg/vendor/libjpeg-turbo-2.0.4/jdcoefct.h +82 -0
  229. data/epeg/vendor/libjpeg-turbo-2.0.4/jdcol565.c +384 -0
  230. data/epeg/vendor/libjpeg-turbo-2.0.4/jdcolext.c +143 -0
  231. data/epeg/vendor/libjpeg-turbo-2.0.4/jdcolor.c +883 -0
  232. data/epeg/vendor/libjpeg-turbo-2.0.4/jdct.h +208 -0
  233. data/epeg/vendor/libjpeg-turbo-2.0.4/jddctmgr.c +352 -0
  234. data/epeg/vendor/libjpeg-turbo-2.0.4/jdhuff.c +831 -0
  235. data/epeg/vendor/libjpeg-turbo-2.0.4/jdhuff.h +238 -0
  236. data/epeg/vendor/libjpeg-turbo-2.0.4/jdicc.c +171 -0
  237. data/epeg/vendor/libjpeg-turbo-2.0.4/jdinput.c +408 -0
  238. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmainct.c +460 -0
  239. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmainct.h +71 -0
  240. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmarker.c +1377 -0
  241. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmaster.c +737 -0
  242. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmaster.h +28 -0
  243. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmerge.c +617 -0
  244. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmrg565.c +354 -0
  245. data/epeg/vendor/libjpeg-turbo-2.0.4/jdmrgext.c +184 -0
  246. data/epeg/vendor/libjpeg-turbo-2.0.4/jdphuff.c +687 -0
  247. data/epeg/vendor/libjpeg-turbo-2.0.4/jdpostct.c +294 -0
  248. data/epeg/vendor/libjpeg-turbo-2.0.4/jdsample.c +518 -0
  249. data/epeg/vendor/libjpeg-turbo-2.0.4/jdsample.h +50 -0
  250. data/epeg/vendor/libjpeg-turbo-2.0.4/jdtrans.c +155 -0
  251. data/epeg/vendor/libjpeg-turbo-2.0.4/jerror.c +251 -0
  252. data/epeg/vendor/libjpeg-turbo-2.0.4/jerror.h +316 -0
  253. data/epeg/vendor/libjpeg-turbo-2.0.4/jfdctflt.c +169 -0
  254. data/epeg/vendor/libjpeg-turbo-2.0.4/jfdctfst.c +227 -0
  255. data/epeg/vendor/libjpeg-turbo-2.0.4/jfdctint.c +288 -0
  256. data/epeg/vendor/libjpeg-turbo-2.0.4/jidctflt.c +240 -0
  257. data/epeg/vendor/libjpeg-turbo-2.0.4/jidctfst.c +371 -0
  258. data/epeg/vendor/libjpeg-turbo-2.0.4/jidctint.c +2627 -0
  259. data/epeg/vendor/libjpeg-turbo-2.0.4/jidctred.c +409 -0
  260. data/epeg/vendor/libjpeg-turbo-2.0.4/jinclude.h +88 -0
  261. data/epeg/vendor/libjpeg-turbo-2.0.4/jmemmgr.c +1179 -0
  262. data/epeg/vendor/libjpeg-turbo-2.0.4/jmemnobs.c +115 -0
  263. data/epeg/vendor/libjpeg-turbo-2.0.4/jmemsys.h +178 -0
  264. data/epeg/vendor/libjpeg-turbo-2.0.4/jmorecfg.h +421 -0
  265. data/epeg/vendor/libjpeg-turbo-2.0.4/jpeg_nbits_table.h +4098 -0
  266. data/epeg/vendor/libjpeg-turbo-2.0.4/jpegcomp.h +31 -0
  267. data/epeg/vendor/libjpeg-turbo-2.0.4/jpegint.h +368 -0
  268. data/epeg/vendor/libjpeg-turbo-2.0.4/jpeglib.h +1132 -0
  269. data/epeg/vendor/libjpeg-turbo-2.0.4/jpegtran.1 +295 -0
  270. data/epeg/vendor/libjpeg-turbo-2.0.4/jpegtran.c +601 -0
  271. data/epeg/vendor/libjpeg-turbo-2.0.4/jquant1.c +859 -0
  272. data/epeg/vendor/libjpeg-turbo-2.0.4/jquant2.c +1285 -0
  273. data/epeg/vendor/libjpeg-turbo-2.0.4/jsimd.h +117 -0
  274. data/epeg/vendor/libjpeg-turbo-2.0.4/jsimd_none.c +418 -0
  275. data/epeg/vendor/libjpeg-turbo-2.0.4/jsimddct.h +70 -0
  276. data/epeg/vendor/libjpeg-turbo-2.0.4/jstdhuff.c +143 -0
  277. data/epeg/vendor/libjpeg-turbo-2.0.4/jutils.c +133 -0
  278. data/epeg/vendor/libjpeg-turbo-2.0.4/jversion.h +52 -0
  279. data/epeg/vendor/libjpeg-turbo-2.0.4/libjpeg.map.in +11 -0
  280. data/epeg/vendor/libjpeg-turbo-2.0.4/libjpeg.txt +3144 -0
  281. data/epeg/vendor/libjpeg-turbo-2.0.4/md5/CMakeLists.txt +1 -0
  282. data/epeg/vendor/libjpeg-turbo-2.0.4/md5/md5.c +275 -0
  283. data/epeg/vendor/libjpeg-turbo-2.0.4/md5/md5.h +57 -0
  284. data/epeg/vendor/libjpeg-turbo-2.0.4/md5/md5cmp.c +59 -0
  285. data/epeg/vendor/libjpeg-turbo-2.0.4/md5/md5hl.c +125 -0
  286. data/epeg/vendor/libjpeg-turbo-2.0.4/rdbmp.c +689 -0
  287. data/epeg/vendor/libjpeg-turbo-2.0.4/rdcolmap.c +254 -0
  288. data/epeg/vendor/libjpeg-turbo-2.0.4/rdgif.c +39 -0
  289. data/epeg/vendor/libjpeg-turbo-2.0.4/rdjpgcom.1 +63 -0
  290. data/epeg/vendor/libjpeg-turbo-2.0.4/rdjpgcom.c +510 -0
  291. data/epeg/vendor/libjpeg-turbo-2.0.4/rdppm.c +766 -0
  292. data/epeg/vendor/libjpeg-turbo-2.0.4/rdrle.c +389 -0
  293. data/epeg/vendor/libjpeg-turbo-2.0.4/rdswitch.c +424 -0
  294. data/epeg/vendor/libjpeg-turbo-2.0.4/rdtarga.c +509 -0
  295. data/epeg/vendor/libjpeg-turbo-2.0.4/release/Distribution.xml.in +24 -0
  296. data/epeg/vendor/libjpeg-turbo-2.0.4/release/License.rtf +20 -0
  297. data/epeg/vendor/libjpeg-turbo-2.0.4/release/ReadMe.txt +5 -0
  298. data/epeg/vendor/libjpeg-turbo-2.0.4/release/Welcome.rtf +17 -0
  299. data/epeg/vendor/libjpeg-turbo-2.0.4/release/deb-control.in +31 -0
  300. data/epeg/vendor/libjpeg-turbo-2.0.4/release/installer.nsi.in +191 -0
  301. data/epeg/vendor/libjpeg-turbo-2.0.4/release/libjpeg.pc.in +10 -0
  302. data/epeg/vendor/libjpeg-turbo-2.0.4/release/libturbojpeg.pc.in +10 -0
  303. data/epeg/vendor/libjpeg-turbo-2.0.4/release/makecygwinpkg.in +66 -0
  304. data/epeg/vendor/libjpeg-turbo-2.0.4/release/makedpkg.in +115 -0
  305. data/epeg/vendor/libjpeg-turbo-2.0.4/release/makemacpkg.in +284 -0
  306. data/epeg/vendor/libjpeg-turbo-2.0.4/release/makerpm.in +30 -0
  307. data/epeg/vendor/libjpeg-turbo-2.0.4/release/makesrpm.in +48 -0
  308. data/epeg/vendor/libjpeg-turbo-2.0.4/release/maketarball.in +51 -0
  309. data/epeg/vendor/libjpeg-turbo-2.0.4/release/rpm.spec.in +221 -0
  310. data/epeg/vendor/libjpeg-turbo-2.0.4/release/uninstall.in +113 -0
  311. data/epeg/vendor/libjpeg-turbo-2.0.4/sharedlib/CMakeLists.txt +99 -0
  312. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/CMakeLists.txt +385 -0
  313. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/arm/jsimd.c +721 -0
  314. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/arm/jsimd_neon.S +2878 -0
  315. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/arm64/jsimd.c +798 -0
  316. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/arm64/jsimd_neon.S +3433 -0
  317. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/gas-preprocessor.in +1 -0
  318. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jccolext-avx2.asm +578 -0
  319. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jccolext-mmx.asm +476 -0
  320. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jccolext-sse2.asm +503 -0
  321. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jccolor-avx2.asm +121 -0
  322. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jccolor-mmx.asm +121 -0
  323. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jccolor-sse2.asm +120 -0
  324. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcgray-avx2.asm +113 -0
  325. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcgray-mmx.asm +113 -0
  326. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcgray-sse2.asm +112 -0
  327. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcgryext-avx2.asm +457 -0
  328. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcgryext-mmx.asm +355 -0
  329. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcgryext-sse2.asm +382 -0
  330. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jchuff-sse2.asm +424 -0
  331. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcphuff-sse2.asm +660 -0
  332. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcsample-avx2.asm +388 -0
  333. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcsample-mmx.asm +324 -0
  334. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jcsample-sse2.asm +351 -0
  335. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdcolext-avx2.asm +515 -0
  336. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdcolext-mmx.asm +404 -0
  337. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdcolext-sse2.asm +458 -0
  338. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdcolor-avx2.asm +118 -0
  339. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdcolor-mmx.asm +117 -0
  340. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdcolor-sse2.asm +117 -0
  341. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdmerge-avx2.asm +136 -0
  342. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdmerge-mmx.asm +123 -0
  343. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdmerge-sse2.asm +135 -0
  344. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdmrgext-avx2.asm +575 -0
  345. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdmrgext-mmx.asm +460 -0
  346. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdmrgext-sse2.asm +517 -0
  347. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdsample-avx2.asm +760 -0
  348. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdsample-mmx.asm +731 -0
  349. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jdsample-sse2.asm +724 -0
  350. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jfdctflt-3dn.asm +318 -0
  351. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jfdctflt-sse.asm +369 -0
  352. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jfdctfst-mmx.asm +395 -0
  353. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jfdctfst-sse2.asm +403 -0
  354. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jfdctint-avx2.asm +331 -0
  355. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jfdctint-mmx.asm +620 -0
  356. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jfdctint-sse2.asm +633 -0
  357. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctflt-3dn.asm +451 -0
  358. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctflt-sse.asm +571 -0
  359. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctflt-sse2.asm +497 -0
  360. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctfst-mmx.asm +499 -0
  361. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctfst-sse2.asm +501 -0
  362. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctint-avx2.asm +453 -0
  363. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctint-mmx.asm +851 -0
  364. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctint-sse2.asm +858 -0
  365. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctred-mmx.asm +704 -0
  366. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jidctred-sse2.asm +592 -0
  367. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jquant-3dn.asm +230 -0
  368. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jquant-mmx.asm +276 -0
  369. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jquant-sse.asm +208 -0
  370. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jquantf-sse2.asm +168 -0
  371. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jquanti-avx2.asm +188 -0
  372. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jquanti-sse2.asm +201 -0
  373. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jsimd.c +1253 -0
  374. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/i386/jsimdcpu.asm +135 -0
  375. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/jsimd.h +1083 -0
  376. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jccolext-mmi.c +483 -0
  377. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jccolor-mmi.c +148 -0
  378. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jcsample-mmi.c +100 -0
  379. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jcsample.h +28 -0
  380. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jdcolext-mmi.c +424 -0
  381. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jdcolor-mmi.c +139 -0
  382. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jdsample-mmi.c +245 -0
  383. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jfdctint-mmi.c +398 -0
  384. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jidctint-mmi.c +571 -0
  385. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jquanti-mmi.c +130 -0
  386. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jsimd.c +610 -0
  387. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/jsimd_mmi.h +57 -0
  388. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/loongson/loongson-mmintrin.h +1324 -0
  389. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/mips/jsimd.c +1123 -0
  390. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/mips/jsimd_dspr2.S +4479 -0
  391. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/mips/jsimd_dspr2_asm.h +292 -0
  392. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/nasm/jcolsamp.inc +135 -0
  393. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/nasm/jdct.inc +31 -0
  394. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/nasm/jpeg_nbits_table.inc +4097 -0
  395. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/nasm/jsimdcfg.inc +93 -0
  396. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/nasm/jsimdcfg.inc.h +131 -0
  397. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/nasm/jsimdext.inc +479 -0
  398. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jccolext-altivec.c +269 -0
  399. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jccolor-altivec.c +116 -0
  400. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jcgray-altivec.c +111 -0
  401. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jcgryext-altivec.c +228 -0
  402. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jcsample-altivec.c +159 -0
  403. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jcsample.h +28 -0
  404. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jdcolext-altivec.c +276 -0
  405. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jdcolor-altivec.c +106 -0
  406. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jdmerge-altivec.c +130 -0
  407. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jdmrgext-altivec.c +329 -0
  408. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jdsample-altivec.c +400 -0
  409. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jfdctfst-altivec.c +154 -0
  410. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jfdctint-altivec.c +258 -0
  411. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jidctfst-altivec.c +255 -0
  412. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jidctint-altivec.c +357 -0
  413. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jquanti-altivec.c +250 -0
  414. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jsimd.c +872 -0
  415. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/powerpc/jsimd_altivec.h +98 -0
  416. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jccolext-avx2.asm +558 -0
  417. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jccolext-sse2.asm +483 -0
  418. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jccolor-avx2.asm +121 -0
  419. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jccolor-sse2.asm +120 -0
  420. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jcgray-avx2.asm +113 -0
  421. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jcgray-sse2.asm +112 -0
  422. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jcgryext-avx2.asm +437 -0
  423. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jcgryext-sse2.asm +362 -0
  424. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jchuff-sse2.asm +346 -0
  425. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jcphuff-sse2.asm +637 -0
  426. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jcsample-avx2.asm +366 -0
  427. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jcsample-sse2.asm +329 -0
  428. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdcolext-avx2.asm +495 -0
  429. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdcolext-sse2.asm +438 -0
  430. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdcolor-avx2.asm +118 -0
  431. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdcolor-sse2.asm +117 -0
  432. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdmerge-avx2.asm +136 -0
  433. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdmerge-sse2.asm +135 -0
  434. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdmrgext-avx2.asm +593 -0
  435. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdmrgext-sse2.asm +535 -0
  436. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdsample-avx2.asm +695 -0
  437. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jdsample-sse2.asm +664 -0
  438. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jfdctflt-sse.asm +355 -0
  439. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jfdctfst-sse2.asm +389 -0
  440. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jfdctint-avx2.asm +320 -0
  441. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jfdctint-sse2.asm +619 -0
  442. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jidctflt-sse2.asm +481 -0
  443. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jidctfst-sse2.asm +490 -0
  444. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jidctint-avx2.asm +417 -0
  445. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jidctint-sse2.asm +846 -0
  446. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jidctred-sse2.asm +573 -0
  447. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jquantf-sse2.asm +154 -0
  448. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jquanti-avx2.asm +162 -0
  449. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jquanti-sse2.asm +187 -0
  450. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jsimd.c +1076 -0
  451. data/epeg/vendor/libjpeg-turbo-2.0.4/simd/x86_64/jsimdcpu.asm +86 -0
  452. data/epeg/vendor/libjpeg-turbo-2.0.4/structure.txt +904 -0
  453. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/nightshot_iso_100.bmp +0 -0
  454. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/nightshot_iso_100.txt +25 -0
  455. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/test.scan +5 -0
  456. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/test1.icc +0 -0
  457. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/test1.icc.txt +20 -0
  458. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/test2.icc +0 -0
  459. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/test2.icc.txt +20 -0
  460. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/testimgari.jpg +0 -0
  461. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/testimgint.jpg +0 -0
  462. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/testorig.jpg +0 -0
  463. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/testorig.ppm +4 -0
  464. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/testorig12.jpg +0 -0
  465. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/vgl_5674_0098.bmp +0 -0
  466. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/vgl_6434_0018a.bmp +0 -0
  467. data/epeg/vendor/libjpeg-turbo-2.0.4/testimages/vgl_6548_0026a.bmp +0 -0
  468. data/epeg/vendor/libjpeg-turbo-2.0.4/tjbench.c +1031 -0
  469. data/epeg/vendor/libjpeg-turbo-2.0.4/tjbenchtest.in +256 -0
  470. data/epeg/vendor/libjpeg-turbo-2.0.4/tjbenchtest.java.in +215 -0
  471. data/epeg/vendor/libjpeg-turbo-2.0.4/tjexample.c +396 -0
  472. data/epeg/vendor/libjpeg-turbo-2.0.4/tjexampletest.in +149 -0
  473. data/epeg/vendor/libjpeg-turbo-2.0.4/tjexampletest.java.in +151 -0
  474. data/epeg/vendor/libjpeg-turbo-2.0.4/tjunittest.c +931 -0
  475. data/epeg/vendor/libjpeg-turbo-2.0.4/tjutil.c +70 -0
  476. data/epeg/vendor/libjpeg-turbo-2.0.4/tjutil.h +47 -0
  477. data/epeg/vendor/libjpeg-turbo-2.0.4/transupp.c +1628 -0
  478. data/epeg/vendor/libjpeg-turbo-2.0.4/transupp.h +210 -0
  479. data/epeg/vendor/libjpeg-turbo-2.0.4/turbojpeg-jni.c +1246 -0
  480. data/epeg/vendor/libjpeg-turbo-2.0.4/turbojpeg-mapfile +65 -0
  481. data/epeg/vendor/libjpeg-turbo-2.0.4/turbojpeg-mapfile.jni +101 -0
  482. data/epeg/vendor/libjpeg-turbo-2.0.4/turbojpeg.c +2152 -0
  483. data/epeg/vendor/libjpeg-turbo-2.0.4/turbojpeg.h +1744 -0
  484. data/epeg/vendor/libjpeg-turbo-2.0.4/usage.txt +635 -0
  485. data/epeg/vendor/libjpeg-turbo-2.0.4/win/jconfig.h.in +34 -0
  486. data/epeg/vendor/libjpeg-turbo-2.0.4/win/jpeg62-memsrcdst.def +108 -0
  487. data/epeg/vendor/libjpeg-turbo-2.0.4/win/jpeg62.def +106 -0
  488. data/epeg/vendor/libjpeg-turbo-2.0.4/win/jpeg7-memsrcdst.def +110 -0
  489. data/epeg/vendor/libjpeg-turbo-2.0.4/win/jpeg7.def +108 -0
  490. data/epeg/vendor/libjpeg-turbo-2.0.4/win/jpeg8.def +111 -0
  491. data/epeg/vendor/libjpeg-turbo-2.0.4/wizard.txt +212 -0
  492. data/epeg/vendor/libjpeg-turbo-2.0.4/wrbmp.c +558 -0
  493. data/epeg/vendor/libjpeg-turbo-2.0.4/wrgif.c +413 -0
  494. data/epeg/vendor/libjpeg-turbo-2.0.4/wrjpgcom.1 +103 -0
  495. data/epeg/vendor/libjpeg-turbo-2.0.4/wrjpgcom.c +591 -0
  496. data/epeg/vendor/libjpeg-turbo-2.0.4/wrppm.c +365 -0
  497. data/epeg/vendor/libjpeg-turbo-2.0.4/wrrle.c +309 -0
  498. data/epeg/vendor/libjpeg-turbo-2.0.4/wrtarga.c +261 -0
  499. data/epeg.c +131 -0
  500. data/epeg.gemspec +18 -0
  501. data/extconf.rb +80 -0
  502. data/test.jpg +0 -0
  503. data/test.rb +42 -0
  504. metadata +546 -0
@@ -0,0 +1,2152 @@
1
+ /*
2
+ * Copyright (C)2009-2019 D. R. Commander. All Rights Reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * - Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * - Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * - Neither the name of the libjpeg-turbo Project nor the names of its
13
+ * contributors may be used to endorse or promote products derived from this
14
+ * software without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ * POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ /* TurboJPEG/LJT: this implements the TurboJPEG API using libjpeg or
30
+ libjpeg-turbo */
31
+
32
+ #include <stdio.h>
33
+ #include <stdlib.h>
34
+ #include <ctype.h>
35
+ #include <jinclude.h>
36
+ #define JPEG_INTERNALS
37
+ #include <jpeglib.h>
38
+ #include <jerror.h>
39
+ #include <setjmp.h>
40
+ #include <errno.h>
41
+ #include "./turbojpeg.h"
42
+ #include "./tjutil.h"
43
+ #include "transupp.h"
44
+ #include "./jpegcomp.h"
45
+ #include "./cdjpeg.h"
46
+
47
+ extern void jpeg_mem_dest_tj(j_compress_ptr, unsigned char **, unsigned long *,
48
+ boolean);
49
+ extern void jpeg_mem_src_tj(j_decompress_ptr, const unsigned char *,
50
+ unsigned long);
51
+
52
+ #define PAD(v, p) ((v + (p) - 1) & (~((p) - 1)))
53
+ #define IS_POW2(x) (((x) & (x - 1)) == 0)
54
+
55
+
56
+ /* Error handling (based on example in example.txt) */
57
+
58
+ static char errStr[JMSG_LENGTH_MAX] = "No error";
59
+
60
+ struct my_error_mgr {
61
+ struct jpeg_error_mgr pub;
62
+ jmp_buf setjmp_buffer;
63
+ void (*emit_message) (j_common_ptr, int);
64
+ boolean warning, stopOnWarning;
65
+ };
66
+ typedef struct my_error_mgr *my_error_ptr;
67
+
68
+ #define JMESSAGE(code, string) string,
69
+ static const char *turbojpeg_message_table[] = {
70
+ #include "cderror.h"
71
+ NULL
72
+ };
73
+
74
+ static void my_error_exit(j_common_ptr cinfo)
75
+ {
76
+ my_error_ptr myerr = (my_error_ptr)cinfo->err;
77
+
78
+ (*cinfo->err->output_message) (cinfo);
79
+ longjmp(myerr->setjmp_buffer, 1);
80
+ }
81
+
82
+ /* Based on output_message() in jerror.c */
83
+
84
+ static void my_output_message(j_common_ptr cinfo)
85
+ {
86
+ (*cinfo->err->format_message) (cinfo, errStr);
87
+ }
88
+
89
+ static void my_emit_message(j_common_ptr cinfo, int msg_level)
90
+ {
91
+ my_error_ptr myerr = (my_error_ptr)cinfo->err;
92
+
93
+ myerr->emit_message(cinfo, msg_level);
94
+ if (msg_level < 0) {
95
+ myerr->warning = TRUE;
96
+ if (myerr->stopOnWarning) longjmp(myerr->setjmp_buffer, 1);
97
+ }
98
+ }
99
+
100
+
101
+ /* Global structures, macros, etc. */
102
+
103
+ enum { COMPRESS = 1, DECOMPRESS = 2 };
104
+
105
+ typedef struct _tjinstance {
106
+ struct jpeg_compress_struct cinfo;
107
+ struct jpeg_decompress_struct dinfo;
108
+ struct my_error_mgr jerr;
109
+ int init, headerRead;
110
+ char errStr[JMSG_LENGTH_MAX];
111
+ boolean isInstanceError;
112
+ } tjinstance;
113
+
114
+ static const int pixelsize[TJ_NUMSAMP] = { 3, 3, 3, 1, 3, 3 };
115
+
116
+ static const JXFORM_CODE xformtypes[TJ_NUMXOP] = {
117
+ JXFORM_NONE, JXFORM_FLIP_H, JXFORM_FLIP_V, JXFORM_TRANSPOSE,
118
+ JXFORM_TRANSVERSE, JXFORM_ROT_90, JXFORM_ROT_180, JXFORM_ROT_270
119
+ };
120
+
121
+ #define NUMSF 16
122
+ static const tjscalingfactor sf[NUMSF] = {
123
+ { 2, 1 },
124
+ { 15, 8 },
125
+ { 7, 4 },
126
+ { 13, 8 },
127
+ { 3, 2 },
128
+ { 11, 8 },
129
+ { 5, 4 },
130
+ { 9, 8 },
131
+ { 1, 1 },
132
+ { 7, 8 },
133
+ { 3, 4 },
134
+ { 5, 8 },
135
+ { 1, 2 },
136
+ { 3, 8 },
137
+ { 1, 4 },
138
+ { 1, 8 }
139
+ };
140
+
141
+ static J_COLOR_SPACE pf2cs[TJ_NUMPF] = {
142
+ JCS_EXT_RGB, JCS_EXT_BGR, JCS_EXT_RGBX, JCS_EXT_BGRX, JCS_EXT_XBGR,
143
+ JCS_EXT_XRGB, JCS_GRAYSCALE, JCS_EXT_RGBA, JCS_EXT_BGRA, JCS_EXT_ABGR,
144
+ JCS_EXT_ARGB, JCS_CMYK
145
+ };
146
+
147
+ static int cs2pf[JPEG_NUMCS] = {
148
+ TJPF_UNKNOWN, TJPF_GRAY,
149
+ #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
150
+ TJPF_RGB,
151
+ #elif RGB_RED == 2 && RGB_GREEN == 1 && RGB_BLUE == 0 && RGB_PIXELSIZE == 3
152
+ TJPF_BGR,
153
+ #elif RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 4
154
+ TJPF_RGBX,
155
+ #elif RGB_RED == 2 && RGB_GREEN == 1 && RGB_BLUE == 0 && RGB_PIXELSIZE == 4
156
+ TJPF_BGRX,
157
+ #elif RGB_RED == 3 && RGB_GREEN == 2 && RGB_BLUE == 1 && RGB_PIXELSIZE == 4
158
+ TJPF_XBGR,
159
+ #elif RGB_RED == 1 && RGB_GREEN == 2 && RGB_BLUE == 3 && RGB_PIXELSIZE == 4
160
+ TJPF_XRGB,
161
+ #endif
162
+ TJPF_UNKNOWN, TJPF_CMYK, TJPF_UNKNOWN, TJPF_RGB, TJPF_RGBX, TJPF_BGR,
163
+ TJPF_BGRX, TJPF_XBGR, TJPF_XRGB, TJPF_RGBA, TJPF_BGRA, TJPF_ABGR, TJPF_ARGB,
164
+ TJPF_UNKNOWN
165
+ };
166
+
167
+ #define THROWG(m) { \
168
+ snprintf(errStr, JMSG_LENGTH_MAX, "%s", m); \
169
+ retval = -1; goto bailout; \
170
+ }
171
+ #define THROW_UNIX(m) { \
172
+ snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
173
+ retval = -1; goto bailout; \
174
+ }
175
+ #define THROW(m) { \
176
+ snprintf(this->errStr, JMSG_LENGTH_MAX, "%s", m); \
177
+ this->isInstanceError = TRUE; THROWG(m) \
178
+ }
179
+
180
+ #define GET_INSTANCE(handle) \
181
+ tjinstance *this = (tjinstance *)handle; \
182
+ j_compress_ptr cinfo = NULL; \
183
+ j_decompress_ptr dinfo = NULL; \
184
+ \
185
+ if (!this) { \
186
+ snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
187
+ return -1; \
188
+ } \
189
+ cinfo = &this->cinfo; dinfo = &this->dinfo; \
190
+ this->jerr.warning = FALSE; \
191
+ this->isInstanceError = FALSE;
192
+
193
+ #define GET_CINSTANCE(handle) \
194
+ tjinstance *this = (tjinstance *)handle; \
195
+ j_compress_ptr cinfo = NULL; \
196
+ \
197
+ if (!this) { \
198
+ snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
199
+ return -1; \
200
+ } \
201
+ cinfo = &this->cinfo; \
202
+ this->jerr.warning = FALSE; \
203
+ this->isInstanceError = FALSE;
204
+
205
+ #define GET_DINSTANCE(handle) \
206
+ tjinstance *this = (tjinstance *)handle; \
207
+ j_decompress_ptr dinfo = NULL; \
208
+ \
209
+ if (!this) { \
210
+ snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
211
+ return -1; \
212
+ } \
213
+ dinfo = &this->dinfo; \
214
+ this->jerr.warning = FALSE; \
215
+ this->isInstanceError = FALSE;
216
+
217
+ static int getPixelFormat(int pixelSize, int flags)
218
+ {
219
+ if (pixelSize == 1) return TJPF_GRAY;
220
+ if (pixelSize == 3) {
221
+ if (flags & TJ_BGR) return TJPF_BGR;
222
+ else return TJPF_RGB;
223
+ }
224
+ if (pixelSize == 4) {
225
+ if (flags & TJ_ALPHAFIRST) {
226
+ if (flags & TJ_BGR) return TJPF_XBGR;
227
+ else return TJPF_XRGB;
228
+ } else {
229
+ if (flags & TJ_BGR) return TJPF_BGRX;
230
+ else return TJPF_RGBX;
231
+ }
232
+ }
233
+ return -1;
234
+ }
235
+
236
+ static int setCompDefaults(struct jpeg_compress_struct *cinfo, int pixelFormat,
237
+ int subsamp, int jpegQual, int flags)
238
+ {
239
+ int retval = 0;
240
+ #ifndef NO_GETENV
241
+ char *env = NULL;
242
+ #endif
243
+
244
+ cinfo->in_color_space = pf2cs[pixelFormat];
245
+ cinfo->input_components = tjPixelSize[pixelFormat];
246
+ jpeg_set_defaults(cinfo);
247
+
248
+ #ifndef NO_GETENV
249
+ if ((env = getenv("TJ_OPTIMIZE")) != NULL && strlen(env) > 0 &&
250
+ !strcmp(env, "1"))
251
+ cinfo->optimize_coding = TRUE;
252
+ if ((env = getenv("TJ_ARITHMETIC")) != NULL && strlen(env) > 0 &&
253
+ !strcmp(env, "1"))
254
+ cinfo->arith_code = TRUE;
255
+ if ((env = getenv("TJ_RESTART")) != NULL && strlen(env) > 0) {
256
+ int temp = -1;
257
+ char tempc = 0;
258
+
259
+ if (sscanf(env, "%d%c", &temp, &tempc) >= 1 && temp >= 0 &&
260
+ temp <= 65535) {
261
+ if (toupper(tempc) == 'B') {
262
+ cinfo->restart_interval = temp;
263
+ cinfo->restart_in_rows = 0;
264
+ } else
265
+ cinfo->restart_in_rows = temp;
266
+ }
267
+ }
268
+ #endif
269
+
270
+ if (jpegQual >= 0) {
271
+ jpeg_set_quality(cinfo, jpegQual, TRUE);
272
+ if (jpegQual >= 96 || flags & TJFLAG_ACCURATEDCT)
273
+ cinfo->dct_method = JDCT_ISLOW;
274
+ else
275
+ cinfo->dct_method = JDCT_FASTEST;
276
+ }
277
+ if (subsamp == TJSAMP_GRAY)
278
+ jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
279
+ else if (pixelFormat == TJPF_CMYK)
280
+ jpeg_set_colorspace(cinfo, JCS_YCCK);
281
+ else
282
+ jpeg_set_colorspace(cinfo, JCS_YCbCr);
283
+
284
+ if (flags & TJFLAG_PROGRESSIVE)
285
+ jpeg_simple_progression(cinfo);
286
+ #ifndef NO_GETENV
287
+ else if ((env = getenv("TJ_PROGRESSIVE")) != NULL && strlen(env) > 0 &&
288
+ !strcmp(env, "1"))
289
+ jpeg_simple_progression(cinfo);
290
+ #endif
291
+
292
+ cinfo->comp_info[0].h_samp_factor = tjMCUWidth[subsamp] / 8;
293
+ cinfo->comp_info[1].h_samp_factor = 1;
294
+ cinfo->comp_info[2].h_samp_factor = 1;
295
+ if (cinfo->num_components > 3)
296
+ cinfo->comp_info[3].h_samp_factor = tjMCUWidth[subsamp] / 8;
297
+ cinfo->comp_info[0].v_samp_factor = tjMCUHeight[subsamp] / 8;
298
+ cinfo->comp_info[1].v_samp_factor = 1;
299
+ cinfo->comp_info[2].v_samp_factor = 1;
300
+ if (cinfo->num_components > 3)
301
+ cinfo->comp_info[3].v_samp_factor = tjMCUHeight[subsamp] / 8;
302
+
303
+ return retval;
304
+ }
305
+
306
+
307
+ static int getSubsamp(j_decompress_ptr dinfo)
308
+ {
309
+ int retval = -1, i, k;
310
+
311
+ /* The sampling factors actually have no meaning with grayscale JPEG files,
312
+ and in fact it's possible to generate grayscale JPEGs with sampling
313
+ factors > 1 (even though those sampling factors are ignored by the
314
+ decompressor.) Thus, we need to treat grayscale as a special case. */
315
+ if (dinfo->num_components == 1 && dinfo->jpeg_color_space == JCS_GRAYSCALE)
316
+ return TJSAMP_GRAY;
317
+
318
+ for (i = 0; i < NUMSUBOPT; i++) {
319
+ if (dinfo->num_components == pixelsize[i] ||
320
+ ((dinfo->jpeg_color_space == JCS_YCCK ||
321
+ dinfo->jpeg_color_space == JCS_CMYK) &&
322
+ pixelsize[i] == 3 && dinfo->num_components == 4)) {
323
+ if (dinfo->comp_info[0].h_samp_factor == tjMCUWidth[i] / 8 &&
324
+ dinfo->comp_info[0].v_samp_factor == tjMCUHeight[i] / 8) {
325
+ int match = 0;
326
+
327
+ for (k = 1; k < dinfo->num_components; k++) {
328
+ int href = 1, vref = 1;
329
+
330
+ if ((dinfo->jpeg_color_space == JCS_YCCK ||
331
+ dinfo->jpeg_color_space == JCS_CMYK) && k == 3) {
332
+ href = tjMCUWidth[i] / 8; vref = tjMCUHeight[i] / 8;
333
+ }
334
+ if (dinfo->comp_info[k].h_samp_factor == href &&
335
+ dinfo->comp_info[k].v_samp_factor == vref)
336
+ match++;
337
+ }
338
+ if (match == dinfo->num_components - 1) {
339
+ retval = i; break;
340
+ }
341
+ }
342
+ /* Handle 4:2:2 and 4:4:0 images whose sampling factors are specified
343
+ in non-standard ways. */
344
+ if (dinfo->comp_info[0].h_samp_factor == 2 &&
345
+ dinfo->comp_info[0].v_samp_factor == 2 &&
346
+ (i == TJSAMP_422 || i == TJSAMP_440)) {
347
+ int match = 0;
348
+
349
+ for (k = 1; k < dinfo->num_components; k++) {
350
+ int href = tjMCUHeight[i] / 8, vref = tjMCUWidth[i] / 8;
351
+
352
+ if ((dinfo->jpeg_color_space == JCS_YCCK ||
353
+ dinfo->jpeg_color_space == JCS_CMYK) && k == 3) {
354
+ href = vref = 2;
355
+ }
356
+ if (dinfo->comp_info[k].h_samp_factor == href &&
357
+ dinfo->comp_info[k].v_samp_factor == vref)
358
+ match++;
359
+ }
360
+ if (match == dinfo->num_components - 1) {
361
+ retval = i; break;
362
+ }
363
+ }
364
+ /* Handle 4:4:4 images whose sampling factors are specified in
365
+ non-standard ways. */
366
+ if (dinfo->comp_info[0].h_samp_factor *
367
+ dinfo->comp_info[0].v_samp_factor <=
368
+ D_MAX_BLOCKS_IN_MCU / pixelsize[i] && i == TJSAMP_444) {
369
+ int match = 0;
370
+ for (k = 1; k < dinfo->num_components; k++) {
371
+ if (dinfo->comp_info[k].h_samp_factor ==
372
+ dinfo->comp_info[0].h_samp_factor &&
373
+ dinfo->comp_info[k].v_samp_factor ==
374
+ dinfo->comp_info[0].v_samp_factor)
375
+ match++;
376
+ if (match == dinfo->num_components - 1) {
377
+ retval = i; break;
378
+ }
379
+ }
380
+ }
381
+ }
382
+ }
383
+ return retval;
384
+ }
385
+
386
+
387
+ /* General API functions */
388
+
389
+ DLLEXPORT char *tjGetErrorStr2(tjhandle handle)
390
+ {
391
+ tjinstance *this = (tjinstance *)handle;
392
+
393
+ if (this && this->isInstanceError) {
394
+ this->isInstanceError = FALSE;
395
+ return this->errStr;
396
+ } else
397
+ return errStr;
398
+ }
399
+
400
+
401
+ DLLEXPORT char *tjGetErrorStr(void)
402
+ {
403
+ return errStr;
404
+ }
405
+
406
+
407
+ DLLEXPORT int tjGetErrorCode(tjhandle handle)
408
+ {
409
+ tjinstance *this = (tjinstance *)handle;
410
+
411
+ if (this && this->jerr.warning) return TJERR_WARNING;
412
+ else return TJERR_FATAL;
413
+ }
414
+
415
+
416
+ DLLEXPORT int tjDestroy(tjhandle handle)
417
+ {
418
+ GET_INSTANCE(handle);
419
+
420
+ if (setjmp(this->jerr.setjmp_buffer)) return -1;
421
+ if (this->init & COMPRESS) jpeg_destroy_compress(cinfo);
422
+ if (this->init & DECOMPRESS) jpeg_destroy_decompress(dinfo);
423
+ free(this);
424
+ return 0;
425
+ }
426
+
427
+
428
+ /* These are exposed mainly because Windows can't malloc() and free() across
429
+ DLL boundaries except when the CRT DLL is used, and we don't use the CRT DLL
430
+ with turbojpeg.dll for compatibility reasons. However, these functions
431
+ can potentially be used for other purposes by different implementations. */
432
+
433
+ DLLEXPORT void tjFree(unsigned char *buf)
434
+ {
435
+ if (buf) free(buf);
436
+ }
437
+
438
+
439
+ DLLEXPORT unsigned char *tjAlloc(int bytes)
440
+ {
441
+ return (unsigned char *)malloc(bytes);
442
+ }
443
+
444
+
445
+ /* Compressor */
446
+
447
+ static tjhandle _tjInitCompress(tjinstance *this)
448
+ {
449
+ static unsigned char buffer[1];
450
+ unsigned char *buf = buffer;
451
+ unsigned long size = 1;
452
+
453
+ /* This is also straight out of example.txt */
454
+ this->cinfo.err = jpeg_std_error(&this->jerr.pub);
455
+ this->jerr.pub.error_exit = my_error_exit;
456
+ this->jerr.pub.output_message = my_output_message;
457
+ this->jerr.emit_message = this->jerr.pub.emit_message;
458
+ this->jerr.pub.emit_message = my_emit_message;
459
+ this->jerr.pub.addon_message_table = turbojpeg_message_table;
460
+ this->jerr.pub.first_addon_message = JMSG_FIRSTADDONCODE;
461
+ this->jerr.pub.last_addon_message = JMSG_LASTADDONCODE;
462
+
463
+ if (setjmp(this->jerr.setjmp_buffer)) {
464
+ /* If we get here, the JPEG code has signaled an error. */
465
+ if (this) free(this);
466
+ return NULL;
467
+ }
468
+
469
+ jpeg_create_compress(&this->cinfo);
470
+ /* Make an initial call so it will create the destination manager */
471
+ jpeg_mem_dest_tj(&this->cinfo, &buf, &size, 0);
472
+
473
+ this->init |= COMPRESS;
474
+ return (tjhandle)this;
475
+ }
476
+
477
+ DLLEXPORT tjhandle tjInitCompress(void)
478
+ {
479
+ tjinstance *this = NULL;
480
+
481
+ if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
482
+ snprintf(errStr, JMSG_LENGTH_MAX,
483
+ "tjInitCompress(): Memory allocation failure");
484
+ return NULL;
485
+ }
486
+ MEMZERO(this, sizeof(tjinstance));
487
+ snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
488
+ return _tjInitCompress(this);
489
+ }
490
+
491
+
492
+ DLLEXPORT unsigned long tjBufSize(int width, int height, int jpegSubsamp)
493
+ {
494
+ unsigned long long retval = 0;
495
+ int mcuw, mcuh, chromasf;
496
+
497
+ if (width < 1 || height < 1 || jpegSubsamp < 0 || jpegSubsamp >= NUMSUBOPT)
498
+ THROWG("tjBufSize(): Invalid argument");
499
+
500
+ /* This allows for rare corner cases in which a JPEG image can actually be
501
+ larger than the uncompressed input (we wouldn't mention it if it hadn't
502
+ happened before.) */
503
+ mcuw = tjMCUWidth[jpegSubsamp];
504
+ mcuh = tjMCUHeight[jpegSubsamp];
505
+ chromasf = jpegSubsamp == TJSAMP_GRAY ? 0 : 4 * 64 / (mcuw * mcuh);
506
+ retval = PAD(width, mcuw) * PAD(height, mcuh) * (2ULL + chromasf) + 2048ULL;
507
+ if (retval > (unsigned long long)((unsigned long)-1))
508
+ THROWG("tjBufSize(): Image is too large");
509
+
510
+ bailout:
511
+ return (unsigned long)retval;
512
+ }
513
+
514
+ DLLEXPORT unsigned long TJBUFSIZE(int width, int height)
515
+ {
516
+ unsigned long long retval = 0;
517
+
518
+ if (width < 1 || height < 1)
519
+ THROWG("TJBUFSIZE(): Invalid argument");
520
+
521
+ /* This allows for rare corner cases in which a JPEG image can actually be
522
+ larger than the uncompressed input (we wouldn't mention it if it hadn't
523
+ happened before.) */
524
+ retval = PAD(width, 16) * PAD(height, 16) * 6ULL + 2048ULL;
525
+ if (retval > (unsigned long long)((unsigned long)-1))
526
+ THROWG("TJBUFSIZE(): Image is too large");
527
+
528
+ bailout:
529
+ return (unsigned long)retval;
530
+ }
531
+
532
+
533
+ DLLEXPORT unsigned long tjBufSizeYUV2(int width, int pad, int height,
534
+ int subsamp)
535
+ {
536
+ unsigned long long retval = 0;
537
+ int nc, i;
538
+
539
+ if (subsamp < 0 || subsamp >= NUMSUBOPT)
540
+ THROWG("tjBufSizeYUV2(): Invalid argument");
541
+
542
+ nc = (subsamp == TJSAMP_GRAY ? 1 : 3);
543
+ for (i = 0; i < nc; i++) {
544
+ int pw = tjPlaneWidth(i, width, subsamp);
545
+ int stride = PAD(pw, pad);
546
+ int ph = tjPlaneHeight(i, height, subsamp);
547
+
548
+ if (pw < 0 || ph < 0) return -1;
549
+ else retval += (unsigned long long)stride * ph;
550
+ }
551
+ if (retval > (unsigned long long)((unsigned long)-1))
552
+ THROWG("tjBufSizeYUV2(): Image is too large");
553
+
554
+ bailout:
555
+ return (unsigned long)retval;
556
+ }
557
+
558
+ DLLEXPORT unsigned long tjBufSizeYUV(int width, int height, int subsamp)
559
+ {
560
+ return tjBufSizeYUV2(width, 4, height, subsamp);
561
+ }
562
+
563
+ DLLEXPORT unsigned long TJBUFSIZEYUV(int width, int height, int subsamp)
564
+ {
565
+ return tjBufSizeYUV(width, height, subsamp);
566
+ }
567
+
568
+
569
+ DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp)
570
+ {
571
+ int pw, nc, retval = 0;
572
+
573
+ if (width < 1 || subsamp < 0 || subsamp >= TJ_NUMSAMP)
574
+ THROWG("tjPlaneWidth(): Invalid argument");
575
+ nc = (subsamp == TJSAMP_GRAY ? 1 : 3);
576
+ if (componentID < 0 || componentID >= nc)
577
+ THROWG("tjPlaneWidth(): Invalid argument");
578
+
579
+ pw = PAD(width, tjMCUWidth[subsamp] / 8);
580
+ if (componentID == 0)
581
+ retval = pw;
582
+ else
583
+ retval = pw * 8 / tjMCUWidth[subsamp];
584
+
585
+ bailout:
586
+ return retval;
587
+ }
588
+
589
+
590
+ DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp)
591
+ {
592
+ int ph, nc, retval = 0;
593
+
594
+ if (height < 1 || subsamp < 0 || subsamp >= TJ_NUMSAMP)
595
+ THROWG("tjPlaneHeight(): Invalid argument");
596
+ nc = (subsamp == TJSAMP_GRAY ? 1 : 3);
597
+ if (componentID < 0 || componentID >= nc)
598
+ THROWG("tjPlaneHeight(): Invalid argument");
599
+
600
+ ph = PAD(height, tjMCUHeight[subsamp] / 8);
601
+ if (componentID == 0)
602
+ retval = ph;
603
+ else
604
+ retval = ph * 8 / tjMCUHeight[subsamp];
605
+
606
+ bailout:
607
+ return retval;
608
+ }
609
+
610
+
611
+ DLLEXPORT unsigned long tjPlaneSizeYUV(int componentID, int width, int stride,
612
+ int height, int subsamp)
613
+ {
614
+ unsigned long long retval = 0;
615
+ int pw, ph;
616
+
617
+ if (width < 1 || height < 1 || subsamp < 0 || subsamp >= NUMSUBOPT)
618
+ THROWG("tjPlaneSizeYUV(): Invalid argument");
619
+
620
+ pw = tjPlaneWidth(componentID, width, subsamp);
621
+ ph = tjPlaneHeight(componentID, height, subsamp);
622
+ if (pw < 0 || ph < 0) return -1;
623
+
624
+ if (stride == 0) stride = pw;
625
+ else stride = abs(stride);
626
+
627
+ retval = (unsigned long long)stride * (ph - 1) + pw;
628
+ if (retval > (unsigned long long)((unsigned long)-1))
629
+ THROWG("tjPlaneSizeYUV(): Image is too large");
630
+
631
+ bailout:
632
+ return (unsigned long)retval;
633
+ }
634
+
635
+
636
+ DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf,
637
+ int width, int pitch, int height, int pixelFormat,
638
+ unsigned char **jpegBuf, unsigned long *jpegSize,
639
+ int jpegSubsamp, int jpegQual, int flags)
640
+ {
641
+ int i, retval = 0, alloc = 1;
642
+ JSAMPROW *row_pointer = NULL;
643
+
644
+ GET_CINSTANCE(handle)
645
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
646
+ if ((this->init & COMPRESS) == 0)
647
+ THROW("tjCompress2(): Instance has not been initialized for compression");
648
+
649
+ if (srcBuf == NULL || width <= 0 || pitch < 0 || height <= 0 ||
650
+ pixelFormat < 0 || pixelFormat >= TJ_NUMPF || jpegBuf == NULL ||
651
+ jpegSize == NULL || jpegSubsamp < 0 || jpegSubsamp >= NUMSUBOPT ||
652
+ jpegQual < 0 || jpegQual > 100)
653
+ THROW("tjCompress2(): Invalid argument");
654
+
655
+ if (pitch == 0) pitch = width * tjPixelSize[pixelFormat];
656
+
657
+ if ((row_pointer = (JSAMPROW *)malloc(sizeof(JSAMPROW) * height)) == NULL)
658
+ THROW("tjCompress2(): Memory allocation failure");
659
+
660
+ if (setjmp(this->jerr.setjmp_buffer)) {
661
+ /* If we get here, the JPEG code has signaled an error. */
662
+ retval = -1; goto bailout;
663
+ }
664
+
665
+ cinfo->image_width = width;
666
+ cinfo->image_height = height;
667
+
668
+ #ifndef NO_PUTENV
669
+ if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
670
+ else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
671
+ else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
672
+ #endif
673
+
674
+ if (flags & TJFLAG_NOREALLOC) {
675
+ alloc = 0; *jpegSize = tjBufSize(width, height, jpegSubsamp);
676
+ }
677
+ jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
678
+ if (setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual, flags) == -1)
679
+ return -1;
680
+
681
+ jpeg_start_compress(cinfo, TRUE);
682
+ for (i = 0; i < height; i++) {
683
+ if (flags & TJFLAG_BOTTOMUP)
684
+ row_pointer[i] = (JSAMPROW)&srcBuf[(height - i - 1) * (size_t)pitch];
685
+ else
686
+ row_pointer[i] = (JSAMPROW)&srcBuf[i * (size_t)pitch];
687
+ }
688
+ while (cinfo->next_scanline < cinfo->image_height)
689
+ jpeg_write_scanlines(cinfo, &row_pointer[cinfo->next_scanline],
690
+ cinfo->image_height - cinfo->next_scanline);
691
+ jpeg_finish_compress(cinfo);
692
+
693
+ bailout:
694
+ if (cinfo->global_state > CSTATE_START) jpeg_abort_compress(cinfo);
695
+ if (row_pointer) free(row_pointer);
696
+ if (this->jerr.warning) retval = -1;
697
+ this->jerr.stopOnWarning = FALSE;
698
+ return retval;
699
+ }
700
+
701
+ DLLEXPORT int tjCompress(tjhandle handle, unsigned char *srcBuf, int width,
702
+ int pitch, int height, int pixelSize,
703
+ unsigned char *jpegBuf, unsigned long *jpegSize,
704
+ int jpegSubsamp, int jpegQual, int flags)
705
+ {
706
+ int retval = 0;
707
+ unsigned long size;
708
+
709
+ if (flags & TJ_YUV) {
710
+ size = tjBufSizeYUV(width, height, jpegSubsamp);
711
+ retval = tjEncodeYUV2(handle, srcBuf, width, pitch, height,
712
+ getPixelFormat(pixelSize, flags), jpegBuf,
713
+ jpegSubsamp, flags);
714
+ } else {
715
+ retval = tjCompress2(handle, srcBuf, width, pitch, height,
716
+ getPixelFormat(pixelSize, flags), &jpegBuf, &size,
717
+ jpegSubsamp, jpegQual, flags | TJFLAG_NOREALLOC);
718
+ }
719
+ *jpegSize = size;
720
+ return retval;
721
+ }
722
+
723
+
724
+ DLLEXPORT int tjEncodeYUVPlanes(tjhandle handle, const unsigned char *srcBuf,
725
+ int width, int pitch, int height,
726
+ int pixelFormat, unsigned char **dstPlanes,
727
+ int *strides, int subsamp, int flags)
728
+ {
729
+ JSAMPROW *row_pointer = NULL;
730
+ JSAMPLE *_tmpbuf[MAX_COMPONENTS], *_tmpbuf2[MAX_COMPONENTS];
731
+ JSAMPROW *tmpbuf[MAX_COMPONENTS], *tmpbuf2[MAX_COMPONENTS];
732
+ JSAMPROW *outbuf[MAX_COMPONENTS];
733
+ int i, retval = 0, row, pw0, ph0, pw[MAX_COMPONENTS], ph[MAX_COMPONENTS];
734
+ JSAMPLE *ptr;
735
+ jpeg_component_info *compptr;
736
+
737
+ GET_CINSTANCE(handle);
738
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
739
+
740
+ for (i = 0; i < MAX_COMPONENTS; i++) {
741
+ tmpbuf[i] = NULL; _tmpbuf[i] = NULL;
742
+ tmpbuf2[i] = NULL; _tmpbuf2[i] = NULL; outbuf[i] = NULL;
743
+ }
744
+
745
+ if ((this->init & COMPRESS) == 0)
746
+ THROW("tjEncodeYUVPlanes(): Instance has not been initialized for compression");
747
+
748
+ if (srcBuf == NULL || width <= 0 || pitch < 0 || height <= 0 ||
749
+ pixelFormat < 0 || pixelFormat >= TJ_NUMPF || !dstPlanes ||
750
+ !dstPlanes[0] || subsamp < 0 || subsamp >= NUMSUBOPT)
751
+ THROW("tjEncodeYUVPlanes(): Invalid argument");
752
+ if (subsamp != TJSAMP_GRAY && (!dstPlanes[1] || !dstPlanes[2]))
753
+ THROW("tjEncodeYUVPlanes(): Invalid argument");
754
+
755
+ if (pixelFormat == TJPF_CMYK)
756
+ THROW("tjEncodeYUVPlanes(): Cannot generate YUV images from CMYK pixels");
757
+
758
+ if (pitch == 0) pitch = width * tjPixelSize[pixelFormat];
759
+
760
+ if (setjmp(this->jerr.setjmp_buffer)) {
761
+ /* If we get here, the JPEG code has signaled an error. */
762
+ retval = -1; goto bailout;
763
+ }
764
+
765
+ cinfo->image_width = width;
766
+ cinfo->image_height = height;
767
+
768
+ #ifndef NO_PUTENV
769
+ if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
770
+ else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
771
+ else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
772
+ #endif
773
+
774
+ if (setCompDefaults(cinfo, pixelFormat, subsamp, -1, flags) == -1) return -1;
775
+
776
+ /* Execute only the parts of jpeg_start_compress() that we need. If we
777
+ were to call the whole jpeg_start_compress() function, then it would try
778
+ to write the file headers, which could overflow the output buffer if the
779
+ YUV image were very small. */
780
+ if (cinfo->global_state != CSTATE_START)
781
+ THROW("tjEncodeYUVPlanes(): libjpeg API is in the wrong state");
782
+ (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
783
+ jinit_c_master_control(cinfo, FALSE);
784
+ jinit_color_converter(cinfo);
785
+ jinit_downsampler(cinfo);
786
+ (*cinfo->cconvert->start_pass) (cinfo);
787
+
788
+ pw0 = PAD(width, cinfo->max_h_samp_factor);
789
+ ph0 = PAD(height, cinfo->max_v_samp_factor);
790
+
791
+ if ((row_pointer = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph0)) == NULL)
792
+ THROW("tjEncodeYUVPlanes(): Memory allocation failure");
793
+ for (i = 0; i < height; i++) {
794
+ if (flags & TJFLAG_BOTTOMUP)
795
+ row_pointer[i] = (JSAMPROW)&srcBuf[(height - i - 1) * (size_t)pitch];
796
+ else
797
+ row_pointer[i] = (JSAMPROW)&srcBuf[i * (size_t)pitch];
798
+ }
799
+ if (height < ph0)
800
+ for (i = height; i < ph0; i++) row_pointer[i] = row_pointer[height - 1];
801
+
802
+ for (i = 0; i < cinfo->num_components; i++) {
803
+ compptr = &cinfo->comp_info[i];
804
+ _tmpbuf[i] = (JSAMPLE *)malloc(
805
+ PAD((compptr->width_in_blocks * cinfo->max_h_samp_factor * DCTSIZE) /
806
+ compptr->h_samp_factor, 32) *
807
+ cinfo->max_v_samp_factor + 32);
808
+ if (!_tmpbuf[i])
809
+ THROW("tjEncodeYUVPlanes(): Memory allocation failure");
810
+ tmpbuf[i] =
811
+ (JSAMPROW *)malloc(sizeof(JSAMPROW) * cinfo->max_v_samp_factor);
812
+ if (!tmpbuf[i])
813
+ THROW("tjEncodeYUVPlanes(): Memory allocation failure");
814
+ for (row = 0; row < cinfo->max_v_samp_factor; row++) {
815
+ unsigned char *_tmpbuf_aligned =
816
+ (unsigned char *)PAD((size_t)_tmpbuf[i], 32);
817
+
818
+ tmpbuf[i][row] = &_tmpbuf_aligned[
819
+ PAD((compptr->width_in_blocks * cinfo->max_h_samp_factor * DCTSIZE) /
820
+ compptr->h_samp_factor, 32) * row];
821
+ }
822
+ _tmpbuf2[i] =
823
+ (JSAMPLE *)malloc(PAD(compptr->width_in_blocks * DCTSIZE, 32) *
824
+ compptr->v_samp_factor + 32);
825
+ if (!_tmpbuf2[i])
826
+ THROW("tjEncodeYUVPlanes(): Memory allocation failure");
827
+ tmpbuf2[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * compptr->v_samp_factor);
828
+ if (!tmpbuf2[i])
829
+ THROW("tjEncodeYUVPlanes(): Memory allocation failure");
830
+ for (row = 0; row < compptr->v_samp_factor; row++) {
831
+ unsigned char *_tmpbuf2_aligned =
832
+ (unsigned char *)PAD((size_t)_tmpbuf2[i], 32);
833
+
834
+ tmpbuf2[i][row] =
835
+ &_tmpbuf2_aligned[PAD(compptr->width_in_blocks * DCTSIZE, 32) * row];
836
+ }
837
+ pw[i] = pw0 * compptr->h_samp_factor / cinfo->max_h_samp_factor;
838
+ ph[i] = ph0 * compptr->v_samp_factor / cinfo->max_v_samp_factor;
839
+ outbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i]);
840
+ if (!outbuf[i])
841
+ THROW("tjEncodeYUVPlanes(): Memory allocation failure");
842
+ ptr = dstPlanes[i];
843
+ for (row = 0; row < ph[i]; row++) {
844
+ outbuf[i][row] = ptr;
845
+ ptr += (strides && strides[i] != 0) ? strides[i] : pw[i];
846
+ }
847
+ }
848
+
849
+ if (setjmp(this->jerr.setjmp_buffer)) {
850
+ /* If we get here, the JPEG code has signaled an error. */
851
+ retval = -1; goto bailout;
852
+ }
853
+
854
+ for (row = 0; row < ph0; row += cinfo->max_v_samp_factor) {
855
+ (*cinfo->cconvert->color_convert) (cinfo, &row_pointer[row], tmpbuf, 0,
856
+ cinfo->max_v_samp_factor);
857
+ (cinfo->downsample->downsample) (cinfo, tmpbuf, 0, tmpbuf2, 0);
858
+ for (i = 0, compptr = cinfo->comp_info; i < cinfo->num_components;
859
+ i++, compptr++)
860
+ jcopy_sample_rows(tmpbuf2[i], 0, outbuf[i],
861
+ row * compptr->v_samp_factor / cinfo->max_v_samp_factor,
862
+ compptr->v_samp_factor, pw[i]);
863
+ }
864
+ cinfo->next_scanline += height;
865
+ jpeg_abort_compress(cinfo);
866
+
867
+ bailout:
868
+ if (cinfo->global_state > CSTATE_START) jpeg_abort_compress(cinfo);
869
+ if (row_pointer) free(row_pointer);
870
+ for (i = 0; i < MAX_COMPONENTS; i++) {
871
+ if (tmpbuf[i] != NULL) free(tmpbuf[i]);
872
+ if (_tmpbuf[i] != NULL) free(_tmpbuf[i]);
873
+ if (tmpbuf2[i] != NULL) free(tmpbuf2[i]);
874
+ if (_tmpbuf2[i] != NULL) free(_tmpbuf2[i]);
875
+ if (outbuf[i] != NULL) free(outbuf[i]);
876
+ }
877
+ if (this->jerr.warning) retval = -1;
878
+ this->jerr.stopOnWarning = FALSE;
879
+ return retval;
880
+ }
881
+
882
+ DLLEXPORT int tjEncodeYUV3(tjhandle handle, const unsigned char *srcBuf,
883
+ int width, int pitch, int height, int pixelFormat,
884
+ unsigned char *dstBuf, int pad, int subsamp,
885
+ int flags)
886
+ {
887
+ unsigned char *dstPlanes[3];
888
+ int pw0, ph0, strides[3], retval = -1;
889
+ tjinstance *this = (tjinstance *)handle;
890
+
891
+ if (!this) THROWG("tjEncodeYUV3(): Invalid handle");
892
+ this->isInstanceError = FALSE;
893
+
894
+ if (width <= 0 || height <= 0 || dstBuf == NULL || pad < 0 ||
895
+ !IS_POW2(pad) || subsamp < 0 || subsamp >= NUMSUBOPT)
896
+ THROW("tjEncodeYUV3(): Invalid argument");
897
+
898
+ pw0 = tjPlaneWidth(0, width, subsamp);
899
+ ph0 = tjPlaneHeight(0, height, subsamp);
900
+ dstPlanes[0] = dstBuf;
901
+ strides[0] = PAD(pw0, pad);
902
+ if (subsamp == TJSAMP_GRAY) {
903
+ strides[1] = strides[2] = 0;
904
+ dstPlanes[1] = dstPlanes[2] = NULL;
905
+ } else {
906
+ int pw1 = tjPlaneWidth(1, width, subsamp);
907
+ int ph1 = tjPlaneHeight(1, height, subsamp);
908
+
909
+ strides[1] = strides[2] = PAD(pw1, pad);
910
+ dstPlanes[1] = dstPlanes[0] + strides[0] * ph0;
911
+ dstPlanes[2] = dstPlanes[1] + strides[1] * ph1;
912
+ }
913
+
914
+ return tjEncodeYUVPlanes(handle, srcBuf, width, pitch, height, pixelFormat,
915
+ dstPlanes, strides, subsamp, flags);
916
+
917
+ bailout:
918
+ return retval;
919
+ }
920
+
921
+ DLLEXPORT int tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, int width,
922
+ int pitch, int height, int pixelFormat,
923
+ unsigned char *dstBuf, int subsamp, int flags)
924
+ {
925
+ return tjEncodeYUV3(handle, srcBuf, width, pitch, height, pixelFormat,
926
+ dstBuf, 4, subsamp, flags);
927
+ }
928
+
929
+ DLLEXPORT int tjEncodeYUV(tjhandle handle, unsigned char *srcBuf, int width,
930
+ int pitch, int height, int pixelSize,
931
+ unsigned char *dstBuf, int subsamp, int flags)
932
+ {
933
+ return tjEncodeYUV2(handle, srcBuf, width, pitch, height,
934
+ getPixelFormat(pixelSize, flags), dstBuf, subsamp,
935
+ flags);
936
+ }
937
+
938
+
939
+ DLLEXPORT int tjCompressFromYUVPlanes(tjhandle handle,
940
+ const unsigned char **srcPlanes,
941
+ int width, const int *strides,
942
+ int height, int subsamp,
943
+ unsigned char **jpegBuf,
944
+ unsigned long *jpegSize, int jpegQual,
945
+ int flags)
946
+ {
947
+ int i, row, retval = 0, alloc = 1;
948
+ int pw[MAX_COMPONENTS], ph[MAX_COMPONENTS], iw[MAX_COMPONENTS],
949
+ tmpbufsize = 0, usetmpbuf = 0, th[MAX_COMPONENTS];
950
+ JSAMPLE *_tmpbuf = NULL, *ptr;
951
+ JSAMPROW *inbuf[MAX_COMPONENTS], *tmpbuf[MAX_COMPONENTS];
952
+
953
+ GET_CINSTANCE(handle)
954
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
955
+
956
+ for (i = 0; i < MAX_COMPONENTS; i++) {
957
+ tmpbuf[i] = NULL; inbuf[i] = NULL;
958
+ }
959
+
960
+ if ((this->init & COMPRESS) == 0)
961
+ THROW("tjCompressFromYUVPlanes(): Instance has not been initialized for compression");
962
+
963
+ if (!srcPlanes || !srcPlanes[0] || width <= 0 || height <= 0 ||
964
+ subsamp < 0 || subsamp >= NUMSUBOPT || jpegBuf == NULL ||
965
+ jpegSize == NULL || jpegQual < 0 || jpegQual > 100)
966
+ THROW("tjCompressFromYUVPlanes(): Invalid argument");
967
+ if (subsamp != TJSAMP_GRAY && (!srcPlanes[1] || !srcPlanes[2]))
968
+ THROW("tjCompressFromYUVPlanes(): Invalid argument");
969
+
970
+ if (setjmp(this->jerr.setjmp_buffer)) {
971
+ /* If we get here, the JPEG code has signaled an error. */
972
+ retval = -1; goto bailout;
973
+ }
974
+
975
+ cinfo->image_width = width;
976
+ cinfo->image_height = height;
977
+
978
+ #ifndef NO_PUTENV
979
+ if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
980
+ else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
981
+ else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
982
+ #endif
983
+
984
+ if (flags & TJFLAG_NOREALLOC) {
985
+ alloc = 0; *jpegSize = tjBufSize(width, height, subsamp);
986
+ }
987
+ jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
988
+ if (setCompDefaults(cinfo, TJPF_RGB, subsamp, jpegQual, flags) == -1)
989
+ return -1;
990
+ cinfo->raw_data_in = TRUE;
991
+
992
+ jpeg_start_compress(cinfo, TRUE);
993
+ for (i = 0; i < cinfo->num_components; i++) {
994
+ jpeg_component_info *compptr = &cinfo->comp_info[i];
995
+ int ih;
996
+
997
+ iw[i] = compptr->width_in_blocks * DCTSIZE;
998
+ ih = compptr->height_in_blocks * DCTSIZE;
999
+ pw[i] = PAD(cinfo->image_width, cinfo->max_h_samp_factor) *
1000
+ compptr->h_samp_factor / cinfo->max_h_samp_factor;
1001
+ ph[i] = PAD(cinfo->image_height, cinfo->max_v_samp_factor) *
1002
+ compptr->v_samp_factor / cinfo->max_v_samp_factor;
1003
+ if (iw[i] != pw[i] || ih != ph[i]) usetmpbuf = 1;
1004
+ th[i] = compptr->v_samp_factor * DCTSIZE;
1005
+ tmpbufsize += iw[i] * th[i];
1006
+ if ((inbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i])) == NULL)
1007
+ THROW("tjCompressFromYUVPlanes(): Memory allocation failure");
1008
+ ptr = (JSAMPLE *)srcPlanes[i];
1009
+ for (row = 0; row < ph[i]; row++) {
1010
+ inbuf[i][row] = ptr;
1011
+ ptr += (strides && strides[i] != 0) ? strides[i] : pw[i];
1012
+ }
1013
+ }
1014
+ if (usetmpbuf) {
1015
+ if ((_tmpbuf = (JSAMPLE *)malloc(sizeof(JSAMPLE) * tmpbufsize)) == NULL)
1016
+ THROW("tjCompressFromYUVPlanes(): Memory allocation failure");
1017
+ ptr = _tmpbuf;
1018
+ for (i = 0; i < cinfo->num_components; i++) {
1019
+ if ((tmpbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * th[i])) == NULL)
1020
+ THROW("tjCompressFromYUVPlanes(): Memory allocation failure");
1021
+ for (row = 0; row < th[i]; row++) {
1022
+ tmpbuf[i][row] = ptr;
1023
+ ptr += iw[i];
1024
+ }
1025
+ }
1026
+ }
1027
+
1028
+ if (setjmp(this->jerr.setjmp_buffer)) {
1029
+ /* If we get here, the JPEG code has signaled an error. */
1030
+ retval = -1; goto bailout;
1031
+ }
1032
+
1033
+ for (row = 0; row < (int)cinfo->image_height;
1034
+ row += cinfo->max_v_samp_factor * DCTSIZE) {
1035
+ JSAMPARRAY yuvptr[MAX_COMPONENTS];
1036
+ int crow[MAX_COMPONENTS];
1037
+
1038
+ for (i = 0; i < cinfo->num_components; i++) {
1039
+ jpeg_component_info *compptr = &cinfo->comp_info[i];
1040
+
1041
+ crow[i] = row * compptr->v_samp_factor / cinfo->max_v_samp_factor;
1042
+ if (usetmpbuf) {
1043
+ int j, k;
1044
+
1045
+ for (j = 0; j < MIN(th[i], ph[i] - crow[i]); j++) {
1046
+ memcpy(tmpbuf[i][j], inbuf[i][crow[i] + j], pw[i]);
1047
+ /* Duplicate last sample in row to fill out MCU */
1048
+ for (k = pw[i]; k < iw[i]; k++)
1049
+ tmpbuf[i][j][k] = tmpbuf[i][j][pw[i] - 1];
1050
+ }
1051
+ /* Duplicate last row to fill out MCU */
1052
+ for (j = ph[i] - crow[i]; j < th[i]; j++)
1053
+ memcpy(tmpbuf[i][j], tmpbuf[i][ph[i] - crow[i] - 1], iw[i]);
1054
+ yuvptr[i] = tmpbuf[i];
1055
+ } else
1056
+ yuvptr[i] = &inbuf[i][crow[i]];
1057
+ }
1058
+ jpeg_write_raw_data(cinfo, yuvptr, cinfo->max_v_samp_factor * DCTSIZE);
1059
+ }
1060
+ jpeg_finish_compress(cinfo);
1061
+
1062
+ bailout:
1063
+ if (cinfo->global_state > CSTATE_START) jpeg_abort_compress(cinfo);
1064
+ for (i = 0; i < MAX_COMPONENTS; i++) {
1065
+ if (tmpbuf[i]) free(tmpbuf[i]);
1066
+ if (inbuf[i]) free(inbuf[i]);
1067
+ }
1068
+ if (_tmpbuf) free(_tmpbuf);
1069
+ if (this->jerr.warning) retval = -1;
1070
+ this->jerr.stopOnWarning = FALSE;
1071
+ return retval;
1072
+ }
1073
+
1074
+ DLLEXPORT int tjCompressFromYUV(tjhandle handle, const unsigned char *srcBuf,
1075
+ int width, int pad, int height, int subsamp,
1076
+ unsigned char **jpegBuf,
1077
+ unsigned long *jpegSize, int jpegQual,
1078
+ int flags)
1079
+ {
1080
+ const unsigned char *srcPlanes[3];
1081
+ int pw0, ph0, strides[3], retval = -1;
1082
+ tjinstance *this = (tjinstance *)handle;
1083
+
1084
+ if (!this) THROWG("tjCompressFromYUV(): Invalid handle");
1085
+ this->isInstanceError = FALSE;
1086
+
1087
+ if (srcBuf == NULL || width <= 0 || pad < 1 || height <= 0 || subsamp < 0 ||
1088
+ subsamp >= NUMSUBOPT)
1089
+ THROW("tjCompressFromYUV(): Invalid argument");
1090
+
1091
+ pw0 = tjPlaneWidth(0, width, subsamp);
1092
+ ph0 = tjPlaneHeight(0, height, subsamp);
1093
+ srcPlanes[0] = srcBuf;
1094
+ strides[0] = PAD(pw0, pad);
1095
+ if (subsamp == TJSAMP_GRAY) {
1096
+ strides[1] = strides[2] = 0;
1097
+ srcPlanes[1] = srcPlanes[2] = NULL;
1098
+ } else {
1099
+ int pw1 = tjPlaneWidth(1, width, subsamp);
1100
+ int ph1 = tjPlaneHeight(1, height, subsamp);
1101
+
1102
+ strides[1] = strides[2] = PAD(pw1, pad);
1103
+ srcPlanes[1] = srcPlanes[0] + strides[0] * ph0;
1104
+ srcPlanes[2] = srcPlanes[1] + strides[1] * ph1;
1105
+ }
1106
+
1107
+ return tjCompressFromYUVPlanes(handle, srcPlanes, width, strides, height,
1108
+ subsamp, jpegBuf, jpegSize, jpegQual, flags);
1109
+
1110
+ bailout:
1111
+ return retval;
1112
+ }
1113
+
1114
+
1115
+ /* Decompressor */
1116
+
1117
+ static tjhandle _tjInitDecompress(tjinstance *this)
1118
+ {
1119
+ static unsigned char buffer[1];
1120
+
1121
+ /* This is also straight out of example.txt */
1122
+ this->dinfo.err = jpeg_std_error(&this->jerr.pub);
1123
+ this->jerr.pub.error_exit = my_error_exit;
1124
+ this->jerr.pub.output_message = my_output_message;
1125
+ this->jerr.emit_message = this->jerr.pub.emit_message;
1126
+ this->jerr.pub.emit_message = my_emit_message;
1127
+ this->jerr.pub.addon_message_table = turbojpeg_message_table;
1128
+ this->jerr.pub.first_addon_message = JMSG_FIRSTADDONCODE;
1129
+ this->jerr.pub.last_addon_message = JMSG_LASTADDONCODE;
1130
+
1131
+ if (setjmp(this->jerr.setjmp_buffer)) {
1132
+ /* If we get here, the JPEG code has signaled an error. */
1133
+ if (this) free(this);
1134
+ return NULL;
1135
+ }
1136
+
1137
+ jpeg_create_decompress(&this->dinfo);
1138
+ /* Make an initial call so it will create the source manager */
1139
+ jpeg_mem_src_tj(&this->dinfo, buffer, 1);
1140
+
1141
+ this->init |= DECOMPRESS;
1142
+ return (tjhandle)this;
1143
+ }
1144
+
1145
+ DLLEXPORT tjhandle tjInitDecompress(void)
1146
+ {
1147
+ tjinstance *this;
1148
+
1149
+ if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
1150
+ snprintf(errStr, JMSG_LENGTH_MAX,
1151
+ "tjInitDecompress(): Memory allocation failure");
1152
+ return NULL;
1153
+ }
1154
+ MEMZERO(this, sizeof(tjinstance));
1155
+ snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
1156
+ return _tjInitDecompress(this);
1157
+ }
1158
+
1159
+
1160
+ DLLEXPORT int tjDecompressHeader3(tjhandle handle,
1161
+ const unsigned char *jpegBuf,
1162
+ unsigned long jpegSize, int *width,
1163
+ int *height, int *jpegSubsamp,
1164
+ int *jpegColorspace)
1165
+ {
1166
+ int retval = 0;
1167
+
1168
+ GET_DINSTANCE(handle);
1169
+ if ((this->init & DECOMPRESS) == 0)
1170
+ THROW("tjDecompressHeader3(): Instance has not been initialized for decompression");
1171
+
1172
+ if (jpegBuf == NULL || jpegSize <= 0 || width == NULL || height == NULL ||
1173
+ jpegSubsamp == NULL || jpegColorspace == NULL)
1174
+ THROW("tjDecompressHeader3(): Invalid argument");
1175
+
1176
+ if (setjmp(this->jerr.setjmp_buffer)) {
1177
+ /* If we get here, the JPEG code has signaled an error. */
1178
+ return -1;
1179
+ }
1180
+
1181
+ jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
1182
+ jpeg_read_header(dinfo, TRUE);
1183
+
1184
+ *width = dinfo->image_width;
1185
+ *height = dinfo->image_height;
1186
+ *jpegSubsamp = getSubsamp(dinfo);
1187
+ switch (dinfo->jpeg_color_space) {
1188
+ case JCS_GRAYSCALE: *jpegColorspace = TJCS_GRAY; break;
1189
+ case JCS_RGB: *jpegColorspace = TJCS_RGB; break;
1190
+ case JCS_YCbCr: *jpegColorspace = TJCS_YCbCr; break;
1191
+ case JCS_CMYK: *jpegColorspace = TJCS_CMYK; break;
1192
+ case JCS_YCCK: *jpegColorspace = TJCS_YCCK; break;
1193
+ default: *jpegColorspace = -1; break;
1194
+ }
1195
+
1196
+ jpeg_abort_decompress(dinfo);
1197
+
1198
+ if (*jpegSubsamp < 0)
1199
+ THROW("tjDecompressHeader3(): Could not determine subsampling type for JPEG image");
1200
+ if (*jpegColorspace < 0)
1201
+ THROW("tjDecompressHeader3(): Could not determine colorspace of JPEG image");
1202
+ if (*width < 1 || *height < 1)
1203
+ THROW("tjDecompressHeader3(): Invalid data returned in header");
1204
+
1205
+ bailout:
1206
+ if (this->jerr.warning) retval = -1;
1207
+ return retval;
1208
+ }
1209
+
1210
+ DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf,
1211
+ unsigned long jpegSize, int *width,
1212
+ int *height, int *jpegSubsamp)
1213
+ {
1214
+ int jpegColorspace;
1215
+
1216
+ return tjDecompressHeader3(handle, jpegBuf, jpegSize, width, height,
1217
+ jpegSubsamp, &jpegColorspace);
1218
+ }
1219
+
1220
+ DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf,
1221
+ unsigned long jpegSize, int *width,
1222
+ int *height)
1223
+ {
1224
+ int jpegSubsamp;
1225
+
1226
+ return tjDecompressHeader2(handle, jpegBuf, jpegSize, width, height,
1227
+ &jpegSubsamp);
1228
+ }
1229
+
1230
+
1231
+ DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors)
1232
+ {
1233
+ if (numscalingfactors == NULL) {
1234
+ snprintf(errStr, JMSG_LENGTH_MAX,
1235
+ "tjGetScalingFactors(): Invalid argument");
1236
+ return NULL;
1237
+ }
1238
+
1239
+ *numscalingfactors = NUMSF;
1240
+ return (tjscalingfactor *)sf;
1241
+ }
1242
+
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
+ JSAMPROW *row_pointer = NULL;
1250
+ int i, retval = 0, jpegwidth, jpegheight, scaledw, scaledh;
1251
+
1252
+ GET_DINSTANCE(handle);
1253
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
1254
+ if ((this->init & DECOMPRESS) == 0)
1255
+ THROW("tjDecompress2(): Instance has not been initialized for decompression");
1256
+
1257
+ if (jpegBuf == NULL || jpegSize <= 0 || dstBuf == NULL || width < 0 ||
1258
+ pitch < 0 || height < 0 || pixelFormat < 0 || pixelFormat >= TJ_NUMPF)
1259
+ THROW("tjDecompress2(): Invalid argument");
1260
+
1261
+ #ifndef NO_PUTENV
1262
+ if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
1263
+ else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
1264
+ else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
1265
+ #endif
1266
+
1267
+ if (setjmp(this->jerr.setjmp_buffer)) {
1268
+ /* If we get here, the JPEG code has signaled an error. */
1269
+ retval = -1; goto bailout;
1270
+ }
1271
+
1272
+ jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
1273
+ jpeg_read_header(dinfo, TRUE);
1274
+ this->dinfo.out_color_space = pf2cs[pixelFormat];
1275
+ if (flags & TJFLAG_FASTDCT) this->dinfo.dct_method = JDCT_FASTEST;
1276
+ if (flags & TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling = FALSE;
1277
+
1278
+ jpegwidth = dinfo->image_width; jpegheight = dinfo->image_height;
1279
+ if (width == 0) width = jpegwidth;
1280
+ if (height == 0) height = jpegheight;
1281
+ for (i = 0; i < NUMSF; i++) {
1282
+ scaledw = TJSCALED(jpegwidth, sf[i]);
1283
+ scaledh = TJSCALED(jpegheight, sf[i]);
1284
+ if (scaledw <= width && scaledh <= height)
1285
+ break;
1286
+ }
1287
+ if (i >= NUMSF)
1288
+ THROW("tjDecompress2(): Could not scale down to desired image dimensions");
1289
+ width = scaledw; height = scaledh;
1290
+ dinfo->scale_num = sf[i].num;
1291
+ dinfo->scale_denom = sf[i].denom;
1292
+
1293
+ jpeg_start_decompress(dinfo);
1294
+ if (pitch == 0) pitch = dinfo->output_width * tjPixelSize[pixelFormat];
1295
+
1296
+ if ((row_pointer =
1297
+ (JSAMPROW *)malloc(sizeof(JSAMPROW) * dinfo->output_height)) == NULL)
1298
+ THROW("tjDecompress2(): Memory allocation failure");
1299
+ if (setjmp(this->jerr.setjmp_buffer)) {
1300
+ /* If we get here, the JPEG code has signaled an error. */
1301
+ retval = -1; goto bailout;
1302
+ }
1303
+ for (i = 0; i < (int)dinfo->output_height; i++) {
1304
+ if (flags & TJFLAG_BOTTOMUP)
1305
+ row_pointer[i] = &dstBuf[(dinfo->output_height - i - 1) * (size_t)pitch];
1306
+ else
1307
+ row_pointer[i] = &dstBuf[i * (size_t)pitch];
1308
+ }
1309
+ while (dinfo->output_scanline < dinfo->output_height)
1310
+ jpeg_read_scanlines(dinfo, &row_pointer[dinfo->output_scanline],
1311
+ dinfo->output_height - dinfo->output_scanline);
1312
+ jpeg_finish_decompress(dinfo);
1313
+
1314
+ bailout:
1315
+ if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo);
1316
+ if (row_pointer) free(row_pointer);
1317
+ if (this->jerr.warning) retval = -1;
1318
+ this->jerr.stopOnWarning = FALSE;
1319
+ return retval;
1320
+ }
1321
+
1322
+ DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf,
1323
+ unsigned long jpegSize, unsigned char *dstBuf,
1324
+ int width, int pitch, int height, int pixelSize,
1325
+ int flags)
1326
+ {
1327
+ if (flags & TJ_YUV)
1328
+ return tjDecompressToYUV(handle, jpegBuf, jpegSize, dstBuf, flags);
1329
+ else
1330
+ return tjDecompress2(handle, jpegBuf, jpegSize, dstBuf, width, pitch,
1331
+ height, getPixelFormat(pixelSize, flags), flags);
1332
+ }
1333
+
1334
+
1335
+ static int setDecodeDefaults(struct jpeg_decompress_struct *dinfo,
1336
+ int pixelFormat, int subsamp, int flags)
1337
+ {
1338
+ int i;
1339
+
1340
+ dinfo->scale_num = dinfo->scale_denom = 1;
1341
+
1342
+ if (subsamp == TJSAMP_GRAY) {
1343
+ dinfo->num_components = dinfo->comps_in_scan = 1;
1344
+ dinfo->jpeg_color_space = JCS_GRAYSCALE;
1345
+ } else {
1346
+ dinfo->num_components = dinfo->comps_in_scan = 3;
1347
+ dinfo->jpeg_color_space = JCS_YCbCr;
1348
+ }
1349
+
1350
+ dinfo->comp_info = (jpeg_component_info *)
1351
+ (*dinfo->mem->alloc_small) ((j_common_ptr)dinfo, JPOOL_IMAGE,
1352
+ dinfo->num_components *
1353
+ sizeof(jpeg_component_info));
1354
+
1355
+ for (i = 0; i < dinfo->num_components; i++) {
1356
+ jpeg_component_info *compptr = &dinfo->comp_info[i];
1357
+
1358
+ compptr->h_samp_factor = (i == 0) ? tjMCUWidth[subsamp] / 8 : 1;
1359
+ compptr->v_samp_factor = (i == 0) ? tjMCUHeight[subsamp] / 8 : 1;
1360
+ compptr->component_index = i;
1361
+ compptr->component_id = i + 1;
1362
+ compptr->quant_tbl_no = compptr->dc_tbl_no =
1363
+ compptr->ac_tbl_no = (i == 0) ? 0 : 1;
1364
+ dinfo->cur_comp_info[i] = compptr;
1365
+ }
1366
+ dinfo->data_precision = 8;
1367
+ for (i = 0; i < 2; i++) {
1368
+ if (dinfo->quant_tbl_ptrs[i] == NULL)
1369
+ dinfo->quant_tbl_ptrs[i] = jpeg_alloc_quant_table((j_common_ptr)dinfo);
1370
+ }
1371
+
1372
+ return 0;
1373
+ }
1374
+
1375
+
1376
+ static int my_read_markers(j_decompress_ptr dinfo)
1377
+ {
1378
+ return JPEG_REACHED_SOS;
1379
+ }
1380
+
1381
+ static void my_reset_marker_reader(j_decompress_ptr dinfo)
1382
+ {
1383
+ }
1384
+
1385
+ DLLEXPORT int tjDecodeYUVPlanes(tjhandle handle,
1386
+ const unsigned char **srcPlanes,
1387
+ const int *strides, int subsamp,
1388
+ unsigned char *dstBuf, int width, int pitch,
1389
+ int height, int pixelFormat, int flags)
1390
+ {
1391
+ JSAMPROW *row_pointer = NULL;
1392
+ JSAMPLE *_tmpbuf[MAX_COMPONENTS];
1393
+ JSAMPROW *tmpbuf[MAX_COMPONENTS], *inbuf[MAX_COMPONENTS];
1394
+ int i, retval = 0, row, pw0, ph0, pw[MAX_COMPONENTS], ph[MAX_COMPONENTS];
1395
+ JSAMPLE *ptr;
1396
+ jpeg_component_info *compptr;
1397
+ int (*old_read_markers) (j_decompress_ptr);
1398
+ void (*old_reset_marker_reader) (j_decompress_ptr);
1399
+
1400
+ GET_DINSTANCE(handle);
1401
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
1402
+
1403
+ for (i = 0; i < MAX_COMPONENTS; i++) {
1404
+ tmpbuf[i] = NULL; _tmpbuf[i] = NULL; inbuf[i] = NULL;
1405
+ }
1406
+
1407
+ if ((this->init & DECOMPRESS) == 0)
1408
+ THROW("tjDecodeYUVPlanes(): Instance has not been initialized for decompression");
1409
+
1410
+ if (!srcPlanes || !srcPlanes[0] || subsamp < 0 || subsamp >= NUMSUBOPT ||
1411
+ dstBuf == NULL || width <= 0 || pitch < 0 || height <= 0 ||
1412
+ pixelFormat < 0 || pixelFormat >= TJ_NUMPF)
1413
+ THROW("tjDecodeYUVPlanes(): Invalid argument");
1414
+ if (subsamp != TJSAMP_GRAY && (!srcPlanes[1] || !srcPlanes[2]))
1415
+ THROW("tjDecodeYUVPlanes(): Invalid argument");
1416
+
1417
+ if (setjmp(this->jerr.setjmp_buffer)) {
1418
+ /* If we get here, the JPEG code has signaled an error. */
1419
+ retval = -1; goto bailout;
1420
+ }
1421
+
1422
+ if (pixelFormat == TJPF_CMYK)
1423
+ THROW("tjDecodeYUVPlanes(): Cannot decode YUV images into CMYK pixels.");
1424
+
1425
+ if (pitch == 0) pitch = width * tjPixelSize[pixelFormat];
1426
+ dinfo->image_width = width;
1427
+ dinfo->image_height = height;
1428
+
1429
+ #ifndef NO_PUTENV
1430
+ if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
1431
+ else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
1432
+ else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
1433
+ #endif
1434
+
1435
+ dinfo->progressive_mode = dinfo->inputctl->has_multiple_scans = FALSE;
1436
+ dinfo->Ss = dinfo->Ah = dinfo->Al = 0;
1437
+ dinfo->Se = DCTSIZE2 - 1;
1438
+ if (setDecodeDefaults(dinfo, pixelFormat, subsamp, flags) == -1) {
1439
+ retval = -1; goto bailout;
1440
+ }
1441
+ old_read_markers = dinfo->marker->read_markers;
1442
+ dinfo->marker->read_markers = my_read_markers;
1443
+ old_reset_marker_reader = dinfo->marker->reset_marker_reader;
1444
+ dinfo->marker->reset_marker_reader = my_reset_marker_reader;
1445
+ jpeg_read_header(dinfo, TRUE);
1446
+ dinfo->marker->read_markers = old_read_markers;
1447
+ dinfo->marker->reset_marker_reader = old_reset_marker_reader;
1448
+
1449
+ this->dinfo.out_color_space = pf2cs[pixelFormat];
1450
+ if (flags & TJFLAG_FASTDCT) this->dinfo.dct_method = JDCT_FASTEST;
1451
+ dinfo->do_fancy_upsampling = FALSE;
1452
+ dinfo->Se = DCTSIZE2 - 1;
1453
+ jinit_master_decompress(dinfo);
1454
+ (*dinfo->upsample->start_pass) (dinfo);
1455
+
1456
+ pw0 = PAD(width, dinfo->max_h_samp_factor);
1457
+ ph0 = PAD(height, dinfo->max_v_samp_factor);
1458
+
1459
+ if (pitch == 0) pitch = dinfo->output_width * tjPixelSize[pixelFormat];
1460
+
1461
+ if ((row_pointer = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph0)) == NULL)
1462
+ THROW("tjDecodeYUVPlanes(): Memory allocation failure");
1463
+ for (i = 0; i < height; i++) {
1464
+ if (flags & TJFLAG_BOTTOMUP)
1465
+ row_pointer[i] = &dstBuf[(height - i - 1) * (size_t)pitch];
1466
+ else
1467
+ row_pointer[i] = &dstBuf[i * (size_t)pitch];
1468
+ }
1469
+ if (height < ph0)
1470
+ for (i = height; i < ph0; i++) row_pointer[i] = row_pointer[height - 1];
1471
+
1472
+ for (i = 0; i < dinfo->num_components; i++) {
1473
+ compptr = &dinfo->comp_info[i];
1474
+ _tmpbuf[i] =
1475
+ (JSAMPLE *)malloc(PAD(compptr->width_in_blocks * DCTSIZE, 32) *
1476
+ compptr->v_samp_factor + 32);
1477
+ if (!_tmpbuf[i])
1478
+ THROW("tjDecodeYUVPlanes(): Memory allocation failure");
1479
+ tmpbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * compptr->v_samp_factor);
1480
+ if (!tmpbuf[i])
1481
+ THROW("tjDecodeYUVPlanes(): Memory allocation failure");
1482
+ for (row = 0; row < compptr->v_samp_factor; row++) {
1483
+ unsigned char *_tmpbuf_aligned =
1484
+ (unsigned char *)PAD((size_t)_tmpbuf[i], 32);
1485
+
1486
+ tmpbuf[i][row] =
1487
+ &_tmpbuf_aligned[PAD(compptr->width_in_blocks * DCTSIZE, 32) * row];
1488
+ }
1489
+ pw[i] = pw0 * compptr->h_samp_factor / dinfo->max_h_samp_factor;
1490
+ ph[i] = ph0 * compptr->v_samp_factor / dinfo->max_v_samp_factor;
1491
+ inbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i]);
1492
+ if (!inbuf[i])
1493
+ THROW("tjDecodeYUVPlanes(): Memory allocation failure");
1494
+ ptr = (JSAMPLE *)srcPlanes[i];
1495
+ for (row = 0; row < ph[i]; row++) {
1496
+ inbuf[i][row] = ptr;
1497
+ ptr += (strides && strides[i] != 0) ? strides[i] : pw[i];
1498
+ }
1499
+ }
1500
+
1501
+ if (setjmp(this->jerr.setjmp_buffer)) {
1502
+ /* If we get here, the JPEG code has signaled an error. */
1503
+ retval = -1; goto bailout;
1504
+ }
1505
+
1506
+ for (row = 0; row < ph0; row += dinfo->max_v_samp_factor) {
1507
+ JDIMENSION inrow = 0, outrow = 0;
1508
+
1509
+ for (i = 0, compptr = dinfo->comp_info; i < dinfo->num_components;
1510
+ i++, compptr++)
1511
+ jcopy_sample_rows(inbuf[i],
1512
+ row * compptr->v_samp_factor / dinfo->max_v_samp_factor, tmpbuf[i], 0,
1513
+ compptr->v_samp_factor, pw[i]);
1514
+ (dinfo->upsample->upsample) (dinfo, tmpbuf, &inrow,
1515
+ dinfo->max_v_samp_factor, &row_pointer[row],
1516
+ &outrow, dinfo->max_v_samp_factor);
1517
+ }
1518
+ jpeg_abort_decompress(dinfo);
1519
+
1520
+ bailout:
1521
+ if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo);
1522
+ if (row_pointer) free(row_pointer);
1523
+ for (i = 0; i < MAX_COMPONENTS; i++) {
1524
+ if (tmpbuf[i] != NULL) free(tmpbuf[i]);
1525
+ if (_tmpbuf[i] != NULL) free(_tmpbuf[i]);
1526
+ if (inbuf[i] != NULL) free(inbuf[i]);
1527
+ }
1528
+ if (this->jerr.warning) retval = -1;
1529
+ this->jerr.stopOnWarning = FALSE;
1530
+ return retval;
1531
+ }
1532
+
1533
+ DLLEXPORT int tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
1534
+ int pad, int subsamp, unsigned char *dstBuf,
1535
+ int width, int pitch, int height, int pixelFormat,
1536
+ int flags)
1537
+ {
1538
+ const unsigned char *srcPlanes[3];
1539
+ int pw0, ph0, strides[3], retval = -1;
1540
+ tjinstance *this = (tjinstance *)handle;
1541
+
1542
+ if (!this) THROWG("tjDecodeYUV(): Invalid handle");
1543
+ this->isInstanceError = FALSE;
1544
+
1545
+ if (srcBuf == NULL || pad < 0 || !IS_POW2(pad) || subsamp < 0 ||
1546
+ subsamp >= NUMSUBOPT || width <= 0 || height <= 0)
1547
+ THROW("tjDecodeYUV(): Invalid argument");
1548
+
1549
+ pw0 = tjPlaneWidth(0, width, subsamp);
1550
+ ph0 = tjPlaneHeight(0, height, subsamp);
1551
+ srcPlanes[0] = srcBuf;
1552
+ strides[0] = PAD(pw0, pad);
1553
+ if (subsamp == TJSAMP_GRAY) {
1554
+ strides[1] = strides[2] = 0;
1555
+ srcPlanes[1] = srcPlanes[2] = NULL;
1556
+ } else {
1557
+ int pw1 = tjPlaneWidth(1, width, subsamp);
1558
+ int ph1 = tjPlaneHeight(1, height, subsamp);
1559
+
1560
+ strides[1] = strides[2] = PAD(pw1, pad);
1561
+ srcPlanes[1] = srcPlanes[0] + strides[0] * ph0;
1562
+ srcPlanes[2] = srcPlanes[1] + strides[1] * ph1;
1563
+ }
1564
+
1565
+ return tjDecodeYUVPlanes(handle, srcPlanes, strides, subsamp, dstBuf, width,
1566
+ pitch, height, pixelFormat, flags);
1567
+
1568
+ bailout:
1569
+ return retval;
1570
+ }
1571
+
1572
+ DLLEXPORT int tjDecompressToYUVPlanes(tjhandle handle,
1573
+ const unsigned char *jpegBuf,
1574
+ unsigned long jpegSize,
1575
+ unsigned char **dstPlanes, int width,
1576
+ int *strides, int height, int flags)
1577
+ {
1578
+ int i, sfi, row, retval = 0;
1579
+ int jpegwidth, jpegheight, jpegSubsamp, scaledw, scaledh;
1580
+ int pw[MAX_COMPONENTS], ph[MAX_COMPONENTS], iw[MAX_COMPONENTS],
1581
+ tmpbufsize = 0, usetmpbuf = 0, th[MAX_COMPONENTS];
1582
+ JSAMPLE *_tmpbuf = NULL, *ptr;
1583
+ JSAMPROW *outbuf[MAX_COMPONENTS], *tmpbuf[MAX_COMPONENTS];
1584
+ int dctsize;
1585
+
1586
+ GET_DINSTANCE(handle);
1587
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
1588
+
1589
+ for (i = 0; i < MAX_COMPONENTS; i++) {
1590
+ tmpbuf[i] = NULL; outbuf[i] = NULL;
1591
+ }
1592
+
1593
+ if ((this->init & DECOMPRESS) == 0)
1594
+ THROW("tjDecompressToYUVPlanes(): Instance has not been initialized for decompression");
1595
+
1596
+ if (jpegBuf == NULL || jpegSize <= 0 || !dstPlanes || !dstPlanes[0] ||
1597
+ width < 0 || height < 0)
1598
+ THROW("tjDecompressToYUVPlanes(): Invalid argument");
1599
+
1600
+ #ifndef NO_PUTENV
1601
+ if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
1602
+ else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
1603
+ else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
1604
+ #endif
1605
+
1606
+ if (setjmp(this->jerr.setjmp_buffer)) {
1607
+ /* If we get here, the JPEG code has signaled an error. */
1608
+ retval = -1; goto bailout;
1609
+ }
1610
+
1611
+ if (!this->headerRead) {
1612
+ jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
1613
+ jpeg_read_header(dinfo, TRUE);
1614
+ }
1615
+ this->headerRead = 0;
1616
+ jpegSubsamp = getSubsamp(dinfo);
1617
+ if (jpegSubsamp < 0)
1618
+ THROW("tjDecompressToYUVPlanes(): Could not determine subsampling type for JPEG image");
1619
+
1620
+ if (jpegSubsamp != TJSAMP_GRAY && (!dstPlanes[1] || !dstPlanes[2]))
1621
+ THROW("tjDecompressToYUVPlanes(): Invalid argument");
1622
+
1623
+ jpegwidth = dinfo->image_width; jpegheight = dinfo->image_height;
1624
+ if (width == 0) width = jpegwidth;
1625
+ if (height == 0) height = jpegheight;
1626
+ for (i = 0; i < NUMSF; i++) {
1627
+ scaledw = TJSCALED(jpegwidth, sf[i]);
1628
+ scaledh = TJSCALED(jpegheight, sf[i]);
1629
+ if (scaledw <= width && scaledh <= height)
1630
+ break;
1631
+ }
1632
+ if (i >= NUMSF)
1633
+ THROW("tjDecompressToYUVPlanes(): Could not scale down to desired image dimensions");
1634
+ if (dinfo->num_components > 3)
1635
+ THROW("tjDecompressToYUVPlanes(): JPEG image must have 3 or fewer components");
1636
+
1637
+ width = scaledw; height = scaledh;
1638
+ dinfo->scale_num = sf[i].num;
1639
+ dinfo->scale_denom = sf[i].denom;
1640
+ sfi = i;
1641
+ jpeg_calc_output_dimensions(dinfo);
1642
+
1643
+ dctsize = DCTSIZE * sf[sfi].num / sf[sfi].denom;
1644
+
1645
+ for (i = 0; i < dinfo->num_components; i++) {
1646
+ jpeg_component_info *compptr = &dinfo->comp_info[i];
1647
+ int ih;
1648
+
1649
+ iw[i] = compptr->width_in_blocks * dctsize;
1650
+ ih = compptr->height_in_blocks * dctsize;
1651
+ pw[i] = tjPlaneWidth(i, dinfo->output_width, jpegSubsamp);
1652
+ ph[i] = tjPlaneHeight(i, dinfo->output_height, jpegSubsamp);
1653
+ if (iw[i] != pw[i] || ih != ph[i]) usetmpbuf = 1;
1654
+ th[i] = compptr->v_samp_factor * dctsize;
1655
+ tmpbufsize += iw[i] * th[i];
1656
+ if ((outbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i])) == NULL)
1657
+ THROW("tjDecompressToYUVPlanes(): Memory allocation failure");
1658
+ ptr = dstPlanes[i];
1659
+ for (row = 0; row < ph[i]; row++) {
1660
+ outbuf[i][row] = ptr;
1661
+ ptr += (strides && strides[i] != 0) ? strides[i] : pw[i];
1662
+ }
1663
+ }
1664
+ if (usetmpbuf) {
1665
+ if ((_tmpbuf = (JSAMPLE *)malloc(sizeof(JSAMPLE) * tmpbufsize)) == NULL)
1666
+ THROW("tjDecompressToYUVPlanes(): Memory allocation failure");
1667
+ ptr = _tmpbuf;
1668
+ for (i = 0; i < dinfo->num_components; i++) {
1669
+ if ((tmpbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * th[i])) == NULL)
1670
+ THROW("tjDecompressToYUVPlanes(): Memory allocation failure");
1671
+ for (row = 0; row < th[i]; row++) {
1672
+ tmpbuf[i][row] = ptr;
1673
+ ptr += iw[i];
1674
+ }
1675
+ }
1676
+ }
1677
+
1678
+ if (setjmp(this->jerr.setjmp_buffer)) {
1679
+ /* If we get here, the JPEG code has signaled an error. */
1680
+ retval = -1; goto bailout;
1681
+ }
1682
+
1683
+ if (flags & TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling = FALSE;
1684
+ if (flags & TJFLAG_FASTDCT) dinfo->dct_method = JDCT_FASTEST;
1685
+ dinfo->raw_data_out = TRUE;
1686
+
1687
+ jpeg_start_decompress(dinfo);
1688
+ for (row = 0; row < (int)dinfo->output_height;
1689
+ row += dinfo->max_v_samp_factor * dinfo->_min_DCT_scaled_size) {
1690
+ JSAMPARRAY yuvptr[MAX_COMPONENTS];
1691
+ int crow[MAX_COMPONENTS];
1692
+
1693
+ for (i = 0; i < dinfo->num_components; i++) {
1694
+ jpeg_component_info *compptr = &dinfo->comp_info[i];
1695
+
1696
+ if (jpegSubsamp == TJ_420) {
1697
+ /* When 4:2:0 subsampling is used with IDCT scaling, libjpeg will try
1698
+ to be clever and use the IDCT to perform upsampling on the U and V
1699
+ planes. For instance, if the output image is to be scaled by 1/2
1700
+ relative to the JPEG image, then the scaling factor and upsampling
1701
+ effectively cancel each other, so a normal 8x8 IDCT can be used.
1702
+ However, this is not desirable when using the decompress-to-YUV
1703
+ functionality in TurboJPEG, since we want to output the U and V
1704
+ planes in their subsampled form. Thus, we have to override some
1705
+ internal libjpeg parameters to force it to use the "scaled" IDCT
1706
+ functions on the U and V planes. */
1707
+ compptr->_DCT_scaled_size = dctsize;
1708
+ compptr->MCU_sample_width = tjMCUWidth[jpegSubsamp] *
1709
+ sf[sfi].num / sf[sfi].denom *
1710
+ compptr->v_samp_factor / dinfo->max_v_samp_factor;
1711
+ dinfo->idct->inverse_DCT[i] = dinfo->idct->inverse_DCT[0];
1712
+ }
1713
+ crow[i] = row * compptr->v_samp_factor / dinfo->max_v_samp_factor;
1714
+ if (usetmpbuf) yuvptr[i] = tmpbuf[i];
1715
+ else yuvptr[i] = &outbuf[i][crow[i]];
1716
+ }
1717
+ jpeg_read_raw_data(dinfo, yuvptr,
1718
+ dinfo->max_v_samp_factor * dinfo->_min_DCT_scaled_size);
1719
+ if (usetmpbuf) {
1720
+ int j;
1721
+
1722
+ for (i = 0; i < dinfo->num_components; i++) {
1723
+ for (j = 0; j < MIN(th[i], ph[i] - crow[i]); j++) {
1724
+ memcpy(outbuf[i][crow[i] + j], tmpbuf[i][j], pw[i]);
1725
+ }
1726
+ }
1727
+ }
1728
+ }
1729
+ jpeg_finish_decompress(dinfo);
1730
+
1731
+ bailout:
1732
+ if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo);
1733
+ for (i = 0; i < MAX_COMPONENTS; i++) {
1734
+ if (tmpbuf[i]) free(tmpbuf[i]);
1735
+ if (outbuf[i]) free(outbuf[i]);
1736
+ }
1737
+ if (_tmpbuf) free(_tmpbuf);
1738
+ if (this->jerr.warning) retval = -1;
1739
+ this->jerr.stopOnWarning = FALSE;
1740
+ return retval;
1741
+ }
1742
+
1743
+ DLLEXPORT int tjDecompressToYUV2(tjhandle handle, const unsigned char *jpegBuf,
1744
+ unsigned long jpegSize, unsigned char *dstBuf,
1745
+ int width, int pad, int height, int flags)
1746
+ {
1747
+ unsigned char *dstPlanes[3];
1748
+ int pw0, ph0, strides[3], retval = -1, jpegSubsamp = -1;
1749
+ int i, jpegwidth, jpegheight, scaledw, scaledh;
1750
+
1751
+ GET_DINSTANCE(handle);
1752
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
1753
+
1754
+ if (jpegBuf == NULL || jpegSize <= 0 || dstBuf == NULL || width < 0 ||
1755
+ pad < 1 || !IS_POW2(pad) || height < 0)
1756
+ THROW("tjDecompressToYUV2(): Invalid argument");
1757
+
1758
+ if (setjmp(this->jerr.setjmp_buffer)) {
1759
+ /* If we get here, the JPEG code has signaled an error. */
1760
+ return -1;
1761
+ }
1762
+
1763
+ jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
1764
+ jpeg_read_header(dinfo, TRUE);
1765
+ jpegSubsamp = getSubsamp(dinfo);
1766
+ if (jpegSubsamp < 0)
1767
+ THROW("tjDecompressToYUV2(): Could not determine subsampling type for JPEG image");
1768
+
1769
+ jpegwidth = dinfo->image_width; jpegheight = dinfo->image_height;
1770
+ if (width == 0) width = jpegwidth;
1771
+ if (height == 0) height = jpegheight;
1772
+
1773
+ for (i = 0; i < NUMSF; i++) {
1774
+ scaledw = TJSCALED(jpegwidth, sf[i]);
1775
+ scaledh = TJSCALED(jpegheight, sf[i]);
1776
+ if (scaledw <= width && scaledh <= height)
1777
+ break;
1778
+ }
1779
+ if (i >= NUMSF)
1780
+ THROW("tjDecompressToYUV2(): Could not scale down to desired image dimensions");
1781
+
1782
+ pw0 = tjPlaneWidth(0, width, jpegSubsamp);
1783
+ ph0 = tjPlaneHeight(0, height, jpegSubsamp);
1784
+ dstPlanes[0] = dstBuf;
1785
+ strides[0] = PAD(pw0, pad);
1786
+ if (jpegSubsamp == TJSAMP_GRAY) {
1787
+ strides[1] = strides[2] = 0;
1788
+ dstPlanes[1] = dstPlanes[2] = NULL;
1789
+ } else {
1790
+ int pw1 = tjPlaneWidth(1, width, jpegSubsamp);
1791
+ int ph1 = tjPlaneHeight(1, height, jpegSubsamp);
1792
+
1793
+ strides[1] = strides[2] = PAD(pw1, pad);
1794
+ dstPlanes[1] = dstPlanes[0] + strides[0] * ph0;
1795
+ dstPlanes[2] = dstPlanes[1] + strides[1] * ph1;
1796
+ }
1797
+
1798
+ this->headerRead = 1;
1799
+ return tjDecompressToYUVPlanes(handle, jpegBuf, jpegSize, dstPlanes, width,
1800
+ strides, height, flags);
1801
+
1802
+ bailout:
1803
+ this->jerr.stopOnWarning = FALSE;
1804
+ return retval;
1805
+ }
1806
+
1807
+ DLLEXPORT int tjDecompressToYUV(tjhandle handle, unsigned char *jpegBuf,
1808
+ unsigned long jpegSize, unsigned char *dstBuf,
1809
+ int flags)
1810
+ {
1811
+ return tjDecompressToYUV2(handle, jpegBuf, jpegSize, dstBuf, 0, 4, 0, flags);
1812
+ }
1813
+
1814
+
1815
+ /* Transformer */
1816
+
1817
+ DLLEXPORT tjhandle tjInitTransform(void)
1818
+ {
1819
+ tjinstance *this = NULL;
1820
+ tjhandle handle = NULL;
1821
+
1822
+ if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
1823
+ snprintf(errStr, JMSG_LENGTH_MAX,
1824
+ "tjInitTransform(): Memory allocation failure");
1825
+ return NULL;
1826
+ }
1827
+ MEMZERO(this, sizeof(tjinstance));
1828
+ snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
1829
+ handle = _tjInitCompress(this);
1830
+ if (!handle) return NULL;
1831
+ handle = _tjInitDecompress(this);
1832
+ return handle;
1833
+ }
1834
+
1835
+
1836
+ DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf,
1837
+ unsigned long jpegSize, int n,
1838
+ unsigned char **dstBufs, unsigned long *dstSizes,
1839
+ tjtransform *t, int flags)
1840
+ {
1841
+ jpeg_transform_info *xinfo = NULL;
1842
+ jvirt_barray_ptr *srccoefs, *dstcoefs;
1843
+ int retval = 0, i, jpegSubsamp, saveMarkers = 0;
1844
+
1845
+ GET_INSTANCE(handle);
1846
+ this->jerr.stopOnWarning = (flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
1847
+ if ((this->init & COMPRESS) == 0 || (this->init & DECOMPRESS) == 0)
1848
+ THROW("tjTransform(): Instance has not been initialized for transformation");
1849
+
1850
+ if (jpegBuf == NULL || jpegSize <= 0 || n < 1 || dstBufs == NULL ||
1851
+ dstSizes == NULL || t == NULL || flags < 0)
1852
+ THROW("tjTransform(): Invalid argument");
1853
+
1854
+ #ifndef NO_PUTENV
1855
+ if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
1856
+ else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
1857
+ else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
1858
+ #endif
1859
+
1860
+ if ((xinfo =
1861
+ (jpeg_transform_info *)malloc(sizeof(jpeg_transform_info) * n)) == NULL)
1862
+ THROW("tjTransform(): Memory allocation failure");
1863
+ MEMZERO(xinfo, sizeof(jpeg_transform_info) * n);
1864
+
1865
+ if (setjmp(this->jerr.setjmp_buffer)) {
1866
+ /* If we get here, the JPEG code has signaled an error. */
1867
+ retval = -1; goto bailout;
1868
+ }
1869
+
1870
+ jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
1871
+
1872
+ for (i = 0; i < n; i++) {
1873
+ xinfo[i].transform = xformtypes[t[i].op];
1874
+ xinfo[i].perfect = (t[i].options & TJXOPT_PERFECT) ? 1 : 0;
1875
+ xinfo[i].trim = (t[i].options & TJXOPT_TRIM) ? 1 : 0;
1876
+ xinfo[i].force_grayscale = (t[i].options & TJXOPT_GRAY) ? 1 : 0;
1877
+ xinfo[i].crop = (t[i].options & TJXOPT_CROP) ? 1 : 0;
1878
+ if (n != 1 && t[i].op == TJXOP_HFLIP) xinfo[i].slow_hflip = 1;
1879
+ else xinfo[i].slow_hflip = 0;
1880
+
1881
+ if (xinfo[i].crop) {
1882
+ xinfo[i].crop_xoffset = t[i].r.x; xinfo[i].crop_xoffset_set = JCROP_POS;
1883
+ xinfo[i].crop_yoffset = t[i].r.y; xinfo[i].crop_yoffset_set = JCROP_POS;
1884
+ if (t[i].r.w != 0) {
1885
+ xinfo[i].crop_width = t[i].r.w; xinfo[i].crop_width_set = JCROP_POS;
1886
+ } else
1887
+ xinfo[i].crop_width = JCROP_UNSET;
1888
+ if (t[i].r.h != 0) {
1889
+ xinfo[i].crop_height = t[i].r.h; xinfo[i].crop_height_set = JCROP_POS;
1890
+ } else
1891
+ xinfo[i].crop_height = JCROP_UNSET;
1892
+ }
1893
+ if (!(t[i].options & TJXOPT_COPYNONE)) saveMarkers = 1;
1894
+ }
1895
+
1896
+ jcopy_markers_setup(dinfo, saveMarkers ? JCOPYOPT_ALL : JCOPYOPT_NONE);
1897
+ jpeg_read_header(dinfo, TRUE);
1898
+ jpegSubsamp = getSubsamp(dinfo);
1899
+ if (jpegSubsamp < 0)
1900
+ THROW("tjTransform(): Could not determine subsampling type for JPEG image");
1901
+
1902
+ for (i = 0; i < n; i++) {
1903
+ if (!jtransform_request_workspace(dinfo, &xinfo[i]))
1904
+ THROW("tjTransform(): Transform is not perfect");
1905
+
1906
+ if (xinfo[i].crop) {
1907
+ if ((t[i].r.x % xinfo[i].iMCU_sample_width) != 0 ||
1908
+ (t[i].r.y % xinfo[i].iMCU_sample_height) != 0) {
1909
+ snprintf(this->errStr, JMSG_LENGTH_MAX,
1910
+ "To crop this JPEG image, x must be a multiple of %d\n"
1911
+ "and y must be a multiple of %d.\n",
1912
+ xinfo[i].iMCU_sample_width, xinfo[i].iMCU_sample_height);
1913
+ this->isInstanceError = TRUE;
1914
+ retval = -1; goto bailout;
1915
+ }
1916
+ }
1917
+ }
1918
+
1919
+ srccoefs = jpeg_read_coefficients(dinfo);
1920
+
1921
+ for (i = 0; i < n; i++) {
1922
+ int w, h, alloc = 1;
1923
+
1924
+ if (!xinfo[i].crop) {
1925
+ w = dinfo->image_width; h = dinfo->image_height;
1926
+ } else {
1927
+ w = xinfo[i].crop_width; h = xinfo[i].crop_height;
1928
+ }
1929
+ if (flags & TJFLAG_NOREALLOC) {
1930
+ alloc = 0; dstSizes[i] = tjBufSize(w, h, jpegSubsamp);
1931
+ }
1932
+ if (!(t[i].options & TJXOPT_NOOUTPUT))
1933
+ jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i], alloc);
1934
+ jpeg_copy_critical_parameters(dinfo, cinfo);
1935
+ dstcoefs = jtransform_adjust_parameters(dinfo, cinfo, srccoefs, &xinfo[i]);
1936
+ if (flags & TJFLAG_PROGRESSIVE || t[i].options & TJXOPT_PROGRESSIVE)
1937
+ jpeg_simple_progression(cinfo);
1938
+ if (!(t[i].options & TJXOPT_NOOUTPUT)) {
1939
+ jpeg_write_coefficients(cinfo, dstcoefs);
1940
+ jcopy_markers_execute(dinfo, cinfo, t[i].options & TJXOPT_COPYNONE ?
1941
+ JCOPYOPT_NONE : JCOPYOPT_ALL);
1942
+ } else
1943
+ jinit_c_master_control(cinfo, TRUE);
1944
+ jtransform_execute_transformation(dinfo, cinfo, srccoefs, &xinfo[i]);
1945
+ if (t[i].customFilter) {
1946
+ int ci, y;
1947
+ JDIMENSION by;
1948
+
1949
+ for (ci = 0; ci < cinfo->num_components; ci++) {
1950
+ jpeg_component_info *compptr = &cinfo->comp_info[ci];
1951
+ tjregion arrayRegion = {
1952
+ 0, 0, compptr->width_in_blocks * DCTSIZE, DCTSIZE
1953
+ };
1954
+ tjregion planeRegion = {
1955
+ 0, 0, compptr->width_in_blocks * DCTSIZE,
1956
+ compptr->height_in_blocks * DCTSIZE
1957
+ };
1958
+
1959
+ for (by = 0; by < compptr->height_in_blocks;
1960
+ by += compptr->v_samp_factor) {
1961
+ JBLOCKARRAY barray = (dinfo->mem->access_virt_barray)
1962
+ ((j_common_ptr)dinfo, dstcoefs[ci], by, compptr->v_samp_factor,
1963
+ TRUE);
1964
+
1965
+ for (y = 0; y < compptr->v_samp_factor; y++) {
1966
+ if (t[i].customFilter(barray[y][0], arrayRegion, planeRegion, ci,
1967
+ i, &t[i]) == -1)
1968
+ THROW("tjTransform(): Error in custom filter");
1969
+ arrayRegion.y += DCTSIZE;
1970
+ }
1971
+ }
1972
+ }
1973
+ }
1974
+ if (!(t[i].options & TJXOPT_NOOUTPUT)) jpeg_finish_compress(cinfo);
1975
+ }
1976
+
1977
+ jpeg_finish_decompress(dinfo);
1978
+
1979
+ bailout:
1980
+ if (cinfo->global_state > CSTATE_START) jpeg_abort_compress(cinfo);
1981
+ if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo);
1982
+ if (xinfo) free(xinfo);
1983
+ if (this->jerr.warning) retval = -1;
1984
+ this->jerr.stopOnWarning = FALSE;
1985
+ return retval;
1986
+ }
1987
+
1988
+
1989
+ DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width,
1990
+ int align, int *height, int *pixelFormat,
1991
+ int flags)
1992
+ {
1993
+ int retval = 0, tempc;
1994
+ size_t pitch;
1995
+ tjhandle handle = NULL;
1996
+ tjinstance *this;
1997
+ j_compress_ptr cinfo = NULL;
1998
+ cjpeg_source_ptr src;
1999
+ unsigned char *dstBuf = NULL;
2000
+ FILE *file = NULL;
2001
+ boolean invert;
2002
+
2003
+ if (!filename || !width || align < 1 || !height || !pixelFormat ||
2004
+ *pixelFormat < TJPF_UNKNOWN || *pixelFormat >= TJ_NUMPF)
2005
+ THROWG("tjLoadImage(): Invalid argument");
2006
+ if ((align & (align - 1)) != 0)
2007
+ THROWG("tjLoadImage(): Alignment must be a power of 2");
2008
+
2009
+ if ((handle = tjInitCompress()) == NULL) return NULL;
2010
+ this = (tjinstance *)handle;
2011
+ cinfo = &this->cinfo;
2012
+
2013
+ if ((file = fopen(filename, "rb")) == NULL)
2014
+ THROW_UNIX("tjLoadImage(): Cannot open input file");
2015
+
2016
+ if ((tempc = getc(file)) < 0 || ungetc(tempc, file) == EOF)
2017
+ THROW_UNIX("tjLoadImage(): Could not read input file")
2018
+ else if (tempc == EOF)
2019
+ THROWG("tjLoadImage(): Input file contains no data");
2020
+
2021
+ if (setjmp(this->jerr.setjmp_buffer)) {
2022
+ /* If we get here, the JPEG code has signaled an error. */
2023
+ retval = -1; goto bailout;
2024
+ }
2025
+
2026
+ if (*pixelFormat == TJPF_UNKNOWN) cinfo->in_color_space = JCS_UNKNOWN;
2027
+ else cinfo->in_color_space = pf2cs[*pixelFormat];
2028
+ if (tempc == 'B') {
2029
+ if ((src = jinit_read_bmp(cinfo, FALSE)) == NULL)
2030
+ THROWG("tjLoadImage(): Could not initialize bitmap loader");
2031
+ invert = (flags & TJFLAG_BOTTOMUP) == 0;
2032
+ } else if (tempc == 'P') {
2033
+ if ((src = jinit_read_ppm(cinfo)) == NULL)
2034
+ THROWG("tjLoadImage(): Could not initialize bitmap loader");
2035
+ invert = (flags & TJFLAG_BOTTOMUP) != 0;
2036
+ } else
2037
+ THROWG("tjLoadImage(): Unsupported file type");
2038
+
2039
+ src->input_file = file;
2040
+ (*src->start_input) (cinfo, src);
2041
+ (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
2042
+
2043
+ *width = cinfo->image_width; *height = cinfo->image_height;
2044
+ *pixelFormat = cs2pf[cinfo->in_color_space];
2045
+
2046
+ pitch = PAD((*width) * tjPixelSize[*pixelFormat], align);
2047
+ if ((unsigned long long)pitch * (unsigned long long)(*height) >
2048
+ (unsigned long long)((size_t)-1) ||
2049
+ (dstBuf = (unsigned char *)malloc(pitch * (*height))) == NULL)
2050
+ THROWG("tjLoadImage(): Memory allocation failure");
2051
+
2052
+ if (setjmp(this->jerr.setjmp_buffer)) {
2053
+ /* If we get here, the JPEG code has signaled an error. */
2054
+ retval = -1; goto bailout;
2055
+ }
2056
+
2057
+ while (cinfo->next_scanline < cinfo->image_height) {
2058
+ int i, nlines = (*src->get_pixel_rows) (cinfo, src);
2059
+
2060
+ for (i = 0; i < nlines; i++) {
2061
+ unsigned char *dstptr;
2062
+ int row;
2063
+
2064
+ row = cinfo->next_scanline + i;
2065
+ if (invert) dstptr = &dstBuf[((*height) - row - 1) * pitch];
2066
+ else dstptr = &dstBuf[row * pitch];
2067
+ memcpy(dstptr, src->buffer[i], (*width) * tjPixelSize[*pixelFormat]);
2068
+ }
2069
+ cinfo->next_scanline += nlines;
2070
+ }
2071
+
2072
+ (*src->finish_input) (cinfo, src);
2073
+
2074
+ bailout:
2075
+ if (handle) tjDestroy(handle);
2076
+ if (file) fclose(file);
2077
+ if (retval < 0 && dstBuf) { free(dstBuf); dstBuf = NULL; }
2078
+ return dstBuf;
2079
+ }
2080
+
2081
+
2082
+ DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer,
2083
+ int width, int pitch, int height, int pixelFormat,
2084
+ int flags)
2085
+ {
2086
+ int retval = 0;
2087
+ tjhandle handle = NULL;
2088
+ tjinstance *this;
2089
+ j_decompress_ptr dinfo = NULL;
2090
+ djpeg_dest_ptr dst;
2091
+ FILE *file = NULL;
2092
+ char *ptr = NULL;
2093
+ boolean invert;
2094
+
2095
+ if (!filename || !buffer || width < 1 || pitch < 0 || height < 1 ||
2096
+ pixelFormat < 0 || pixelFormat >= TJ_NUMPF)
2097
+ THROWG("tjSaveImage(): Invalid argument");
2098
+
2099
+ if ((handle = tjInitDecompress()) == NULL)
2100
+ return -1;
2101
+ this = (tjinstance *)handle;
2102
+ dinfo = &this->dinfo;
2103
+
2104
+ if ((file = fopen(filename, "wb")) == NULL)
2105
+ THROW_UNIX("tjSaveImage(): Cannot open output file");
2106
+
2107
+ if (setjmp(this->jerr.setjmp_buffer)) {
2108
+ /* If we get here, the JPEG code has signaled an error. */
2109
+ retval = -1; goto bailout;
2110
+ }
2111
+
2112
+ this->dinfo.out_color_space = pf2cs[pixelFormat];
2113
+ dinfo->image_width = width; dinfo->image_height = height;
2114
+ dinfo->global_state = DSTATE_READY;
2115
+ dinfo->scale_num = dinfo->scale_denom = 1;
2116
+
2117
+ ptr = strrchr(filename, '.');
2118
+ if (ptr && !strcasecmp(ptr, ".bmp")) {
2119
+ if ((dst = jinit_write_bmp(dinfo, FALSE, FALSE)) == NULL)
2120
+ THROWG("tjSaveImage(): Could not initialize bitmap writer");
2121
+ invert = (flags & TJFLAG_BOTTOMUP) == 0;
2122
+ } else {
2123
+ if ((dst = jinit_write_ppm(dinfo)) == NULL)
2124
+ THROWG("tjSaveImage(): Could not initialize PPM writer");
2125
+ invert = (flags & TJFLAG_BOTTOMUP) != 0;
2126
+ }
2127
+
2128
+ dst->output_file = file;
2129
+ (*dst->start_output) (dinfo, dst);
2130
+ (*dinfo->mem->realize_virt_arrays) ((j_common_ptr)dinfo);
2131
+
2132
+ if (pitch == 0) pitch = width * tjPixelSize[pixelFormat];
2133
+
2134
+ while (dinfo->output_scanline < dinfo->output_height) {
2135
+ unsigned char *rowptr;
2136
+
2137
+ if (invert)
2138
+ rowptr = &buffer[(height - dinfo->output_scanline - 1) * pitch];
2139
+ else
2140
+ rowptr = &buffer[dinfo->output_scanline * pitch];
2141
+ memcpy(dst->buffer[0], rowptr, width * tjPixelSize[pixelFormat]);
2142
+ (*dst->put_pixel_rows) (dinfo, dst, 1);
2143
+ dinfo->output_scanline++;
2144
+ }
2145
+
2146
+ (*dst->finish_output) (dinfo, dst);
2147
+
2148
+ bailout:
2149
+ if (handle) tjDestroy(handle);
2150
+ if (file) fclose(file);
2151
+ return retval;
2152
+ }