rfreeimage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (860) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +1 -0
  4. data/Rakefile +34 -0
  5. data/ext/rfreeimage/extconf.rb +35 -0
  6. data/ext/rfreeimage/rfi_main.c +389 -0
  7. data/lib/rfreeimage/image.rb +26 -0
  8. data/lib/rfreeimage/version.rb +3 -0
  9. data/lib/rfreeimage.rb +3 -0
  10. data/rfreeimage.gemspec +32 -0
  11. data/vendor/FreeImage/Makefile +34 -0
  12. data/vendor/FreeImage/Makefile.cygwin +74 -0
  13. data/vendor/FreeImage/Makefile.fip +84 -0
  14. data/vendor/FreeImage/Makefile.gnu +83 -0
  15. data/vendor/FreeImage/Makefile.iphone +96 -0
  16. data/vendor/FreeImage/Makefile.mingw +136 -0
  17. data/vendor/FreeImage/Makefile.osx +115 -0
  18. data/vendor/FreeImage/Makefile.solaris +66 -0
  19. data/vendor/FreeImage/Makefile.srcs +6 -0
  20. data/vendor/FreeImage/README.iphone +19 -0
  21. data/vendor/FreeImage/README.linux +50 -0
  22. data/vendor/FreeImage/README.minGW +236 -0
  23. data/vendor/FreeImage/README.osx +44 -0
  24. data/vendor/FreeImage/README.solaris +67 -0
  25. data/vendor/FreeImage/Source/CacheFile.h +92 -0
  26. data/vendor/FreeImage/Source/DeprecationManager/Deprecated.cpp +36 -0
  27. data/vendor/FreeImage/Source/DeprecationManager/DeprecationMgr.cpp +103 -0
  28. data/vendor/FreeImage/Source/DeprecationManager/DeprecationMgr.h +83 -0
  29. data/vendor/FreeImage/Source/FreeImage/BitmapAccess.cpp +1573 -0
  30. data/vendor/FreeImage/Source/FreeImage/CacheFile.cpp +271 -0
  31. data/vendor/FreeImage/Source/FreeImage/ColorLookup.cpp +785 -0
  32. data/vendor/FreeImage/Source/FreeImage/Conversion.cpp +551 -0
  33. data/vendor/FreeImage/Source/FreeImage/Conversion16_555.cpp +209 -0
  34. data/vendor/FreeImage/Source/FreeImage/Conversion16_565.cpp +204 -0
  35. data/vendor/FreeImage/Source/FreeImage/Conversion24.cpp +252 -0
  36. data/vendor/FreeImage/Source/FreeImage/Conversion32.cpp +345 -0
  37. data/vendor/FreeImage/Source/FreeImage/Conversion4.cpp +246 -0
  38. data/vendor/FreeImage/Source/FreeImage/Conversion8.cpp +305 -0
  39. data/vendor/FreeImage/Source/FreeImage/ConversionFloat.cpp +194 -0
  40. data/vendor/FreeImage/Source/FreeImage/ConversionRGB16.cpp +144 -0
  41. data/vendor/FreeImage/Source/FreeImage/ConversionRGBA16.cpp +147 -0
  42. data/vendor/FreeImage/Source/FreeImage/ConversionRGBAF.cpp +250 -0
  43. data/vendor/FreeImage/Source/FreeImage/ConversionRGBF.cpp +243 -0
  44. data/vendor/FreeImage/Source/FreeImage/ConversionType.cpp +699 -0
  45. data/vendor/FreeImage/Source/FreeImage/ConversionUINT16.cpp +134 -0
  46. data/vendor/FreeImage/Source/FreeImage/FreeImage.cpp +226 -0
  47. data/vendor/FreeImage/Source/FreeImage/FreeImageC.c +22 -0
  48. data/vendor/FreeImage/Source/FreeImage/FreeImageIO.cpp +175 -0
  49. data/vendor/FreeImage/Source/FreeImage/GetType.cpp +92 -0
  50. data/vendor/FreeImage/Source/FreeImage/Halftoning.cpp +474 -0
  51. data/vendor/FreeImage/Source/FreeImage/J2KHelper.cpp +591 -0
  52. data/vendor/FreeImage/Source/FreeImage/J2KHelper.h +36 -0
  53. data/vendor/FreeImage/Source/FreeImage/LFPQuantizer.cpp +208 -0
  54. data/vendor/FreeImage/Source/FreeImage/MNGHelper.cpp +1320 -0
  55. data/vendor/FreeImage/Source/FreeImage/MemoryIO.cpp +237 -0
  56. data/vendor/FreeImage/Source/FreeImage/MultiPage.cpp +974 -0
  57. data/vendor/FreeImage/Source/FreeImage/NNQuantizer.cpp +507 -0
  58. data/vendor/FreeImage/Source/FreeImage/PSDParser.cpp +1057 -0
  59. data/vendor/FreeImage/Source/FreeImage/PSDParser.h +271 -0
  60. data/vendor/FreeImage/Source/FreeImage/PixelAccess.cpp +197 -0
  61. data/vendor/FreeImage/Source/FreeImage/Plugin.cpp +822 -0
  62. data/vendor/FreeImage/Source/FreeImage/PluginBMP.cpp +1494 -0
  63. data/vendor/FreeImage/Source/FreeImage/PluginCUT.cpp +240 -0
  64. data/vendor/FreeImage/Source/FreeImage/PluginDDS.cpp +655 -0
  65. data/vendor/FreeImage/Source/FreeImage/PluginEXR.cpp +773 -0
  66. data/vendor/FreeImage/Source/FreeImage/PluginG3.cpp +433 -0
  67. data/vendor/FreeImage/Source/FreeImage/PluginGIF.cpp +1407 -0
  68. data/vendor/FreeImage/Source/FreeImage/PluginHDR.cpp +722 -0
  69. data/vendor/FreeImage/Source/FreeImage/PluginICO.cpp +824 -0
  70. data/vendor/FreeImage/Source/FreeImage/PluginIFF.cpp +459 -0
  71. data/vendor/FreeImage/Source/FreeImage/PluginJ2K.cpp +328 -0
  72. data/vendor/FreeImage/Source/FreeImage/PluginJNG.cpp +162 -0
  73. data/vendor/FreeImage/Source/FreeImage/PluginJP2.cpp +328 -0
  74. data/vendor/FreeImage/Source/FreeImage/PluginJPEG.cpp +1706 -0
  75. data/vendor/FreeImage/Source/FreeImage/PluginJXR.cpp +1475 -0
  76. data/vendor/FreeImage/Source/FreeImage/PluginKOALA.cpp +243 -0
  77. data/vendor/FreeImage/Source/FreeImage/PluginMNG.cpp +153 -0
  78. data/vendor/FreeImage/Source/FreeImage/PluginPCD.cpp +251 -0
  79. data/vendor/FreeImage/Source/FreeImage/PluginPCX.cpp +659 -0
  80. data/vendor/FreeImage/Source/FreeImage/PluginPFM.cpp +409 -0
  81. data/vendor/FreeImage/Source/FreeImage/PluginPICT.cpp +1343 -0
  82. data/vendor/FreeImage/Source/FreeImage/PluginPNG.cpp +1115 -0
  83. data/vendor/FreeImage/Source/FreeImage/PluginPNM.cpp +838 -0
  84. data/vendor/FreeImage/Source/FreeImage/PluginPSD.cpp +131 -0
  85. data/vendor/FreeImage/Source/FreeImage/PluginRAS.cpp +512 -0
  86. data/vendor/FreeImage/Source/FreeImage/PluginRAW.cpp +793 -0
  87. data/vendor/FreeImage/Source/FreeImage/PluginSGI.cpp +425 -0
  88. data/vendor/FreeImage/Source/FreeImage/PluginTARGA.cpp +1591 -0
  89. data/vendor/FreeImage/Source/FreeImage/PluginTIFF.cpp +2631 -0
  90. data/vendor/FreeImage/Source/FreeImage/PluginWBMP.cpp +372 -0
  91. data/vendor/FreeImage/Source/FreeImage/PluginWebP.cpp +698 -0
  92. data/vendor/FreeImage/Source/FreeImage/PluginXBM.cpp +399 -0
  93. data/vendor/FreeImage/Source/FreeImage/PluginXPM.cpp +487 -0
  94. data/vendor/FreeImage/Source/FreeImage/TIFFLogLuv.cpp +65 -0
  95. data/vendor/FreeImage/Source/FreeImage/ToneMapping.cpp +75 -0
  96. data/vendor/FreeImage/Source/FreeImage/WuQuantizer.cpp +559 -0
  97. data/vendor/FreeImage/Source/FreeImage/ZLibInterface.cpp +223 -0
  98. data/vendor/FreeImage/Source/FreeImage/tmoColorConvert.cpp +479 -0
  99. data/vendor/FreeImage/Source/FreeImage/tmoDrago03.cpp +295 -0
  100. data/vendor/FreeImage/Source/FreeImage/tmoFattal02.cpp +689 -0
  101. data/vendor/FreeImage/Source/FreeImage/tmoReinhard05.cpp +260 -0
  102. data/vendor/FreeImage/Source/FreeImage.h +1153 -0
  103. data/vendor/FreeImage/Source/FreeImageIO.h +63 -0
  104. data/vendor/FreeImage/Source/FreeImageToolkit/BSplineRotate.cpp +730 -0
  105. data/vendor/FreeImage/Source/FreeImageToolkit/Background.cpp +895 -0
  106. data/vendor/FreeImage/Source/FreeImageToolkit/Channels.cpp +488 -0
  107. data/vendor/FreeImage/Source/FreeImageToolkit/ClassicRotate.cpp +917 -0
  108. data/vendor/FreeImage/Source/FreeImageToolkit/Colors.cpp +967 -0
  109. data/vendor/FreeImage/Source/FreeImageToolkit/CopyPaste.cpp +861 -0
  110. data/vendor/FreeImage/Source/FreeImageToolkit/Display.cpp +230 -0
  111. data/vendor/FreeImage/Source/FreeImageToolkit/Filters.h +287 -0
  112. data/vendor/FreeImage/Source/FreeImageToolkit/Flip.cpp +166 -0
  113. data/vendor/FreeImage/Source/FreeImageToolkit/JPEGTransform.cpp +623 -0
  114. data/vendor/FreeImage/Source/FreeImageToolkit/MultigridPoissonSolver.cpp +505 -0
  115. data/vendor/FreeImage/Source/FreeImageToolkit/Rescale.cpp +192 -0
  116. data/vendor/FreeImage/Source/FreeImageToolkit/Resize.cpp +2116 -0
  117. data/vendor/FreeImage/Source/FreeImageToolkit/Resize.h +196 -0
  118. data/vendor/FreeImage/Source/LibJPEG/ansi2knr.c +739 -0
  119. data/vendor/FreeImage/Source/LibJPEG/cderror.h +134 -0
  120. data/vendor/FreeImage/Source/LibJPEG/cdjpeg.c +181 -0
  121. data/vendor/FreeImage/Source/LibJPEG/cdjpeg.h +187 -0
  122. data/vendor/FreeImage/Source/LibJPEG/cjpeg.c +664 -0
  123. data/vendor/FreeImage/Source/LibJPEG/ckconfig.c +402 -0
  124. data/vendor/FreeImage/Source/LibJPEG/djpeg.c +617 -0
  125. data/vendor/FreeImage/Source/LibJPEG/example.c +433 -0
  126. data/vendor/FreeImage/Source/LibJPEG/jaricom.c +153 -0
  127. data/vendor/FreeImage/Source/LibJPEG/jcapimin.c +288 -0
  128. data/vendor/FreeImage/Source/LibJPEG/jcapistd.c +162 -0
  129. data/vendor/FreeImage/Source/LibJPEG/jcarith.c +944 -0
  130. data/vendor/FreeImage/Source/LibJPEG/jccoefct.c +454 -0
  131. data/vendor/FreeImage/Source/LibJPEG/jccolor.c +604 -0
  132. data/vendor/FreeImage/Source/LibJPEG/jcdctmgr.c +477 -0
  133. data/vendor/FreeImage/Source/LibJPEG/jchuff.c +1573 -0
  134. data/vendor/FreeImage/Source/LibJPEG/jcinit.c +84 -0
  135. data/vendor/FreeImage/Source/LibJPEG/jcmainct.c +297 -0
  136. data/vendor/FreeImage/Source/LibJPEG/jcmarker.c +719 -0
  137. data/vendor/FreeImage/Source/LibJPEG/jcmaster.c +856 -0
  138. data/vendor/FreeImage/Source/LibJPEG/jcomapi.c +106 -0
  139. data/vendor/FreeImage/Source/LibJPEG/jconfig.h +161 -0
  140. data/vendor/FreeImage/Source/LibJPEG/jcparam.c +675 -0
  141. data/vendor/FreeImage/Source/LibJPEG/jcprepct.c +358 -0
  142. data/vendor/FreeImage/Source/LibJPEG/jcsample.c +545 -0
  143. data/vendor/FreeImage/Source/LibJPEG/jctrans.c +385 -0
  144. data/vendor/FreeImage/Source/LibJPEG/jdapimin.c +399 -0
  145. data/vendor/FreeImage/Source/LibJPEG/jdapistd.c +276 -0
  146. data/vendor/FreeImage/Source/LibJPEG/jdarith.c +796 -0
  147. data/vendor/FreeImage/Source/LibJPEG/jdatadst.c +270 -0
  148. data/vendor/FreeImage/Source/LibJPEG/jdatasrc.c +275 -0
  149. data/vendor/FreeImage/Source/LibJPEG/jdcoefct.c +741 -0
  150. data/vendor/FreeImage/Source/LibJPEG/jdcolor.c +748 -0
  151. data/vendor/FreeImage/Source/LibJPEG/jdct.h +393 -0
  152. data/vendor/FreeImage/Source/LibJPEG/jddctmgr.c +384 -0
  153. data/vendor/FreeImage/Source/LibJPEG/jdhuff.c +1554 -0
  154. data/vendor/FreeImage/Source/LibJPEG/jdinput.c +662 -0
  155. data/vendor/FreeImage/Source/LibJPEG/jdmainct.c +513 -0
  156. data/vendor/FreeImage/Source/LibJPEG/jdmarker.c +1511 -0
  157. data/vendor/FreeImage/Source/LibJPEG/jdmaster.c +543 -0
  158. data/vendor/FreeImage/Source/LibJPEG/jdmerge.c +401 -0
  159. data/vendor/FreeImage/Source/LibJPEG/jdpostct.c +290 -0
  160. data/vendor/FreeImage/Source/LibJPEG/jdsample.c +361 -0
  161. data/vendor/FreeImage/Source/LibJPEG/jdtrans.c +140 -0
  162. data/vendor/FreeImage/Source/LibJPEG/jerror.c +253 -0
  163. data/vendor/FreeImage/Source/LibJPEG/jerror.h +304 -0
  164. data/vendor/FreeImage/Source/LibJPEG/jfdctflt.c +174 -0
  165. data/vendor/FreeImage/Source/LibJPEG/jfdctfst.c +230 -0
  166. data/vendor/FreeImage/Source/LibJPEG/jfdctint.c +4406 -0
  167. data/vendor/FreeImage/Source/LibJPEG/jidctflt.c +235 -0
  168. data/vendor/FreeImage/Source/LibJPEG/jidctfst.c +368 -0
  169. data/vendor/FreeImage/Source/LibJPEG/jidctint.c +5179 -0
  170. data/vendor/FreeImage/Source/LibJPEG/jinclude.h +91 -0
  171. data/vendor/FreeImage/Source/LibJPEG/jmemansi.c +167 -0
  172. data/vendor/FreeImage/Source/LibJPEG/jmemdos.c +638 -0
  173. data/vendor/FreeImage/Source/LibJPEG/jmemmac.c +289 -0
  174. data/vendor/FreeImage/Source/LibJPEG/jmemmgr.c +1119 -0
  175. data/vendor/FreeImage/Source/LibJPEG/jmemname.c +276 -0
  176. data/vendor/FreeImage/Source/LibJPEG/jmemnobs.c +109 -0
  177. data/vendor/FreeImage/Source/LibJPEG/jmemsys.h +198 -0
  178. data/vendor/FreeImage/Source/LibJPEG/jmorecfg.h +442 -0
  179. data/vendor/FreeImage/Source/LibJPEG/jpegint.h +426 -0
  180. data/vendor/FreeImage/Source/LibJPEG/jpeglib.h +1180 -0
  181. data/vendor/FreeImage/Source/LibJPEG/jpegtran.c +577 -0
  182. data/vendor/FreeImage/Source/LibJPEG/jquant1.c +857 -0
  183. data/vendor/FreeImage/Source/LibJPEG/jquant2.c +1311 -0
  184. data/vendor/FreeImage/Source/LibJPEG/jutils.c +227 -0
  185. data/vendor/FreeImage/Source/LibJPEG/jversion.h +14 -0
  186. data/vendor/FreeImage/Source/LibJPEG/rdbmp.c +480 -0
  187. data/vendor/FreeImage/Source/LibJPEG/rdcolmap.c +253 -0
  188. data/vendor/FreeImage/Source/LibJPEG/rdgif.c +38 -0
  189. data/vendor/FreeImage/Source/LibJPEG/rdjpgcom.c +515 -0
  190. data/vendor/FreeImage/Source/LibJPEG/rdppm.c +459 -0
  191. data/vendor/FreeImage/Source/LibJPEG/rdrle.c +387 -0
  192. data/vendor/FreeImage/Source/LibJPEG/rdswitch.c +365 -0
  193. data/vendor/FreeImage/Source/LibJPEG/rdtarga.c +500 -0
  194. data/vendor/FreeImage/Source/LibJPEG/transupp.c +1763 -0
  195. data/vendor/FreeImage/Source/LibJPEG/transupp.h +219 -0
  196. data/vendor/FreeImage/Source/LibJPEG/wrbmp.c +442 -0
  197. data/vendor/FreeImage/Source/LibJPEG/wrgif.c +399 -0
  198. data/vendor/FreeImage/Source/LibJPEG/wrjpgcom.c +583 -0
  199. data/vendor/FreeImage/Source/LibJPEG/wrppm.c +269 -0
  200. data/vendor/FreeImage/Source/LibJPEG/wrrle.c +305 -0
  201. data/vendor/FreeImage/Source/LibJPEG/wrtarga.c +253 -0
  202. data/vendor/FreeImage/Source/LibJXR/common/include/guiddef.h +230 -0
  203. data/vendor/FreeImage/Source/LibJXR/common/include/wmsal.h +757 -0
  204. data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstring.h +342 -0
  205. data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstrings_adt.h +71 -0
  206. data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstrings_strict.h +1096 -0
  207. data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstrings_undef.h +406 -0
  208. data/vendor/FreeImage/Source/LibJXR/image/decode/JXRTranscode.c +987 -0
  209. data/vendor/FreeImage/Source/LibJXR/image/decode/decode.c +200 -0
  210. data/vendor/FreeImage/Source/LibJXR/image/decode/decode.h +143 -0
  211. data/vendor/FreeImage/Source/LibJXR/image/decode/postprocess.c +288 -0
  212. data/vendor/FreeImage/Source/LibJXR/image/decode/segdec.c +1205 -0
  213. data/vendor/FreeImage/Source/LibJXR/image/decode/strInvTransform.c +1888 -0
  214. data/vendor/FreeImage/Source/LibJXR/image/decode/strPredQuantDec.c +539 -0
  215. data/vendor/FreeImage/Source/LibJXR/image/decode/strdec.c +3628 -0
  216. data/vendor/FreeImage/Source/LibJXR/image/decode/strdec_x86.c +1640 -0
  217. data/vendor/FreeImage/Source/LibJXR/image/encode/encode.c +144 -0
  218. data/vendor/FreeImage/Source/LibJXR/image/encode/encode.h +113 -0
  219. data/vendor/FreeImage/Source/LibJXR/image/encode/segenc.c +1186 -0
  220. data/vendor/FreeImage/Source/LibJXR/image/encode/strFwdTransform.c +1111 -0
  221. data/vendor/FreeImage/Source/LibJXR/image/encode/strPredQuantEnc.c +511 -0
  222. data/vendor/FreeImage/Source/LibJXR/image/encode/strenc.c +2370 -0
  223. data/vendor/FreeImage/Source/LibJXR/image/encode/strenc_x86.c +409 -0
  224. data/vendor/FreeImage/Source/LibJXR/image/sys/adapthuff.c +511 -0
  225. data/vendor/FreeImage/Source/LibJXR/image/sys/ansi.h +61 -0
  226. data/vendor/FreeImage/Source/LibJXR/image/sys/common.h +131 -0
  227. data/vendor/FreeImage/Source/LibJXR/image/sys/image.c +183 -0
  228. data/vendor/FreeImage/Source/LibJXR/image/sys/perfTimer.h +115 -0
  229. data/vendor/FreeImage/Source/LibJXR/image/sys/perfTimerANSI.c +274 -0
  230. data/vendor/FreeImage/Source/LibJXR/image/sys/strPredQuant.c +306 -0
  231. data/vendor/FreeImage/Source/LibJXR/image/sys/strTransform.c +85 -0
  232. data/vendor/FreeImage/Source/LibJXR/image/sys/strTransform.h +50 -0
  233. data/vendor/FreeImage/Source/LibJXR/image/sys/strcodec.c +1251 -0
  234. data/vendor/FreeImage/Source/LibJXR/image/sys/strcodec.h +681 -0
  235. data/vendor/FreeImage/Source/LibJXR/image/sys/windowsmediaphoto.h +515 -0
  236. data/vendor/FreeImage/Source/LibJXR/image/sys/xplatform_image.h +84 -0
  237. data/vendor/FreeImage/Source/LibJXR/image/x86/x86.h +58 -0
  238. data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGlue.c +930 -0
  239. data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGlue.h +636 -0
  240. data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGlueJxr.c +2246 -0
  241. data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGluePFC.c +2338 -0
  242. data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRMeta.c +905 -0
  243. data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRMeta.h +258 -0
  244. data/vendor/FreeImage/Source/LibOpenJPEG/bio.c +188 -0
  245. data/vendor/FreeImage/Source/LibOpenJPEG/bio.h +128 -0
  246. data/vendor/FreeImage/Source/LibOpenJPEG/cidx_manager.c +239 -0
  247. data/vendor/FreeImage/Source/LibOpenJPEG/cidx_manager.h +68 -0
  248. data/vendor/FreeImage/Source/LibOpenJPEG/cio.c +644 -0
  249. data/vendor/FreeImage/Source/LibOpenJPEG/cio.h +393 -0
  250. data/vendor/FreeImage/Source/LibOpenJPEG/dwt.c +919 -0
  251. data/vendor/FreeImage/Source/LibOpenJPEG/dwt.h +116 -0
  252. data/vendor/FreeImage/Source/LibOpenJPEG/event.c +141 -0
  253. data/vendor/FreeImage/Source/LibOpenJPEG/event.h +97 -0
  254. data/vendor/FreeImage/Source/LibOpenJPEG/function_list.c +114 -0
  255. data/vendor/FreeImage/Source/LibOpenJPEG/function_list.h +126 -0
  256. data/vendor/FreeImage/Source/LibOpenJPEG/image.c +235 -0
  257. data/vendor/FreeImage/Source/LibOpenJPEG/image.h +63 -0
  258. data/vendor/FreeImage/Source/LibOpenJPEG/indexbox_manager.h +148 -0
  259. data/vendor/FreeImage/Source/LibOpenJPEG/invert.c +289 -0
  260. data/vendor/FreeImage/Source/LibOpenJPEG/invert.h +59 -0
  261. data/vendor/FreeImage/Source/LibOpenJPEG/j2k.c +10238 -0
  262. data/vendor/FreeImage/Source/LibOpenJPEG/j2k.h +838 -0
  263. data/vendor/FreeImage/Source/LibOpenJPEG/jp2.c +2776 -0
  264. data/vendor/FreeImage/Source/LibOpenJPEG/jp2.h +490 -0
  265. data/vendor/FreeImage/Source/LibOpenJPEG/mct.c +319 -0
  266. data/vendor/FreeImage/Source/LibOpenJPEG/mct.h +149 -0
  267. data/vendor/FreeImage/Source/LibOpenJPEG/mqc.c +604 -0
  268. data/vendor/FreeImage/Source/LibOpenJPEG/mqc.h +201 -0
  269. data/vendor/FreeImage/Source/LibOpenJPEG/openjpeg.c +955 -0
  270. data/vendor/FreeImage/Source/LibOpenJPEG/openjpeg.h +1475 -0
  271. data/vendor/FreeImage/Source/LibOpenJPEG/opj_clock.c +59 -0
  272. data/vendor/FreeImage/Source/LibOpenJPEG/opj_clock.h +54 -0
  273. data/vendor/FreeImage/Source/LibOpenJPEG/opj_codec.h +160 -0
  274. data/vendor/FreeImage/Source/LibOpenJPEG/opj_config.h +9 -0
  275. data/vendor/FreeImage/Source/LibOpenJPEG/opj_config_private.h +16 -0
  276. data/vendor/FreeImage/Source/LibOpenJPEG/opj_includes.h +175 -0
  277. data/vendor/FreeImage/Source/LibOpenJPEG/opj_intmath.h +172 -0
  278. data/vendor/FreeImage/Source/LibOpenJPEG/opj_inttypes.h +43 -0
  279. data/vendor/FreeImage/Source/LibOpenJPEG/opj_malloc.h +180 -0
  280. data/vendor/FreeImage/Source/LibOpenJPEG/opj_stdint.h +47 -0
  281. data/vendor/FreeImage/Source/LibOpenJPEG/phix_manager.c +191 -0
  282. data/vendor/FreeImage/Source/LibOpenJPEG/pi.c +1870 -0
  283. data/vendor/FreeImage/Source/LibOpenJPEG/pi.h +182 -0
  284. data/vendor/FreeImage/Source/LibOpenJPEG/ppix_manager.c +194 -0
  285. data/vendor/FreeImage/Source/LibOpenJPEG/raw.c +89 -0
  286. data/vendor/FreeImage/Source/LibOpenJPEG/raw.h +100 -0
  287. data/vendor/FreeImage/Source/LibOpenJPEG/t1.c +1751 -0
  288. data/vendor/FreeImage/Source/LibOpenJPEG/t1.h +157 -0
  289. data/vendor/FreeImage/Source/LibOpenJPEG/t1_generate_luts.c +276 -0
  290. data/vendor/FreeImage/Source/LibOpenJPEG/t1_luts.h +143 -0
  291. data/vendor/FreeImage/Source/LibOpenJPEG/t2.c +1334 -0
  292. data/vendor/FreeImage/Source/LibOpenJPEG/t2.h +127 -0
  293. data/vendor/FreeImage/Source/LibOpenJPEG/tcd.c +2123 -0
  294. data/vendor/FreeImage/Source/LibOpenJPEG/tcd.h +348 -0
  295. data/vendor/FreeImage/Source/LibOpenJPEG/tgt.c +331 -0
  296. data/vendor/FreeImage/Source/LibOpenJPEG/tgt.h +140 -0
  297. data/vendor/FreeImage/Source/LibOpenJPEG/thix_manager.c +134 -0
  298. data/vendor/FreeImage/Source/LibOpenJPEG/tpix_manager.c +185 -0
  299. data/vendor/FreeImage/Source/LibPNG/example.c +1061 -0
  300. data/vendor/FreeImage/Source/LibPNG/png.c +4493 -0
  301. data/vendor/FreeImage/Source/LibPNG/png.h +3282 -0
  302. data/vendor/FreeImage/Source/LibPNG/pngconf.h +644 -0
  303. data/vendor/FreeImage/Source/LibPNG/pngdebug.h +154 -0
  304. data/vendor/FreeImage/Source/LibPNG/pngerror.c +963 -0
  305. data/vendor/FreeImage/Source/LibPNG/pngget.c +1213 -0
  306. data/vendor/FreeImage/Source/LibPNG/pnginfo.h +260 -0
  307. data/vendor/FreeImage/Source/LibPNG/pnglibconf.h +218 -0
  308. data/vendor/FreeImage/Source/LibPNG/pngmem.c +281 -0
  309. data/vendor/FreeImage/Source/LibPNG/pngpread.c +1168 -0
  310. data/vendor/FreeImage/Source/LibPNG/pngpriv.h +1944 -0
  311. data/vendor/FreeImage/Source/LibPNG/pngread.c +4121 -0
  312. data/vendor/FreeImage/Source/LibPNG/pngrio.c +120 -0
  313. data/vendor/FreeImage/Source/LibPNG/pngrtran.c +4994 -0
  314. data/vendor/FreeImage/Source/LibPNG/pngrutil.c +4474 -0
  315. data/vendor/FreeImage/Source/LibPNG/pngset.c +1611 -0
  316. data/vendor/FreeImage/Source/LibPNG/pngstruct.h +489 -0
  317. data/vendor/FreeImage/Source/LibPNG/pngtest.c +2011 -0
  318. data/vendor/FreeImage/Source/LibPNG/pngtrans.c +849 -0
  319. data/vendor/FreeImage/Source/LibPNG/pngwio.c +168 -0
  320. data/vendor/FreeImage/Source/LibPNG/pngwrite.c +2455 -0
  321. data/vendor/FreeImage/Source/LibPNG/pngwtran.c +574 -0
  322. data/vendor/FreeImage/Source/LibPNG/pngwutil.c +3029 -0
  323. data/vendor/FreeImage/Source/LibRawLite/dcraw/dcraw.c +15462 -0
  324. data/vendor/FreeImage/Source/LibRawLite/internal/aahd_demosaic.cpp +706 -0
  325. data/vendor/FreeImage/Source/LibRawLite/internal/dcb_demosaicing.c +710 -0
  326. data/vendor/FreeImage/Source/LibRawLite/internal/dcraw_common.cpp +13593 -0
  327. data/vendor/FreeImage/Source/LibRawLite/internal/dcraw_fileio.cpp +240 -0
  328. data/vendor/FreeImage/Source/LibRawLite/internal/defines.h +167 -0
  329. data/vendor/FreeImage/Source/LibRawLite/internal/demosaic_packs.cpp +99 -0
  330. data/vendor/FreeImage/Source/LibRawLite/internal/dht_demosaic.cpp +873 -0
  331. data/vendor/FreeImage/Source/LibRawLite/internal/libraw_internal_funcs.h +282 -0
  332. data/vendor/FreeImage/Source/LibRawLite/internal/libraw_x3f.cpp +1919 -0
  333. data/vendor/FreeImage/Source/LibRawLite/internal/var_defines.h +216 -0
  334. data/vendor/FreeImage/Source/LibRawLite/internal/wf_filtering.cpp +1950 -0
  335. data/vendor/FreeImage/Source/LibRawLite/libraw/libraw.h +338 -0
  336. data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_alloc.h +99 -0
  337. data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_const.h +233 -0
  338. data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_datastream.h +238 -0
  339. data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_internal.h +225 -0
  340. data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_types.h +442 -0
  341. data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_version.h +62 -0
  342. data/vendor/FreeImage/Source/LibRawLite/src/libraw_c_api.cpp +230 -0
  343. data/vendor/FreeImage/Source/LibRawLite/src/libraw_cxx.cpp +4533 -0
  344. data/vendor/FreeImage/Source/LibRawLite/src/libraw_datastream.cpp +703 -0
  345. data/vendor/FreeImage/Source/LibTIFF4/mkg3states.c +451 -0
  346. data/vendor/FreeImage/Source/LibTIFF4/mkspans.c +82 -0
  347. data/vendor/FreeImage/Source/LibTIFF4/t4.h +292 -0
  348. data/vendor/FreeImage/Source/LibTIFF4/tif_aux.c +358 -0
  349. data/vendor/FreeImage/Source/LibTIFF4/tif_close.c +140 -0
  350. data/vendor/FreeImage/Source/LibTIFF4/tif_codec.c +166 -0
  351. data/vendor/FreeImage/Source/LibTIFF4/tif_color.c +287 -0
  352. data/vendor/FreeImage/Source/LibTIFF4/tif_compress.c +304 -0
  353. data/vendor/FreeImage/Source/LibTIFF4/tif_config.h +97 -0
  354. data/vendor/FreeImage/Source/LibTIFF4/tif_config.vc.h +74 -0
  355. data/vendor/FreeImage/Source/LibTIFF4/tif_config.wince.h +71 -0
  356. data/vendor/FreeImage/Source/LibTIFF4/tif_dir.c +1700 -0
  357. data/vendor/FreeImage/Source/LibTIFF4/tif_dir.h +308 -0
  358. data/vendor/FreeImage/Source/LibTIFF4/tif_dirinfo.c +959 -0
  359. data/vendor/FreeImage/Source/LibTIFF4/tif_dirread.c +5640 -0
  360. data/vendor/FreeImage/Source/LibTIFF4/tif_dirwrite.c +2910 -0
  361. data/vendor/FreeImage/Source/LibTIFF4/tif_dumpmode.c +143 -0
  362. data/vendor/FreeImage/Source/LibTIFF4/tif_error.c +80 -0
  363. data/vendor/FreeImage/Source/LibTIFF4/tif_extension.c +118 -0
  364. data/vendor/FreeImage/Source/LibTIFF4/tif_fax3.c +1595 -0
  365. data/vendor/FreeImage/Source/LibTIFF4/tif_fax3.h +538 -0
  366. data/vendor/FreeImage/Source/LibTIFF4/tif_fax3sm.c +1260 -0
  367. data/vendor/FreeImage/Source/LibTIFF4/tif_flush.c +118 -0
  368. data/vendor/FreeImage/Source/LibTIFF4/tif_getimage.c +2890 -0
  369. data/vendor/FreeImage/Source/LibTIFF4/tif_jbig.c +213 -0
  370. data/vendor/FreeImage/Source/LibTIFF4/tif_jpeg.c +2354 -0
  371. data/vendor/FreeImage/Source/LibTIFF4/tif_jpeg_12.c +65 -0
  372. data/vendor/FreeImage/Source/LibTIFF4/tif_luv.c +1683 -0
  373. data/vendor/FreeImage/Source/LibTIFF4/tif_lzma.c +495 -0
  374. data/vendor/FreeImage/Source/LibTIFF4/tif_lzw.c +1169 -0
  375. data/vendor/FreeImage/Source/LibTIFF4/tif_next.c +181 -0
  376. data/vendor/FreeImage/Source/LibTIFF4/tif_ojpeg.c +2501 -0
  377. data/vendor/FreeImage/Source/LibTIFF4/tif_open.c +725 -0
  378. data/vendor/FreeImage/Source/LibTIFF4/tif_packbits.c +300 -0
  379. data/vendor/FreeImage/Source/LibTIFF4/tif_pixarlog.c +1442 -0
  380. data/vendor/FreeImage/Source/LibTIFF4/tif_predict.c +764 -0
  381. data/vendor/FreeImage/Source/LibTIFF4/tif_predict.h +77 -0
  382. data/vendor/FreeImage/Source/LibTIFF4/tif_print.c +716 -0
  383. data/vendor/FreeImage/Source/LibTIFF4/tif_read.c +1086 -0
  384. data/vendor/FreeImage/Source/LibTIFF4/tif_strip.c +383 -0
  385. data/vendor/FreeImage/Source/LibTIFF4/tif_swab.c +310 -0
  386. data/vendor/FreeImage/Source/LibTIFF4/tif_thunder.c +207 -0
  387. data/vendor/FreeImage/Source/LibTIFF4/tif_tile.c +299 -0
  388. data/vendor/FreeImage/Source/LibTIFF4/tif_unix.c +325 -0
  389. data/vendor/FreeImage/Source/LibTIFF4/tif_version.c +40 -0
  390. data/vendor/FreeImage/Source/LibTIFF4/tif_vms.c +603 -0
  391. data/vendor/FreeImage/Source/LibTIFF4/tif_warning.c +81 -0
  392. data/vendor/FreeImage/Source/LibTIFF4/tif_win32.c +443 -0
  393. data/vendor/FreeImage/Source/LibTIFF4/tif_wince.c +293 -0
  394. data/vendor/FreeImage/Source/LibTIFF4/tif_write.c +771 -0
  395. data/vendor/FreeImage/Source/LibTIFF4/tif_zip.c +472 -0
  396. data/vendor/FreeImage/Source/LibTIFF4/tiff.h +681 -0
  397. data/vendor/FreeImage/Source/LibTIFF4/tiffconf.h +170 -0
  398. data/vendor/FreeImage/Source/LibTIFF4/tiffconf.vc.h +160 -0
  399. data/vendor/FreeImage/Source/LibTIFF4/tiffconf.wince.h +121 -0
  400. data/vendor/FreeImage/Source/LibTIFF4/tiffio.h +557 -0
  401. data/vendor/FreeImage/Source/LibTIFF4/tiffiop.h +367 -0
  402. data/vendor/FreeImage/Source/LibTIFF4/tiffvers.h +9 -0
  403. data/vendor/FreeImage/Source/LibTIFF4/uvcode.h +180 -0
  404. data/vendor/FreeImage/Source/LibWebP/src/dec/alphai.h +55 -0
  405. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.alpha.c +167 -0
  406. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.buffer.c +249 -0
  407. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.frame.c +827 -0
  408. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.idec.c +857 -0
  409. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.io.c +640 -0
  410. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.quant.c +110 -0
  411. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.tree.c +525 -0
  412. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.vp8.c +663 -0
  413. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.vp8l.c +1584 -0
  414. data/vendor/FreeImage/Source/LibWebP/src/dec/dec.webp.c +834 -0
  415. data/vendor/FreeImage/Source/LibWebP/src/dec/decode_vp8.h +185 -0
  416. data/vendor/FreeImage/Source/LibWebP/src/dec/vp8i.h +353 -0
  417. data/vendor/FreeImage/Source/LibWebP/src/dec/vp8li.h +136 -0
  418. data/vendor/FreeImage/Source/LibWebP/src/dec/webpi.h +120 -0
  419. data/vendor/FreeImage/Source/LibWebP/src/demux/demux.demux.c +957 -0
  420. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.alpha_processing.c +377 -0
  421. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.alpha_processing_mips_dsp_r2.c +139 -0
  422. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.alpha_processing_sse2.c +296 -0
  423. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.argb.c +68 -0
  424. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.argb_mips_dsp_r2.c +108 -0
  425. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.argb_sse2.c +62 -0
  426. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost.c +412 -0
  427. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost_mips32.c +154 -0
  428. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost_mips_dsp_r2.c +107 -0
  429. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost_sse2.c +121 -0
  430. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cpu.c +138 -0
  431. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec.c +760 -0
  432. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_clip_tables.c +366 -0
  433. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_mips32.c +585 -0
  434. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_mips_dsp_r2.c +992 -0
  435. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_neon.c +1489 -0
  436. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_sse2.c +1284 -0
  437. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc.c +788 -0
  438. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_avx2.c +24 -0
  439. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_mips32.c +670 -0
  440. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_mips_dsp_r2.c +1510 -0
  441. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_neon.c +932 -0
  442. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_sse2.c +940 -0
  443. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.filters.c +240 -0
  444. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.filters_mips_dsp_r2.c +404 -0
  445. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.filters_sse2.c +349 -0
  446. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.h +434 -0
  447. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless.c +1838 -0
  448. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_mips32.c +416 -0
  449. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_mips_dsp_r2.c +921 -0
  450. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_neon.c +357 -0
  451. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_sse2.c +535 -0
  452. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.rescaler.c +115 -0
  453. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.rescaler_mips32.c +192 -0
  454. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.rescaler_mips_dsp_r2.c +210 -0
  455. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling.c +252 -0
  456. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling_mips_dsp_r2.c +280 -0
  457. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling_neon.c +267 -0
  458. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling_sse2.c +214 -0
  459. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv.c +166 -0
  460. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv_mips32.c +100 -0
  461. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv_mips_dsp_r2.c +131 -0
  462. data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv_sse2.c +322 -0
  463. data/vendor/FreeImage/Source/LibWebP/src/dsp/lossless.h +313 -0
  464. data/vendor/FreeImage/Source/LibWebP/src/dsp/mips_macro.h +200 -0
  465. data/vendor/FreeImage/Source/LibWebP/src/dsp/neon.h +82 -0
  466. data/vendor/FreeImage/Source/LibWebP/src/dsp/yuv.h +321 -0
  467. data/vendor/FreeImage/Source/LibWebP/src/dsp/yuv_tables_sse2.h +536 -0
  468. data/vendor/FreeImage/Source/LibWebP/src/enc/backward_references.h +202 -0
  469. data/vendor/FreeImage/Source/LibWebP/src/enc/cost.h +69 -0
  470. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.alpha.c +440 -0
  471. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.analysis.c +501 -0
  472. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.backward_references.c +1076 -0
  473. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.config.c +163 -0
  474. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.cost.c +355 -0
  475. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.filter.c +296 -0
  476. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.frame.c +850 -0
  477. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.histogram.c +897 -0
  478. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.iterator.c +456 -0
  479. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.near_lossless.c +160 -0
  480. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture.c +290 -0
  481. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_csp.c +1100 -0
  482. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_psnr.c +150 -0
  483. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_rescale.c +285 -0
  484. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_tools.c +206 -0
  485. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.quant.c +1191 -0
  486. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.syntax.c +383 -0
  487. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.token.c +285 -0
  488. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.tree.c +504 -0
  489. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.vp8l.c +1437 -0
  490. data/vendor/FreeImage/Source/LibWebP/src/enc/enc.webpenc.c +379 -0
  491. data/vendor/FreeImage/Source/LibWebP/src/enc/histogram.h +114 -0
  492. data/vendor/FreeImage/Source/LibWebP/src/enc/vp8enci.h +551 -0
  493. data/vendor/FreeImage/Source/LibWebP/src/enc/vp8li.h +78 -0
  494. data/vendor/FreeImage/Source/LibWebP/src/mux/mux.anim_encode.c +1241 -0
  495. data/vendor/FreeImage/Source/LibWebP/src/mux/mux.muxedit.c +696 -0
  496. data/vendor/FreeImage/Source/LibWebP/src/mux/mux.muxinternal.c +551 -0
  497. data/vendor/FreeImage/Source/LibWebP/src/mux/mux.muxread.c +544 -0
  498. data/vendor/FreeImage/Source/LibWebP/src/mux/muxi.h +232 -0
  499. data/vendor/FreeImage/Source/LibWebP/src/utils/bit_reader.h +168 -0
  500. data/vendor/FreeImage/Source/LibWebP/src/utils/bit_reader_inl.h +172 -0
  501. data/vendor/FreeImage/Source/LibWebP/src/utils/bit_writer.h +120 -0
  502. data/vendor/FreeImage/Source/LibWebP/src/utils/color_cache.h +74 -0
  503. data/vendor/FreeImage/Source/LibWebP/src/utils/endian_inl.h +100 -0
  504. data/vendor/FreeImage/Source/LibWebP/src/utils/filters.h +32 -0
  505. data/vendor/FreeImage/Source/LibWebP/src/utils/huffman.h +67 -0
  506. data/vendor/FreeImage/Source/LibWebP/src/utils/huffman_encode.h +60 -0
  507. data/vendor/FreeImage/Source/LibWebP/src/utils/quant_levels.h +36 -0
  508. data/vendor/FreeImage/Source/LibWebP/src/utils/quant_levels_dec.h +35 -0
  509. data/vendor/FreeImage/Source/LibWebP/src/utils/random.h +63 -0
  510. data/vendor/FreeImage/Source/LibWebP/src/utils/rescaler.h +78 -0
  511. data/vendor/FreeImage/Source/LibWebP/src/utils/thread.h +93 -0
  512. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.bit_reader.c +208 -0
  513. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.bit_writer.c +308 -0
  514. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.color_cache.c +49 -0
  515. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.filters.c +76 -0
  516. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.h +121 -0
  517. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.huffman.c +205 -0
  518. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.huffman_encode.c +417 -0
  519. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.quant_levels.c +140 -0
  520. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.quant_levels_dec.c +279 -0
  521. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.random.c +43 -0
  522. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.rescaler.c +82 -0
  523. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.thread.c +309 -0
  524. data/vendor/FreeImage/Source/LibWebP/src/utils/utils.utils.c +211 -0
  525. data/vendor/FreeImage/Source/LibWebP/src/webp/decode.h +493 -0
  526. data/vendor/FreeImage/Source/LibWebP/src/webp/demux.h +224 -0
  527. data/vendor/FreeImage/Source/LibWebP/src/webp/encode.h +515 -0
  528. data/vendor/FreeImage/Source/LibWebP/src/webp/format_constants.h +88 -0
  529. data/vendor/FreeImage/Source/LibWebP/src/webp/mux.h +507 -0
  530. data/vendor/FreeImage/Source/LibWebP/src/webp/mux_types.h +97 -0
  531. data/vendor/FreeImage/Source/LibWebP/src/webp/types.h +52 -0
  532. data/vendor/FreeImage/Source/MapIntrospector.h +212 -0
  533. data/vendor/FreeImage/Source/Metadata/Exif.cpp +1253 -0
  534. data/vendor/FreeImage/Source/Metadata/FIRational.cpp +176 -0
  535. data/vendor/FreeImage/Source/Metadata/FIRational.h +108 -0
  536. data/vendor/FreeImage/Source/Metadata/FreeImageTag.cpp +353 -0
  537. data/vendor/FreeImage/Source/Metadata/FreeImageTag.h +500 -0
  538. data/vendor/FreeImage/Source/Metadata/IPTC.cpp +342 -0
  539. data/vendor/FreeImage/Source/Metadata/TagConversion.cpp +1094 -0
  540. data/vendor/FreeImage/Source/Metadata/TagLib.cpp +1618 -0
  541. data/vendor/FreeImage/Source/Metadata/XTIFF.cpp +766 -0
  542. data/vendor/FreeImage/Source/OpenEXR/Half/eLut.cpp +114 -0
  543. data/vendor/FreeImage/Source/OpenEXR/Half/eLut.h +71 -0
  544. data/vendor/FreeImage/Source/OpenEXR/Half/half.cpp +310 -0
  545. data/vendor/FreeImage/Source/OpenEXR/Half/half.h +757 -0
  546. data/vendor/FreeImage/Source/OpenEXR/Half/halfExport.h +27 -0
  547. data/vendor/FreeImage/Source/OpenEXR/Half/halfFunction.h +179 -0
  548. data/vendor/FreeImage/Source/OpenEXR/Half/halfLimits.h +102 -0
  549. data/vendor/FreeImage/Source/OpenEXR/Half/toFloat.cpp +164 -0
  550. data/vendor/FreeImage/Source/OpenEXR/Half/toFloat.h +16391 -0
  551. data/vendor/FreeImage/Source/OpenEXR/Iex/Iex.h +60 -0
  552. data/vendor/FreeImage/Source/OpenEXR/Iex/IexBaseExc.cpp +156 -0
  553. data/vendor/FreeImage/Source/OpenEXR/Iex/IexBaseExc.h +264 -0
  554. data/vendor/FreeImage/Source/OpenEXR/Iex/IexErrnoExc.h +208 -0
  555. data/vendor/FreeImage/Source/OpenEXR/Iex/IexExport.h +51 -0
  556. data/vendor/FreeImage/Source/OpenEXR/Iex/IexForward.h +229 -0
  557. data/vendor/FreeImage/Source/OpenEXR/Iex/IexMacros.h +170 -0
  558. data/vendor/FreeImage/Source/OpenEXR/Iex/IexMathExc.h +57 -0
  559. data/vendor/FreeImage/Source/OpenEXR/Iex/IexNamespace.h +112 -0
  560. data/vendor/FreeImage/Source/OpenEXR/Iex/IexThrowErrnoExc.cpp +873 -0
  561. data/vendor/FreeImage/Source/OpenEXR/Iex/IexThrowErrnoExc.h +97 -0
  562. data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFloatExc.cpp +113 -0
  563. data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFloatExc.h +146 -0
  564. data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFpu.cpp +530 -0
  565. data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFpu.h +91 -0
  566. data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathIeeeExc.h +62 -0
  567. data/vendor/FreeImage/Source/OpenEXR/IlmBaseConfig.h +61 -0
  568. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAcesFile.cpp +633 -0
  569. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAcesFile.h +324 -0
  570. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfArray.h +285 -0
  571. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAttribute.cpp +158 -0
  572. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAttribute.h +407 -0
  573. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAutoArray.h +95 -0
  574. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfB44Compressor.cpp +1072 -0
  575. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfB44Compressor.h +118 -0
  576. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfBoxAttribute.cpp +111 -0
  577. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfBoxAttribute.h +87 -0
  578. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCRgbaFile.cpp +1438 -0
  579. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCRgbaFile.h +555 -0
  580. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelList.cpp +322 -0
  581. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelList.h +436 -0
  582. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelListAttribute.cpp +150 -0
  583. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelListAttribute.h +74 -0
  584. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCheckedArithmetic.h +163 -0
  585. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticities.cpp +151 -0
  586. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticities.h +131 -0
  587. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticitiesAttribute.cpp +87 -0
  588. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticitiesAttribute.h +73 -0
  589. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompositeDeepScanLine.cpp +591 -0
  590. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompositeDeepScanLine.h +142 -0
  591. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompression.h +84 -0
  592. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressionAttribute.cpp +78 -0
  593. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressionAttribute.h +64 -0
  594. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressor.cpp +226 -0
  595. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressor.h +265 -0
  596. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfConvert.cpp +143 -0
  597. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfConvert.h +107 -0
  598. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepCompositing.cpp +110 -0
  599. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepCompositing.h +132 -0
  600. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepFrameBuffer.cpp +230 -0
  601. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepFrameBuffer.h +339 -0
  602. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepImageState.h +96 -0
  603. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepImageStateAttribute.cpp +78 -0
  604. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepImageStateAttribute.h +68 -0
  605. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputFile.cpp +2025 -0
  606. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputFile.h +276 -0
  607. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputPart.cpp +149 -0
  608. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputPart.h +181 -0
  609. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputFile.cpp +1552 -0
  610. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputFile.h +244 -0
  611. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputPart.cpp +107 -0
  612. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputPart.h +168 -0
  613. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputFile.cpp +1979 -0
  614. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputFile.h +437 -0
  615. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputPart.cpp +273 -0
  616. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputPart.h +362 -0
  617. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputFile.cpp +2055 -0
  618. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputFile.h +475 -0
  619. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputPart.cpp +250 -0
  620. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputPart.h +394 -0
  621. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDoubleAttribute.cpp +57 -0
  622. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDoubleAttribute.h +59 -0
  623. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDwaCompressor.cpp +3424 -0
  624. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDwaCompressor.h +210 -0
  625. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDwaCompressorSimd.h +2145 -0
  626. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmap.cpp +335 -0
  627. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmap.h +336 -0
  628. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmapAttribute.cpp +76 -0
  629. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmapAttribute.h +68 -0
  630. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfExport.h +46 -0
  631. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFastHuf.cpp +768 -0
  632. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFastHuf.h +148 -0
  633. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatAttribute.cpp +57 -0
  634. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatAttribute.h +58 -0
  635. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatVectorAttribute.cpp +84 -0
  636. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatVectorAttribute.h +76 -0
  637. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfForward.h +127 -0
  638. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFrameBuffer.cpp +228 -0
  639. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFrameBuffer.h +386 -0
  640. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFramesPerSecond.cpp +76 -0
  641. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFramesPerSecond.h +94 -0
  642. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericInputFile.cpp +76 -0
  643. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericInputFile.h +58 -0
  644. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericOutputFile.cpp +112 -0
  645. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericOutputFile.h +62 -0
  646. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHeader.cpp +1283 -0
  647. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHeader.h +699 -0
  648. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHuf.cpp +1114 -0
  649. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHuf.h +82 -0
  650. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIO.cpp +110 -0
  651. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIO.h +255 -0
  652. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputFile.cpp +895 -0
  653. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputFile.h +240 -0
  654. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPart.cpp +114 -0
  655. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPart.h +84 -0
  656. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPartData.cpp +51 -0
  657. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPartData.h +69 -0
  658. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputStreamMutex.h +68 -0
  659. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInt64.h +56 -0
  660. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIntAttribute.cpp +57 -0
  661. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIntAttribute.h +58 -0
  662. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCode.cpp +217 -0
  663. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCode.h +167 -0
  664. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCodeAttribute.cpp +99 -0
  665. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCodeAttribute.h +73 -0
  666. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLineOrder.h +69 -0
  667. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLineOrderAttribute.cpp +78 -0
  668. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLineOrderAttribute.h +72 -0
  669. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLut.cpp +178 -0
  670. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLut.h +188 -0
  671. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMatrixAttribute.cpp +263 -0
  672. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMatrixAttribute.h +83 -0
  673. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMisc.cpp +1872 -0
  674. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMisc.h +466 -0
  675. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartInputFile.cpp +783 -0
  676. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartInputFile.h +128 -0
  677. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartOutputFile.cpp +519 -0
  678. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartOutputFile.h +118 -0
  679. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiView.cpp +435 -0
  680. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiView.h +187 -0
  681. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfName.h +150 -0
  682. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfNamespace.h +115 -0
  683. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOpaqueAttribute.cpp +126 -0
  684. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOpaqueAttribute.h +110 -0
  685. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOptimizedPixelReading.h +646 -0
  686. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputFile.cpp +1378 -0
  687. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputFile.h +263 -0
  688. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPart.cpp +105 -0
  689. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPart.h +77 -0
  690. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPartData.cpp +52 -0
  691. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPartData.h +62 -0
  692. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputStreamMutex.h +70 -0
  693. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPartHelper.h +262 -0
  694. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPartType.cpp +63 -0
  695. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPartType.h +62 -0
  696. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPixelType.h +67 -0
  697. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPizCompressor.cpp +667 -0
  698. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPizCompressor.h +117 -0
  699. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImage.cpp +104 -0
  700. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImage.h +135 -0
  701. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImageAttribute.cpp +103 -0
  702. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImageAttribute.h +70 -0
  703. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPxr24Compressor.cpp +553 -0
  704. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPxr24Compressor.h +109 -0
  705. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRational.cpp +127 -0
  706. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRational.h +98 -0
  707. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRationalAttribute.cpp +74 -0
  708. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRationalAttribute.h +69 -0
  709. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgba.h +109 -0
  710. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaFile.cpp +1405 -0
  711. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaFile.h +346 -0
  712. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaYca.cpp +497 -0
  713. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaYca.h +259 -0
  714. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRle.cpp +157 -0
  715. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRle.h +63 -0
  716. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRleCompressor.cpp +220 -0
  717. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRleCompressor.h +80 -0
  718. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfScanLineInputFile.cpp +1702 -0
  719. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfScanLineInputFile.h +210 -0
  720. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfSimd.h +59 -0
  721. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStandardAttributes.cpp +125 -0
  722. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStandardAttributes.h +382 -0
  723. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStdIO.cpp +242 -0
  724. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStdIO.h +160 -0
  725. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringAttribute.cpp +80 -0
  726. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringAttribute.h +71 -0
  727. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringVectorAttribute.cpp +100 -0
  728. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringVectorAttribute.h +74 -0
  729. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfSystemSpecific.cpp +129 -0
  730. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfSystemSpecific.h +172 -0
  731. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTestFile.cpp +216 -0
  732. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTestFile.h +97 -0
  733. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfThreading.cpp +62 -0
  734. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfThreading.h +95 -0
  735. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileDescription.h +107 -0
  736. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileDescriptionAttribute.cpp +86 -0
  737. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileDescriptionAttribute.h +72 -0
  738. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileOffsets.cpp +552 -0
  739. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileOffsets.h +125 -0
  740. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputFile.cpp +1533 -0
  741. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputFile.h +401 -0
  742. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputPart.cpp +208 -0
  743. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputPart.h +100 -0
  744. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledMisc.cpp +389 -0
  745. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledMisc.h +106 -0
  746. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputFile.cpp +1841 -0
  747. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputFile.h +495 -0
  748. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputPart.cpp +228 -0
  749. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputPart.h +105 -0
  750. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledRgbaFile.cpp +1163 -0
  751. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledRgbaFile.h +482 -0
  752. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCode.cpp +431 -0
  753. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCode.h +242 -0
  754. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCodeAttribute.cpp +79 -0
  755. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCodeAttribute.h +74 -0
  756. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVecAttribute.cpp +217 -0
  757. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVecAttribute.h +100 -0
  758. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVersion.cpp +60 -0
  759. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVersion.h +136 -0
  760. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfWav.cpp +391 -0
  761. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfWav.h +78 -0
  762. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfXdr.h +927 -0
  763. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZip.cpp +196 -0
  764. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZip.h +78 -0
  765. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZipCompressor.cpp +127 -0
  766. data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZipCompressor.h +89 -0
  767. data/vendor/FreeImage/Source/OpenEXR/IlmImf/b44ExpLogTable.cpp +136 -0
  768. data/vendor/FreeImage/Source/OpenEXR/IlmImf/b44ExpLogTable.h +16396 -0
  769. data/vendor/FreeImage/Source/OpenEXR/IlmImf/dwaLookups.cpp +573 -0
  770. data/vendor/FreeImage/Source/OpenEXR/IlmImf/dwaLookups.h +98334 -0
  771. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThread.cpp +80 -0
  772. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThread.h +143 -0
  773. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadExport.h +46 -0
  774. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadForward.h +52 -0
  775. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutex.cpp +59 -0
  776. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutex.h +160 -0
  777. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutexPosix.cpp +85 -0
  778. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutexWin32.cpp +79 -0
  779. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadNamespace.h +114 -0
  780. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadPool.cpp +483 -0
  781. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadPool.h +160 -0
  782. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadPosix.cpp +98 -0
  783. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphore.cpp +60 -0
  784. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphore.h +112 -0
  785. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphorePosix.cpp +106 -0
  786. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphorePosixCompat.cpp +155 -0
  787. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphoreWin32.cpp +153 -0
  788. data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadWin32.cpp +100 -0
  789. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathBox.cpp +37 -0
  790. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathBox.h +849 -0
  791. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathBoxAlgo.h +1016 -0
  792. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathColor.h +736 -0
  793. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathColorAlgo.cpp +178 -0
  794. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathColorAlgo.h +257 -0
  795. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathEuler.h +926 -0
  796. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathExc.h +73 -0
  797. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathExport.h +46 -0
  798. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathForward.h +72 -0
  799. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFrame.h +192 -0
  800. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFrustum.h +741 -0
  801. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFrustumTest.h +417 -0
  802. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFun.cpp +181 -0
  803. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFun.h +269 -0
  804. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathGL.h +166 -0
  805. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathGLU.h +54 -0
  806. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathHalfLimits.h +68 -0
  807. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathInt64.h +62 -0
  808. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathInterval.h +226 -0
  809. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathLimits.h +268 -0
  810. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathLine.h +185 -0
  811. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathLineAlgo.h +288 -0
  812. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMath.h +208 -0
  813. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMatrix.h +3441 -0
  814. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMatrixAlgo.cpp +1252 -0
  815. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMatrixAlgo.h +1425 -0
  816. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathNamespace.h +115 -0
  817. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathPlane.h +257 -0
  818. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathPlatform.h +112 -0
  819. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathQuat.h +964 -0
  820. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathRandom.cpp +194 -0
  821. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathRandom.h +401 -0
  822. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathRoots.h +219 -0
  823. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathShear.cpp +54 -0
  824. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathShear.h +656 -0
  825. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathSphere.h +177 -0
  826. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathVec.cpp +583 -0
  827. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathVec.h +2227 -0
  828. data/vendor/FreeImage/Source/OpenEXR/Imath/ImathVecAlgo.h +147 -0
  829. data/vendor/FreeImage/Source/OpenEXR/OpenEXRConfig.h +72 -0
  830. data/vendor/FreeImage/Source/Plugin.h +144 -0
  831. data/vendor/FreeImage/Source/Quantizers.h +354 -0
  832. data/vendor/FreeImage/Source/ToneMapping.h +44 -0
  833. data/vendor/FreeImage/Source/Utilities.h +516 -0
  834. data/vendor/FreeImage/Source/ZLib/adler32.c +179 -0
  835. data/vendor/FreeImage/Source/ZLib/compress.c +80 -0
  836. data/vendor/FreeImage/Source/ZLib/crc32.c +425 -0
  837. data/vendor/FreeImage/Source/ZLib/crc32.h +441 -0
  838. data/vendor/FreeImage/Source/ZLib/deflate.c +1967 -0
  839. data/vendor/FreeImage/Source/ZLib/deflate.h +346 -0
  840. data/vendor/FreeImage/Source/ZLib/gzclose.c +25 -0
  841. data/vendor/FreeImage/Source/ZLib/gzguts.h +209 -0
  842. data/vendor/FreeImage/Source/ZLib/gzlib.c +634 -0
  843. data/vendor/FreeImage/Source/ZLib/gzread.c +594 -0
  844. data/vendor/FreeImage/Source/ZLib/gzwrite.c +577 -0
  845. data/vendor/FreeImage/Source/ZLib/infback.c +640 -0
  846. data/vendor/FreeImage/Source/ZLib/inffast.c +340 -0
  847. data/vendor/FreeImage/Source/ZLib/inffast.h +11 -0
  848. data/vendor/FreeImage/Source/ZLib/inffixed.h +94 -0
  849. data/vendor/FreeImage/Source/ZLib/inflate.c +1512 -0
  850. data/vendor/FreeImage/Source/ZLib/inflate.h +122 -0
  851. data/vendor/FreeImage/Source/ZLib/inftrees.c +306 -0
  852. data/vendor/FreeImage/Source/ZLib/inftrees.h +62 -0
  853. data/vendor/FreeImage/Source/ZLib/trees.c +1226 -0
  854. data/vendor/FreeImage/Source/ZLib/trees.h +128 -0
  855. data/vendor/FreeImage/Source/ZLib/uncompr.c +59 -0
  856. data/vendor/FreeImage/Source/ZLib/zconf.h +511 -0
  857. data/vendor/FreeImage/Source/ZLib/zlib.h +1768 -0
  858. data/vendor/FreeImage/Source/ZLib/zutil.c +324 -0
  859. data/vendor/FreeImage/Source/ZLib/zutil.h +253 -0
  860. metadata +931 -0
@@ -0,0 +1,1584 @@
1
+ // Copyright 2012 Google Inc. All Rights Reserved.
2
+ //
3
+ // Use of this source code is governed by a BSD-style license
4
+ // that can be found in the COPYING file in the root of the source
5
+ // tree. An additional intellectual property rights grant can be found
6
+ // in the file PATENTS. All contributing project authors may
7
+ // be found in the AUTHORS file in the root of the source tree.
8
+ // -----------------------------------------------------------------------------
9
+ //
10
+ // main entry for the decoder
11
+ //
12
+ // Authors: Vikas Arora (vikaas.arora@gmail.com)
13
+ // Jyrki Alakuijala (jyrki@google.com)
14
+
15
+ #include <stdlib.h>
16
+
17
+ #include "./alphai.h"
18
+ #include "./vp8li.h"
19
+ #include "../dsp/dsp.h"
20
+ #include "../dsp/lossless.h"
21
+ #include "../dsp/yuv.h"
22
+ #include "../utils/huffman.h"
23
+ #include "../utils/utils.h"
24
+
25
+ #define NUM_ARGB_CACHE_ROWS 16
26
+
27
+ static const int kCodeLengthLiterals = 16;
28
+ static const int kCodeLengthRepeatCode = 16;
29
+ static const int kCodeLengthExtraBits[3] = { 2, 3, 7 };
30
+ static const int kCodeLengthRepeatOffsets[3] = { 3, 3, 11 };
31
+
32
+ // -----------------------------------------------------------------------------
33
+ // Five Huffman codes are used at each meta code:
34
+ // 1. green + length prefix codes + color cache codes,
35
+ // 2. alpha,
36
+ // 3. red,
37
+ // 4. blue, and,
38
+ // 5. distance prefix codes.
39
+ typedef enum {
40
+ GREEN = 0,
41
+ RED = 1,
42
+ BLUE = 2,
43
+ ALPHA = 3,
44
+ DIST = 4
45
+ } HuffIndex;
46
+
47
+ static const uint16_t kAlphabetSize[HUFFMAN_CODES_PER_META_CODE] = {
48
+ NUM_LITERAL_CODES + NUM_LENGTH_CODES,
49
+ NUM_LITERAL_CODES, NUM_LITERAL_CODES, NUM_LITERAL_CODES,
50
+ NUM_DISTANCE_CODES
51
+ };
52
+
53
+ static const uint8_t kLiteralMap[HUFFMAN_CODES_PER_META_CODE] = {
54
+ 0, 1, 1, 1, 0
55
+ };
56
+
57
+ #define NUM_CODE_LENGTH_CODES 19
58
+ static const uint8_t kCodeLengthCodeOrder[NUM_CODE_LENGTH_CODES] = {
59
+ 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
60
+ };
61
+
62
+ #define CODE_TO_PLANE_CODES 120
63
+ static const uint8_t kCodeToPlane[CODE_TO_PLANE_CODES] = {
64
+ 0x18, 0x07, 0x17, 0x19, 0x28, 0x06, 0x27, 0x29, 0x16, 0x1a,
65
+ 0x26, 0x2a, 0x38, 0x05, 0x37, 0x39, 0x15, 0x1b, 0x36, 0x3a,
66
+ 0x25, 0x2b, 0x48, 0x04, 0x47, 0x49, 0x14, 0x1c, 0x35, 0x3b,
67
+ 0x46, 0x4a, 0x24, 0x2c, 0x58, 0x45, 0x4b, 0x34, 0x3c, 0x03,
68
+ 0x57, 0x59, 0x13, 0x1d, 0x56, 0x5a, 0x23, 0x2d, 0x44, 0x4c,
69
+ 0x55, 0x5b, 0x33, 0x3d, 0x68, 0x02, 0x67, 0x69, 0x12, 0x1e,
70
+ 0x66, 0x6a, 0x22, 0x2e, 0x54, 0x5c, 0x43, 0x4d, 0x65, 0x6b,
71
+ 0x32, 0x3e, 0x78, 0x01, 0x77, 0x79, 0x53, 0x5d, 0x11, 0x1f,
72
+ 0x64, 0x6c, 0x42, 0x4e, 0x76, 0x7a, 0x21, 0x2f, 0x75, 0x7b,
73
+ 0x31, 0x3f, 0x63, 0x6d, 0x52, 0x5e, 0x00, 0x74, 0x7c, 0x41,
74
+ 0x4f, 0x10, 0x20, 0x62, 0x6e, 0x30, 0x73, 0x7d, 0x51, 0x5f,
75
+ 0x40, 0x72, 0x7e, 0x61, 0x6f, 0x50, 0x71, 0x7f, 0x60, 0x70
76
+ };
77
+
78
+ // Memory needed for lookup tables of one Huffman tree group. Red, blue, alpha
79
+ // and distance alphabets are constant (256 for red, blue and alpha, 40 for
80
+ // distance) and lookup table sizes for them in worst case are 630 and 410
81
+ // respectively. Size of green alphabet depends on color cache size and is equal
82
+ // to 256 (green component values) + 24 (length prefix values)
83
+ // + color_cache_size (between 0 and 2048).
84
+ // All values computed for 8-bit first level lookup with Mark Adler's tool:
85
+ // http://www.hdfgroup.org/ftp/lib-external/zlib/zlib-1.2.5/examples/enough.c
86
+ #define FIXED_TABLE_SIZE (630 * 3 + 410)
87
+ static const int kTableSize[12] = {
88
+ FIXED_TABLE_SIZE + 654,
89
+ FIXED_TABLE_SIZE + 656,
90
+ FIXED_TABLE_SIZE + 658,
91
+ FIXED_TABLE_SIZE + 662,
92
+ FIXED_TABLE_SIZE + 670,
93
+ FIXED_TABLE_SIZE + 686,
94
+ FIXED_TABLE_SIZE + 718,
95
+ FIXED_TABLE_SIZE + 782,
96
+ FIXED_TABLE_SIZE + 912,
97
+ FIXED_TABLE_SIZE + 1168,
98
+ FIXED_TABLE_SIZE + 1680,
99
+ FIXED_TABLE_SIZE + 2704
100
+ };
101
+
102
+ static int DecodeImageStream(int xsize, int ysize,
103
+ int is_level0,
104
+ VP8LDecoder* const dec,
105
+ uint32_t** const decoded_data);
106
+
107
+ //------------------------------------------------------------------------------
108
+
109
+ int VP8LCheckSignature(const uint8_t* const data, size_t size) {
110
+ return (size >= VP8L_FRAME_HEADER_SIZE &&
111
+ data[0] == VP8L_MAGIC_BYTE &&
112
+ (data[4] >> 5) == 0); // version
113
+ }
114
+
115
+ static int ReadImageInfo(VP8LBitReader* const br,
116
+ int* const width, int* const height,
117
+ int* const has_alpha) {
118
+ if (VP8LReadBits(br, 8) != VP8L_MAGIC_BYTE) return 0;
119
+ *width = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
120
+ *height = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
121
+ *has_alpha = VP8LReadBits(br, 1);
122
+ if (VP8LReadBits(br, VP8L_VERSION_BITS) != 0) return 0;
123
+ return !br->eos_;
124
+ }
125
+
126
+ int VP8LGetInfo(const uint8_t* data, size_t data_size,
127
+ int* const width, int* const height, int* const has_alpha) {
128
+ if (data == NULL || data_size < VP8L_FRAME_HEADER_SIZE) {
129
+ return 0; // not enough data
130
+ } else if (!VP8LCheckSignature(data, data_size)) {
131
+ return 0; // bad signature
132
+ } else {
133
+ int w, h, a;
134
+ VP8LBitReader br;
135
+ VP8LInitBitReader(&br, data, data_size);
136
+ if (!ReadImageInfo(&br, &w, &h, &a)) {
137
+ return 0;
138
+ }
139
+ if (width != NULL) *width = w;
140
+ if (height != NULL) *height = h;
141
+ if (has_alpha != NULL) *has_alpha = a;
142
+ return 1;
143
+ }
144
+ }
145
+
146
+ //------------------------------------------------------------------------------
147
+
148
+ static WEBP_INLINE int GetCopyDistance(int distance_symbol,
149
+ VP8LBitReader* const br) {
150
+ int extra_bits, offset;
151
+ if (distance_symbol < 4) {
152
+ return distance_symbol + 1;
153
+ }
154
+ extra_bits = (distance_symbol - 2) >> 1;
155
+ offset = (2 + (distance_symbol & 1)) << extra_bits;
156
+ return offset + VP8LReadBits(br, extra_bits) + 1;
157
+ }
158
+
159
+ static WEBP_INLINE int GetCopyLength(int length_symbol,
160
+ VP8LBitReader* const br) {
161
+ // Length and distance prefixes are encoded the same way.
162
+ return GetCopyDistance(length_symbol, br);
163
+ }
164
+
165
+ static WEBP_INLINE int PlaneCodeToDistance(int xsize, int plane_code) {
166
+ if (plane_code > CODE_TO_PLANE_CODES) {
167
+ return plane_code - CODE_TO_PLANE_CODES;
168
+ } else {
169
+ const int dist_code = kCodeToPlane[plane_code - 1];
170
+ const int yoffset = dist_code >> 4;
171
+ const int xoffset = 8 - (dist_code & 0xf);
172
+ const int dist = yoffset * xsize + xoffset;
173
+ return (dist >= 1) ? dist : 1; // dist<1 can happen if xsize is very small
174
+ }
175
+ }
176
+
177
+ //------------------------------------------------------------------------------
178
+ // Decodes the next Huffman code from bit-stream.
179
+ // FillBitWindow(br) needs to be called at minimum every second call
180
+ // to ReadSymbol, in order to pre-fetch enough bits.
181
+ static WEBP_INLINE int ReadSymbol(const HuffmanCode* table,
182
+ VP8LBitReader* const br) {
183
+ int nbits;
184
+ uint32_t val = VP8LPrefetchBits(br);
185
+ table += val & HUFFMAN_TABLE_MASK;
186
+ nbits = table->bits - HUFFMAN_TABLE_BITS;
187
+ if (nbits > 0) {
188
+ VP8LSetBitPos(br, br->bit_pos_ + HUFFMAN_TABLE_BITS);
189
+ val = VP8LPrefetchBits(br);
190
+ table += table->value;
191
+ table += val & ((1 << nbits) - 1);
192
+ }
193
+ VP8LSetBitPos(br, br->bit_pos_ + table->bits);
194
+ return table->value;
195
+ }
196
+
197
+ static int ReadHuffmanCodeLengths(
198
+ VP8LDecoder* const dec, const int* const code_length_code_lengths,
199
+ int num_symbols, int* const code_lengths) {
200
+ int ok = 0;
201
+ VP8LBitReader* const br = &dec->br_;
202
+ int symbol;
203
+ int max_symbol;
204
+ int prev_code_len = DEFAULT_CODE_LENGTH;
205
+ HuffmanCode table[1 << LENGTHS_TABLE_BITS];
206
+
207
+ if (!VP8LBuildHuffmanTable(table, LENGTHS_TABLE_BITS,
208
+ code_length_code_lengths,
209
+ NUM_CODE_LENGTH_CODES)) {
210
+ goto End;
211
+ }
212
+
213
+ if (VP8LReadBits(br, 1)) { // use length
214
+ const int length_nbits = 2 + 2 * VP8LReadBits(br, 3);
215
+ max_symbol = 2 + VP8LReadBits(br, length_nbits);
216
+ if (max_symbol > num_symbols) {
217
+ goto End;
218
+ }
219
+ } else {
220
+ max_symbol = num_symbols;
221
+ }
222
+
223
+ symbol = 0;
224
+ while (symbol < num_symbols) {
225
+ const HuffmanCode* p;
226
+ int code_len;
227
+ if (max_symbol-- == 0) break;
228
+ VP8LFillBitWindow(br);
229
+ p = &table[VP8LPrefetchBits(br) & LENGTHS_TABLE_MASK];
230
+ VP8LSetBitPos(br, br->bit_pos_ + p->bits);
231
+ code_len = p->value;
232
+ if (code_len < kCodeLengthLiterals) {
233
+ code_lengths[symbol++] = code_len;
234
+ if (code_len != 0) prev_code_len = code_len;
235
+ } else {
236
+ const int use_prev = (code_len == kCodeLengthRepeatCode);
237
+ const int slot = code_len - kCodeLengthLiterals;
238
+ const int extra_bits = kCodeLengthExtraBits[slot];
239
+ const int repeat_offset = kCodeLengthRepeatOffsets[slot];
240
+ int repeat = VP8LReadBits(br, extra_bits) + repeat_offset;
241
+ if (symbol + repeat > num_symbols) {
242
+ goto End;
243
+ } else {
244
+ const int length = use_prev ? prev_code_len : 0;
245
+ while (repeat-- > 0) code_lengths[symbol++] = length;
246
+ }
247
+ }
248
+ }
249
+ ok = 1;
250
+
251
+ End:
252
+ if (!ok) dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
253
+ return ok;
254
+ }
255
+
256
+ // 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman
257
+ // tree.
258
+ static int ReadHuffmanCode(int alphabet_size, VP8LDecoder* const dec,
259
+ int* const code_lengths, HuffmanCode* const table) {
260
+ int ok = 0;
261
+ int size = 0;
262
+ VP8LBitReader* const br = &dec->br_;
263
+ const int simple_code = VP8LReadBits(br, 1);
264
+
265
+ memset(code_lengths, 0, alphabet_size * sizeof(*code_lengths));
266
+
267
+ if (simple_code) { // Read symbols, codes & code lengths directly.
268
+ const int num_symbols = VP8LReadBits(br, 1) + 1;
269
+ const int first_symbol_len_code = VP8LReadBits(br, 1);
270
+ // The first code is either 1 bit or 8 bit code.
271
+ int symbol = VP8LReadBits(br, (first_symbol_len_code == 0) ? 1 : 8);
272
+ code_lengths[symbol] = 1;
273
+ // The second code (if present), is always 8 bit long.
274
+ if (num_symbols == 2) {
275
+ symbol = VP8LReadBits(br, 8);
276
+ code_lengths[symbol] = 1;
277
+ }
278
+ ok = 1;
279
+ } else { // Decode Huffman-coded code lengths.
280
+ int i;
281
+ int code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 };
282
+ const int num_codes = VP8LReadBits(br, 4) + 4;
283
+ if (num_codes > NUM_CODE_LENGTH_CODES) {
284
+ dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
285
+ return 0;
286
+ }
287
+
288
+ for (i = 0; i < num_codes; ++i) {
289
+ code_length_code_lengths[kCodeLengthCodeOrder[i]] = VP8LReadBits(br, 3);
290
+ }
291
+ ok = ReadHuffmanCodeLengths(dec, code_length_code_lengths, alphabet_size,
292
+ code_lengths);
293
+ }
294
+
295
+ ok = ok && !br->eos_;
296
+ if (ok) {
297
+ size = VP8LBuildHuffmanTable(table, HUFFMAN_TABLE_BITS,
298
+ code_lengths, alphabet_size);
299
+ }
300
+ if (!ok || size == 0) {
301
+ dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
302
+ return 0;
303
+ }
304
+ return size;
305
+ }
306
+
307
+ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
308
+ int color_cache_bits, int allow_recursion) {
309
+ int i, j;
310
+ VP8LBitReader* const br = &dec->br_;
311
+ VP8LMetadata* const hdr = &dec->hdr_;
312
+ uint32_t* huffman_image = NULL;
313
+ HTreeGroup* htree_groups = NULL;
314
+ HuffmanCode* huffman_tables = NULL;
315
+ HuffmanCode* next = NULL;
316
+ int num_htree_groups = 1;
317
+ int max_alphabet_size = 0;
318
+ int* code_lengths = NULL;
319
+ const int table_size = kTableSize[color_cache_bits];
320
+
321
+ if (allow_recursion && VP8LReadBits(br, 1)) {
322
+ // use meta Huffman codes.
323
+ const int huffman_precision = VP8LReadBits(br, 3) + 2;
324
+ const int huffman_xsize = VP8LSubSampleSize(xsize, huffman_precision);
325
+ const int huffman_ysize = VP8LSubSampleSize(ysize, huffman_precision);
326
+ const int huffman_pixs = huffman_xsize * huffman_ysize;
327
+ if (!DecodeImageStream(huffman_xsize, huffman_ysize, 0, dec,
328
+ &huffman_image)) {
329
+ goto Error;
330
+ }
331
+ hdr->huffman_subsample_bits_ = huffman_precision;
332
+ for (i = 0; i < huffman_pixs; ++i) {
333
+ // The huffman data is stored in red and green bytes.
334
+ const int group = (huffman_image[i] >> 8) & 0xffff;
335
+ huffman_image[i] = group;
336
+ if (group >= num_htree_groups) {
337
+ num_htree_groups = group + 1;
338
+ }
339
+ }
340
+ }
341
+
342
+ if (br->eos_) goto Error;
343
+
344
+ // Find maximum alphabet size for the htree group.
345
+ for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) {
346
+ int alphabet_size = kAlphabetSize[j];
347
+ if (j == 0 && color_cache_bits > 0) {
348
+ alphabet_size += 1 << color_cache_bits;
349
+ }
350
+ if (max_alphabet_size < alphabet_size) {
351
+ max_alphabet_size = alphabet_size;
352
+ }
353
+ }
354
+
355
+ huffman_tables = (HuffmanCode*)WebPSafeMalloc(num_htree_groups * table_size,
356
+ sizeof(*huffman_tables));
357
+ htree_groups = VP8LHtreeGroupsNew(num_htree_groups);
358
+ code_lengths = (int*)WebPSafeCalloc((uint64_t)max_alphabet_size,
359
+ sizeof(*code_lengths));
360
+
361
+ if (htree_groups == NULL || code_lengths == NULL || huffman_tables == NULL) {
362
+ dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
363
+ goto Error;
364
+ }
365
+
366
+ next = huffman_tables;
367
+ for (i = 0; i < num_htree_groups; ++i) {
368
+ HTreeGroup* const htree_group = &htree_groups[i];
369
+ HuffmanCode** const htrees = htree_group->htrees;
370
+ int size;
371
+ int is_trivial_literal = 1;
372
+ for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) {
373
+ int alphabet_size = kAlphabetSize[j];
374
+ htrees[j] = next;
375
+ if (j == 0 && color_cache_bits > 0) {
376
+ alphabet_size += 1 << color_cache_bits;
377
+ }
378
+ size = ReadHuffmanCode(alphabet_size, dec, code_lengths, next);
379
+ if (is_trivial_literal && kLiteralMap[j] == 1) {
380
+ is_trivial_literal = (next->bits == 0);
381
+ }
382
+ next += size;
383
+ if (size == 0) {
384
+ goto Error;
385
+ }
386
+ }
387
+ htree_group->is_trivial_literal = is_trivial_literal;
388
+ if (is_trivial_literal) {
389
+ const int red = htrees[RED][0].value;
390
+ const int blue = htrees[BLUE][0].value;
391
+ const int alpha = htrees[ALPHA][0].value;
392
+ htree_group->literal_arb =
393
+ ((uint32_t)alpha << 24) | (red << 16) | blue;
394
+ }
395
+ }
396
+ WebPSafeFree(code_lengths);
397
+
398
+ // All OK. Finalize pointers and return.
399
+ hdr->huffman_image_ = huffman_image;
400
+ hdr->num_htree_groups_ = num_htree_groups;
401
+ hdr->htree_groups_ = htree_groups;
402
+ hdr->huffman_tables_ = huffman_tables;
403
+ return 1;
404
+
405
+ Error:
406
+ WebPSafeFree(code_lengths);
407
+ WebPSafeFree(huffman_image);
408
+ WebPSafeFree(huffman_tables);
409
+ VP8LHtreeGroupsFree(htree_groups);
410
+ return 0;
411
+ }
412
+
413
+ //------------------------------------------------------------------------------
414
+ // Scaling.
415
+
416
+ static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) {
417
+ const int num_channels = 4;
418
+ const int in_width = io->mb_w;
419
+ const int out_width = io->scaled_width;
420
+ const int in_height = io->mb_h;
421
+ const int out_height = io->scaled_height;
422
+ const uint64_t work_size = 2 * num_channels * (uint64_t)out_width;
423
+ int32_t* work; // Rescaler work area.
424
+ const uint64_t scaled_data_size = num_channels * (uint64_t)out_width;
425
+ uint32_t* scaled_data; // Temporary storage for scaled BGRA data.
426
+ const uint64_t memory_size = sizeof(*dec->rescaler) +
427
+ work_size * sizeof(*work) +
428
+ scaled_data_size * sizeof(*scaled_data);
429
+ uint8_t* memory = (uint8_t*)WebPSafeCalloc(memory_size, sizeof(*memory));
430
+ if (memory == NULL) {
431
+ dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
432
+ return 0;
433
+ }
434
+ assert(dec->rescaler_memory == NULL);
435
+ dec->rescaler_memory = memory;
436
+
437
+ dec->rescaler = (WebPRescaler*)memory;
438
+ memory += sizeof(*dec->rescaler);
439
+ work = (int32_t*)memory;
440
+ memory += work_size * sizeof(*work);
441
+ scaled_data = (uint32_t*)memory;
442
+
443
+ WebPRescalerInit(dec->rescaler, in_width, in_height, (uint8_t*)scaled_data,
444
+ out_width, out_height, 0, num_channels,
445
+ in_width, out_width, in_height, out_height, work);
446
+ return 1;
447
+ }
448
+
449
+ //------------------------------------------------------------------------------
450
+ // Export to ARGB
451
+
452
+ // We have special "export" function since we need to convert from BGRA
453
+ static int Export(WebPRescaler* const rescaler, WEBP_CSP_MODE colorspace,
454
+ int rgba_stride, uint8_t* const rgba) {
455
+ uint32_t* const src = (uint32_t*)rescaler->dst;
456
+ const int dst_width = rescaler->dst_width;
457
+ int num_lines_out = 0;
458
+ while (WebPRescalerHasPendingOutput(rescaler)) {
459
+ uint8_t* const dst = rgba + num_lines_out * rgba_stride;
460
+ WebPRescalerExportRow(rescaler, 0);
461
+ WebPMultARGBRow(src, dst_width, 1);
462
+ VP8LConvertFromBGRA(src, dst_width, colorspace, dst);
463
+ ++num_lines_out;
464
+ }
465
+ return num_lines_out;
466
+ }
467
+
468
+ // Emit scaled rows.
469
+ static int EmitRescaledRowsRGBA(const VP8LDecoder* const dec,
470
+ uint8_t* in, int in_stride, int mb_h,
471
+ uint8_t* const out, int out_stride) {
472
+ const WEBP_CSP_MODE colorspace = dec->output_->colorspace;
473
+ int num_lines_in = 0;
474
+ int num_lines_out = 0;
475
+ while (num_lines_in < mb_h) {
476
+ uint8_t* const row_in = in + num_lines_in * in_stride;
477
+ uint8_t* const row_out = out + num_lines_out * out_stride;
478
+ const int lines_left = mb_h - num_lines_in;
479
+ const int needed_lines = WebPRescaleNeededLines(dec->rescaler, lines_left);
480
+ assert(needed_lines > 0 && needed_lines <= lines_left);
481
+ WebPMultARGBRows(row_in, in_stride,
482
+ dec->rescaler->src_width, needed_lines, 0);
483
+ WebPRescalerImport(dec->rescaler, lines_left, row_in, in_stride);
484
+ num_lines_in += needed_lines;
485
+ num_lines_out += Export(dec->rescaler, colorspace, out_stride, row_out);
486
+ }
487
+ return num_lines_out;
488
+ }
489
+
490
+ // Emit rows without any scaling.
491
+ static int EmitRows(WEBP_CSP_MODE colorspace,
492
+ const uint8_t* row_in, int in_stride,
493
+ int mb_w, int mb_h,
494
+ uint8_t* const out, int out_stride) {
495
+ int lines = mb_h;
496
+ uint8_t* row_out = out;
497
+ while (lines-- > 0) {
498
+ VP8LConvertFromBGRA((const uint32_t*)row_in, mb_w, colorspace, row_out);
499
+ row_in += in_stride;
500
+ row_out += out_stride;
501
+ }
502
+ return mb_h; // Num rows out == num rows in.
503
+ }
504
+
505
+ //------------------------------------------------------------------------------
506
+ // Export to YUVA
507
+
508
+ // TODO(skal): should be in yuv.c
509
+ static void ConvertToYUVA(const uint32_t* const src, int width, int y_pos,
510
+ const WebPDecBuffer* const output) {
511
+ const WebPYUVABuffer* const buf = &output->u.YUVA;
512
+ // first, the luma plane
513
+ {
514
+ int i;
515
+ uint8_t* const y = buf->y + y_pos * buf->y_stride;
516
+ for (i = 0; i < width; ++i) {
517
+ const uint32_t p = src[i];
518
+ y[i] = VP8RGBToY((p >> 16) & 0xff, (p >> 8) & 0xff, (p >> 0) & 0xff,
519
+ YUV_HALF);
520
+ }
521
+ }
522
+
523
+ // then U/V planes
524
+ {
525
+ uint8_t* const u = buf->u + (y_pos >> 1) * buf->u_stride;
526
+ uint8_t* const v = buf->v + (y_pos >> 1) * buf->v_stride;
527
+ const int uv_width = width >> 1;
528
+ int i;
529
+ for (i = 0; i < uv_width; ++i) {
530
+ const uint32_t v0 = src[2 * i + 0];
531
+ const uint32_t v1 = src[2 * i + 1];
532
+ // VP8RGBToU/V expects four accumulated pixels. Hence we need to
533
+ // scale r/g/b value by a factor 2. We just shift v0/v1 one bit less.
534
+ const int r = ((v0 >> 15) & 0x1fe) + ((v1 >> 15) & 0x1fe);
535
+ const int g = ((v0 >> 7) & 0x1fe) + ((v1 >> 7) & 0x1fe);
536
+ const int b = ((v0 << 1) & 0x1fe) + ((v1 << 1) & 0x1fe);
537
+ if (!(y_pos & 1)) { // even lines: store values
538
+ u[i] = VP8RGBToU(r, g, b, YUV_HALF << 2);
539
+ v[i] = VP8RGBToV(r, g, b, YUV_HALF << 2);
540
+ } else { // odd lines: average with previous values
541
+ const int tmp_u = VP8RGBToU(r, g, b, YUV_HALF << 2);
542
+ const int tmp_v = VP8RGBToV(r, g, b, YUV_HALF << 2);
543
+ // Approximated average-of-four. But it's an acceptable diff.
544
+ u[i] = (u[i] + tmp_u + 1) >> 1;
545
+ v[i] = (v[i] + tmp_v + 1) >> 1;
546
+ }
547
+ }
548
+ if (width & 1) { // last pixel
549
+ const uint32_t v0 = src[2 * i + 0];
550
+ const int r = (v0 >> 14) & 0x3fc;
551
+ const int g = (v0 >> 6) & 0x3fc;
552
+ const int b = (v0 << 2) & 0x3fc;
553
+ if (!(y_pos & 1)) { // even lines
554
+ u[i] = VP8RGBToU(r, g, b, YUV_HALF << 2);
555
+ v[i] = VP8RGBToV(r, g, b, YUV_HALF << 2);
556
+ } else { // odd lines (note: we could just skip this)
557
+ const int tmp_u = VP8RGBToU(r, g, b, YUV_HALF << 2);
558
+ const int tmp_v = VP8RGBToV(r, g, b, YUV_HALF << 2);
559
+ u[i] = (u[i] + tmp_u + 1) >> 1;
560
+ v[i] = (v[i] + tmp_v + 1) >> 1;
561
+ }
562
+ }
563
+ }
564
+ // Lastly, store alpha if needed.
565
+ if (buf->a != NULL) {
566
+ int i;
567
+ uint8_t* const a = buf->a + y_pos * buf->a_stride;
568
+ for (i = 0; i < width; ++i) a[i] = (src[i] >> 24);
569
+ }
570
+ }
571
+
572
+ static int ExportYUVA(const VP8LDecoder* const dec, int y_pos) {
573
+ WebPRescaler* const rescaler = dec->rescaler;
574
+ uint32_t* const src = (uint32_t*)rescaler->dst;
575
+ const int dst_width = rescaler->dst_width;
576
+ int num_lines_out = 0;
577
+ while (WebPRescalerHasPendingOutput(rescaler)) {
578
+ WebPRescalerExportRow(rescaler, 0);
579
+ WebPMultARGBRow(src, dst_width, 1);
580
+ ConvertToYUVA(src, dst_width, y_pos, dec->output_);
581
+ ++y_pos;
582
+ ++num_lines_out;
583
+ }
584
+ return num_lines_out;
585
+ }
586
+
587
+ static int EmitRescaledRowsYUVA(const VP8LDecoder* const dec,
588
+ uint8_t* in, int in_stride, int mb_h) {
589
+ int num_lines_in = 0;
590
+ int y_pos = dec->last_out_row_;
591
+ while (num_lines_in < mb_h) {
592
+ const int lines_left = mb_h - num_lines_in;
593
+ const int needed_lines = WebPRescaleNeededLines(dec->rescaler, lines_left);
594
+ WebPMultARGBRows(in, in_stride, dec->rescaler->src_width, needed_lines, 0);
595
+ WebPRescalerImport(dec->rescaler, lines_left, in, in_stride);
596
+ num_lines_in += needed_lines;
597
+ in += needed_lines * in_stride;
598
+ y_pos += ExportYUVA(dec, y_pos);
599
+ }
600
+ return y_pos;
601
+ }
602
+
603
+ static int EmitRowsYUVA(const VP8LDecoder* const dec,
604
+ const uint8_t* in, int in_stride,
605
+ int mb_w, int num_rows) {
606
+ int y_pos = dec->last_out_row_;
607
+ while (num_rows-- > 0) {
608
+ ConvertToYUVA((const uint32_t*)in, mb_w, y_pos, dec->output_);
609
+ in += in_stride;
610
+ ++y_pos;
611
+ }
612
+ return y_pos;
613
+ }
614
+
615
+ //------------------------------------------------------------------------------
616
+ // Cropping.
617
+
618
+ // Sets io->mb_y, io->mb_h & io->mb_w according to start row, end row and
619
+ // crop options. Also updates the input data pointer, so that it points to the
620
+ // start of the cropped window. Note that pixels are in ARGB format even if
621
+ // 'in_data' is uint8_t*.
622
+ // Returns true if the crop window is not empty.
623
+ static int SetCropWindow(VP8Io* const io, int y_start, int y_end,
624
+ uint8_t** const in_data, int pixel_stride) {
625
+ assert(y_start < y_end);
626
+ assert(io->crop_left < io->crop_right);
627
+ if (y_end > io->crop_bottom) {
628
+ y_end = io->crop_bottom; // make sure we don't overflow on last row.
629
+ }
630
+ if (y_start < io->crop_top) {
631
+ const int delta = io->crop_top - y_start;
632
+ y_start = io->crop_top;
633
+ *in_data += delta * pixel_stride;
634
+ }
635
+ if (y_start >= y_end) return 0; // Crop window is empty.
636
+
637
+ *in_data += io->crop_left * sizeof(uint32_t);
638
+
639
+ io->mb_y = y_start - io->crop_top;
640
+ io->mb_w = io->crop_right - io->crop_left;
641
+ io->mb_h = y_end - y_start;
642
+ return 1; // Non-empty crop window.
643
+ }
644
+
645
+ //------------------------------------------------------------------------------
646
+
647
+ static WEBP_INLINE int GetMetaIndex(
648
+ const uint32_t* const image, int xsize, int bits, int x, int y) {
649
+ if (bits == 0) return 0;
650
+ return image[xsize * (y >> bits) + (x >> bits)];
651
+ }
652
+
653
+ static WEBP_INLINE HTreeGroup* GetHtreeGroupForPos(VP8LMetadata* const hdr,
654
+ int x, int y) {
655
+ const int meta_index = GetMetaIndex(hdr->huffman_image_, hdr->huffman_xsize_,
656
+ hdr->huffman_subsample_bits_, x, y);
657
+ assert(meta_index < hdr->num_htree_groups_);
658
+ return hdr->htree_groups_ + meta_index;
659
+ }
660
+
661
+ //------------------------------------------------------------------------------
662
+ // Main loop, with custom row-processing function
663
+
664
+ typedef void (*ProcessRowsFunc)(VP8LDecoder* const dec, int row);
665
+
666
+ static void ApplyInverseTransforms(VP8LDecoder* const dec, int num_rows,
667
+ const uint32_t* const rows) {
668
+ int n = dec->next_transform_;
669
+ const int cache_pixs = dec->width_ * num_rows;
670
+ const int start_row = dec->last_row_;
671
+ const int end_row = start_row + num_rows;
672
+ const uint32_t* rows_in = rows;
673
+ uint32_t* const rows_out = dec->argb_cache_;
674
+
675
+ // Inverse transforms.
676
+ // TODO: most transforms only need to operate on the cropped region only.
677
+ memcpy(rows_out, rows_in, cache_pixs * sizeof(*rows_out));
678
+ while (n-- > 0) {
679
+ VP8LTransform* const transform = &dec->transforms_[n];
680
+ VP8LInverseTransform(transform, start_row, end_row, rows_in, rows_out);
681
+ rows_in = rows_out;
682
+ }
683
+ }
684
+
685
+ // Special method for paletted alpha data.
686
+ static void ApplyInverseTransformsAlpha(VP8LDecoder* const dec, int num_rows,
687
+ const uint8_t* const rows) {
688
+ const int start_row = dec->last_row_;
689
+ const int end_row = start_row + num_rows;
690
+ const uint8_t* rows_in = rows;
691
+ uint8_t* rows_out = (uint8_t*)dec->io_->opaque + dec->io_->width * start_row;
692
+ VP8LTransform* const transform = &dec->transforms_[0];
693
+ assert(dec->next_transform_ == 1);
694
+ assert(transform->type_ == COLOR_INDEXING_TRANSFORM);
695
+ VP8LColorIndexInverseTransformAlpha(transform, start_row, end_row, rows_in,
696
+ rows_out);
697
+ }
698
+
699
+ // Processes (transforms, scales & color-converts) the rows decoded after the
700
+ // last call.
701
+ static void ProcessRows(VP8LDecoder* const dec, int row) {
702
+ const uint32_t* const rows = dec->pixels_ + dec->width_ * dec->last_row_;
703
+ const int num_rows = row - dec->last_row_;
704
+
705
+ if (num_rows <= 0) return; // Nothing to be done.
706
+ ApplyInverseTransforms(dec, num_rows, rows);
707
+
708
+ // Emit output.
709
+ {
710
+ VP8Io* const io = dec->io_;
711
+ uint8_t* rows_data = (uint8_t*)dec->argb_cache_;
712
+ const int in_stride = io->width * sizeof(uint32_t); // in unit of RGBA
713
+ if (!SetCropWindow(io, dec->last_row_, row, &rows_data, in_stride)) {
714
+ // Nothing to output (this time).
715
+ } else {
716
+ const WebPDecBuffer* const output = dec->output_;
717
+ if (output->colorspace < MODE_YUV) { // convert to RGBA
718
+ const WebPRGBABuffer* const buf = &output->u.RGBA;
719
+ uint8_t* const rgba = buf->rgba + dec->last_out_row_ * buf->stride;
720
+ const int num_rows_out = io->use_scaling ?
721
+ EmitRescaledRowsRGBA(dec, rows_data, in_stride, io->mb_h,
722
+ rgba, buf->stride) :
723
+ EmitRows(output->colorspace, rows_data, in_stride,
724
+ io->mb_w, io->mb_h, rgba, buf->stride);
725
+ // Update 'last_out_row_'.
726
+ dec->last_out_row_ += num_rows_out;
727
+ } else { // convert to YUVA
728
+ dec->last_out_row_ = io->use_scaling ?
729
+ EmitRescaledRowsYUVA(dec, rows_data, in_stride, io->mb_h) :
730
+ EmitRowsYUVA(dec, rows_data, in_stride, io->mb_w, io->mb_h);
731
+ }
732
+ assert(dec->last_out_row_ <= output->height);
733
+ }
734
+ }
735
+
736
+ // Update 'last_row_'.
737
+ dec->last_row_ = row;
738
+ assert(dec->last_row_ <= dec->height_);
739
+ }
740
+
741
+ // Row-processing for the special case when alpha data contains only one
742
+ // transform (color indexing), and trivial non-green literals.
743
+ static int Is8bOptimizable(const VP8LMetadata* const hdr) {
744
+ int i;
745
+ if (hdr->color_cache_size_ > 0) return 0;
746
+ // When the Huffman tree contains only one symbol, we can skip the
747
+ // call to ReadSymbol() for red/blue/alpha channels.
748
+ for (i = 0; i < hdr->num_htree_groups_; ++i) {
749
+ HuffmanCode** const htrees = hdr->htree_groups_[i].htrees;
750
+ if (htrees[RED][0].bits > 0) return 0;
751
+ if (htrees[BLUE][0].bits > 0) return 0;
752
+ if (htrees[ALPHA][0].bits > 0) return 0;
753
+ }
754
+ return 1;
755
+ }
756
+
757
+ static void ExtractPalettedAlphaRows(VP8LDecoder* const dec, int row) {
758
+ const int num_rows = row - dec->last_row_;
759
+ const uint8_t* const in =
760
+ (uint8_t*)dec->pixels_ + dec->width_ * dec->last_row_;
761
+ if (num_rows > 0) {
762
+ ApplyInverseTransformsAlpha(dec, num_rows, in);
763
+ }
764
+ dec->last_row_ = dec->last_out_row_ = row;
765
+ }
766
+
767
+ //------------------------------------------------------------------------------
768
+ // Helper functions for fast pattern copy (8b and 32b)
769
+
770
+ // cyclic rotation of pattern word
771
+ static WEBP_INLINE uint32_t Rotate8b(uint32_t V) {
772
+ #if defined(WORDS_BIGENDIAN)
773
+ return ((V & 0xff000000u) >> 24) | (V << 8);
774
+ #else
775
+ return ((V & 0xffu) << 24) | (V >> 8);
776
+ #endif
777
+ }
778
+
779
+ // copy 1, 2 or 4-bytes pattern
780
+ static WEBP_INLINE void CopySmallPattern8b(const uint8_t* src, uint8_t* dst,
781
+ int length, uint32_t pattern) {
782
+ int i;
783
+ // align 'dst' to 4-bytes boundary. Adjust the pattern along the way.
784
+ while ((uintptr_t)dst & 3) {
785
+ *dst++ = *src++;
786
+ pattern = Rotate8b(pattern);
787
+ --length;
788
+ }
789
+ // Copy the pattern 4 bytes at a time.
790
+ for (i = 0; i < (length >> 2); ++i) {
791
+ ((uint32_t*)dst)[i] = pattern;
792
+ }
793
+ // Finish with left-overs. 'pattern' is still correctly positioned,
794
+ // so no Rotate8b() call is needed.
795
+ for (i <<= 2; i < length; ++i) {
796
+ dst[i] = src[i];
797
+ }
798
+ }
799
+
800
+ static WEBP_INLINE void CopyBlock8b(uint8_t* const dst, int dist, int length) {
801
+ const uint8_t* src = dst - dist;
802
+ if (length >= 8) {
803
+ uint32_t pattern = 0;
804
+ switch (dist) {
805
+ case 1:
806
+ pattern = src[0];
807
+ #if defined(__arm__) || defined(_M_ARM) // arm doesn't like multiply that much
808
+ pattern |= pattern << 8;
809
+ pattern |= pattern << 16;
810
+ #elif defined(WEBP_USE_MIPS_DSP_R2)
811
+ __asm__ volatile ("replv.qb %0, %0" : "+r"(pattern));
812
+ #else
813
+ pattern = 0x01010101u * pattern;
814
+ #endif
815
+ break;
816
+ case 2:
817
+ memcpy(&pattern, src, sizeof(uint16_t));
818
+ #if defined(__arm__) || defined(_M_ARM)
819
+ pattern |= pattern << 16;
820
+ #elif defined(WEBP_USE_MIPS_DSP_R2)
821
+ __asm__ volatile ("replv.ph %0, %0" : "+r"(pattern));
822
+ #else
823
+ pattern = 0x00010001u * pattern;
824
+ #endif
825
+ break;
826
+ case 4:
827
+ memcpy(&pattern, src, sizeof(uint32_t));
828
+ break;
829
+ default:
830
+ goto Copy;
831
+ break;
832
+ }
833
+ CopySmallPattern8b(src, dst, length, pattern);
834
+ return;
835
+ }
836
+ Copy:
837
+ if (dist >= length) { // no overlap -> use memcpy()
838
+ memcpy(dst, src, length * sizeof(*dst));
839
+ } else {
840
+ int i;
841
+ for (i = 0; i < length; ++i) dst[i] = src[i];
842
+ }
843
+ }
844
+
845
+ // copy pattern of 1 or 2 uint32_t's
846
+ static WEBP_INLINE void CopySmallPattern32b(const uint32_t* src,
847
+ uint32_t* dst,
848
+ int length, uint64_t pattern) {
849
+ int i;
850
+ if ((uintptr_t)dst & 4) { // Align 'dst' to 8-bytes boundary.
851
+ *dst++ = *src++;
852
+ pattern = (pattern >> 32) | (pattern << 32);
853
+ --length;
854
+ }
855
+ assert(0 == ((uintptr_t)dst & 7));
856
+ for (i = 0; i < (length >> 1); ++i) {
857
+ ((uint64_t*)dst)[i] = pattern; // Copy the pattern 8 bytes at a time.
858
+ }
859
+ if (length & 1) { // Finish with left-over.
860
+ dst[i << 1] = src[i << 1];
861
+ }
862
+ }
863
+
864
+ static WEBP_INLINE void CopyBlock32b(uint32_t* const dst,
865
+ int dist, int length) {
866
+ const uint32_t* const src = dst - dist;
867
+ if (dist <= 2 && length >= 4 && ((uintptr_t)dst & 3) == 0) {
868
+ uint64_t pattern;
869
+ if (dist == 1) {
870
+ pattern = (uint64_t)src[0];
871
+ pattern |= pattern << 32;
872
+ } else {
873
+ memcpy(&pattern, src, sizeof(pattern));
874
+ }
875
+ CopySmallPattern32b(src, dst, length, pattern);
876
+ } else if (dist >= length) { // no overlap
877
+ memcpy(dst, src, length * sizeof(*dst));
878
+ } else {
879
+ int i;
880
+ for (i = 0; i < length; ++i) dst[i] = src[i];
881
+ }
882
+ }
883
+
884
+ //------------------------------------------------------------------------------
885
+
886
+ static int DecodeAlphaData(VP8LDecoder* const dec, uint8_t* const data,
887
+ int width, int height, int last_row) {
888
+ int ok = 1;
889
+ int row = dec->last_pixel_ / width;
890
+ int col = dec->last_pixel_ % width;
891
+ VP8LBitReader* const br = &dec->br_;
892
+ VP8LMetadata* const hdr = &dec->hdr_;
893
+ const HTreeGroup* htree_group = GetHtreeGroupForPos(hdr, col, row);
894
+ int pos = dec->last_pixel_; // current position
895
+ const int end = width * height; // End of data
896
+ const int last = width * last_row; // Last pixel to decode
897
+ const int len_code_limit = NUM_LITERAL_CODES + NUM_LENGTH_CODES;
898
+ const int mask = hdr->huffman_mask_;
899
+ assert(htree_group != NULL);
900
+ assert(pos < end);
901
+ assert(last_row <= height);
902
+ assert(Is8bOptimizable(hdr));
903
+
904
+ while (!br->eos_ && pos < last) {
905
+ int code;
906
+ // Only update when changing tile.
907
+ if ((col & mask) == 0) {
908
+ htree_group = GetHtreeGroupForPos(hdr, col, row);
909
+ }
910
+ VP8LFillBitWindow(br);
911
+ code = ReadSymbol(htree_group->htrees[GREEN], br);
912
+ if (code < NUM_LITERAL_CODES) { // Literal
913
+ data[pos] = code;
914
+ ++pos;
915
+ ++col;
916
+ if (col >= width) {
917
+ col = 0;
918
+ ++row;
919
+ if (row % NUM_ARGB_CACHE_ROWS == 0) {
920
+ ExtractPalettedAlphaRows(dec, row);
921
+ }
922
+ }
923
+ } else if (code < len_code_limit) { // Backward reference
924
+ int dist_code, dist;
925
+ const int length_sym = code - NUM_LITERAL_CODES;
926
+ const int length = GetCopyLength(length_sym, br);
927
+ const int dist_symbol = ReadSymbol(htree_group->htrees[DIST], br);
928
+ VP8LFillBitWindow(br);
929
+ dist_code = GetCopyDistance(dist_symbol, br);
930
+ dist = PlaneCodeToDistance(width, dist_code);
931
+ if (pos >= dist && end - pos >= length) {
932
+ CopyBlock8b(data + pos, dist, length);
933
+ } else {
934
+ ok = 0;
935
+ goto End;
936
+ }
937
+ pos += length;
938
+ col += length;
939
+ while (col >= width) {
940
+ col -= width;
941
+ ++row;
942
+ if (row % NUM_ARGB_CACHE_ROWS == 0) {
943
+ ExtractPalettedAlphaRows(dec, row);
944
+ }
945
+ }
946
+ if (pos < last && (col & mask)) {
947
+ htree_group = GetHtreeGroupForPos(hdr, col, row);
948
+ }
949
+ } else { // Not reached
950
+ ok = 0;
951
+ goto End;
952
+ }
953
+ assert(br->eos_ == VP8LIsEndOfStream(br));
954
+ }
955
+ // Process the remaining rows corresponding to last row-block.
956
+ ExtractPalettedAlphaRows(dec, row);
957
+
958
+ End:
959
+ if (!ok || (br->eos_ && pos < end)) {
960
+ ok = 0;
961
+ dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED
962
+ : VP8_STATUS_BITSTREAM_ERROR;
963
+ } else {
964
+ dec->last_pixel_ = (int)pos;
965
+ }
966
+ return ok;
967
+ }
968
+
969
+ static void SaveState(VP8LDecoder* const dec, int last_pixel) {
970
+ assert(dec->incremental_);
971
+ dec->saved_br_ = dec->br_;
972
+ dec->saved_last_pixel_ = last_pixel;
973
+ if (dec->hdr_.color_cache_size_ > 0) {
974
+ VP8LColorCacheCopy(&dec->hdr_.color_cache_, &dec->hdr_.saved_color_cache_);
975
+ }
976
+ }
977
+
978
+ static void RestoreState(VP8LDecoder* const dec) {
979
+ assert(dec->br_.eos_);
980
+ dec->status_ = VP8_STATUS_SUSPENDED;
981
+ dec->br_ = dec->saved_br_;
982
+ dec->last_pixel_ = dec->saved_last_pixel_;
983
+ if (dec->hdr_.color_cache_size_ > 0) {
984
+ VP8LColorCacheCopy(&dec->hdr_.saved_color_cache_, &dec->hdr_.color_cache_);
985
+ }
986
+ }
987
+
988
+ #define SYNC_EVERY_N_ROWS 8 // minimum number of rows between check-points
989
+ static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data,
990
+ int width, int height, int last_row,
991
+ ProcessRowsFunc process_func) {
992
+ int row = dec->last_pixel_ / width;
993
+ int col = dec->last_pixel_ % width;
994
+ VP8LBitReader* const br = &dec->br_;
995
+ VP8LMetadata* const hdr = &dec->hdr_;
996
+ HTreeGroup* htree_group = GetHtreeGroupForPos(hdr, col, row);
997
+ uint32_t* src = data + dec->last_pixel_;
998
+ uint32_t* last_cached = src;
999
+ uint32_t* const src_end = data + width * height; // End of data
1000
+ uint32_t* const src_last = data + width * last_row; // Last pixel to decode
1001
+ const int len_code_limit = NUM_LITERAL_CODES + NUM_LENGTH_CODES;
1002
+ const int color_cache_limit = len_code_limit + hdr->color_cache_size_;
1003
+ int next_sync_row = dec->incremental_ ? row : 1 << 24;
1004
+ VP8LColorCache* const color_cache =
1005
+ (hdr->color_cache_size_ > 0) ? &hdr->color_cache_ : NULL;
1006
+ const int mask = hdr->huffman_mask_;
1007
+ assert(htree_group != NULL);
1008
+ assert(src < src_end);
1009
+ assert(src_last <= src_end);
1010
+
1011
+ while (src < src_last) {
1012
+ int code;
1013
+ if (row >= next_sync_row) {
1014
+ SaveState(dec, (int)(src - data));
1015
+ next_sync_row = row + SYNC_EVERY_N_ROWS;
1016
+ }
1017
+ // Only update when changing tile. Note we could use this test:
1018
+ // if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed
1019
+ // but that's actually slower and needs storing the previous col/row.
1020
+ if ((col & mask) == 0) {
1021
+ htree_group = GetHtreeGroupForPos(hdr, col, row);
1022
+ }
1023
+ VP8LFillBitWindow(br);
1024
+ code = ReadSymbol(htree_group->htrees[GREEN], br);
1025
+ if (br->eos_) break; // early out
1026
+ if (code < NUM_LITERAL_CODES) { // Literal
1027
+ if (htree_group->is_trivial_literal) {
1028
+ *src = htree_group->literal_arb | (code << 8);
1029
+ } else {
1030
+ int red, blue, alpha;
1031
+ red = ReadSymbol(htree_group->htrees[RED], br);
1032
+ VP8LFillBitWindow(br);
1033
+ blue = ReadSymbol(htree_group->htrees[BLUE], br);
1034
+ alpha = ReadSymbol(htree_group->htrees[ALPHA], br);
1035
+ if (br->eos_) break;
1036
+ *src = ((uint32_t)alpha << 24) | (red << 16) | (code << 8) | blue;
1037
+ }
1038
+ AdvanceByOne:
1039
+ ++src;
1040
+ ++col;
1041
+ if (col >= width) {
1042
+ col = 0;
1043
+ ++row;
1044
+ if ((row % NUM_ARGB_CACHE_ROWS == 0) && (process_func != NULL)) {
1045
+ process_func(dec, row);
1046
+ }
1047
+ if (color_cache != NULL) {
1048
+ while (last_cached < src) {
1049
+ VP8LColorCacheInsert(color_cache, *last_cached++);
1050
+ }
1051
+ }
1052
+ }
1053
+ } else if (code < len_code_limit) { // Backward reference
1054
+ int dist_code, dist;
1055
+ const int length_sym = code - NUM_LITERAL_CODES;
1056
+ const int length = GetCopyLength(length_sym, br);
1057
+ const int dist_symbol = ReadSymbol(htree_group->htrees[DIST], br);
1058
+ VP8LFillBitWindow(br);
1059
+ dist_code = GetCopyDistance(dist_symbol, br);
1060
+ dist = PlaneCodeToDistance(width, dist_code);
1061
+ if (br->eos_) break;
1062
+ if (src - data < (ptrdiff_t)dist || src_end - src < (ptrdiff_t)length) {
1063
+ goto Error;
1064
+ } else {
1065
+ CopyBlock32b(src, dist, length);
1066
+ }
1067
+ src += length;
1068
+ col += length;
1069
+ while (col >= width) {
1070
+ col -= width;
1071
+ ++row;
1072
+ if ((row % NUM_ARGB_CACHE_ROWS == 0) && (process_func != NULL)) {
1073
+ process_func(dec, row);
1074
+ }
1075
+ }
1076
+ // Because of the check done above (before 'src' was incremented by
1077
+ // 'length'), the following holds true.
1078
+ assert(src <= src_end);
1079
+ if (col & mask) htree_group = GetHtreeGroupForPos(hdr, col, row);
1080
+ if (color_cache != NULL) {
1081
+ while (last_cached < src) {
1082
+ VP8LColorCacheInsert(color_cache, *last_cached++);
1083
+ }
1084
+ }
1085
+ } else if (code < color_cache_limit) { // Color cache
1086
+ const int key = code - len_code_limit;
1087
+ assert(color_cache != NULL);
1088
+ while (last_cached < src) {
1089
+ VP8LColorCacheInsert(color_cache, *last_cached++);
1090
+ }
1091
+ *src = VP8LColorCacheLookup(color_cache, key);
1092
+ goto AdvanceByOne;
1093
+ } else { // Not reached
1094
+ goto Error;
1095
+ }
1096
+ assert(br->eos_ == VP8LIsEndOfStream(br));
1097
+ }
1098
+
1099
+ if (dec->incremental_ && br->eos_ && src < src_end) {
1100
+ RestoreState(dec);
1101
+ } else if (!br->eos_) {
1102
+ // Process the remaining rows corresponding to last row-block.
1103
+ if (process_func != NULL) {
1104
+ process_func(dec, row);
1105
+ }
1106
+ dec->status_ = VP8_STATUS_OK;
1107
+ dec->last_pixel_ = (int)(src - data); // end-of-scan marker
1108
+ } else {
1109
+ // if not incremental, and we are past the end of buffer (eos_=1), then this
1110
+ // is a real bitstream error.
1111
+ goto Error;
1112
+ }
1113
+ return 1;
1114
+
1115
+ Error:
1116
+ dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
1117
+ return 0;
1118
+ }
1119
+
1120
+ // -----------------------------------------------------------------------------
1121
+ // VP8LTransform
1122
+
1123
+ static void ClearTransform(VP8LTransform* const transform) {
1124
+ WebPSafeFree(transform->data_);
1125
+ transform->data_ = NULL;
1126
+ }
1127
+
1128
+ // For security reason, we need to remap the color map to span
1129
+ // the total possible bundled values, and not just the num_colors.
1130
+ static int ExpandColorMap(int num_colors, VP8LTransform* const transform) {
1131
+ int i;
1132
+ const int final_num_colors = 1 << (8 >> transform->bits_);
1133
+ uint32_t* const new_color_map =
1134
+ (uint32_t*)WebPSafeMalloc((uint64_t)final_num_colors,
1135
+ sizeof(*new_color_map));
1136
+ if (new_color_map == NULL) {
1137
+ return 0;
1138
+ } else {
1139
+ uint8_t* const data = (uint8_t*)transform->data_;
1140
+ uint8_t* const new_data = (uint8_t*)new_color_map;
1141
+ new_color_map[0] = transform->data_[0];
1142
+ for (i = 4; i < 4 * num_colors; ++i) {
1143
+ // Equivalent to AddPixelEq(), on a byte-basis.
1144
+ new_data[i] = (data[i] + new_data[i - 4]) & 0xff;
1145
+ }
1146
+ for (; i < 4 * final_num_colors; ++i)
1147
+ new_data[i] = 0; // black tail.
1148
+ WebPSafeFree(transform->data_);
1149
+ transform->data_ = new_color_map;
1150
+ }
1151
+ return 1;
1152
+ }
1153
+
1154
+ static int ReadTransform(int* const xsize, int const* ysize,
1155
+ VP8LDecoder* const dec) {
1156
+ int ok = 1;
1157
+ VP8LBitReader* const br = &dec->br_;
1158
+ VP8LTransform* transform = &dec->transforms_[dec->next_transform_];
1159
+ const VP8LImageTransformType type =
1160
+ (VP8LImageTransformType)VP8LReadBits(br, 2);
1161
+
1162
+ // Each transform type can only be present once in the stream.
1163
+ if (dec->transforms_seen_ & (1U << type)) {
1164
+ return 0; // Already there, let's not accept the second same transform.
1165
+ }
1166
+ dec->transforms_seen_ |= (1U << type);
1167
+
1168
+ transform->type_ = type;
1169
+ transform->xsize_ = *xsize;
1170
+ transform->ysize_ = *ysize;
1171
+ transform->data_ = NULL;
1172
+ ++dec->next_transform_;
1173
+ assert(dec->next_transform_ <= NUM_TRANSFORMS);
1174
+
1175
+ switch (type) {
1176
+ case PREDICTOR_TRANSFORM:
1177
+ case CROSS_COLOR_TRANSFORM:
1178
+ transform->bits_ = VP8LReadBits(br, 3) + 2;
1179
+ ok = DecodeImageStream(VP8LSubSampleSize(transform->xsize_,
1180
+ transform->bits_),
1181
+ VP8LSubSampleSize(transform->ysize_,
1182
+ transform->bits_),
1183
+ 0, dec, &transform->data_);
1184
+ break;
1185
+ case COLOR_INDEXING_TRANSFORM: {
1186
+ const int num_colors = VP8LReadBits(br, 8) + 1;
1187
+ const int bits = (num_colors > 16) ? 0
1188
+ : (num_colors > 4) ? 1
1189
+ : (num_colors > 2) ? 2
1190
+ : 3;
1191
+ *xsize = VP8LSubSampleSize(transform->xsize_, bits);
1192
+ transform->bits_ = bits;
1193
+ ok = DecodeImageStream(num_colors, 1, 0, dec, &transform->data_);
1194
+ ok = ok && ExpandColorMap(num_colors, transform);
1195
+ break;
1196
+ }
1197
+ case SUBTRACT_GREEN:
1198
+ break;
1199
+ default:
1200
+ assert(0); // can't happen
1201
+ break;
1202
+ }
1203
+
1204
+ return ok;
1205
+ }
1206
+
1207
+ // -----------------------------------------------------------------------------
1208
+ // VP8LMetadata
1209
+
1210
+ static void InitMetadata(VP8LMetadata* const hdr) {
1211
+ assert(hdr != NULL);
1212
+ memset(hdr, 0, sizeof(*hdr));
1213
+ }
1214
+
1215
+ static void ClearMetadata(VP8LMetadata* const hdr) {
1216
+ assert(hdr != NULL);
1217
+
1218
+ WebPSafeFree(hdr->huffman_image_);
1219
+ WebPSafeFree(hdr->huffman_tables_);
1220
+ VP8LHtreeGroupsFree(hdr->htree_groups_);
1221
+ VP8LColorCacheClear(&hdr->color_cache_);
1222
+ VP8LColorCacheClear(&hdr->saved_color_cache_);
1223
+ InitMetadata(hdr);
1224
+ }
1225
+
1226
+ // -----------------------------------------------------------------------------
1227
+ // VP8LDecoder
1228
+
1229
+ VP8LDecoder* VP8LNew(void) {
1230
+ VP8LDecoder* const dec = (VP8LDecoder*)WebPSafeCalloc(1ULL, sizeof(*dec));
1231
+ if (dec == NULL) return NULL;
1232
+ dec->status_ = VP8_STATUS_OK;
1233
+ dec->state_ = READ_DIM;
1234
+
1235
+ VP8LDspInit(); // Init critical function pointers.
1236
+
1237
+ return dec;
1238
+ }
1239
+
1240
+ void VP8LClear(VP8LDecoder* const dec) {
1241
+ int i;
1242
+ if (dec == NULL) return;
1243
+ ClearMetadata(&dec->hdr_);
1244
+
1245
+ WebPSafeFree(dec->pixels_);
1246
+ dec->pixels_ = NULL;
1247
+ for (i = 0; i < dec->next_transform_; ++i) {
1248
+ ClearTransform(&dec->transforms_[i]);
1249
+ }
1250
+ dec->next_transform_ = 0;
1251
+ dec->transforms_seen_ = 0;
1252
+
1253
+ WebPSafeFree(dec->rescaler_memory);
1254
+ dec->rescaler_memory = NULL;
1255
+
1256
+ dec->output_ = NULL; // leave no trace behind
1257
+ }
1258
+
1259
+ void VP8LDelete(VP8LDecoder* const dec) {
1260
+ if (dec != NULL) {
1261
+ VP8LClear(dec);
1262
+ WebPSafeFree(dec);
1263
+ }
1264
+ }
1265
+
1266
+ static void UpdateDecoder(VP8LDecoder* const dec, int width, int height) {
1267
+ VP8LMetadata* const hdr = &dec->hdr_;
1268
+ const int num_bits = hdr->huffman_subsample_bits_;
1269
+ dec->width_ = width;
1270
+ dec->height_ = height;
1271
+
1272
+ hdr->huffman_xsize_ = VP8LSubSampleSize(width, num_bits);
1273
+ hdr->huffman_mask_ = (num_bits == 0) ? ~0 : (1 << num_bits) - 1;
1274
+ }
1275
+
1276
+ static int DecodeImageStream(int xsize, int ysize,
1277
+ int is_level0,
1278
+ VP8LDecoder* const dec,
1279
+ uint32_t** const decoded_data) {
1280
+ int ok = 1;
1281
+ int transform_xsize = xsize;
1282
+ int transform_ysize = ysize;
1283
+ VP8LBitReader* const br = &dec->br_;
1284
+ VP8LMetadata* const hdr = &dec->hdr_;
1285
+ uint32_t* data = NULL;
1286
+ int color_cache_bits = 0;
1287
+
1288
+ // Read the transforms (may recurse).
1289
+ if (is_level0) {
1290
+ while (ok && VP8LReadBits(br, 1)) {
1291
+ ok = ReadTransform(&transform_xsize, &transform_ysize, dec);
1292
+ }
1293
+ }
1294
+
1295
+ // Color cache
1296
+ if (ok && VP8LReadBits(br, 1)) {
1297
+ color_cache_bits = VP8LReadBits(br, 4);
1298
+ ok = (color_cache_bits >= 1 && color_cache_bits <= MAX_CACHE_BITS);
1299
+ if (!ok) {
1300
+ dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
1301
+ goto End;
1302
+ }
1303
+ }
1304
+
1305
+ // Read the Huffman codes (may recurse).
1306
+ ok = ok && ReadHuffmanCodes(dec, transform_xsize, transform_ysize,
1307
+ color_cache_bits, is_level0);
1308
+ if (!ok) {
1309
+ dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
1310
+ goto End;
1311
+ }
1312
+
1313
+ // Finish setting up the color-cache
1314
+ if (color_cache_bits > 0) {
1315
+ hdr->color_cache_size_ = 1 << color_cache_bits;
1316
+ if (!VP8LColorCacheInit(&hdr->color_cache_, color_cache_bits)) {
1317
+ dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1318
+ ok = 0;
1319
+ goto End;
1320
+ }
1321
+ } else {
1322
+ hdr->color_cache_size_ = 0;
1323
+ }
1324
+ UpdateDecoder(dec, transform_xsize, transform_ysize);
1325
+
1326
+ if (is_level0) { // level 0 complete
1327
+ dec->state_ = READ_HDR;
1328
+ goto End;
1329
+ }
1330
+
1331
+ {
1332
+ const uint64_t total_size = (uint64_t)transform_xsize * transform_ysize;
1333
+ data = (uint32_t*)WebPSafeMalloc(total_size, sizeof(*data));
1334
+ if (data == NULL) {
1335
+ dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1336
+ ok = 0;
1337
+ goto End;
1338
+ }
1339
+ }
1340
+
1341
+ // Use the Huffman trees to decode the LZ77 encoded data.
1342
+ ok = DecodeImageData(dec, data, transform_xsize, transform_ysize,
1343
+ transform_ysize, NULL);
1344
+ ok = ok && !br->eos_;
1345
+
1346
+ End:
1347
+ if (!ok) {
1348
+ WebPSafeFree(data);
1349
+ ClearMetadata(hdr);
1350
+ } else {
1351
+ if (decoded_data != NULL) {
1352
+ *decoded_data = data;
1353
+ } else {
1354
+ // We allocate image data in this function only for transforms. At level 0
1355
+ // (that is: not the transforms), we shouldn't have allocated anything.
1356
+ assert(data == NULL);
1357
+ assert(is_level0);
1358
+ }
1359
+ dec->last_pixel_ = 0; // Reset for future DECODE_DATA_FUNC() calls.
1360
+ if (!is_level0) ClearMetadata(hdr); // Clean up temporary data behind.
1361
+ }
1362
+ return ok;
1363
+ }
1364
+
1365
+ //------------------------------------------------------------------------------
1366
+ // Allocate internal buffers dec->pixels_ and dec->argb_cache_.
1367
+ static int AllocateInternalBuffers32b(VP8LDecoder* const dec, int final_width) {
1368
+ const uint64_t num_pixels = (uint64_t)dec->width_ * dec->height_;
1369
+ // Scratch buffer corresponding to top-prediction row for transforming the
1370
+ // first row in the row-blocks. Not needed for paletted alpha.
1371
+ const uint64_t cache_top_pixels = (uint16_t)final_width;
1372
+ // Scratch buffer for temporary BGRA storage. Not needed for paletted alpha.
1373
+ const uint64_t cache_pixels = (uint64_t)final_width * NUM_ARGB_CACHE_ROWS;
1374
+ const uint64_t total_num_pixels =
1375
+ num_pixels + cache_top_pixels + cache_pixels;
1376
+
1377
+ assert(dec->width_ <= final_width);
1378
+ dec->pixels_ = (uint32_t*)WebPSafeMalloc(total_num_pixels, sizeof(uint32_t));
1379
+ if (dec->pixels_ == NULL) {
1380
+ dec->argb_cache_ = NULL; // for sanity check
1381
+ dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1382
+ return 0;
1383
+ }
1384
+ dec->argb_cache_ = dec->pixels_ + num_pixels + cache_top_pixels;
1385
+ return 1;
1386
+ }
1387
+
1388
+ static int AllocateInternalBuffers8b(VP8LDecoder* const dec) {
1389
+ const uint64_t total_num_pixels = (uint64_t)dec->width_ * dec->height_;
1390
+ dec->argb_cache_ = NULL; // for sanity check
1391
+ dec->pixels_ = (uint32_t*)WebPSafeMalloc(total_num_pixels, sizeof(uint8_t));
1392
+ if (dec->pixels_ == NULL) {
1393
+ dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1394
+ return 0;
1395
+ }
1396
+ return 1;
1397
+ }
1398
+
1399
+ //------------------------------------------------------------------------------
1400
+
1401
+ // Special row-processing that only stores the alpha data.
1402
+ static void ExtractAlphaRows(VP8LDecoder* const dec, int row) {
1403
+ const int num_rows = row - dec->last_row_;
1404
+ const uint32_t* const in = dec->pixels_ + dec->width_ * dec->last_row_;
1405
+
1406
+ if (num_rows <= 0) return; // Nothing to be done.
1407
+ ApplyInverseTransforms(dec, num_rows, in);
1408
+
1409
+ // Extract alpha (which is stored in the green plane).
1410
+ {
1411
+ const int width = dec->io_->width; // the final width (!= dec->width_)
1412
+ const int cache_pixs = width * num_rows;
1413
+ uint8_t* const dst = (uint8_t*)dec->io_->opaque + width * dec->last_row_;
1414
+ const uint32_t* const src = dec->argb_cache_;
1415
+ int i;
1416
+ for (i = 0; i < cache_pixs; ++i) dst[i] = (src[i] >> 8) & 0xff;
1417
+ }
1418
+ dec->last_row_ = dec->last_out_row_ = row;
1419
+ }
1420
+
1421
+ int VP8LDecodeAlphaHeader(ALPHDecoder* const alph_dec,
1422
+ const uint8_t* const data, size_t data_size,
1423
+ uint8_t* const output) {
1424
+ int ok = 0;
1425
+ VP8LDecoder* dec;
1426
+ VP8Io* io;
1427
+ assert(alph_dec != NULL);
1428
+ alph_dec->vp8l_dec_ = VP8LNew();
1429
+ if (alph_dec->vp8l_dec_ == NULL) return 0;
1430
+ dec = alph_dec->vp8l_dec_;
1431
+
1432
+ dec->width_ = alph_dec->width_;
1433
+ dec->height_ = alph_dec->height_;
1434
+ dec->io_ = &alph_dec->io_;
1435
+ io = dec->io_;
1436
+
1437
+ VP8InitIo(io);
1438
+ WebPInitCustomIo(NULL, io); // Just a sanity Init. io won't be used.
1439
+ io->opaque = output;
1440
+ io->width = alph_dec->width_;
1441
+ io->height = alph_dec->height_;
1442
+
1443
+ dec->status_ = VP8_STATUS_OK;
1444
+ VP8LInitBitReader(&dec->br_, data, data_size);
1445
+
1446
+ if (!DecodeImageStream(alph_dec->width_, alph_dec->height_, 1, dec, NULL)) {
1447
+ goto Err;
1448
+ }
1449
+
1450
+ // Special case: if alpha data uses only the color indexing transform and
1451
+ // doesn't use color cache (a frequent case), we will use DecodeAlphaData()
1452
+ // method that only needs allocation of 1 byte per pixel (alpha channel).
1453
+ if (dec->next_transform_ == 1 &&
1454
+ dec->transforms_[0].type_ == COLOR_INDEXING_TRANSFORM &&
1455
+ Is8bOptimizable(&dec->hdr_)) {
1456
+ alph_dec->use_8b_decode = 1;
1457
+ ok = AllocateInternalBuffers8b(dec);
1458
+ } else {
1459
+ // Allocate internal buffers (note that dec->width_ may have changed here).
1460
+ alph_dec->use_8b_decode = 0;
1461
+ ok = AllocateInternalBuffers32b(dec, alph_dec->width_);
1462
+ }
1463
+
1464
+ if (!ok) goto Err;
1465
+
1466
+ return 1;
1467
+
1468
+ Err:
1469
+ VP8LDelete(alph_dec->vp8l_dec_);
1470
+ alph_dec->vp8l_dec_ = NULL;
1471
+ return 0;
1472
+ }
1473
+
1474
+ int VP8LDecodeAlphaImageStream(ALPHDecoder* const alph_dec, int last_row) {
1475
+ VP8LDecoder* const dec = alph_dec->vp8l_dec_;
1476
+ assert(dec != NULL);
1477
+ assert(last_row <= dec->height_);
1478
+
1479
+ if (dec->last_pixel_ == dec->width_ * dec->height_) {
1480
+ return 1; // done
1481
+ }
1482
+
1483
+ // Decode (with special row processing).
1484
+ return alph_dec->use_8b_decode ?
1485
+ DecodeAlphaData(dec, (uint8_t*)dec->pixels_, dec->width_, dec->height_,
1486
+ last_row) :
1487
+ DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_,
1488
+ last_row, ExtractAlphaRows);
1489
+ }
1490
+
1491
+ //------------------------------------------------------------------------------
1492
+
1493
+ int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io) {
1494
+ int width, height, has_alpha;
1495
+
1496
+ if (dec == NULL) return 0;
1497
+ if (io == NULL) {
1498
+ dec->status_ = VP8_STATUS_INVALID_PARAM;
1499
+ return 0;
1500
+ }
1501
+
1502
+ dec->io_ = io;
1503
+ dec->status_ = VP8_STATUS_OK;
1504
+ VP8LInitBitReader(&dec->br_, io->data, io->data_size);
1505
+ if (!ReadImageInfo(&dec->br_, &width, &height, &has_alpha)) {
1506
+ dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
1507
+ goto Error;
1508
+ }
1509
+ dec->state_ = READ_DIM;
1510
+ io->width = width;
1511
+ io->height = height;
1512
+
1513
+ if (!DecodeImageStream(width, height, 1, dec, NULL)) goto Error;
1514
+ return 1;
1515
+
1516
+ Error:
1517
+ VP8LClear(dec);
1518
+ assert(dec->status_ != VP8_STATUS_OK);
1519
+ return 0;
1520
+ }
1521
+
1522
+ int VP8LDecodeImage(VP8LDecoder* const dec) {
1523
+ VP8Io* io = NULL;
1524
+ WebPDecParams* params = NULL;
1525
+
1526
+ // Sanity checks.
1527
+ if (dec == NULL) return 0;
1528
+
1529
+ assert(dec->hdr_.huffman_tables_ != NULL);
1530
+ assert(dec->hdr_.htree_groups_ != NULL);
1531
+ assert(dec->hdr_.num_htree_groups_ > 0);
1532
+
1533
+ io = dec->io_;
1534
+ assert(io != NULL);
1535
+ params = (WebPDecParams*)io->opaque;
1536
+ assert(params != NULL);
1537
+
1538
+ // Initialization.
1539
+ if (dec->state_ != READ_DATA) {
1540
+ dec->output_ = params->output;
1541
+ assert(dec->output_ != NULL);
1542
+
1543
+ if (!WebPIoInitFromOptions(params->options, io, MODE_BGRA)) {
1544
+ dec->status_ = VP8_STATUS_INVALID_PARAM;
1545
+ goto Err;
1546
+ }
1547
+
1548
+ if (!AllocateInternalBuffers32b(dec, io->width)) goto Err;
1549
+
1550
+ if (io->use_scaling && !AllocateAndInitRescaler(dec, io)) goto Err;
1551
+
1552
+ if (io->use_scaling || WebPIsPremultipliedMode(dec->output_->colorspace)) {
1553
+ // need the alpha-multiply functions for premultiplied output or rescaling
1554
+ WebPInitAlphaProcessing();
1555
+ }
1556
+ if (dec->incremental_) {
1557
+ if (dec->hdr_.color_cache_size_ > 0 &&
1558
+ dec->hdr_.saved_color_cache_.colors_ == NULL) {
1559
+ if (!VP8LColorCacheInit(&dec->hdr_.saved_color_cache_,
1560
+ dec->hdr_.color_cache_.hash_bits_)) {
1561
+ dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1562
+ goto Err;
1563
+ }
1564
+ }
1565
+ }
1566
+ dec->state_ = READ_DATA;
1567
+ }
1568
+
1569
+ // Decode.
1570
+ if (!DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_,
1571
+ dec->height_, ProcessRows)) {
1572
+ goto Err;
1573
+ }
1574
+
1575
+ params->last_y = dec->last_out_row_;
1576
+ return 1;
1577
+
1578
+ Err:
1579
+ VP8LClear(dec);
1580
+ assert(dec->status_ != VP8_STATUS_OK);
1581
+ return 0;
1582
+ }
1583
+
1584
+ //------------------------------------------------------------------------------