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,1096 @@
1
+ /*
2
+ * jchuff.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1991-1997, Thomas G. Lane.
6
+ * libjpeg-turbo Modifications:
7
+ * Copyright (C) 2009-2011, 2014-2016, 2018-2019, D. R. Commander.
8
+ * Copyright (C) 2015, Matthieu Darbois.
9
+ * For conditions of distribution and use, see the accompanying README.ijg
10
+ * file.
11
+ *
12
+ * This file contains Huffman entropy encoding routines.
13
+ *
14
+ * Much of the complexity here has to do with supporting output suspension.
15
+ * If the data destination module demands suspension, we want to be able to
16
+ * back up to the start of the current MCU. To do this, we copy state
17
+ * variables into local working storage, and update them back to the
18
+ * permanent JPEG objects only upon successful completion of an MCU.
19
+ *
20
+ * NOTE: All referenced figures are from
21
+ * Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
22
+ */
23
+
24
+ #define JPEG_INTERNALS
25
+ #include "jinclude.h"
26
+ #include "jpeglib.h"
27
+ #include "jsimd.h"
28
+ #include "jconfigint.h"
29
+ #include <limits.h>
30
+
31
+ /*
32
+ * NOTE: If USE_CLZ_INTRINSIC is defined, then clz/bsr instructions will be
33
+ * used for bit counting rather than the lookup table. This will reduce the
34
+ * memory footprint by 64k, which is important for some mobile applications
35
+ * that create many isolated instances of libjpeg-turbo (web browsers, for
36
+ * instance.) This may improve performance on some mobile platforms as well.
37
+ * This feature is enabled by default only on ARM processors, because some x86
38
+ * chips have a slow implementation of bsr, and the use of clz/bsr cannot be
39
+ * shown to have a significant performance impact even on the x86 chips that
40
+ * have a fast implementation of it. When building for ARMv6, you can
41
+ * explicitly disable the use of clz/bsr by adding -mthumb to the compiler
42
+ * flags (this defines __thumb__).
43
+ */
44
+
45
+ /* NOTE: Both GCC and Clang define __GNUC__ */
46
+ #if defined(__GNUC__) && (defined(__arm__) || defined(__aarch64__))
47
+ #if !defined(__thumb__) || defined(__thumb2__)
48
+ #define USE_CLZ_INTRINSIC
49
+ #endif
50
+ #endif
51
+
52
+ #ifdef USE_CLZ_INTRINSIC
53
+ #define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
54
+ #define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
55
+ #else
56
+ #include "jpeg_nbits_table.h"
57
+ #define JPEG_NBITS(x) (jpeg_nbits_table[x])
58
+ #define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x)
59
+ #endif
60
+
61
+
62
+ /* Expanded entropy encoder object for Huffman encoding.
63
+ *
64
+ * The savable_state subrecord contains fields that change within an MCU,
65
+ * but must not be updated permanently until we complete the MCU.
66
+ */
67
+
68
+ typedef struct {
69
+ size_t put_buffer; /* current bit-accumulation buffer */
70
+ int put_bits; /* # of bits now in it */
71
+ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
72
+ } savable_state;
73
+
74
+ /* This macro is to work around compilers with missing or broken
75
+ * structure assignment. You'll need to fix this code if you have
76
+ * such a compiler and you change MAX_COMPS_IN_SCAN.
77
+ */
78
+
79
+ #ifndef NO_STRUCT_ASSIGN
80
+ #define ASSIGN_STATE(dest, src) ((dest) = (src))
81
+ #else
82
+ #if MAX_COMPS_IN_SCAN == 4
83
+ #define ASSIGN_STATE(dest, src) \
84
+ ((dest).put_buffer = (src).put_buffer, \
85
+ (dest).put_bits = (src).put_bits, \
86
+ (dest).last_dc_val[0] = (src).last_dc_val[0], \
87
+ (dest).last_dc_val[1] = (src).last_dc_val[1], \
88
+ (dest).last_dc_val[2] = (src).last_dc_val[2], \
89
+ (dest).last_dc_val[3] = (src).last_dc_val[3])
90
+ #endif
91
+ #endif
92
+
93
+
94
+ typedef struct {
95
+ struct jpeg_entropy_encoder pub; /* public fields */
96
+
97
+ savable_state saved; /* Bit buffer & DC state at start of MCU */
98
+
99
+ /* These fields are NOT loaded into local working state. */
100
+ unsigned int restarts_to_go; /* MCUs left in this restart interval */
101
+ int next_restart_num; /* next restart number to write (0-7) */
102
+
103
+ /* Pointers to derived tables (these workspaces have image lifespan) */
104
+ c_derived_tbl *dc_derived_tbls[NUM_HUFF_TBLS];
105
+ c_derived_tbl *ac_derived_tbls[NUM_HUFF_TBLS];
106
+
107
+ #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
108
+ long *dc_count_ptrs[NUM_HUFF_TBLS];
109
+ long *ac_count_ptrs[NUM_HUFF_TBLS];
110
+ #endif
111
+
112
+ int simd;
113
+ } huff_entropy_encoder;
114
+
115
+ typedef huff_entropy_encoder *huff_entropy_ptr;
116
+
117
+ /* Working state while writing an MCU.
118
+ * This struct contains all the fields that are needed by subroutines.
119
+ */
120
+
121
+ typedef struct {
122
+ JOCTET *next_output_byte; /* => next byte to write in buffer */
123
+ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
124
+ savable_state cur; /* Current bit buffer & DC state */
125
+ j_compress_ptr cinfo; /* dump_buffer needs access to this */
126
+ } working_state;
127
+
128
+
129
+ /* Forward declarations */
130
+ METHODDEF(boolean) encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data);
131
+ METHODDEF(void) finish_pass_huff(j_compress_ptr cinfo);
132
+ #ifdef ENTROPY_OPT_SUPPORTED
133
+ METHODDEF(boolean) encode_mcu_gather(j_compress_ptr cinfo,
134
+ JBLOCKROW *MCU_data);
135
+ METHODDEF(void) finish_pass_gather(j_compress_ptr cinfo);
136
+ #endif
137
+
138
+
139
+ /*
140
+ * Initialize for a Huffman-compressed scan.
141
+ * If gather_statistics is TRUE, we do not output anything during the scan,
142
+ * just count the Huffman symbols used and generate Huffman code tables.
143
+ */
144
+
145
+ METHODDEF(void)
146
+ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
147
+ {
148
+ huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
149
+ int ci, dctbl, actbl;
150
+ jpeg_component_info *compptr;
151
+
152
+ if (gather_statistics) {
153
+ #ifdef ENTROPY_OPT_SUPPORTED
154
+ entropy->pub.encode_mcu = encode_mcu_gather;
155
+ entropy->pub.finish_pass = finish_pass_gather;
156
+ #else
157
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
158
+ #endif
159
+ } else {
160
+ entropy->pub.encode_mcu = encode_mcu_huff;
161
+ entropy->pub.finish_pass = finish_pass_huff;
162
+ }
163
+
164
+ entropy->simd = jsimd_can_huff_encode_one_block();
165
+
166
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
167
+ compptr = cinfo->cur_comp_info[ci];
168
+ dctbl = compptr->dc_tbl_no;
169
+ actbl = compptr->ac_tbl_no;
170
+ if (gather_statistics) {
171
+ #ifdef ENTROPY_OPT_SUPPORTED
172
+ /* Check for invalid table indexes */
173
+ /* (make_c_derived_tbl does this in the other path) */
174
+ if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
175
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
176
+ if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
177
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
178
+ /* Allocate and zero the statistics tables */
179
+ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
180
+ if (entropy->dc_count_ptrs[dctbl] == NULL)
181
+ entropy->dc_count_ptrs[dctbl] = (long *)
182
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
183
+ 257 * sizeof(long));
184
+ MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * sizeof(long));
185
+ if (entropy->ac_count_ptrs[actbl] == NULL)
186
+ entropy->ac_count_ptrs[actbl] = (long *)
187
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
188
+ 257 * sizeof(long));
189
+ MEMZERO(entropy->ac_count_ptrs[actbl], 257 * sizeof(long));
190
+ #endif
191
+ } else {
192
+ /* Compute derived values for Huffman tables */
193
+ /* We may do this more than once for a table, but it's not expensive */
194
+ jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
195
+ &entropy->dc_derived_tbls[dctbl]);
196
+ jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
197
+ &entropy->ac_derived_tbls[actbl]);
198
+ }
199
+ /* Initialize DC predictions to 0 */
200
+ entropy->saved.last_dc_val[ci] = 0;
201
+ }
202
+
203
+ /* Initialize bit buffer to empty */
204
+ entropy->saved.put_buffer = 0;
205
+ entropy->saved.put_bits = 0;
206
+
207
+ /* Initialize restart stuff */
208
+ entropy->restarts_to_go = cinfo->restart_interval;
209
+ entropy->next_restart_num = 0;
210
+ }
211
+
212
+
213
+ /*
214
+ * Compute the derived values for a Huffman table.
215
+ * This routine also performs some validation checks on the table.
216
+ *
217
+ * Note this is also used by jcphuff.c.
218
+ */
219
+
220
+ GLOBAL(void)
221
+ jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno,
222
+ c_derived_tbl **pdtbl)
223
+ {
224
+ JHUFF_TBL *htbl;
225
+ c_derived_tbl *dtbl;
226
+ int p, i, l, lastp, si, maxsymbol;
227
+ char huffsize[257];
228
+ unsigned int huffcode[257];
229
+ unsigned int code;
230
+
231
+ /* Note that huffsize[] and huffcode[] are filled in code-length order,
232
+ * paralleling the order of the symbols themselves in htbl->huffval[].
233
+ */
234
+
235
+ /* Find the input Huffman table */
236
+ if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
237
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
238
+ htbl =
239
+ isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
240
+ if (htbl == NULL)
241
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
242
+
243
+ /* Allocate a workspace if we haven't already done so. */
244
+ if (*pdtbl == NULL)
245
+ *pdtbl = (c_derived_tbl *)
246
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
247
+ sizeof(c_derived_tbl));
248
+ dtbl = *pdtbl;
249
+
250
+ /* Figure C.1: make table of Huffman code length for each symbol */
251
+
252
+ p = 0;
253
+ for (l = 1; l <= 16; l++) {
254
+ i = (int)htbl->bits[l];
255
+ if (i < 0 || p + i > 256) /* protect against table overrun */
256
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
257
+ while (i--)
258
+ huffsize[p++] = (char)l;
259
+ }
260
+ huffsize[p] = 0;
261
+ lastp = p;
262
+
263
+ /* Figure C.2: generate the codes themselves */
264
+ /* We also validate that the counts represent a legal Huffman code tree. */
265
+
266
+ code = 0;
267
+ si = huffsize[0];
268
+ p = 0;
269
+ while (huffsize[p]) {
270
+ while (((int)huffsize[p]) == si) {
271
+ huffcode[p++] = code;
272
+ code++;
273
+ }
274
+ /* code is now 1 more than the last code used for codelength si; but
275
+ * it must still fit in si bits, since no code is allowed to be all ones.
276
+ */
277
+ if (((JLONG)code) >= (((JLONG)1) << si))
278
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
279
+ code <<= 1;
280
+ si++;
281
+ }
282
+
283
+ /* Figure C.3: generate encoding tables */
284
+ /* These are code and size indexed by symbol value */
285
+
286
+ /* Set all codeless symbols to have code length 0;
287
+ * this lets us detect duplicate VAL entries here, and later
288
+ * allows emit_bits to detect any attempt to emit such symbols.
289
+ */
290
+ MEMZERO(dtbl->ehufsi, sizeof(dtbl->ehufsi));
291
+
292
+ /* This is also a convenient place to check for out-of-range
293
+ * and duplicated VAL entries. We allow 0..255 for AC symbols
294
+ * but only 0..15 for DC. (We could constrain them further
295
+ * based on data depth and mode, but this seems enough.)
296
+ */
297
+ maxsymbol = isDC ? 15 : 255;
298
+
299
+ for (p = 0; p < lastp; p++) {
300
+ i = htbl->huffval[p];
301
+ if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
302
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
303
+ dtbl->ehufco[i] = huffcode[p];
304
+ dtbl->ehufsi[i] = huffsize[p];
305
+ }
306
+ }
307
+
308
+
309
+ /* Outputting bytes to the file */
310
+
311
+ /* Emit a byte, taking 'action' if must suspend. */
312
+ #define emit_byte(state, val, action) { \
313
+ *(state)->next_output_byte++ = (JOCTET)(val); \
314
+ if (--(state)->free_in_buffer == 0) \
315
+ if (!dump_buffer(state)) \
316
+ { action; } \
317
+ }
318
+
319
+
320
+ LOCAL(boolean)
321
+ dump_buffer(working_state *state)
322
+ /* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
323
+ {
324
+ struct jpeg_destination_mgr *dest = state->cinfo->dest;
325
+
326
+ if (!(*dest->empty_output_buffer) (state->cinfo))
327
+ return FALSE;
328
+ /* After a successful buffer dump, must reset buffer pointers */
329
+ state->next_output_byte = dest->next_output_byte;
330
+ state->free_in_buffer = dest->free_in_buffer;
331
+ return TRUE;
332
+ }
333
+
334
+
335
+ /* Outputting bits to the file */
336
+
337
+ /* These macros perform the same task as the emit_bits() function in the
338
+ * original libjpeg code. In addition to reducing overhead by explicitly
339
+ * inlining the code, additional performance is achieved by taking into
340
+ * account the size of the bit buffer and waiting until it is almost full
341
+ * before emptying it. This mostly benefits 64-bit platforms, since 6
342
+ * bytes can be stored in a 64-bit bit buffer before it has to be emptied.
343
+ */
344
+
345
+ #define EMIT_BYTE() { \
346
+ JOCTET c; \
347
+ put_bits -= 8; \
348
+ c = (JOCTET)GETJOCTET(put_buffer >> put_bits); \
349
+ *buffer++ = c; \
350
+ if (c == 0xFF) /* need to stuff a zero byte? */ \
351
+ *buffer++ = 0; \
352
+ }
353
+
354
+ #define PUT_BITS(code, size) { \
355
+ put_bits += size; \
356
+ put_buffer = (put_buffer << size) | code; \
357
+ }
358
+
359
+ #if SIZEOF_SIZE_T != 8 && !defined(_WIN64)
360
+
361
+ #define CHECKBUF15() { \
362
+ if (put_bits > 15) { \
363
+ EMIT_BYTE() \
364
+ EMIT_BYTE() \
365
+ } \
366
+ }
367
+
368
+ #endif
369
+
370
+ #define CHECKBUF31() { \
371
+ if (put_bits > 31) { \
372
+ EMIT_BYTE() \
373
+ EMIT_BYTE() \
374
+ EMIT_BYTE() \
375
+ EMIT_BYTE() \
376
+ } \
377
+ }
378
+
379
+ #define CHECKBUF47() { \
380
+ if (put_bits > 47) { \
381
+ EMIT_BYTE() \
382
+ EMIT_BYTE() \
383
+ EMIT_BYTE() \
384
+ EMIT_BYTE() \
385
+ EMIT_BYTE() \
386
+ EMIT_BYTE() \
387
+ } \
388
+ }
389
+
390
+ #if !defined(_WIN32) && !defined(SIZEOF_SIZE_T)
391
+ #error Cannot determine word size
392
+ #endif
393
+
394
+ #if SIZEOF_SIZE_T == 8 || defined(_WIN64)
395
+
396
+ #define EMIT_BITS(code, size) { \
397
+ CHECKBUF47() \
398
+ PUT_BITS(code, size) \
399
+ }
400
+
401
+ #define EMIT_CODE(code, size) { \
402
+ temp2 &= (((JLONG)1) << nbits) - 1; \
403
+ CHECKBUF31() \
404
+ PUT_BITS(code, size) \
405
+ PUT_BITS(temp2, nbits) \
406
+ }
407
+
408
+ #else
409
+
410
+ #define EMIT_BITS(code, size) { \
411
+ PUT_BITS(code, size) \
412
+ CHECKBUF15() \
413
+ }
414
+
415
+ #define EMIT_CODE(code, size) { \
416
+ temp2 &= (((JLONG)1) << nbits) - 1; \
417
+ PUT_BITS(code, size) \
418
+ CHECKBUF15() \
419
+ PUT_BITS(temp2, nbits) \
420
+ CHECKBUF15() \
421
+ }
422
+
423
+ #endif
424
+
425
+
426
+ /* Although it is exceedingly rare, it is possible for a Huffman-encoded
427
+ * coefficient block to be larger than the 128-byte unencoded block. For each
428
+ * of the 64 coefficients, PUT_BITS is invoked twice, and each invocation can
429
+ * theoretically store 16 bits (for a maximum of 2048 bits or 256 bytes per
430
+ * encoded block.) If, for instance, one artificially sets the AC
431
+ * coefficients to alternating values of 32767 and -32768 (using the JPEG
432
+ * scanning order-- 1, 8, 16, etc.), then this will produce an encoded block
433
+ * larger than 200 bytes.
434
+ */
435
+ #define BUFSIZE (DCTSIZE2 * 8)
436
+
437
+ #define LOAD_BUFFER() { \
438
+ if (state->free_in_buffer < BUFSIZE) { \
439
+ localbuf = 1; \
440
+ buffer = _buffer; \
441
+ } else \
442
+ buffer = state->next_output_byte; \
443
+ }
444
+
445
+ #define STORE_BUFFER() { \
446
+ if (localbuf) { \
447
+ bytes = buffer - _buffer; \
448
+ buffer = _buffer; \
449
+ while (bytes > 0) { \
450
+ bytestocopy = MIN(bytes, state->free_in_buffer); \
451
+ MEMCOPY(state->next_output_byte, buffer, bytestocopy); \
452
+ state->next_output_byte += bytestocopy; \
453
+ buffer += bytestocopy; \
454
+ state->free_in_buffer -= bytestocopy; \
455
+ if (state->free_in_buffer == 0) \
456
+ if (!dump_buffer(state)) return FALSE; \
457
+ bytes -= bytestocopy; \
458
+ } \
459
+ } else { \
460
+ state->free_in_buffer -= (buffer - state->next_output_byte); \
461
+ state->next_output_byte = buffer; \
462
+ } \
463
+ }
464
+
465
+
466
+ LOCAL(boolean)
467
+ flush_bits(working_state *state)
468
+ {
469
+ JOCTET _buffer[BUFSIZE], *buffer;
470
+ size_t put_buffer; int put_bits;
471
+ size_t bytes, bytestocopy; int localbuf = 0;
472
+
473
+ put_buffer = state->cur.put_buffer;
474
+ put_bits = state->cur.put_bits;
475
+ LOAD_BUFFER()
476
+
477
+ /* fill any partial byte with ones */
478
+ PUT_BITS(0x7F, 7)
479
+ while (put_bits >= 8) EMIT_BYTE()
480
+
481
+ state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
482
+ state->cur.put_bits = 0;
483
+ STORE_BUFFER()
484
+
485
+ return TRUE;
486
+ }
487
+
488
+
489
+ /* Encode a single block's worth of coefficients */
490
+
491
+ LOCAL(boolean)
492
+ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val,
493
+ c_derived_tbl *dctbl, c_derived_tbl *actbl)
494
+ {
495
+ JOCTET _buffer[BUFSIZE], *buffer;
496
+ size_t bytes, bytestocopy; int localbuf = 0;
497
+
498
+ LOAD_BUFFER()
499
+
500
+ buffer = jsimd_huff_encode_one_block(state, buffer, block, last_dc_val,
501
+ dctbl, actbl);
502
+
503
+ STORE_BUFFER()
504
+
505
+ return TRUE;
506
+ }
507
+
508
+ LOCAL(boolean)
509
+ encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
510
+ c_derived_tbl *dctbl, c_derived_tbl *actbl)
511
+ {
512
+ int temp, temp2, temp3;
513
+ int nbits;
514
+ int r, code, size;
515
+ JOCTET _buffer[BUFSIZE], *buffer;
516
+ size_t put_buffer; int put_bits;
517
+ int code_0xf0 = actbl->ehufco[0xf0], size_0xf0 = actbl->ehufsi[0xf0];
518
+ size_t bytes, bytestocopy; int localbuf = 0;
519
+
520
+ put_buffer = state->cur.put_buffer;
521
+ put_bits = state->cur.put_bits;
522
+ LOAD_BUFFER()
523
+
524
+ /* Encode the DC coefficient difference per section F.1.2.1 */
525
+
526
+ temp = temp2 = block[0] - last_dc_val;
527
+
528
+ /* This is a well-known technique for obtaining the absolute value without a
529
+ * branch. It is derived from an assembly language technique presented in
530
+ * "How to Optimize for the Pentium Processors", Copyright (c) 1996, 1997 by
531
+ * Agner Fog.
532
+ */
533
+ temp3 = temp >> (CHAR_BIT * sizeof(int) - 1);
534
+ temp ^= temp3;
535
+ temp -= temp3;
536
+
537
+ /* For a negative input, want temp2 = bitwise complement of abs(input) */
538
+ /* This code assumes we are on a two's complement machine */
539
+ temp2 += temp3;
540
+
541
+ /* Find the number of bits needed for the magnitude of the coefficient */
542
+ nbits = JPEG_NBITS(temp);
543
+
544
+ /* Emit the Huffman-coded symbol for the number of bits */
545
+ code = dctbl->ehufco[nbits];
546
+ size = dctbl->ehufsi[nbits];
547
+ EMIT_BITS(code, size)
548
+
549
+ /* Mask off any extra bits in code */
550
+ temp2 &= (((JLONG)1) << nbits) - 1;
551
+
552
+ /* Emit that number of bits of the value, if positive, */
553
+ /* or the complement of its magnitude, if negative. */
554
+ EMIT_BITS(temp2, nbits)
555
+
556
+ /* Encode the AC coefficients per section F.1.2.2 */
557
+
558
+ r = 0; /* r = run length of zeros */
559
+
560
+ /* Manually unroll the k loop to eliminate the counter variable. This
561
+ * improves performance greatly on systems with a limited number of
562
+ * registers (such as x86.)
563
+ */
564
+ #define kloop(jpeg_natural_order_of_k) { \
565
+ if ((temp = block[jpeg_natural_order_of_k]) == 0) { \
566
+ r++; \
567
+ } else { \
568
+ temp2 = temp; \
569
+ /* Branch-less absolute value, bitwise complement, etc., same as above */ \
570
+ temp3 = temp >> (CHAR_BIT * sizeof(int) - 1); \
571
+ temp ^= temp3; \
572
+ temp -= temp3; \
573
+ temp2 += temp3; \
574
+ nbits = JPEG_NBITS_NONZERO(temp); \
575
+ /* if run length > 15, must emit special run-length-16 codes (0xF0) */ \
576
+ while (r > 15) { \
577
+ EMIT_BITS(code_0xf0, size_0xf0) \
578
+ r -= 16; \
579
+ } \
580
+ /* Emit Huffman symbol for run length / number of bits */ \
581
+ temp3 = (r << 4) + nbits; \
582
+ code = actbl->ehufco[temp3]; \
583
+ size = actbl->ehufsi[temp3]; \
584
+ EMIT_CODE(code, size) \
585
+ r = 0; \
586
+ } \
587
+ }
588
+
589
+ /* One iteration for each value in jpeg_natural_order[] */
590
+ kloop(1); kloop(8); kloop(16); kloop(9); kloop(2); kloop(3);
591
+ kloop(10); kloop(17); kloop(24); kloop(32); kloop(25); kloop(18);
592
+ kloop(11); kloop(4); kloop(5); kloop(12); kloop(19); kloop(26);
593
+ kloop(33); kloop(40); kloop(48); kloop(41); kloop(34); kloop(27);
594
+ kloop(20); kloop(13); kloop(6); kloop(7); kloop(14); kloop(21);
595
+ kloop(28); kloop(35); kloop(42); kloop(49); kloop(56); kloop(57);
596
+ kloop(50); kloop(43); kloop(36); kloop(29); kloop(22); kloop(15);
597
+ kloop(23); kloop(30); kloop(37); kloop(44); kloop(51); kloop(58);
598
+ kloop(59); kloop(52); kloop(45); kloop(38); kloop(31); kloop(39);
599
+ kloop(46); kloop(53); kloop(60); kloop(61); kloop(54); kloop(47);
600
+ kloop(55); kloop(62); kloop(63);
601
+
602
+ /* If the last coef(s) were zero, emit an end-of-block code */
603
+ if (r > 0) {
604
+ code = actbl->ehufco[0];
605
+ size = actbl->ehufsi[0];
606
+ EMIT_BITS(code, size)
607
+ }
608
+
609
+ state->cur.put_buffer = put_buffer;
610
+ state->cur.put_bits = put_bits;
611
+ STORE_BUFFER()
612
+
613
+ return TRUE;
614
+ }
615
+
616
+
617
+ /*
618
+ * Emit a restart marker & resynchronize predictions.
619
+ */
620
+
621
+ LOCAL(boolean)
622
+ emit_restart(working_state *state, int restart_num)
623
+ {
624
+ int ci;
625
+
626
+ if (!flush_bits(state))
627
+ return FALSE;
628
+
629
+ emit_byte(state, 0xFF, return FALSE);
630
+ emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
631
+
632
+ /* Re-initialize DC predictions to 0 */
633
+ for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
634
+ state->cur.last_dc_val[ci] = 0;
635
+
636
+ /* The restart counter is not updated until we successfully write the MCU. */
637
+
638
+ return TRUE;
639
+ }
640
+
641
+
642
+ /*
643
+ * Encode and output one MCU's worth of Huffman-compressed coefficients.
644
+ */
645
+
646
+ METHODDEF(boolean)
647
+ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
648
+ {
649
+ huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
650
+ working_state state;
651
+ int blkn, ci;
652
+ jpeg_component_info *compptr;
653
+
654
+ /* Load up working state */
655
+ state.next_output_byte = cinfo->dest->next_output_byte;
656
+ state.free_in_buffer = cinfo->dest->free_in_buffer;
657
+ ASSIGN_STATE(state.cur, entropy->saved);
658
+ state.cinfo = cinfo;
659
+
660
+ /* Emit restart marker if needed */
661
+ if (cinfo->restart_interval) {
662
+ if (entropy->restarts_to_go == 0)
663
+ if (!emit_restart(&state, entropy->next_restart_num))
664
+ return FALSE;
665
+ }
666
+
667
+ /* Encode the MCU data blocks */
668
+ if (entropy->simd) {
669
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
670
+ ci = cinfo->MCU_membership[blkn];
671
+ compptr = cinfo->cur_comp_info[ci];
672
+ if (!encode_one_block_simd(&state,
673
+ MCU_data[blkn][0], state.cur.last_dc_val[ci],
674
+ entropy->dc_derived_tbls[compptr->dc_tbl_no],
675
+ entropy->ac_derived_tbls[compptr->ac_tbl_no]))
676
+ return FALSE;
677
+ /* Update last_dc_val */
678
+ state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
679
+ }
680
+ } else {
681
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
682
+ ci = cinfo->MCU_membership[blkn];
683
+ compptr = cinfo->cur_comp_info[ci];
684
+ if (!encode_one_block(&state,
685
+ MCU_data[blkn][0], state.cur.last_dc_val[ci],
686
+ entropy->dc_derived_tbls[compptr->dc_tbl_no],
687
+ entropy->ac_derived_tbls[compptr->ac_tbl_no]))
688
+ return FALSE;
689
+ /* Update last_dc_val */
690
+ state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
691
+ }
692
+ }
693
+
694
+ /* Completed MCU, so update state */
695
+ cinfo->dest->next_output_byte = state.next_output_byte;
696
+ cinfo->dest->free_in_buffer = state.free_in_buffer;
697
+ ASSIGN_STATE(entropy->saved, state.cur);
698
+
699
+ /* Update restart-interval state too */
700
+ if (cinfo->restart_interval) {
701
+ if (entropy->restarts_to_go == 0) {
702
+ entropy->restarts_to_go = cinfo->restart_interval;
703
+ entropy->next_restart_num++;
704
+ entropy->next_restart_num &= 7;
705
+ }
706
+ entropy->restarts_to_go--;
707
+ }
708
+
709
+ return TRUE;
710
+ }
711
+
712
+
713
+ /*
714
+ * Finish up at the end of a Huffman-compressed scan.
715
+ */
716
+
717
+ METHODDEF(void)
718
+ finish_pass_huff(j_compress_ptr cinfo)
719
+ {
720
+ huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
721
+ working_state state;
722
+
723
+ /* Load up working state ... flush_bits needs it */
724
+ state.next_output_byte = cinfo->dest->next_output_byte;
725
+ state.free_in_buffer = cinfo->dest->free_in_buffer;
726
+ ASSIGN_STATE(state.cur, entropy->saved);
727
+ state.cinfo = cinfo;
728
+
729
+ /* Flush out the last data */
730
+ if (!flush_bits(&state))
731
+ ERREXIT(cinfo, JERR_CANT_SUSPEND);
732
+
733
+ /* Update state */
734
+ cinfo->dest->next_output_byte = state.next_output_byte;
735
+ cinfo->dest->free_in_buffer = state.free_in_buffer;
736
+ ASSIGN_STATE(entropy->saved, state.cur);
737
+ }
738
+
739
+
740
+ /*
741
+ * Huffman coding optimization.
742
+ *
743
+ * We first scan the supplied data and count the number of uses of each symbol
744
+ * that is to be Huffman-coded. (This process MUST agree with the code above.)
745
+ * Then we build a Huffman coding tree for the observed counts.
746
+ * Symbols which are not needed at all for the particular image are not
747
+ * assigned any code, which saves space in the DHT marker as well as in
748
+ * the compressed data.
749
+ */
750
+
751
+ #ifdef ENTROPY_OPT_SUPPORTED
752
+
753
+
754
+ /* Process a single block's worth of coefficients */
755
+
756
+ LOCAL(void)
757
+ htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
758
+ long dc_counts[], long ac_counts[])
759
+ {
760
+ register int temp;
761
+ register int nbits;
762
+ register int k, r;
763
+
764
+ /* Encode the DC coefficient difference per section F.1.2.1 */
765
+
766
+ temp = block[0] - last_dc_val;
767
+ if (temp < 0)
768
+ temp = -temp;
769
+
770
+ /* Find the number of bits needed for the magnitude of the coefficient */
771
+ nbits = 0;
772
+ while (temp) {
773
+ nbits++;
774
+ temp >>= 1;
775
+ }
776
+ /* Check for out-of-range coefficient values.
777
+ * Since we're encoding a difference, the range limit is twice as much.
778
+ */
779
+ if (nbits > MAX_COEF_BITS + 1)
780
+ ERREXIT(cinfo, JERR_BAD_DCT_COEF);
781
+
782
+ /* Count the Huffman symbol for the number of bits */
783
+ dc_counts[nbits]++;
784
+
785
+ /* Encode the AC coefficients per section F.1.2.2 */
786
+
787
+ r = 0; /* r = run length of zeros */
788
+
789
+ for (k = 1; k < DCTSIZE2; k++) {
790
+ if ((temp = block[jpeg_natural_order[k]]) == 0) {
791
+ r++;
792
+ } else {
793
+ /* if run length > 15, must emit special run-length-16 codes (0xF0) */
794
+ while (r > 15) {
795
+ ac_counts[0xF0]++;
796
+ r -= 16;
797
+ }
798
+
799
+ /* Find the number of bits needed for the magnitude of the coefficient */
800
+ if (temp < 0)
801
+ temp = -temp;
802
+
803
+ /* Find the number of bits needed for the magnitude of the coefficient */
804
+ nbits = 1; /* there must be at least one 1 bit */
805
+ while ((temp >>= 1))
806
+ nbits++;
807
+ /* Check for out-of-range coefficient values */
808
+ if (nbits > MAX_COEF_BITS)
809
+ ERREXIT(cinfo, JERR_BAD_DCT_COEF);
810
+
811
+ /* Count Huffman symbol for run length / number of bits */
812
+ ac_counts[(r << 4) + nbits]++;
813
+
814
+ r = 0;
815
+ }
816
+ }
817
+
818
+ /* If the last coef(s) were zero, emit an end-of-block code */
819
+ if (r > 0)
820
+ ac_counts[0]++;
821
+ }
822
+
823
+
824
+ /*
825
+ * Trial-encode one MCU's worth of Huffman-compressed coefficients.
826
+ * No data is actually output, so no suspension return is possible.
827
+ */
828
+
829
+ METHODDEF(boolean)
830
+ encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
831
+ {
832
+ huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
833
+ int blkn, ci;
834
+ jpeg_component_info *compptr;
835
+
836
+ /* Take care of restart intervals if needed */
837
+ if (cinfo->restart_interval) {
838
+ if (entropy->restarts_to_go == 0) {
839
+ /* Re-initialize DC predictions to 0 */
840
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++)
841
+ entropy->saved.last_dc_val[ci] = 0;
842
+ /* Update restart state */
843
+ entropy->restarts_to_go = cinfo->restart_interval;
844
+ }
845
+ entropy->restarts_to_go--;
846
+ }
847
+
848
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
849
+ ci = cinfo->MCU_membership[blkn];
850
+ compptr = cinfo->cur_comp_info[ci];
851
+ htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
852
+ entropy->dc_count_ptrs[compptr->dc_tbl_no],
853
+ entropy->ac_count_ptrs[compptr->ac_tbl_no]);
854
+ entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
855
+ }
856
+
857
+ return TRUE;
858
+ }
859
+
860
+
861
+ /*
862
+ * Generate the best Huffman code table for the given counts, fill htbl.
863
+ * Note this is also used by jcphuff.c.
864
+ *
865
+ * The JPEG standard requires that no symbol be assigned a codeword of all
866
+ * one bits (so that padding bits added at the end of a compressed segment
867
+ * can't look like a valid code). Because of the canonical ordering of
868
+ * codewords, this just means that there must be an unused slot in the
869
+ * longest codeword length category. Annex K (Clause K.2) of
870
+ * Rec. ITU-T T.81 (1992) | ISO/IEC 10918-1:1994 suggests reserving such a slot
871
+ * by pretending that symbol 256 is a valid symbol with count 1. In theory
872
+ * that's not optimal; giving it count zero but including it in the symbol set
873
+ * anyway should give a better Huffman code. But the theoretically better code
874
+ * actually seems to come out worse in practice, because it produces more
875
+ * all-ones bytes (which incur stuffed zero bytes in the final file). In any
876
+ * case the difference is tiny.
877
+ *
878
+ * The JPEG standard requires Huffman codes to be no more than 16 bits long.
879
+ * If some symbols have a very small but nonzero probability, the Huffman tree
880
+ * must be adjusted to meet the code length restriction. We currently use
881
+ * the adjustment method suggested in JPEG section K.2. This method is *not*
882
+ * optimal; it may not choose the best possible limited-length code. But
883
+ * typically only very-low-frequency symbols will be given less-than-optimal
884
+ * lengths, so the code is almost optimal. Experimental comparisons against
885
+ * an optimal limited-length-code algorithm indicate that the difference is
886
+ * microscopic --- usually less than a hundredth of a percent of total size.
887
+ * So the extra complexity of an optimal algorithm doesn't seem worthwhile.
888
+ */
889
+
890
+ GLOBAL(void)
891
+ jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
892
+ {
893
+ #define MAX_CLEN 32 /* assumed maximum initial code length */
894
+ UINT8 bits[MAX_CLEN + 1]; /* bits[k] = # of symbols with code length k */
895
+ int codesize[257]; /* codesize[k] = code length of symbol k */
896
+ int others[257]; /* next symbol in current branch of tree */
897
+ int c1, c2;
898
+ int p, i, j;
899
+ long v;
900
+
901
+ /* This algorithm is explained in section K.2 of the JPEG standard */
902
+
903
+ MEMZERO(bits, sizeof(bits));
904
+ MEMZERO(codesize, sizeof(codesize));
905
+ for (i = 0; i < 257; i++)
906
+ others[i] = -1; /* init links to empty */
907
+
908
+ freq[256] = 1; /* make sure 256 has a nonzero count */
909
+ /* Including the pseudo-symbol 256 in the Huffman procedure guarantees
910
+ * that no real symbol is given code-value of all ones, because 256
911
+ * will be placed last in the largest codeword category.
912
+ */
913
+
914
+ /* Huffman's basic algorithm to assign optimal code lengths to symbols */
915
+
916
+ for (;;) {
917
+ /* Find the smallest nonzero frequency, set c1 = its symbol */
918
+ /* In case of ties, take the larger symbol number */
919
+ c1 = -1;
920
+ v = 1000000000L;
921
+ for (i = 0; i <= 256; i++) {
922
+ if (freq[i] && freq[i] <= v) {
923
+ v = freq[i];
924
+ c1 = i;
925
+ }
926
+ }
927
+
928
+ /* Find the next smallest nonzero frequency, set c2 = its symbol */
929
+ /* In case of ties, take the larger symbol number */
930
+ c2 = -1;
931
+ v = 1000000000L;
932
+ for (i = 0; i <= 256; i++) {
933
+ if (freq[i] && freq[i] <= v && i != c1) {
934
+ v = freq[i];
935
+ c2 = i;
936
+ }
937
+ }
938
+
939
+ /* Done if we've merged everything into one frequency */
940
+ if (c2 < 0)
941
+ break;
942
+
943
+ /* Else merge the two counts/trees */
944
+ freq[c1] += freq[c2];
945
+ freq[c2] = 0;
946
+
947
+ /* Increment the codesize of everything in c1's tree branch */
948
+ codesize[c1]++;
949
+ while (others[c1] >= 0) {
950
+ c1 = others[c1];
951
+ codesize[c1]++;
952
+ }
953
+
954
+ others[c1] = c2; /* chain c2 onto c1's tree branch */
955
+
956
+ /* Increment the codesize of everything in c2's tree branch */
957
+ codesize[c2]++;
958
+ while (others[c2] >= 0) {
959
+ c2 = others[c2];
960
+ codesize[c2]++;
961
+ }
962
+ }
963
+
964
+ /* Now count the number of symbols of each code length */
965
+ for (i = 0; i <= 256; i++) {
966
+ if (codesize[i]) {
967
+ /* The JPEG standard seems to think that this can't happen, */
968
+ /* but I'm paranoid... */
969
+ if (codesize[i] > MAX_CLEN)
970
+ ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
971
+
972
+ bits[codesize[i]]++;
973
+ }
974
+ }
975
+
976
+ /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
977
+ * Huffman procedure assigned any such lengths, we must adjust the coding.
978
+ * Here is what Rec. ITU-T T.81 | ISO/IEC 10918-1 says about how this next
979
+ * bit works: Since symbols are paired for the longest Huffman code, the
980
+ * symbols are removed from this length category two at a time. The prefix
981
+ * for the pair (which is one bit shorter) is allocated to one of the pair;
982
+ * then, skipping the BITS entry for that prefix length, a code word from the
983
+ * next shortest nonzero BITS entry is converted into a prefix for two code
984
+ * words one bit longer.
985
+ */
986
+
987
+ for (i = MAX_CLEN; i > 16; i--) {
988
+ while (bits[i] > 0) {
989
+ j = i - 2; /* find length of new prefix to be used */
990
+ while (bits[j] == 0)
991
+ j--;
992
+
993
+ bits[i] -= 2; /* remove two symbols */
994
+ bits[i - 1]++; /* one goes in this length */
995
+ bits[j + 1] += 2; /* two new symbols in this length */
996
+ bits[j]--; /* symbol of this length is now a prefix */
997
+ }
998
+ }
999
+
1000
+ /* Remove the count for the pseudo-symbol 256 from the largest codelength */
1001
+ while (bits[i] == 0) /* find largest codelength still in use */
1002
+ i--;
1003
+ bits[i]--;
1004
+
1005
+ /* Return final symbol counts (only for lengths 0..16) */
1006
+ MEMCOPY(htbl->bits, bits, sizeof(htbl->bits));
1007
+
1008
+ /* Return a list of the symbols sorted by code length */
1009
+ /* It's not real clear to me why we don't need to consider the codelength
1010
+ * changes made above, but Rec. ITU-T T.81 | ISO/IEC 10918-1 seems to think
1011
+ * this works.
1012
+ */
1013
+ p = 0;
1014
+ for (i = 1; i <= MAX_CLEN; i++) {
1015
+ for (j = 0; j <= 255; j++) {
1016
+ if (codesize[j] == i) {
1017
+ htbl->huffval[p] = (UINT8)j;
1018
+ p++;
1019
+ }
1020
+ }
1021
+ }
1022
+
1023
+ /* Set sent_table FALSE so updated table will be written to JPEG file. */
1024
+ htbl->sent_table = FALSE;
1025
+ }
1026
+
1027
+
1028
+ /*
1029
+ * Finish up a statistics-gathering pass and create the new Huffman tables.
1030
+ */
1031
+
1032
+ METHODDEF(void)
1033
+ finish_pass_gather(j_compress_ptr cinfo)
1034
+ {
1035
+ huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
1036
+ int ci, dctbl, actbl;
1037
+ jpeg_component_info *compptr;
1038
+ JHUFF_TBL **htblptr;
1039
+ boolean did_dc[NUM_HUFF_TBLS];
1040
+ boolean did_ac[NUM_HUFF_TBLS];
1041
+
1042
+ /* It's important not to apply jpeg_gen_optimal_table more than once
1043
+ * per table, because it clobbers the input frequency counts!
1044
+ */
1045
+ MEMZERO(did_dc, sizeof(did_dc));
1046
+ MEMZERO(did_ac, sizeof(did_ac));
1047
+
1048
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
1049
+ compptr = cinfo->cur_comp_info[ci];
1050
+ dctbl = compptr->dc_tbl_no;
1051
+ actbl = compptr->ac_tbl_no;
1052
+ if (!did_dc[dctbl]) {
1053
+ htblptr = &cinfo->dc_huff_tbl_ptrs[dctbl];
1054
+ if (*htblptr == NULL)
1055
+ *htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
1056
+ jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
1057
+ did_dc[dctbl] = TRUE;
1058
+ }
1059
+ if (!did_ac[actbl]) {
1060
+ htblptr = &cinfo->ac_huff_tbl_ptrs[actbl];
1061
+ if (*htblptr == NULL)
1062
+ *htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
1063
+ jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
1064
+ did_ac[actbl] = TRUE;
1065
+ }
1066
+ }
1067
+ }
1068
+
1069
+
1070
+ #endif /* ENTROPY_OPT_SUPPORTED */
1071
+
1072
+
1073
+ /*
1074
+ * Module initialization routine for Huffman entropy encoding.
1075
+ */
1076
+
1077
+ GLOBAL(void)
1078
+ jinit_huff_encoder(j_compress_ptr cinfo)
1079
+ {
1080
+ huff_entropy_ptr entropy;
1081
+ int i;
1082
+
1083
+ entropy = (huff_entropy_ptr)
1084
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
1085
+ sizeof(huff_entropy_encoder));
1086
+ cinfo->entropy = (struct jpeg_entropy_encoder *)entropy;
1087
+ entropy->pub.start_pass = start_pass_huff;
1088
+
1089
+ /* Mark tables unallocated */
1090
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
1091
+ entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
1092
+ #ifdef ENTROPY_OPT_SUPPORTED
1093
+ entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
1094
+ #endif
1095
+ }
1096
+ }