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,2354 @@
1
+ /* $Id: tif_jpeg.c,v 1.11 2015/02/19 22:39:58 drolon Exp $ */
2
+
3
+ /*
4
+ * Copyright (c) 1994-1997 Sam Leffler
5
+ * Copyright (c) 1994-1997 Silicon Graphics, Inc.
6
+ *
7
+ * Permission to use, copy, modify, distribute, and sell this software and
8
+ * its documentation for any purpose is hereby granted without fee, provided
9
+ * that (i) the above copyright notices and this permission notice appear in
10
+ * all copies of the software and related documentation, and (ii) the names of
11
+ * Sam Leffler and Silicon Graphics may not be used in any advertising or
12
+ * publicity relating to the software without the specific, prior written
13
+ * permission of Sam Leffler and Silicon Graphics.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18
+ *
19
+ * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20
+ * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21
+ * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24
+ * OF THIS SOFTWARE.
25
+ */
26
+
27
+ #define WIN32_LEAN_AND_MEAN
28
+ #define VC_EXTRALEAN
29
+
30
+ #include "tiffiop.h"
31
+ #ifdef JPEG_SUPPORT
32
+
33
+ /*
34
+ * TIFF Library
35
+ *
36
+ * JPEG Compression support per TIFF Technical Note #2
37
+ * (*not* per the original TIFF 6.0 spec).
38
+ *
39
+ * This file is simply an interface to the libjpeg library written by
40
+ * the Independent JPEG Group. You need release 5 or later of the IJG
41
+ * code, which you can find on the Internet at ftp.uu.net:/graphics/jpeg/.
42
+ *
43
+ * Contributed by Tom Lane <tgl@sss.pgh.pa.us>.
44
+ */
45
+ #include <setjmp.h>
46
+
47
+ int TIFFFillStrip(TIFF* tif, uint32 strip);
48
+ int TIFFFillTile(TIFF* tif, uint32 tile);
49
+ int TIFFReInitJPEG_12( TIFF *tif, int scheme, int is_encode );
50
+
51
+ /* We undefine FAR to avoid conflict with JPEG definition */
52
+
53
+ #ifdef FAR
54
+ #undef FAR
55
+ #endif
56
+
57
+ /*
58
+ Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is
59
+ not defined. Unfortunately, the MinGW and Borland compilers include
60
+ a typedef for INT32, which causes a conflict. MSVC does not include
61
+ a conficting typedef given the headers which are included.
62
+ */
63
+ #if defined(__BORLANDC__) || defined(__MINGW32__)
64
+ # define XMD_H 1
65
+ #endif
66
+
67
+ /*
68
+ The windows RPCNDR.H file defines boolean, but defines it with the
69
+ unsigned char size. You should compile JPEG library using appropriate
70
+ definitions in jconfig.h header, but many users compile library in wrong
71
+ way. That causes errors of the following type:
72
+
73
+ "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
74
+ caller expects 464"
75
+
76
+ For such users we wil fix the problem here. See install.doc file from
77
+ the JPEG library distribution for details.
78
+ */
79
+
80
+ /* Define "boolean" as unsigned char, not int, per Windows custom. */
81
+ #if defined(__WIN32__) && !defined(__MINGW32__)
82
+ # ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
83
+ typedef unsigned char boolean;
84
+ # endif
85
+ # define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
86
+ #endif
87
+
88
+ #include "../LibJPEG/jpeglib.h"
89
+ #include "../LibJPEG/jerror.h"
90
+
91
+ /*
92
+ * Do we want to do special processing suitable for when JSAMPLE is a
93
+ * 16bit value?
94
+ */
95
+
96
+ #if defined(JPEG_LIB_MK1)
97
+ # define JPEG_LIB_MK1_OR_12BIT 1
98
+ #elif BITS_IN_JSAMPLE == 12
99
+ # define JPEG_LIB_MK1_OR_12BIT 1
100
+ #endif
101
+
102
+ /*
103
+ * We are using width_in_blocks which is supposed to be private to
104
+ * libjpeg. Unfortunately, the libjpeg delivered with Cygwin has
105
+ * renamed this member to width_in_data_units. Since the header has
106
+ * also renamed a define, use that unique define name in order to
107
+ * detect the problem header and adjust to suit.
108
+ */
109
+ #if defined(D_MAX_DATA_UNITS_IN_MCU)
110
+ #define width_in_blocks width_in_data_units
111
+ #endif
112
+
113
+ /*
114
+ * On some machines it may be worthwhile to use _setjmp or sigsetjmp
115
+ * in place of plain setjmp. These macros will make it easier.
116
+ */
117
+ #define SETJMP(jbuf) setjmp(jbuf)
118
+ #define LONGJMP(jbuf,code) longjmp(jbuf,code)
119
+ #define JMP_BUF jmp_buf
120
+
121
+ typedef struct jpeg_destination_mgr jpeg_destination_mgr;
122
+ typedef struct jpeg_source_mgr jpeg_source_mgr;
123
+ typedef struct jpeg_error_mgr jpeg_error_mgr;
124
+
125
+ /*
126
+ * State block for each open TIFF file using
127
+ * libjpeg to do JPEG compression/decompression.
128
+ *
129
+ * libjpeg's visible state is either a jpeg_compress_struct
130
+ * or jpeg_decompress_struct depending on which way we
131
+ * are going. comm can be used to refer to the fields
132
+ * which are common to both.
133
+ *
134
+ * NB: cinfo is required to be the first member of JPEGState,
135
+ * so we can safely cast JPEGState* -> jpeg_xxx_struct*
136
+ * and vice versa!
137
+ */
138
+ typedef struct {
139
+ union {
140
+ struct jpeg_compress_struct c;
141
+ struct jpeg_decompress_struct d;
142
+ struct jpeg_common_struct comm;
143
+ } cinfo; /* NB: must be first */
144
+ int cinfo_initialized;
145
+
146
+ jpeg_error_mgr err; /* libjpeg error manager */
147
+ JMP_BUF exit_jmpbuf; /* for catching libjpeg failures */
148
+ /*
149
+ * The following two members could be a union, but
150
+ * they're small enough that it's not worth the effort.
151
+ */
152
+ jpeg_destination_mgr dest; /* data dest for compression */
153
+ jpeg_source_mgr src; /* data source for decompression */
154
+ /* private state */
155
+ TIFF* tif; /* back link needed by some code */
156
+ uint16 photometric; /* copy of PhotometricInterpretation */
157
+ uint16 h_sampling; /* luminance sampling factors */
158
+ uint16 v_sampling;
159
+ tmsize_t bytesperline; /* decompressed bytes per scanline */
160
+ /* pointers to intermediate buffers when processing downsampled data */
161
+ JSAMPARRAY ds_buffer[MAX_COMPONENTS];
162
+ int scancount; /* number of "scanlines" accumulated */
163
+ int samplesperclump;
164
+
165
+ TIFFVGetMethod vgetparent; /* super-class method */
166
+ TIFFVSetMethod vsetparent; /* super-class method */
167
+ TIFFPrintMethod printdir; /* super-class method */
168
+ TIFFStripMethod defsparent; /* super-class method */
169
+ TIFFTileMethod deftparent; /* super-class method */
170
+ /* pseudo-tag fields */
171
+ void* jpegtables; /* JPEGTables tag value, or NULL */
172
+ uint32 jpegtables_length; /* number of bytes in same */
173
+ int jpegquality; /* Compression quality level */
174
+ int jpegcolormode; /* Auto RGB<=>YCbCr convert? */
175
+ int jpegtablesmode; /* What to put in JPEGTables */
176
+
177
+ int ycbcrsampling_fetched;
178
+ } JPEGState;
179
+
180
+ #define JState(tif) ((JPEGState*)(tif)->tif_data)
181
+
182
+ static int JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
183
+ static int JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
184
+ static int JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
185
+ static int JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
186
+ static int JPEGInitializeLibJPEG(TIFF * tif, int decode );
187
+ static int DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
188
+
189
+ #define FIELD_JPEGTABLES (FIELD_CODEC+0)
190
+
191
+ static const TIFFField jpegFields[] = {
192
+ { TIFFTAG_JPEGTABLES, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_C32_UINT8, FIELD_JPEGTABLES, FALSE, TRUE, "JPEGTables", NULL },
193
+ { TIFFTAG_JPEGQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
194
+ { TIFFTAG_JPEGCOLORMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL },
195
+ { TIFFTAG_JPEGTABLESMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL }
196
+ };
197
+
198
+ /*
199
+ * libjpeg interface layer.
200
+ *
201
+ * We use setjmp/longjmp to return control to libtiff
202
+ * when a fatal error is encountered within the JPEG
203
+ * library. We also direct libjpeg error and warning
204
+ * messages through the appropriate libtiff handlers.
205
+ */
206
+
207
+ /*
208
+ * Error handling routines (these replace corresponding
209
+ * IJG routines from jerror.c). These are used for both
210
+ * compression and decompression.
211
+ */
212
+ static void
213
+ TIFFjpeg_error_exit(j_common_ptr cinfo)
214
+ {
215
+ JPEGState *sp = (JPEGState *) cinfo; /* NB: cinfo assumed first */
216
+ char buffer[JMSG_LENGTH_MAX];
217
+
218
+ (*cinfo->err->format_message) (cinfo, buffer);
219
+ TIFFErrorExt(sp->tif->tif_clientdata, "JPEGLib", "%s", buffer); /* display the error message */
220
+ jpeg_abort(cinfo); /* clean up libjpeg state */
221
+ LONGJMP(sp->exit_jmpbuf, 1); /* return to libtiff caller */
222
+ }
223
+
224
+ /*
225
+ * This routine is invoked only for warning messages,
226
+ * since error_exit does its own thing and trace_level
227
+ * is never set > 0.
228
+ */
229
+ static void
230
+ TIFFjpeg_output_message(j_common_ptr cinfo)
231
+ {
232
+ char buffer[JMSG_LENGTH_MAX];
233
+
234
+ (*cinfo->err->format_message) (cinfo, buffer);
235
+ TIFFWarningExt(((JPEGState *) cinfo)->tif->tif_clientdata, "JPEGLib", "%s", buffer);
236
+ }
237
+
238
+ /*
239
+ * Interface routines. This layer of routines exists
240
+ * primarily to limit side-effects from using setjmp.
241
+ * Also, normal/error returns are converted into return
242
+ * values per libtiff practice.
243
+ */
244
+ #define CALLJPEG(sp, fail, op) (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op))
245
+ #define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op),1))
246
+
247
+ static int
248
+ TIFFjpeg_create_compress(JPEGState* sp)
249
+ {
250
+ /* initialize JPEG error handling */
251
+ sp->cinfo.c.err = jpeg_std_error(&sp->err);
252
+ sp->err.error_exit = TIFFjpeg_error_exit;
253
+ sp->err.output_message = TIFFjpeg_output_message;
254
+
255
+ return CALLVJPEG(sp, jpeg_create_compress(&sp->cinfo.c));
256
+ }
257
+
258
+ static int
259
+ TIFFjpeg_create_decompress(JPEGState* sp)
260
+ {
261
+ /* initialize JPEG error handling */
262
+ sp->cinfo.d.err = jpeg_std_error(&sp->err);
263
+ sp->err.error_exit = TIFFjpeg_error_exit;
264
+ sp->err.output_message = TIFFjpeg_output_message;
265
+
266
+ return CALLVJPEG(sp, jpeg_create_decompress(&sp->cinfo.d));
267
+ }
268
+
269
+ static int
270
+ TIFFjpeg_set_defaults(JPEGState* sp)
271
+ {
272
+ return CALLVJPEG(sp, jpeg_set_defaults(&sp->cinfo.c));
273
+ }
274
+
275
+ static int
276
+ TIFFjpeg_set_colorspace(JPEGState* sp, J_COLOR_SPACE colorspace)
277
+ {
278
+ return CALLVJPEG(sp, jpeg_set_colorspace(&sp->cinfo.c, colorspace));
279
+ }
280
+
281
+ static int
282
+ TIFFjpeg_set_quality(JPEGState* sp, int quality, boolean force_baseline)
283
+ {
284
+ return CALLVJPEG(sp,
285
+ jpeg_set_quality(&sp->cinfo.c, quality, force_baseline));
286
+ }
287
+
288
+ static int
289
+ TIFFjpeg_suppress_tables(JPEGState* sp, boolean suppress)
290
+ {
291
+ return CALLVJPEG(sp, jpeg_suppress_tables(&sp->cinfo.c, suppress));
292
+ }
293
+
294
+ static int
295
+ TIFFjpeg_start_compress(JPEGState* sp, boolean write_all_tables)
296
+ {
297
+ return CALLVJPEG(sp,
298
+ jpeg_start_compress(&sp->cinfo.c, write_all_tables));
299
+ }
300
+
301
+ static int
302
+ TIFFjpeg_write_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int num_lines)
303
+ {
304
+ return CALLJPEG(sp, -1, (int) jpeg_write_scanlines(&sp->cinfo.c,
305
+ scanlines, (JDIMENSION) num_lines));
306
+ }
307
+
308
+ static int
309
+ TIFFjpeg_write_raw_data(JPEGState* sp, JSAMPIMAGE data, int num_lines)
310
+ {
311
+ return CALLJPEG(sp, -1, (int) jpeg_write_raw_data(&sp->cinfo.c,
312
+ data, (JDIMENSION) num_lines));
313
+ }
314
+
315
+ static int
316
+ TIFFjpeg_finish_compress(JPEGState* sp)
317
+ {
318
+ return CALLVJPEG(sp, jpeg_finish_compress(&sp->cinfo.c));
319
+ }
320
+
321
+ static int
322
+ TIFFjpeg_write_tables(JPEGState* sp)
323
+ {
324
+ return CALLVJPEG(sp, jpeg_write_tables(&sp->cinfo.c));
325
+ }
326
+
327
+ static int
328
+ TIFFjpeg_read_header(JPEGState* sp, boolean require_image)
329
+ {
330
+ return CALLJPEG(sp, -1, jpeg_read_header(&sp->cinfo.d, require_image));
331
+ }
332
+
333
+ static int
334
+ TIFFjpeg_start_decompress(JPEGState* sp)
335
+ {
336
+ return CALLVJPEG(sp, jpeg_start_decompress(&sp->cinfo.d));
337
+ }
338
+
339
+ static int
340
+ TIFFjpeg_read_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int max_lines)
341
+ {
342
+ return CALLJPEG(sp, -1, (int) jpeg_read_scanlines(&sp->cinfo.d,
343
+ scanlines, (JDIMENSION) max_lines));
344
+ }
345
+
346
+ static int
347
+ TIFFjpeg_read_raw_data(JPEGState* sp, JSAMPIMAGE data, int max_lines)
348
+ {
349
+ return CALLJPEG(sp, -1, (int) jpeg_read_raw_data(&sp->cinfo.d,
350
+ data, (JDIMENSION) max_lines));
351
+ }
352
+
353
+ static int
354
+ TIFFjpeg_finish_decompress(JPEGState* sp)
355
+ {
356
+ return CALLJPEG(sp, -1, (int) jpeg_finish_decompress(&sp->cinfo.d));
357
+ }
358
+
359
+ static int
360
+ TIFFjpeg_abort(JPEGState* sp)
361
+ {
362
+ return CALLVJPEG(sp, jpeg_abort(&sp->cinfo.comm));
363
+ }
364
+
365
+ static int
366
+ TIFFjpeg_destroy(JPEGState* sp)
367
+ {
368
+ return CALLVJPEG(sp, jpeg_destroy(&sp->cinfo.comm));
369
+ }
370
+
371
+ static JSAMPARRAY
372
+ TIFFjpeg_alloc_sarray(JPEGState* sp, int pool_id,
373
+ JDIMENSION samplesperrow, JDIMENSION numrows)
374
+ {
375
+ return CALLJPEG(sp, (JSAMPARRAY) NULL,
376
+ (*sp->cinfo.comm.mem->alloc_sarray)
377
+ (&sp->cinfo.comm, pool_id, samplesperrow, numrows));
378
+ }
379
+
380
+ /*
381
+ * JPEG library destination data manager.
382
+ * These routines direct compressed data from libjpeg into the
383
+ * libtiff output buffer.
384
+ */
385
+
386
+ static void
387
+ std_init_destination(j_compress_ptr cinfo)
388
+ {
389
+ JPEGState* sp = (JPEGState*) cinfo;
390
+ TIFF* tif = sp->tif;
391
+
392
+ sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata;
393
+ sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize;
394
+ }
395
+
396
+ static boolean
397
+ std_empty_output_buffer(j_compress_ptr cinfo)
398
+ {
399
+ JPEGState* sp = (JPEGState*) cinfo;
400
+ TIFF* tif = sp->tif;
401
+
402
+ /* the entire buffer has been filled */
403
+ tif->tif_rawcc = tif->tif_rawdatasize;
404
+
405
+ #ifdef IPPJ_HUFF
406
+ /*
407
+ * The Intel IPP performance library does not necessarily fill up
408
+ * the whole output buffer on each pass, so only dump out the parts
409
+ * that have been filled.
410
+ * http://trac.osgeo.org/gdal/wiki/JpegIPP
411
+ */
412
+ if ( sp->dest.free_in_buffer >= 0 ) {
413
+ tif->tif_rawcc = tif->tif_rawdatasize - sp->dest.free_in_buffer;
414
+ }
415
+ #endif
416
+
417
+ TIFFFlushData1(tif);
418
+ sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata;
419
+ sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize;
420
+
421
+ return (TRUE);
422
+ }
423
+
424
+ static void
425
+ std_term_destination(j_compress_ptr cinfo)
426
+ {
427
+ JPEGState* sp = (JPEGState*) cinfo;
428
+ TIFF* tif = sp->tif;
429
+
430
+ tif->tif_rawcp = (uint8*) sp->dest.next_output_byte;
431
+ tif->tif_rawcc =
432
+ tif->tif_rawdatasize - (tmsize_t) sp->dest.free_in_buffer;
433
+ /* NB: libtiff does the final buffer flush */
434
+ }
435
+
436
+ static void
437
+ TIFFjpeg_data_dest(JPEGState* sp, TIFF* tif)
438
+ {
439
+ (void) tif;
440
+ sp->cinfo.c.dest = &sp->dest;
441
+ sp->dest.init_destination = std_init_destination;
442
+ sp->dest.empty_output_buffer = std_empty_output_buffer;
443
+ sp->dest.term_destination = std_term_destination;
444
+ }
445
+
446
+ /*
447
+ * Alternate destination manager for outputting to JPEGTables field.
448
+ */
449
+
450
+ static void
451
+ tables_init_destination(j_compress_ptr cinfo)
452
+ {
453
+ JPEGState* sp = (JPEGState*) cinfo;
454
+
455
+ /* while building, jpegtables_length is allocated buffer size */
456
+ sp->dest.next_output_byte = (JOCTET*) sp->jpegtables;
457
+ sp->dest.free_in_buffer = (size_t) sp->jpegtables_length;
458
+ }
459
+
460
+ static boolean
461
+ tables_empty_output_buffer(j_compress_ptr cinfo)
462
+ {
463
+ JPEGState* sp = (JPEGState*) cinfo;
464
+ void* newbuf;
465
+
466
+ /* the entire buffer has been filled; enlarge it by 1000 bytes */
467
+ newbuf = _TIFFrealloc((void*) sp->jpegtables,
468
+ (tmsize_t) (sp->jpegtables_length + 1000));
469
+ if (newbuf == NULL)
470
+ ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 100);
471
+ sp->dest.next_output_byte = (JOCTET*) newbuf + sp->jpegtables_length;
472
+ sp->dest.free_in_buffer = (size_t) 1000;
473
+ sp->jpegtables = newbuf;
474
+ sp->jpegtables_length += 1000;
475
+ return (TRUE);
476
+ }
477
+
478
+ static void
479
+ tables_term_destination(j_compress_ptr cinfo)
480
+ {
481
+ JPEGState* sp = (JPEGState*) cinfo;
482
+
483
+ /* set tables length to number of bytes actually emitted */
484
+ sp->jpegtables_length -= (uint32) sp->dest.free_in_buffer;
485
+ }
486
+
487
+ static int
488
+ TIFFjpeg_tables_dest(JPEGState* sp, TIFF* tif)
489
+ {
490
+ (void) tif;
491
+ /*
492
+ * Allocate a working buffer for building tables.
493
+ * Initial size is 1000 bytes, which is usually adequate.
494
+ */
495
+ if (sp->jpegtables)
496
+ _TIFFfree(sp->jpegtables);
497
+ sp->jpegtables_length = 1000;
498
+ sp->jpegtables = (void*) _TIFFmalloc((tmsize_t) sp->jpegtables_length);
499
+ if (sp->jpegtables == NULL) {
500
+ sp->jpegtables_length = 0;
501
+ TIFFErrorExt(sp->tif->tif_clientdata, "TIFFjpeg_tables_dest", "No space for JPEGTables");
502
+ return (0);
503
+ }
504
+ sp->cinfo.c.dest = &sp->dest;
505
+ sp->dest.init_destination = tables_init_destination;
506
+ sp->dest.empty_output_buffer = tables_empty_output_buffer;
507
+ sp->dest.term_destination = tables_term_destination;
508
+ return (1);
509
+ }
510
+
511
+ /*
512
+ * JPEG library source data manager.
513
+ * These routines supply compressed data to libjpeg.
514
+ */
515
+
516
+ static void
517
+ std_init_source(j_decompress_ptr cinfo)
518
+ {
519
+ JPEGState* sp = (JPEGState*) cinfo;
520
+ TIFF* tif = sp->tif;
521
+
522
+ sp->src.next_input_byte = (const JOCTET*) tif->tif_rawdata;
523
+ sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc;
524
+ }
525
+
526
+ static boolean
527
+ std_fill_input_buffer(j_decompress_ptr cinfo)
528
+ {
529
+ JPEGState* sp = (JPEGState* ) cinfo;
530
+ static const JOCTET dummy_EOI[2] = { 0xFF, JPEG_EOI };
531
+
532
+ #ifdef IPPJ_HUFF
533
+ /*
534
+ * The Intel IPP performance library does not necessarily read the whole
535
+ * input buffer in one pass, so it is possible to get here with data
536
+ * yet to read.
537
+ *
538
+ * We just return without doing anything, until the entire buffer has
539
+ * been read.
540
+ * http://trac.osgeo.org/gdal/wiki/JpegIPP
541
+ */
542
+ if( sp->src.bytes_in_buffer > 0 ) {
543
+ return (TRUE);
544
+ }
545
+ #endif
546
+
547
+ /*
548
+ * Normally the whole strip/tile is read and so we don't need to do
549
+ * a fill. In the case of CHUNKY_STRIP_READ_SUPPORT we might not have
550
+ * all the data, but the rawdata is refreshed between scanlines and
551
+ * we push this into the io machinery in JPEGDecode().
552
+ * http://trac.osgeo.org/gdal/ticket/3894
553
+ */
554
+
555
+ WARNMS(cinfo, JWRN_JPEG_EOF);
556
+ /* insert a fake EOI marker */
557
+ sp->src.next_input_byte = dummy_EOI;
558
+ sp->src.bytes_in_buffer = 2;
559
+ return (TRUE);
560
+ }
561
+
562
+ static void
563
+ std_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
564
+ {
565
+ JPEGState* sp = (JPEGState*) cinfo;
566
+
567
+ if (num_bytes > 0) {
568
+ if ((size_t)num_bytes > sp->src.bytes_in_buffer) {
569
+ /* oops, buffer overrun */
570
+ (void) std_fill_input_buffer(cinfo);
571
+ } else {
572
+ sp->src.next_input_byte += (size_t) num_bytes;
573
+ sp->src.bytes_in_buffer -= (size_t) num_bytes;
574
+ }
575
+ }
576
+ }
577
+
578
+ static void
579
+ std_term_source(j_decompress_ptr cinfo)
580
+ {
581
+ /* No work necessary here */
582
+ (void) cinfo;
583
+ }
584
+
585
+ static void
586
+ TIFFjpeg_data_src(JPEGState* sp, TIFF* tif)
587
+ {
588
+ (void) tif;
589
+ sp->cinfo.d.src = &sp->src;
590
+ sp->src.init_source = std_init_source;
591
+ sp->src.fill_input_buffer = std_fill_input_buffer;
592
+ sp->src.skip_input_data = std_skip_input_data;
593
+ sp->src.resync_to_restart = jpeg_resync_to_restart;
594
+ sp->src.term_source = std_term_source;
595
+ sp->src.bytes_in_buffer = 0; /* for safety */
596
+ sp->src.next_input_byte = NULL;
597
+ }
598
+
599
+ /*
600
+ * Alternate source manager for reading from JPEGTables.
601
+ * We can share all the code except for the init routine.
602
+ */
603
+
604
+ static void
605
+ tables_init_source(j_decompress_ptr cinfo)
606
+ {
607
+ JPEGState* sp = (JPEGState*) cinfo;
608
+
609
+ sp->src.next_input_byte = (const JOCTET*) sp->jpegtables;
610
+ sp->src.bytes_in_buffer = (size_t) sp->jpegtables_length;
611
+ }
612
+
613
+ static void
614
+ TIFFjpeg_tables_src(JPEGState* sp, TIFF* tif)
615
+ {
616
+ TIFFjpeg_data_src(sp, tif);
617
+ sp->src.init_source = tables_init_source;
618
+ }
619
+
620
+ /*
621
+ * Allocate downsampled-data buffers needed for downsampled I/O.
622
+ * We use values computed in jpeg_start_compress or jpeg_start_decompress.
623
+ * We use libjpeg's allocator so that buffers will be released automatically
624
+ * when done with strip/tile.
625
+ * This is also a handy place to compute samplesperclump, bytesperline.
626
+ */
627
+ static int
628
+ alloc_downsampled_buffers(TIFF* tif, jpeg_component_info* comp_info,
629
+ int num_components)
630
+ {
631
+ JPEGState* sp = JState(tif);
632
+ int ci;
633
+ jpeg_component_info* compptr;
634
+ JSAMPARRAY buf;
635
+ int samples_per_clump = 0;
636
+
637
+ for (ci = 0, compptr = comp_info; ci < num_components;
638
+ ci++, compptr++) {
639
+ samples_per_clump += compptr->h_samp_factor *
640
+ compptr->v_samp_factor;
641
+ buf = TIFFjpeg_alloc_sarray(sp, JPOOL_IMAGE,
642
+ compptr->width_in_blocks * DCTSIZE,
643
+ (JDIMENSION) (compptr->v_samp_factor*DCTSIZE));
644
+ if (buf == NULL)
645
+ return (0);
646
+ sp->ds_buffer[ci] = buf;
647
+ }
648
+ sp->samplesperclump = samples_per_clump;
649
+ return (1);
650
+ }
651
+
652
+
653
+ /*
654
+ * JPEG Decoding.
655
+ */
656
+
657
+ #ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
658
+
659
+ #define JPEG_MARKER_SOF0 0xC0
660
+ #define JPEG_MARKER_SOF1 0xC1
661
+ #define JPEG_MARKER_SOF2 0xC2
662
+ #define JPEG_MARKER_SOF9 0xC9
663
+ #define JPEG_MARKER_SOF10 0xCA
664
+ #define JPEG_MARKER_DHT 0xC4
665
+ #define JPEG_MARKER_SOI 0xD8
666
+ #define JPEG_MARKER_SOS 0xDA
667
+ #define JPEG_MARKER_DQT 0xDB
668
+ #define JPEG_MARKER_DRI 0xDD
669
+ #define JPEG_MARKER_APP0 0xE0
670
+ #define JPEG_MARKER_COM 0xFE
671
+ struct JPEGFixupTagsSubsamplingData
672
+ {
673
+ TIFF* tif;
674
+ void* buffer;
675
+ uint32 buffersize;
676
+ uint8* buffercurrentbyte;
677
+ uint32 bufferbytesleft;
678
+ uint64 fileoffset;
679
+ uint64 filebytesleft;
680
+ uint8 filepositioned;
681
+ };
682
+ static void JPEGFixupTagsSubsampling(TIFF* tif);
683
+ static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data);
684
+ static int JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result);
685
+ static int JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result);
686
+ static void JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength);
687
+
688
+ #endif
689
+
690
+ static int
691
+ JPEGFixupTags(TIFF* tif)
692
+ {
693
+ #ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
694
+ if ((tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR)&&
695
+ (tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&&
696
+ (tif->tif_dir.td_samplesperpixel==3))
697
+ JPEGFixupTagsSubsampling(tif);
698
+ #endif
699
+
700
+ return(1);
701
+ }
702
+
703
+ #ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
704
+
705
+ static void
706
+ JPEGFixupTagsSubsampling(TIFF* tif)
707
+ {
708
+ /*
709
+ * Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in
710
+ * the TIFF tags, but still use non-default (2,2) values within the jpeg
711
+ * data stream itself. In order for TIFF applications to work properly
712
+ * - for instance to get the strip buffer size right - it is imperative
713
+ * that the subsampling be available before we start reading the image
714
+ * data normally. This function will attempt to analyze the first strip in
715
+ * order to get the sampling values from the jpeg data stream.
716
+ *
717
+ * Note that JPEGPreDeocode() will produce a fairly loud warning when the
718
+ * discovered sampling does not match the default sampling (2,2) or whatever
719
+ * was actually in the tiff tags.
720
+ *
721
+ * See the bug in bugzilla for details:
722
+ *
723
+ * http://bugzilla.remotesensing.org/show_bug.cgi?id=168
724
+ *
725
+ * Frank Warmerdam, July 2002
726
+ * Joris Van Damme, May 2007
727
+ */
728
+ static const char module[] = "JPEGFixupTagsSubsampling";
729
+ struct JPEGFixupTagsSubsamplingData m;
730
+
731
+ _TIFFFillStriles( tif );
732
+
733
+ if( tif->tif_dir.td_stripbytecount == NULL
734
+ || tif->tif_dir.td_stripoffset == NULL
735
+ || tif->tif_dir.td_stripbytecount[0] == 0 )
736
+ {
737
+ /* Do not even try to check if the first strip/tile does not
738
+ yet exist, as occurs when GDAL has created a new NULL file
739
+ for instance. */
740
+ return;
741
+ }
742
+
743
+ m.tif=tif;
744
+ m.buffersize=2048;
745
+ m.buffer=_TIFFmalloc(m.buffersize);
746
+ if (m.buffer==NULL)
747
+ {
748
+ TIFFWarningExt(tif->tif_clientdata,module,
749
+ "Unable to allocate memory for auto-correcting of subsampling values; auto-correcting skipped");
750
+ return;
751
+ }
752
+ m.buffercurrentbyte=NULL;
753
+ m.bufferbytesleft=0;
754
+ m.fileoffset=tif->tif_dir.td_stripoffset[0];
755
+ m.filepositioned=0;
756
+ m.filebytesleft=tif->tif_dir.td_stripbytecount[0];
757
+ if (!JPEGFixupTagsSubsamplingSec(&m))
758
+ TIFFWarningExt(tif->tif_clientdata,module,
759
+ "Unable to auto-correct subsampling values, likely corrupt JPEG compressed data in first strip/tile; auto-correcting skipped");
760
+ _TIFFfree(m.buffer);
761
+ }
762
+
763
+ static int
764
+ JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data)
765
+ {
766
+ static const char module[] = "JPEGFixupTagsSubsamplingSec";
767
+ uint8 m;
768
+ while (1)
769
+ {
770
+ while (1)
771
+ {
772
+ if (!JPEGFixupTagsSubsamplingReadByte(data,&m))
773
+ return(0);
774
+ if (m==255)
775
+ break;
776
+ }
777
+ while (1)
778
+ {
779
+ if (!JPEGFixupTagsSubsamplingReadByte(data,&m))
780
+ return(0);
781
+ if (m!=255)
782
+ break;
783
+ }
784
+ switch (m)
785
+ {
786
+ case JPEG_MARKER_SOI:
787
+ /* this type of marker has no data and should be skipped */
788
+ break;
789
+ case JPEG_MARKER_COM:
790
+ case JPEG_MARKER_APP0:
791
+ case JPEG_MARKER_APP0+1:
792
+ case JPEG_MARKER_APP0+2:
793
+ case JPEG_MARKER_APP0+3:
794
+ case JPEG_MARKER_APP0+4:
795
+ case JPEG_MARKER_APP0+5:
796
+ case JPEG_MARKER_APP0+6:
797
+ case JPEG_MARKER_APP0+7:
798
+ case JPEG_MARKER_APP0+8:
799
+ case JPEG_MARKER_APP0+9:
800
+ case JPEG_MARKER_APP0+10:
801
+ case JPEG_MARKER_APP0+11:
802
+ case JPEG_MARKER_APP0+12:
803
+ case JPEG_MARKER_APP0+13:
804
+ case JPEG_MARKER_APP0+14:
805
+ case JPEG_MARKER_APP0+15:
806
+ case JPEG_MARKER_DQT:
807
+ case JPEG_MARKER_SOS:
808
+ case JPEG_MARKER_DHT:
809
+ case JPEG_MARKER_DRI:
810
+ /* this type of marker has data, but it has no use to us and should be skipped */
811
+ {
812
+ uint16 n;
813
+ if (!JPEGFixupTagsSubsamplingReadWord(data,&n))
814
+ return(0);
815
+ if (n<2)
816
+ return(0);
817
+ n-=2;
818
+ if (n>0)
819
+ JPEGFixupTagsSubsamplingSkip(data,n);
820
+ }
821
+ break;
822
+ case JPEG_MARKER_SOF0: /* Baseline sequential Huffman */
823
+ case JPEG_MARKER_SOF1: /* Extended sequential Huffman */
824
+ case JPEG_MARKER_SOF2: /* Progressive Huffman: normally not allowed by TechNote, but that doesn't hurt supporting it */
825
+ case JPEG_MARKER_SOF9: /* Extended sequential arithmetic */
826
+ case JPEG_MARKER_SOF10: /* Progressive arithmetic: normally not allowed by TechNote, but that doesn't hurt supporting it */
827
+ /* this marker contains the subsampling factors we're scanning for */
828
+ {
829
+ uint16 n;
830
+ uint16 o;
831
+ uint8 p;
832
+ uint8 ph,pv;
833
+ if (!JPEGFixupTagsSubsamplingReadWord(data,&n))
834
+ return(0);
835
+ if (n!=8+data->tif->tif_dir.td_samplesperpixel*3)
836
+ return(0);
837
+ JPEGFixupTagsSubsamplingSkip(data,7);
838
+ if (!JPEGFixupTagsSubsamplingReadByte(data,&p))
839
+ return(0);
840
+ ph=(p>>4);
841
+ pv=(p&15);
842
+ JPEGFixupTagsSubsamplingSkip(data,1);
843
+ for (o=1; o<data->tif->tif_dir.td_samplesperpixel; o++)
844
+ {
845
+ JPEGFixupTagsSubsamplingSkip(data,1);
846
+ if (!JPEGFixupTagsSubsamplingReadByte(data,&p))
847
+ return(0);
848
+ if (p!=0x11)
849
+ {
850
+ TIFFWarningExt(data->tif->tif_clientdata,module,
851
+ "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed");
852
+ return(1);
853
+ }
854
+ JPEGFixupTagsSubsamplingSkip(data,1);
855
+ }
856
+ if (((ph!=1)&&(ph!=2)&&(ph!=4))||((pv!=1)&&(pv!=2)&&(pv!=4)))
857
+ {
858
+ TIFFWarningExt(data->tif->tif_clientdata,module,
859
+ "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed");
860
+ return(1);
861
+ }
862
+ if ((ph!=data->tif->tif_dir.td_ycbcrsubsampling[0])||(pv!=data->tif->tif_dir.td_ycbcrsubsampling[1]))
863
+ {
864
+ TIFFWarningExt(data->tif->tif_clientdata,module,
865
+ "Auto-corrected former TIFF subsampling values [%d,%d] to match subsampling values inside JPEG compressed data [%d,%d]",
866
+ (int)data->tif->tif_dir.td_ycbcrsubsampling[0],
867
+ (int)data->tif->tif_dir.td_ycbcrsubsampling[1],
868
+ (int)ph,(int)pv);
869
+ data->tif->tif_dir.td_ycbcrsubsampling[0]=ph;
870
+ data->tif->tif_dir.td_ycbcrsubsampling[1]=pv;
871
+ }
872
+ }
873
+ return(1);
874
+ default:
875
+ return(0);
876
+ }
877
+ }
878
+ }
879
+
880
+ static int
881
+ JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result)
882
+ {
883
+ if (data->bufferbytesleft==0)
884
+ {
885
+ uint32 m;
886
+ if (data->filebytesleft==0)
887
+ return(0);
888
+ if (!data->filepositioned)
889
+ {
890
+ TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET);
891
+ data->filepositioned=1;
892
+ }
893
+ m=data->buffersize;
894
+ if ((uint64)m>data->filebytesleft)
895
+ m=(uint32)data->filebytesleft;
896
+ assert(m<0x80000000UL);
897
+ if (TIFFReadFile(data->tif,data->buffer,(tmsize_t)m)!=(tmsize_t)m)
898
+ return(0);
899
+ data->buffercurrentbyte=data->buffer;
900
+ data->bufferbytesleft=m;
901
+ data->fileoffset+=m;
902
+ data->filebytesleft-=m;
903
+ }
904
+ *result=*data->buffercurrentbyte;
905
+ data->buffercurrentbyte++;
906
+ data->bufferbytesleft--;
907
+ return(1);
908
+ }
909
+
910
+ static int
911
+ JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result)
912
+ {
913
+ uint8 ma;
914
+ uint8 mb;
915
+ if (!JPEGFixupTagsSubsamplingReadByte(data,&ma))
916
+ return(0);
917
+ if (!JPEGFixupTagsSubsamplingReadByte(data,&mb))
918
+ return(0);
919
+ *result=(ma<<8)|mb;
920
+ return(1);
921
+ }
922
+
923
+ static void
924
+ JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength)
925
+ {
926
+ if ((uint32)skiplength<=data->bufferbytesleft)
927
+ {
928
+ data->buffercurrentbyte+=skiplength;
929
+ data->bufferbytesleft-=skiplength;
930
+ }
931
+ else
932
+ {
933
+ uint16 m;
934
+ m=skiplength-data->bufferbytesleft;
935
+ if (m<=data->filebytesleft)
936
+ {
937
+ data->bufferbytesleft=0;
938
+ data->fileoffset+=m;
939
+ data->filebytesleft-=m;
940
+ data->filepositioned=0;
941
+ }
942
+ else
943
+ {
944
+ data->bufferbytesleft=0;
945
+ data->filebytesleft=0;
946
+ }
947
+ }
948
+ }
949
+
950
+ #endif
951
+
952
+
953
+ static int
954
+ JPEGSetupDecode(TIFF* tif)
955
+ {
956
+ JPEGState* sp = JState(tif);
957
+ TIFFDirectory *td = &tif->tif_dir;
958
+
959
+ #if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG)
960
+ if( tif->tif_dir.td_bitspersample == 12 )
961
+ return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 0 );
962
+ #endif
963
+
964
+ JPEGInitializeLibJPEG( tif, TRUE );
965
+
966
+ assert(sp != NULL);
967
+ assert(sp->cinfo.comm.is_decompressor);
968
+
969
+ /* Read JPEGTables if it is present */
970
+ if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) {
971
+ TIFFjpeg_tables_src(sp, tif);
972
+ if(TIFFjpeg_read_header(sp,FALSE) != JPEG_HEADER_TABLES_ONLY) {
973
+ TIFFErrorExt(tif->tif_clientdata, "JPEGSetupDecode", "Bogus JPEGTables field");
974
+ return (0);
975
+ }
976
+ }
977
+
978
+ /* Grab parameters that are same for all strips/tiles */
979
+ sp->photometric = td->td_photometric;
980
+ switch (sp->photometric) {
981
+ case PHOTOMETRIC_YCBCR:
982
+ sp->h_sampling = td->td_ycbcrsubsampling[0];
983
+ sp->v_sampling = td->td_ycbcrsubsampling[1];
984
+ break;
985
+ default:
986
+ /* TIFF 6.0 forbids subsampling of all other color spaces */
987
+ sp->h_sampling = 1;
988
+ sp->v_sampling = 1;
989
+ break;
990
+ }
991
+
992
+ /* Set up for reading normal data */
993
+ TIFFjpeg_data_src(sp, tif);
994
+ tif->tif_postdecode = _TIFFNoPostDecode; /* override byte swapping */
995
+ return (1);
996
+ }
997
+
998
+ /*
999
+ * Set up for decoding a strip or tile.
1000
+ */
1001
+ static int
1002
+ JPEGPreDecode(TIFF* tif, uint16 s)
1003
+ {
1004
+ JPEGState *sp = JState(tif);
1005
+ TIFFDirectory *td = &tif->tif_dir;
1006
+ static const char module[] = "JPEGPreDecode";
1007
+ uint32 segment_width, segment_height;
1008
+ int downsampled_output;
1009
+ int ci;
1010
+
1011
+ assert(sp != NULL);
1012
+
1013
+ if (sp->cinfo.comm.is_decompressor == 0)
1014
+ {
1015
+ tif->tif_setupdecode( tif );
1016
+ }
1017
+
1018
+ assert(sp->cinfo.comm.is_decompressor);
1019
+ /*
1020
+ * Reset decoder state from any previous strip/tile,
1021
+ * in case application didn't read the whole strip.
1022
+ */
1023
+ if (!TIFFjpeg_abort(sp))
1024
+ return (0);
1025
+ /*
1026
+ * Read the header for this strip/tile.
1027
+ */
1028
+
1029
+ if (TIFFjpeg_read_header(sp, TRUE) != JPEG_HEADER_OK)
1030
+ return (0);
1031
+
1032
+ tif->tif_rawcp = (uint8*) sp->src.next_input_byte;
1033
+ tif->tif_rawcc = sp->src.bytes_in_buffer;
1034
+
1035
+ /*
1036
+ * Check image parameters and set decompression parameters.
1037
+ */
1038
+ segment_width = td->td_imagewidth;
1039
+ segment_height = td->td_imagelength - tif->tif_row;
1040
+ if (isTiled(tif)) {
1041
+ segment_width = td->td_tilewidth;
1042
+ segment_height = td->td_tilelength;
1043
+ sp->bytesperline = TIFFTileRowSize(tif);
1044
+ } else {
1045
+ if (segment_height > td->td_rowsperstrip)
1046
+ segment_height = td->td_rowsperstrip;
1047
+ sp->bytesperline = TIFFScanlineSize(tif);
1048
+ }
1049
+ if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) {
1050
+ /*
1051
+ * For PC 2, scale down the expected strip/tile size
1052
+ * to match a downsampled component
1053
+ */
1054
+ segment_width = TIFFhowmany_32(segment_width, sp->h_sampling);
1055
+ segment_height = TIFFhowmany_32(segment_height, sp->v_sampling);
1056
+ }
1057
+ if (sp->cinfo.d.image_width < segment_width ||
1058
+ sp->cinfo.d.image_height < segment_height) {
1059
+ TIFFWarningExt(tif->tif_clientdata, module,
1060
+ "Improper JPEG strip/tile size, "
1061
+ "expected %dx%d, got %dx%d",
1062
+ segment_width, segment_height,
1063
+ sp->cinfo.d.image_width,
1064
+ sp->cinfo.d.image_height);
1065
+ }
1066
+ if (sp->cinfo.d.image_width > segment_width ||
1067
+ sp->cinfo.d.image_height > segment_height) {
1068
+ /*
1069
+ * This case could be dangerous, if the strip or tile size has
1070
+ * been reported as less than the amount of data jpeg will
1071
+ * return, some potential security issues arise. Catch this
1072
+ * case and error out.
1073
+ */
1074
+ TIFFErrorExt(tif->tif_clientdata, module,
1075
+ "JPEG strip/tile size exceeds expected dimensions,"
1076
+ " expected %dx%d, got %dx%d",
1077
+ segment_width, segment_height,
1078
+ sp->cinfo.d.image_width, sp->cinfo.d.image_height);
1079
+ return (0);
1080
+ }
1081
+ if (sp->cinfo.d.num_components !=
1082
+ (td->td_planarconfig == PLANARCONFIG_CONTIG ?
1083
+ td->td_samplesperpixel : 1)) {
1084
+ TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG component count");
1085
+ return (0);
1086
+ }
1087
+ #ifdef JPEG_LIB_MK1
1088
+ if (12 != td->td_bitspersample && 8 != td->td_bitspersample) {
1089
+ TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision");
1090
+ return (0);
1091
+ }
1092
+ sp->cinfo.d.data_precision = td->td_bitspersample;
1093
+ sp->cinfo.d.bits_in_jsample = td->td_bitspersample;
1094
+ #else
1095
+ if (sp->cinfo.d.data_precision != td->td_bitspersample) {
1096
+ TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision");
1097
+ return (0);
1098
+ }
1099
+ #endif
1100
+ if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
1101
+ /* Component 0 should have expected sampling factors */
1102
+ if (sp->cinfo.d.comp_info[0].h_samp_factor != sp->h_sampling ||
1103
+ sp->cinfo.d.comp_info[0].v_samp_factor != sp->v_sampling) {
1104
+ TIFFErrorExt(tif->tif_clientdata, module,
1105
+ "Improper JPEG sampling factors %d,%d\n"
1106
+ "Apparently should be %d,%d.",
1107
+ sp->cinfo.d.comp_info[0].h_samp_factor,
1108
+ sp->cinfo.d.comp_info[0].v_samp_factor,
1109
+ sp->h_sampling, sp->v_sampling);
1110
+ return (0);
1111
+ }
1112
+ /* Rest should have sampling factors 1,1 */
1113
+ for (ci = 1; ci < sp->cinfo.d.num_components; ci++) {
1114
+ if (sp->cinfo.d.comp_info[ci].h_samp_factor != 1 ||
1115
+ sp->cinfo.d.comp_info[ci].v_samp_factor != 1) {
1116
+ TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors");
1117
+ return (0);
1118
+ }
1119
+ }
1120
+ } else {
1121
+ /* PC 2's single component should have sampling factors 1,1 */
1122
+ if (sp->cinfo.d.comp_info[0].h_samp_factor != 1 ||
1123
+ sp->cinfo.d.comp_info[0].v_samp_factor != 1) {
1124
+ TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors");
1125
+ return (0);
1126
+ }
1127
+ }
1128
+ downsampled_output = FALSE;
1129
+ if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
1130
+ sp->photometric == PHOTOMETRIC_YCBCR &&
1131
+ sp->jpegcolormode == JPEGCOLORMODE_RGB) {
1132
+ /* Convert YCbCr to RGB */
1133
+ sp->cinfo.d.jpeg_color_space = JCS_YCbCr;
1134
+ sp->cinfo.d.out_color_space = JCS_RGB;
1135
+ } else {
1136
+ /* Suppress colorspace handling */
1137
+ sp->cinfo.d.jpeg_color_space = JCS_UNKNOWN;
1138
+ sp->cinfo.d.out_color_space = JCS_UNKNOWN;
1139
+ if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
1140
+ (sp->h_sampling != 1 || sp->v_sampling != 1))
1141
+ downsampled_output = TRUE;
1142
+ /* XXX what about up-sampling? */
1143
+ }
1144
+ if (downsampled_output) {
1145
+ /* Need to use raw-data interface to libjpeg */
1146
+ sp->cinfo.d.raw_data_out = TRUE;
1147
+ #if JPEG_LIB_VERSION >= 70
1148
+ sp->cinfo.d.do_fancy_upsampling = FALSE;
1149
+ #endif /* JPEG_LIB_VERSION >= 70 */
1150
+ tif->tif_decoderow = DecodeRowError;
1151
+ tif->tif_decodestrip = JPEGDecodeRaw;
1152
+ tif->tif_decodetile = JPEGDecodeRaw;
1153
+ } else {
1154
+ /* Use normal interface to libjpeg */
1155
+ sp->cinfo.d.raw_data_out = FALSE;
1156
+ tif->tif_decoderow = JPEGDecode;
1157
+ tif->tif_decodestrip = JPEGDecode;
1158
+ tif->tif_decodetile = JPEGDecode;
1159
+ }
1160
+ /* Start JPEG decompressor */
1161
+ if (!TIFFjpeg_start_decompress(sp))
1162
+ return (0);
1163
+ /* Allocate downsampled-data buffers if needed */
1164
+ if (downsampled_output) {
1165
+ if (!alloc_downsampled_buffers(tif, sp->cinfo.d.comp_info,
1166
+ sp->cinfo.d.num_components))
1167
+ return (0);
1168
+ sp->scancount = DCTSIZE; /* mark buffer empty */
1169
+ }
1170
+ return (1);
1171
+ }
1172
+
1173
+ /*
1174
+ * Decode a chunk of pixels.
1175
+ * "Standard" case: returned data is not downsampled.
1176
+ */
1177
+ /*ARGSUSED*/ static int
1178
+ JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1179
+ {
1180
+ JPEGState *sp = JState(tif);
1181
+ tmsize_t nrows;
1182
+ (void) s;
1183
+
1184
+ /*
1185
+ ** Update available information, buffer may have been refilled
1186
+ ** between decode requests
1187
+ */
1188
+ sp->src.next_input_byte = (const JOCTET*) tif->tif_rawcp;
1189
+ sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc;
1190
+
1191
+ if( sp->bytesperline == 0 )
1192
+ return 0;
1193
+
1194
+ nrows = cc / sp->bytesperline;
1195
+ if (cc % sp->bytesperline)
1196
+ TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline not read");
1197
+
1198
+ if( nrows > (tmsize_t) sp->cinfo.d.image_height )
1199
+ nrows = sp->cinfo.d.image_height;
1200
+
1201
+ /* data is expected to be read in multiples of a scanline */
1202
+ if (nrows)
1203
+ {
1204
+ JSAMPROW line_work_buf = NULL;
1205
+
1206
+ /*
1207
+ * For 6B, only use temporary buffer for 12 bit imagery.
1208
+ * For Mk1 always use it.
1209
+ */
1210
+ #if !defined(JPEG_LIB_MK1)
1211
+ if( sp->cinfo.d.data_precision == 12 )
1212
+ #endif
1213
+ {
1214
+ line_work_buf = (JSAMPROW)
1215
+ _TIFFmalloc(sizeof(short) * sp->cinfo.d.output_width
1216
+ * sp->cinfo.d.num_components );
1217
+ }
1218
+
1219
+ do {
1220
+ if( line_work_buf != NULL )
1221
+ {
1222
+ /*
1223
+ * In the MK1 case, we aways read into a 16bit buffer, and then
1224
+ * pack down to 12bit or 8bit. In 6B case we only read into 16
1225
+ * bit buffer for 12bit data, which we need to repack.
1226
+ */
1227
+ if (TIFFjpeg_read_scanlines(sp, &line_work_buf, 1) != 1)
1228
+ return (0);
1229
+
1230
+ if( sp->cinfo.d.data_precision == 12 )
1231
+ {
1232
+ int value_pairs = (sp->cinfo.d.output_width
1233
+ * sp->cinfo.d.num_components) / 2;
1234
+ int iPair;
1235
+
1236
+ for( iPair = 0; iPair < value_pairs; iPair++ )
1237
+ {
1238
+ unsigned char *out_ptr =
1239
+ ((unsigned char *) buf) + iPair * 3;
1240
+ JSAMPLE *in_ptr = line_work_buf + iPair * 2;
1241
+
1242
+ out_ptr[0] = (in_ptr[0] & 0xff0) >> 4;
1243
+ out_ptr[1] = ((in_ptr[0] & 0xf) << 4)
1244
+ | ((in_ptr[1] & 0xf00) >> 8);
1245
+ out_ptr[2] = ((in_ptr[1] & 0xff) >> 0);
1246
+ }
1247
+ }
1248
+ else if( sp->cinfo.d.data_precision == 8 )
1249
+ {
1250
+ int value_count = (sp->cinfo.d.output_width
1251
+ * sp->cinfo.d.num_components);
1252
+ int iValue;
1253
+
1254
+ for( iValue = 0; iValue < value_count; iValue++ )
1255
+ {
1256
+ ((unsigned char *) buf)[iValue] =
1257
+ line_work_buf[iValue] & 0xff;
1258
+ }
1259
+ }
1260
+ }
1261
+ else
1262
+ {
1263
+ /*
1264
+ * In the libjpeg6b 8bit case. We read directly into the
1265
+ * TIFF buffer.
1266
+ */
1267
+ JSAMPROW bufptr = (JSAMPROW)buf;
1268
+
1269
+ if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1)
1270
+ return (0);
1271
+ }
1272
+
1273
+ ++tif->tif_row;
1274
+ buf += sp->bytesperline;
1275
+ cc -= sp->bytesperline;
1276
+ } while (--nrows > 0);
1277
+
1278
+ if( line_work_buf != NULL )
1279
+ _TIFFfree( line_work_buf );
1280
+ }
1281
+
1282
+ /* Update information on consumed data */
1283
+ tif->tif_rawcp = (uint8*) sp->src.next_input_byte;
1284
+ tif->tif_rawcc = sp->src.bytes_in_buffer;
1285
+
1286
+ /* Close down the decompressor if we've finished the strip or tile. */
1287
+ return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
1288
+ || TIFFjpeg_finish_decompress(sp);
1289
+ }
1290
+
1291
+ /*ARGSUSED*/ static int
1292
+ DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1293
+
1294
+ {
1295
+ (void) buf;
1296
+ (void) cc;
1297
+ (void) s;
1298
+
1299
+ TIFFErrorExt(tif->tif_clientdata, "TIFFReadScanline",
1300
+ "scanline oriented access is not supported for downsampled JPEG compressed images, consider enabling TIFF_JPEGCOLORMODE as JPEGCOLORMODE_RGB." );
1301
+ return 0;
1302
+ }
1303
+
1304
+ /*
1305
+ * Decode a chunk of pixels.
1306
+ * Returned data is downsampled per sampling factors.
1307
+ */
1308
+ /*ARGSUSED*/ static int
1309
+ JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1310
+ {
1311
+ JPEGState *sp = JState(tif);
1312
+ tmsize_t nrows;
1313
+ (void) s;
1314
+
1315
+ /* data is expected to be read in multiples of a scanline */
1316
+ if ( (nrows = sp->cinfo.d.image_height) ) {
1317
+
1318
+ /* Cb,Cr both have sampling factors 1, so this is correct */
1319
+ JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width;
1320
+ int samples_per_clump = sp->samplesperclump;
1321
+
1322
+ #if defined(JPEG_LIB_MK1_OR_12BIT)
1323
+ unsigned short* tmpbuf = _TIFFmalloc(sizeof(unsigned short) *
1324
+ sp->cinfo.d.output_width *
1325
+ sp->cinfo.d.num_components);
1326
+ if(tmpbuf==NULL) {
1327
+ TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
1328
+ "Out of memory");
1329
+ return 0;
1330
+ }
1331
+ #endif
1332
+
1333
+ do {
1334
+ jpeg_component_info *compptr;
1335
+ int ci, clumpoffset;
1336
+
1337
+ if( cc < sp->bytesperline ) {
1338
+ TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
1339
+ "application buffer not large enough for all data.");
1340
+ return 0;
1341
+ }
1342
+
1343
+ /* Reload downsampled-data buffer if needed */
1344
+ if (sp->scancount >= DCTSIZE) {
1345
+ int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE;
1346
+ if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) != n)
1347
+ return (0);
1348
+ sp->scancount = 0;
1349
+ }
1350
+ /*
1351
+ * Fastest way to unseparate data is to make one pass
1352
+ * over the scanline for each row of each component.
1353
+ */
1354
+ clumpoffset = 0; /* first sample in clump */
1355
+ for (ci = 0, compptr = sp->cinfo.d.comp_info;
1356
+ ci < sp->cinfo.d.num_components;
1357
+ ci++, compptr++) {
1358
+ int hsamp = compptr->h_samp_factor;
1359
+ int vsamp = compptr->v_samp_factor;
1360
+ int ypos;
1361
+
1362
+ for (ypos = 0; ypos < vsamp; ypos++) {
1363
+ JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
1364
+ JDIMENSION nclump;
1365
+ #if defined(JPEG_LIB_MK1_OR_12BIT)
1366
+ JSAMPLE *outptr = (JSAMPLE*)tmpbuf + clumpoffset;
1367
+ #else
1368
+ JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset;
1369
+ if (cc < (tmsize_t) (clumpoffset + samples_per_clump*(clumps_per_line-1) + hsamp)) {
1370
+ TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
1371
+ "application buffer not large enough for all data, possible subsampling issue");
1372
+ return 0;
1373
+ }
1374
+ #endif
1375
+
1376
+ if (hsamp == 1) {
1377
+ /* fast path for at least Cb and Cr */
1378
+ for (nclump = clumps_per_line; nclump-- > 0; ) {
1379
+ outptr[0] = *inptr++;
1380
+ outptr += samples_per_clump;
1381
+ }
1382
+ } else {
1383
+ int xpos;
1384
+
1385
+ /* general case */
1386
+ for (nclump = clumps_per_line; nclump-- > 0; ) {
1387
+ for (xpos = 0; xpos < hsamp; xpos++)
1388
+ outptr[xpos] = *inptr++;
1389
+ outptr += samples_per_clump;
1390
+ }
1391
+ }
1392
+ clumpoffset += hsamp;
1393
+ }
1394
+ }
1395
+
1396
+ #if defined(JPEG_LIB_MK1_OR_12BIT)
1397
+ {
1398
+ if (sp->cinfo.d.data_precision == 8)
1399
+ {
1400
+ int i=0;
1401
+ int len = sp->cinfo.d.output_width * sp->cinfo.d.num_components;
1402
+ for (i=0; i<len; i++)
1403
+ {
1404
+ ((unsigned char*)buf)[i] = tmpbuf[i] & 0xff;
1405
+ }
1406
+ }
1407
+ else
1408
+ { /* 12-bit */
1409
+ int value_pairs = (sp->cinfo.d.output_width
1410
+ * sp->cinfo.d.num_components) / 2;
1411
+ int iPair;
1412
+ for( iPair = 0; iPair < value_pairs; iPair++ )
1413
+ {
1414
+ unsigned char *out_ptr = ((unsigned char *) buf) + iPair * 3;
1415
+ JSAMPLE *in_ptr = (JSAMPLE *) (tmpbuf + iPair * 2);
1416
+ out_ptr[0] = (in_ptr[0] & 0xff0) >> 4;
1417
+ out_ptr[1] = ((in_ptr[0] & 0xf) << 4)
1418
+ | ((in_ptr[1] & 0xf00) >> 8);
1419
+ out_ptr[2] = ((in_ptr[1] & 0xff) >> 0);
1420
+ }
1421
+ }
1422
+ }
1423
+ #endif
1424
+
1425
+ sp->scancount ++;
1426
+ tif->tif_row += sp->v_sampling;
1427
+
1428
+ buf += sp->bytesperline;
1429
+ cc -= sp->bytesperline;
1430
+
1431
+ nrows -= sp->v_sampling;
1432
+ } while (nrows > 0);
1433
+
1434
+ #if defined(JPEG_LIB_MK1_OR_12BIT)
1435
+ _TIFFfree(tmpbuf);
1436
+ #endif
1437
+
1438
+ }
1439
+
1440
+ /* Close down the decompressor if done. */
1441
+ return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
1442
+ || TIFFjpeg_finish_decompress(sp);
1443
+ }
1444
+
1445
+
1446
+ /*
1447
+ * JPEG Encoding.
1448
+ */
1449
+
1450
+ static void
1451
+ unsuppress_quant_table (JPEGState* sp, int tblno)
1452
+ {
1453
+ JQUANT_TBL* qtbl;
1454
+
1455
+ if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL)
1456
+ qtbl->sent_table = FALSE;
1457
+ }
1458
+
1459
+ static void
1460
+ suppress_quant_table (JPEGState* sp, int tblno)
1461
+ {
1462
+ JQUANT_TBL* qtbl;
1463
+
1464
+ if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL)
1465
+ qtbl->sent_table = TRUE;
1466
+ }
1467
+
1468
+ static void
1469
+ unsuppress_huff_table (JPEGState* sp, int tblno)
1470
+ {
1471
+ JHUFF_TBL* htbl;
1472
+
1473
+ if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL)
1474
+ htbl->sent_table = FALSE;
1475
+ if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL)
1476
+ htbl->sent_table = FALSE;
1477
+ }
1478
+
1479
+ static void
1480
+ suppress_huff_table (JPEGState* sp, int tblno)
1481
+ {
1482
+ JHUFF_TBL* htbl;
1483
+
1484
+ if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL)
1485
+ htbl->sent_table = TRUE;
1486
+ if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL)
1487
+ htbl->sent_table = TRUE;
1488
+ }
1489
+
1490
+ static int
1491
+ prepare_JPEGTables(TIFF* tif)
1492
+ {
1493
+ JPEGState* sp = JState(tif);
1494
+
1495
+ /* Initialize quant tables for current quality setting */
1496
+ if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
1497
+ return (0);
1498
+ /* Mark only the tables we want for output */
1499
+ /* NB: chrominance tables are currently used only with YCbCr */
1500
+ if (!TIFFjpeg_suppress_tables(sp, TRUE))
1501
+ return (0);
1502
+ if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) {
1503
+ unsuppress_quant_table(sp, 0);
1504
+ if (sp->photometric == PHOTOMETRIC_YCBCR)
1505
+ unsuppress_quant_table(sp, 1);
1506
+ }
1507
+ if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) {
1508
+ unsuppress_huff_table(sp, 0);
1509
+ if (sp->photometric == PHOTOMETRIC_YCBCR)
1510
+ unsuppress_huff_table(sp, 1);
1511
+ }
1512
+ /* Direct libjpeg output into jpegtables */
1513
+ if (!TIFFjpeg_tables_dest(sp, tif))
1514
+ return (0);
1515
+ /* Emit tables-only datastream */
1516
+ if (!TIFFjpeg_write_tables(sp))
1517
+ return (0);
1518
+
1519
+ return (1);
1520
+ }
1521
+
1522
+ static int
1523
+ JPEGSetupEncode(TIFF* tif)
1524
+ {
1525
+ JPEGState* sp = JState(tif);
1526
+ TIFFDirectory *td = &tif->tif_dir;
1527
+ static const char module[] = "JPEGSetupEncode";
1528
+
1529
+ #if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG)
1530
+ if( tif->tif_dir.td_bitspersample == 12 )
1531
+ return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 1 );
1532
+ #endif
1533
+
1534
+ JPEGInitializeLibJPEG( tif, FALSE );
1535
+
1536
+ assert(sp != NULL);
1537
+ assert(!sp->cinfo.comm.is_decompressor);
1538
+
1539
+ sp->photometric = td->td_photometric;
1540
+
1541
+ /*
1542
+ * Initialize all JPEG parameters to default values.
1543
+ * Note that jpeg_set_defaults needs legal values for
1544
+ * in_color_space and input_components.
1545
+ */
1546
+ if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
1547
+ sp->cinfo.c.input_components = td->td_samplesperpixel;
1548
+ if (sp->photometric == PHOTOMETRIC_YCBCR) {
1549
+ if (sp->jpegcolormode == JPEGCOLORMODE_RGB) {
1550
+ sp->cinfo.c.in_color_space = JCS_RGB;
1551
+ } else {
1552
+ sp->cinfo.c.in_color_space = JCS_YCbCr;
1553
+ }
1554
+ } else {
1555
+ if ((td->td_photometric == PHOTOMETRIC_MINISWHITE || td->td_photometric == PHOTOMETRIC_MINISBLACK) && td->td_samplesperpixel == 1)
1556
+ sp->cinfo.c.in_color_space = JCS_GRAYSCALE;
1557
+ else if (td->td_photometric == PHOTOMETRIC_RGB && td->td_samplesperpixel == 3)
1558
+ sp->cinfo.c.in_color_space = JCS_RGB;
1559
+ else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td->td_samplesperpixel == 4)
1560
+ sp->cinfo.c.in_color_space = JCS_CMYK;
1561
+ else
1562
+ sp->cinfo.c.in_color_space = JCS_UNKNOWN;
1563
+ }
1564
+ } else {
1565
+ sp->cinfo.c.input_components = 1;
1566
+ sp->cinfo.c.in_color_space = JCS_UNKNOWN;
1567
+ }
1568
+ if (!TIFFjpeg_set_defaults(sp))
1569
+ return (0);
1570
+ /* Set per-file parameters */
1571
+ switch (sp->photometric) {
1572
+ case PHOTOMETRIC_YCBCR:
1573
+ sp->h_sampling = td->td_ycbcrsubsampling[0];
1574
+ sp->v_sampling = td->td_ycbcrsubsampling[1];
1575
+ /*
1576
+ * A ReferenceBlackWhite field *must* be present since the
1577
+ * default value is inappropriate for YCbCr. Fill in the
1578
+ * proper value if application didn't set it.
1579
+ */
1580
+ {
1581
+ float *ref;
1582
+ if (!TIFFGetField(tif, TIFFTAG_REFERENCEBLACKWHITE,
1583
+ &ref)) {
1584
+ float refbw[6];
1585
+ long top = 1L << td->td_bitspersample;
1586
+ refbw[0] = 0;
1587
+ refbw[1] = (float)(top-1L);
1588
+ refbw[2] = (float)(top>>1);
1589
+ refbw[3] = refbw[1];
1590
+ refbw[4] = refbw[2];
1591
+ refbw[5] = refbw[1];
1592
+ TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE,
1593
+ refbw);
1594
+ }
1595
+ }
1596
+ break;
1597
+ case PHOTOMETRIC_PALETTE: /* disallowed by Tech Note */
1598
+ case PHOTOMETRIC_MASK:
1599
+ TIFFErrorExt(tif->tif_clientdata, module,
1600
+ "PhotometricInterpretation %d not allowed for JPEG",
1601
+ (int) sp->photometric);
1602
+ return (0);
1603
+ default:
1604
+ /* TIFF 6.0 forbids subsampling of all other color spaces */
1605
+ sp->h_sampling = 1;
1606
+ sp->v_sampling = 1;
1607
+ break;
1608
+ }
1609
+
1610
+ /* Verify miscellaneous parameters */
1611
+
1612
+ /*
1613
+ * This would need work if libtiff ever supports different
1614
+ * depths for different components, or if libjpeg ever supports
1615
+ * run-time selection of depth. Neither is imminent.
1616
+ */
1617
+ #ifdef JPEG_LIB_MK1
1618
+ /* BITS_IN_JSAMPLE now permits 8 and 12 --- dgilbert */
1619
+ if (td->td_bitspersample != 8 && td->td_bitspersample != 12)
1620
+ #else
1621
+ if (td->td_bitspersample != BITS_IN_JSAMPLE )
1622
+ #endif
1623
+ {
1624
+ TIFFErrorExt(tif->tif_clientdata, module, "BitsPerSample %d not allowed for JPEG",
1625
+ (int) td->td_bitspersample);
1626
+ return (0);
1627
+ }
1628
+ sp->cinfo.c.data_precision = td->td_bitspersample;
1629
+ #ifdef JPEG_LIB_MK1
1630
+ sp->cinfo.c.bits_in_jsample = td->td_bitspersample;
1631
+ #endif
1632
+ if (isTiled(tif)) {
1633
+ if ((td->td_tilelength % (sp->v_sampling * DCTSIZE)) != 0) {
1634
+ TIFFErrorExt(tif->tif_clientdata, module,
1635
+ "JPEG tile height must be multiple of %d",
1636
+ sp->v_sampling * DCTSIZE);
1637
+ return (0);
1638
+ }
1639
+ if ((td->td_tilewidth % (sp->h_sampling * DCTSIZE)) != 0) {
1640
+ TIFFErrorExt(tif->tif_clientdata, module,
1641
+ "JPEG tile width must be multiple of %d",
1642
+ sp->h_sampling * DCTSIZE);
1643
+ return (0);
1644
+ }
1645
+ } else {
1646
+ if (td->td_rowsperstrip < td->td_imagelength &&
1647
+ (td->td_rowsperstrip % (sp->v_sampling * DCTSIZE)) != 0) {
1648
+ TIFFErrorExt(tif->tif_clientdata, module,
1649
+ "RowsPerStrip must be multiple of %d for JPEG",
1650
+ sp->v_sampling * DCTSIZE);
1651
+ return (0);
1652
+ }
1653
+ }
1654
+
1655
+ /* Create a JPEGTables field if appropriate */
1656
+ if (sp->jpegtablesmode & (JPEGTABLESMODE_QUANT|JPEGTABLESMODE_HUFF)) {
1657
+ if( sp->jpegtables == NULL
1658
+ || memcmp(sp->jpegtables,"\0\0\0\0\0\0\0\0\0",8) == 0 )
1659
+ {
1660
+ if (!prepare_JPEGTables(tif))
1661
+ return (0);
1662
+ /* Mark the field present */
1663
+ /* Can't use TIFFSetField since BEENWRITING is already set! */
1664
+ tif->tif_flags |= TIFF_DIRTYDIRECT;
1665
+ TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
1666
+ }
1667
+ } else {
1668
+ /* We do not support application-supplied JPEGTables, */
1669
+ /* so mark the field not present */
1670
+ TIFFClrFieldBit(tif, FIELD_JPEGTABLES);
1671
+ }
1672
+
1673
+ /* Direct libjpeg output to libtiff's output buffer */
1674
+ TIFFjpeg_data_dest(sp, tif);
1675
+
1676
+ return (1);
1677
+ }
1678
+
1679
+ /*
1680
+ * Set encoding state at the start of a strip or tile.
1681
+ */
1682
+ static int
1683
+ JPEGPreEncode(TIFF* tif, uint16 s)
1684
+ {
1685
+ JPEGState *sp = JState(tif);
1686
+ TIFFDirectory *td = &tif->tif_dir;
1687
+ static const char module[] = "JPEGPreEncode";
1688
+ uint32 segment_width, segment_height;
1689
+ int downsampled_input;
1690
+
1691
+ assert(sp != NULL);
1692
+
1693
+ if (sp->cinfo.comm.is_decompressor == 1)
1694
+ {
1695
+ tif->tif_setupencode( tif );
1696
+ }
1697
+
1698
+ assert(!sp->cinfo.comm.is_decompressor);
1699
+ /*
1700
+ * Set encoding parameters for this strip/tile.
1701
+ */
1702
+ if (isTiled(tif)) {
1703
+ segment_width = td->td_tilewidth;
1704
+ segment_height = td->td_tilelength;
1705
+ sp->bytesperline = TIFFTileRowSize(tif);
1706
+ } else {
1707
+ segment_width = td->td_imagewidth;
1708
+ segment_height = td->td_imagelength - tif->tif_row;
1709
+ if (segment_height > td->td_rowsperstrip)
1710
+ segment_height = td->td_rowsperstrip;
1711
+ sp->bytesperline = TIFFScanlineSize(tif);
1712
+ }
1713
+ if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) {
1714
+ /* for PC 2, scale down the strip/tile size
1715
+ * to match a downsampled component
1716
+ */
1717
+ segment_width = TIFFhowmany_32(segment_width, sp->h_sampling);
1718
+ segment_height = TIFFhowmany_32(segment_height, sp->v_sampling);
1719
+ }
1720
+ if (segment_width > 65535 || segment_height > 65535) {
1721
+ TIFFErrorExt(tif->tif_clientdata, module, "Strip/tile too large for JPEG");
1722
+ return (0);
1723
+ }
1724
+ sp->cinfo.c.image_width = segment_width;
1725
+ sp->cinfo.c.image_height = segment_height;
1726
+ downsampled_input = FALSE;
1727
+ if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
1728
+ sp->cinfo.c.input_components = td->td_samplesperpixel;
1729
+ if (sp->photometric == PHOTOMETRIC_YCBCR) {
1730
+ if (sp->jpegcolormode != JPEGCOLORMODE_RGB) {
1731
+ if (sp->h_sampling != 1 || sp->v_sampling != 1)
1732
+ downsampled_input = TRUE;
1733
+ }
1734
+ if (!TIFFjpeg_set_colorspace(sp, JCS_YCbCr))
1735
+ return (0);
1736
+ /*
1737
+ * Set Y sampling factors;
1738
+ * we assume jpeg_set_colorspace() set the rest to 1
1739
+ */
1740
+ sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling;
1741
+ sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling;
1742
+ } else {
1743
+ if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_space))
1744
+ return (0);
1745
+ /* jpeg_set_colorspace set all sampling factors to 1 */
1746
+ }
1747
+ } else {
1748
+ if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN))
1749
+ return (0);
1750
+ sp->cinfo.c.comp_info[0].component_id = s;
1751
+ /* jpeg_set_colorspace() set sampling factors to 1 */
1752
+ if (sp->photometric == PHOTOMETRIC_YCBCR && s > 0) {
1753
+ sp->cinfo.c.comp_info[0].quant_tbl_no = 1;
1754
+ sp->cinfo.c.comp_info[0].dc_tbl_no = 1;
1755
+ sp->cinfo.c.comp_info[0].ac_tbl_no = 1;
1756
+ }
1757
+ }
1758
+ /* ensure libjpeg won't write any extraneous markers */
1759
+ sp->cinfo.c.write_JFIF_header = FALSE;
1760
+ sp->cinfo.c.write_Adobe_marker = FALSE;
1761
+ /* set up table handling correctly */
1762
+ /* calling TIFFjpeg_set_quality() causes quantization tables to be flagged */
1763
+ /* as being to be emitted, which we don't want in the JPEGTABLESMODE_QUANT */
1764
+ /* mode, so we must manually suppress them. However TIFFjpeg_set_quality() */
1765
+ /* should really be called when dealing with files with directories with */
1766
+ /* mixed qualities. see http://trac.osgeo.org/gdal/ticket/3539 */
1767
+ if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
1768
+ return (0);
1769
+ if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) {
1770
+ suppress_quant_table(sp, 0);
1771
+ suppress_quant_table(sp, 1);
1772
+ }
1773
+ else {
1774
+ unsuppress_quant_table(sp, 0);
1775
+ unsuppress_quant_table(sp, 1);
1776
+ }
1777
+ if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF)
1778
+ {
1779
+ /* Explicit suppression is only needed if we did not go through the */
1780
+ /* prepare_JPEGTables() code path, which may be the case if updating */
1781
+ /* an existing file */
1782
+ suppress_huff_table(sp, 0);
1783
+ suppress_huff_table(sp, 1);
1784
+ sp->cinfo.c.optimize_coding = FALSE;
1785
+ }
1786
+ else
1787
+ sp->cinfo.c.optimize_coding = TRUE;
1788
+ if (downsampled_input) {
1789
+ /* Need to use raw-data interface to libjpeg */
1790
+ sp->cinfo.c.raw_data_in = TRUE;
1791
+ tif->tif_encoderow = JPEGEncodeRaw;
1792
+ tif->tif_encodestrip = JPEGEncodeRaw;
1793
+ tif->tif_encodetile = JPEGEncodeRaw;
1794
+ } else {
1795
+ /* Use normal interface to libjpeg */
1796
+ sp->cinfo.c.raw_data_in = FALSE;
1797
+ tif->tif_encoderow = JPEGEncode;
1798
+ tif->tif_encodestrip = JPEGEncode;
1799
+ tif->tif_encodetile = JPEGEncode;
1800
+ }
1801
+ /* Start JPEG compressor */
1802
+ if (!TIFFjpeg_start_compress(sp, FALSE))
1803
+ return (0);
1804
+ /* Allocate downsampled-data buffers if needed */
1805
+ if (downsampled_input) {
1806
+ if (!alloc_downsampled_buffers(tif, sp->cinfo.c.comp_info,
1807
+ sp->cinfo.c.num_components))
1808
+ return (0);
1809
+ }
1810
+ sp->scancount = 0;
1811
+
1812
+ return (1);
1813
+ }
1814
+
1815
+ /*
1816
+ * Encode a chunk of pixels.
1817
+ * "Standard" case: incoming data is not downsampled.
1818
+ */
1819
+ static int
1820
+ JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1821
+ {
1822
+ JPEGState *sp = JState(tif);
1823
+ tmsize_t nrows;
1824
+ JSAMPROW bufptr[1];
1825
+ short *line16 = NULL;
1826
+ int line16_count = 0;
1827
+
1828
+ (void) s;
1829
+ assert(sp != NULL);
1830
+ /* data is expected to be supplied in multiples of a scanline */
1831
+ nrows = cc / sp->bytesperline;
1832
+ if (cc % sp->bytesperline)
1833
+ TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
1834
+ "fractional scanline discarded");
1835
+
1836
+ /* The last strip will be limited to image size */
1837
+ if( !isTiled(tif) && tif->tif_row+nrows > tif->tif_dir.td_imagelength )
1838
+ nrows = tif->tif_dir.td_imagelength - tif->tif_row;
1839
+
1840
+ if( sp->cinfo.c.data_precision == 12 )
1841
+ {
1842
+ line16_count = (sp->bytesperline * 2) / 3;
1843
+ line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count);
1844
+ // FIXME: undiagnosed malloc failure
1845
+ }
1846
+
1847
+ while (nrows-- > 0) {
1848
+
1849
+ if( sp->cinfo.c.data_precision == 12 )
1850
+ {
1851
+
1852
+ int value_pairs = line16_count / 2;
1853
+ int iPair;
1854
+
1855
+ bufptr[0] = (JSAMPROW) line16;
1856
+
1857
+ for( iPair = 0; iPair < value_pairs; iPair++ )
1858
+ {
1859
+ unsigned char *in_ptr =
1860
+ ((unsigned char *) buf) + iPair * 3;
1861
+ JSAMPLE *out_ptr = (JSAMPLE *) (line16 + iPair * 2);
1862
+
1863
+ out_ptr[0] = (in_ptr[0] << 4) | ((in_ptr[1] & 0xf0) >> 4);
1864
+ out_ptr[1] = ((in_ptr[1] & 0x0f) << 8) | in_ptr[2];
1865
+ }
1866
+ }
1867
+ else
1868
+ {
1869
+ bufptr[0] = (JSAMPROW) buf;
1870
+ }
1871
+ if (TIFFjpeg_write_scanlines(sp, bufptr, 1) != 1)
1872
+ return (0);
1873
+ if (nrows > 0)
1874
+ tif->tif_row++;
1875
+ buf += sp->bytesperline;
1876
+ }
1877
+
1878
+ if( sp->cinfo.c.data_precision == 12 )
1879
+ {
1880
+ _TIFFfree( line16 );
1881
+ }
1882
+
1883
+ return (1);
1884
+ }
1885
+
1886
+ /*
1887
+ * Encode a chunk of pixels.
1888
+ * Incoming data is expected to be downsampled per sampling factors.
1889
+ */
1890
+ static int
1891
+ JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1892
+ {
1893
+ JPEGState *sp = JState(tif);
1894
+ JSAMPLE* inptr;
1895
+ JSAMPLE* outptr;
1896
+ tmsize_t nrows;
1897
+ JDIMENSION clumps_per_line, nclump;
1898
+ int clumpoffset, ci, xpos, ypos;
1899
+ jpeg_component_info* compptr;
1900
+ int samples_per_clump = sp->samplesperclump;
1901
+ tmsize_t bytesperclumpline;
1902
+
1903
+ (void) s;
1904
+ assert(sp != NULL);
1905
+ /* data is expected to be supplied in multiples of a clumpline */
1906
+ /* a clumpline is equivalent to v_sampling desubsampled scanlines */
1907
+ /* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */
1908
+ bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling)
1909
+ *(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7)
1910
+ /8;
1911
+
1912
+ nrows = ( cc / bytesperclumpline ) * sp->v_sampling;
1913
+ if (cc % bytesperclumpline)
1914
+ TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline discarded");
1915
+
1916
+ /* Cb,Cr both have sampling factors 1, so this is correct */
1917
+ clumps_per_line = sp->cinfo.c.comp_info[1].downsampled_width;
1918
+
1919
+ while (nrows > 0) {
1920
+ /*
1921
+ * Fastest way to separate the data is to make one pass
1922
+ * over the scanline for each row of each component.
1923
+ */
1924
+ clumpoffset = 0; /* first sample in clump */
1925
+ for (ci = 0, compptr = sp->cinfo.c.comp_info;
1926
+ ci < sp->cinfo.c.num_components;
1927
+ ci++, compptr++) {
1928
+ int hsamp = compptr->h_samp_factor;
1929
+ int vsamp = compptr->v_samp_factor;
1930
+ int padding = (int) (compptr->width_in_blocks * DCTSIZE -
1931
+ clumps_per_line * hsamp);
1932
+ for (ypos = 0; ypos < vsamp; ypos++) {
1933
+ inptr = ((JSAMPLE*) buf) + clumpoffset;
1934
+ outptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
1935
+ if (hsamp == 1) {
1936
+ /* fast path for at least Cb and Cr */
1937
+ for (nclump = clumps_per_line; nclump-- > 0; ) {
1938
+ *outptr++ = inptr[0];
1939
+ inptr += samples_per_clump;
1940
+ }
1941
+ } else {
1942
+ /* general case */
1943
+ for (nclump = clumps_per_line; nclump-- > 0; ) {
1944
+ for (xpos = 0; xpos < hsamp; xpos++)
1945
+ *outptr++ = inptr[xpos];
1946
+ inptr += samples_per_clump;
1947
+ }
1948
+ }
1949
+ /* pad each scanline as needed */
1950
+ for (xpos = 0; xpos < padding; xpos++) {
1951
+ *outptr = outptr[-1];
1952
+ outptr++;
1953
+ }
1954
+ clumpoffset += hsamp;
1955
+ }
1956
+ }
1957
+ sp->scancount++;
1958
+ if (sp->scancount >= DCTSIZE) {
1959
+ int n = sp->cinfo.c.max_v_samp_factor * DCTSIZE;
1960
+ if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n)
1961
+ return (0);
1962
+ sp->scancount = 0;
1963
+ }
1964
+ tif->tif_row += sp->v_sampling;
1965
+ buf += bytesperclumpline;
1966
+ nrows -= sp->v_sampling;
1967
+ }
1968
+ return (1);
1969
+ }
1970
+
1971
+ /*
1972
+ * Finish up at the end of a strip or tile.
1973
+ */
1974
+ static int
1975
+ JPEGPostEncode(TIFF* tif)
1976
+ {
1977
+ JPEGState *sp = JState(tif);
1978
+
1979
+ if (sp->scancount > 0) {
1980
+ /*
1981
+ * Need to emit a partial bufferload of downsampled data.
1982
+ * Pad the data vertically.
1983
+ */
1984
+ int ci, ypos, n;
1985
+ jpeg_component_info* compptr;
1986
+
1987
+ for (ci = 0, compptr = sp->cinfo.c.comp_info;
1988
+ ci < sp->cinfo.c.num_components;
1989
+ ci++, compptr++) {
1990
+ int vsamp = compptr->v_samp_factor;
1991
+ tmsize_t row_width = compptr->width_in_blocks * DCTSIZE
1992
+ * sizeof(JSAMPLE);
1993
+ for (ypos = sp->scancount * vsamp;
1994
+ ypos < DCTSIZE * vsamp; ypos++) {
1995
+ _TIFFmemcpy((void*)sp->ds_buffer[ci][ypos],
1996
+ (void*)sp->ds_buffer[ci][ypos-1],
1997
+ row_width);
1998
+
1999
+ }
2000
+ }
2001
+ n = sp->cinfo.c.max_v_samp_factor * DCTSIZE;
2002
+ if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n)
2003
+ return (0);
2004
+ }
2005
+
2006
+ return (TIFFjpeg_finish_compress(JState(tif)));
2007
+ }
2008
+
2009
+ static void
2010
+ JPEGCleanup(TIFF* tif)
2011
+ {
2012
+ JPEGState *sp = JState(tif);
2013
+
2014
+ assert(sp != 0);
2015
+
2016
+ tif->tif_tagmethods.vgetfield = sp->vgetparent;
2017
+ tif->tif_tagmethods.vsetfield = sp->vsetparent;
2018
+ tif->tif_tagmethods.printdir = sp->printdir;
2019
+
2020
+ if( sp != NULL ) {
2021
+ if( sp->cinfo_initialized )
2022
+ TIFFjpeg_destroy(sp); /* release libjpeg resources */
2023
+ if (sp->jpegtables) /* tag value */
2024
+ _TIFFfree(sp->jpegtables);
2025
+ }
2026
+ _TIFFfree(tif->tif_data); /* release local state */
2027
+ tif->tif_data = NULL;
2028
+
2029
+ _TIFFSetDefaultCompressionState(tif);
2030
+ }
2031
+
2032
+ static void
2033
+ JPEGResetUpsampled( TIFF* tif )
2034
+ {
2035
+ JPEGState* sp = JState(tif);
2036
+ TIFFDirectory* td = &tif->tif_dir;
2037
+
2038
+ /*
2039
+ * Mark whether returned data is up-sampled or not so TIFFStripSize
2040
+ * and TIFFTileSize return values that reflect the true amount of
2041
+ * data.
2042
+ */
2043
+ tif->tif_flags &= ~TIFF_UPSAMPLED;
2044
+ if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
2045
+ if (td->td_photometric == PHOTOMETRIC_YCBCR &&
2046
+ sp->jpegcolormode == JPEGCOLORMODE_RGB) {
2047
+ tif->tif_flags |= TIFF_UPSAMPLED;
2048
+ } else {
2049
+ #ifdef notdef
2050
+ if (td->td_ycbcrsubsampling[0] != 1 ||
2051
+ td->td_ycbcrsubsampling[1] != 1)
2052
+ ; /* XXX what about up-sampling? */
2053
+ #endif
2054
+ }
2055
+ }
2056
+
2057
+ /*
2058
+ * Must recalculate cached tile size in case sampling state changed.
2059
+ * Should we really be doing this now if image size isn't set?
2060
+ */
2061
+ if( tif->tif_tilesize > 0 )
2062
+ tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t)(-1);
2063
+ if( tif->tif_scanlinesize > 0 )
2064
+ tif->tif_scanlinesize = TIFFScanlineSize(tif);
2065
+ }
2066
+
2067
+ static int
2068
+ JPEGVSetField(TIFF* tif, uint32 tag, va_list ap)
2069
+ {
2070
+ JPEGState* sp = JState(tif);
2071
+ const TIFFField* fip;
2072
+ uint32 v32;
2073
+
2074
+ assert(sp != NULL);
2075
+
2076
+ switch (tag) {
2077
+ case TIFFTAG_JPEGTABLES:
2078
+ v32 = (uint32) va_arg(ap, uint32);
2079
+ if (v32 == 0) {
2080
+ /* XXX */
2081
+ return (0);
2082
+ }
2083
+ _TIFFsetByteArray(&sp->jpegtables, va_arg(ap, void*),
2084
+ (long) v32);
2085
+ sp->jpegtables_length = v32;
2086
+ TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
2087
+ break;
2088
+ case TIFFTAG_JPEGQUALITY:
2089
+ sp->jpegquality = (int) va_arg(ap, int);
2090
+ return (1); /* pseudo tag */
2091
+ case TIFFTAG_JPEGCOLORMODE:
2092
+ sp->jpegcolormode = (int) va_arg(ap, int);
2093
+ JPEGResetUpsampled( tif );
2094
+ return (1); /* pseudo tag */
2095
+ case TIFFTAG_PHOTOMETRIC:
2096
+ {
2097
+ int ret_value = (*sp->vsetparent)(tif, tag, ap);
2098
+ JPEGResetUpsampled( tif );
2099
+ return ret_value;
2100
+ }
2101
+ case TIFFTAG_JPEGTABLESMODE:
2102
+ sp->jpegtablesmode = (int) va_arg(ap, int);
2103
+ return (1); /* pseudo tag */
2104
+ case TIFFTAG_YCBCRSUBSAMPLING:
2105
+ /* mark the fact that we have a real ycbcrsubsampling! */
2106
+ sp->ycbcrsampling_fetched = 1;
2107
+ /* should we be recomputing upsampling info here? */
2108
+ return (*sp->vsetparent)(tif, tag, ap);
2109
+ default:
2110
+ return (*sp->vsetparent)(tif, tag, ap);
2111
+ }
2112
+
2113
+ if ((fip = TIFFFieldWithTag(tif, tag))) {
2114
+ TIFFSetFieldBit(tif, fip->field_bit);
2115
+ } else {
2116
+ return (0);
2117
+ }
2118
+
2119
+ tif->tif_flags |= TIFF_DIRTYDIRECT;
2120
+ return (1);
2121
+ }
2122
+
2123
+ static int
2124
+ JPEGVGetField(TIFF* tif, uint32 tag, va_list ap)
2125
+ {
2126
+ JPEGState* sp = JState(tif);
2127
+
2128
+ assert(sp != NULL);
2129
+
2130
+ switch (tag) {
2131
+ case TIFFTAG_JPEGTABLES:
2132
+ *va_arg(ap, uint32*) = sp->jpegtables_length;
2133
+ *va_arg(ap, void**) = sp->jpegtables;
2134
+ break;
2135
+ case TIFFTAG_JPEGQUALITY:
2136
+ *va_arg(ap, int*) = sp->jpegquality;
2137
+ break;
2138
+ case TIFFTAG_JPEGCOLORMODE:
2139
+ *va_arg(ap, int*) = sp->jpegcolormode;
2140
+ break;
2141
+ case TIFFTAG_JPEGTABLESMODE:
2142
+ *va_arg(ap, int*) = sp->jpegtablesmode;
2143
+ break;
2144
+ default:
2145
+ return (*sp->vgetparent)(tif, tag, ap);
2146
+ }
2147
+ return (1);
2148
+ }
2149
+
2150
+ static void
2151
+ JPEGPrintDir(TIFF* tif, FILE* fd, long flags)
2152
+ {
2153
+ JPEGState* sp = JState(tif);
2154
+
2155
+ assert(sp != NULL);
2156
+ (void) flags;
2157
+
2158
+ if( sp != NULL ) {
2159
+ if (TIFFFieldSet(tif,FIELD_JPEGTABLES))
2160
+ fprintf(fd, " JPEG Tables: (%lu bytes)\n",
2161
+ (unsigned long) sp->jpegtables_length);
2162
+ if (sp->printdir)
2163
+ (*sp->printdir)(tif, fd, flags);
2164
+ }
2165
+ }
2166
+
2167
+ static uint32
2168
+ JPEGDefaultStripSize(TIFF* tif, uint32 s)
2169
+ {
2170
+ JPEGState* sp = JState(tif);
2171
+ TIFFDirectory *td = &tif->tif_dir;
2172
+
2173
+ s = (*sp->defsparent)(tif, s);
2174
+ if (s < td->td_imagelength)
2175
+ s = TIFFroundup_32(s, td->td_ycbcrsubsampling[1] * DCTSIZE);
2176
+ return (s);
2177
+ }
2178
+
2179
+ static void
2180
+ JPEGDefaultTileSize(TIFF* tif, uint32* tw, uint32* th)
2181
+ {
2182
+ JPEGState* sp = JState(tif);
2183
+ TIFFDirectory *td = &tif->tif_dir;
2184
+
2185
+ (*sp->deftparent)(tif, tw, th);
2186
+ *tw = TIFFroundup_32(*tw, td->td_ycbcrsubsampling[0] * DCTSIZE);
2187
+ *th = TIFFroundup_32(*th, td->td_ycbcrsubsampling[1] * DCTSIZE);
2188
+ }
2189
+
2190
+ /*
2191
+ * The JPEG library initialized used to be done in TIFFInitJPEG(), but
2192
+ * now that we allow a TIFF file to be opened in update mode it is necessary
2193
+ * to have some way of deciding whether compression or decompression is
2194
+ * desired other than looking at tif->tif_mode. We accomplish this by
2195
+ * examining {TILE/STRIP}BYTECOUNTS to see if there is a non-zero entry.
2196
+ * If so, we assume decompression is desired.
2197
+ *
2198
+ * This is tricky, because TIFFInitJPEG() is called while the directory is
2199
+ * being read, and generally speaking the BYTECOUNTS tag won't have been read
2200
+ * at that point. So we try to defer jpeg library initialization till we
2201
+ * do have that tag ... basically any access that might require the compressor
2202
+ * or decompressor that occurs after the reading of the directory.
2203
+ *
2204
+ * In an ideal world compressors or decompressors would be setup
2205
+ * at the point where a single tile or strip was accessed (for read or write)
2206
+ * so that stuff like update of missing tiles, or replacement of tiles could
2207
+ * be done. However, we aren't trying to crack that nut just yet ...
2208
+ *
2209
+ * NFW, Feb 3rd, 2003.
2210
+ */
2211
+
2212
+ static int JPEGInitializeLibJPEG( TIFF * tif, int decompress )
2213
+ {
2214
+ JPEGState* sp = JState(tif);
2215
+
2216
+ if(sp->cinfo_initialized)
2217
+ {
2218
+ if( !decompress && sp->cinfo.comm.is_decompressor )
2219
+ TIFFjpeg_destroy( sp );
2220
+ else if( decompress && !sp->cinfo.comm.is_decompressor )
2221
+ TIFFjpeg_destroy( sp );
2222
+ else
2223
+ return 1;
2224
+
2225
+ sp->cinfo_initialized = 0;
2226
+ }
2227
+
2228
+ /*
2229
+ * Initialize libjpeg.
2230
+ */
2231
+ if ( decompress ) {
2232
+ if (!TIFFjpeg_create_decompress(sp))
2233
+ return (0);
2234
+ } else {
2235
+ if (!TIFFjpeg_create_compress(sp))
2236
+ return (0);
2237
+ }
2238
+
2239
+ sp->cinfo_initialized = TRUE;
2240
+
2241
+ return 1;
2242
+ }
2243
+
2244
+ int
2245
+ TIFFInitJPEG(TIFF* tif, int scheme)
2246
+ {
2247
+ JPEGState* sp;
2248
+
2249
+ assert(scheme == COMPRESSION_JPEG);
2250
+
2251
+ /*
2252
+ * Merge codec-specific tag information.
2253
+ */
2254
+ if (!_TIFFMergeFields(tif, jpegFields, TIFFArrayCount(jpegFields))) {
2255
+ TIFFErrorExt(tif->tif_clientdata,
2256
+ "TIFFInitJPEG",
2257
+ "Merging JPEG codec-specific tags failed");
2258
+ return 0;
2259
+ }
2260
+
2261
+ /*
2262
+ * Allocate state block so tag methods have storage to record values.
2263
+ */
2264
+ tif->tif_data = (uint8*) _TIFFmalloc(sizeof (JPEGState));
2265
+
2266
+ if (tif->tif_data == NULL) {
2267
+ TIFFErrorExt(tif->tif_clientdata,
2268
+ "TIFFInitJPEG", "No space for JPEG state block");
2269
+ return 0;
2270
+ }
2271
+ _TIFFmemset(tif->tif_data, 0, sizeof(JPEGState));
2272
+
2273
+ sp = JState(tif);
2274
+ sp->tif = tif; /* back link */
2275
+
2276
+ /*
2277
+ * Override parent get/set field methods.
2278
+ */
2279
+ sp->vgetparent = tif->tif_tagmethods.vgetfield;
2280
+ tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */
2281
+ sp->vsetparent = tif->tif_tagmethods.vsetfield;
2282
+ tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */
2283
+ sp->printdir = tif->tif_tagmethods.printdir;
2284
+ tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */
2285
+
2286
+ /* Default values for codec-specific fields */
2287
+ sp->jpegtables = NULL;
2288
+ sp->jpegtables_length = 0;
2289
+ sp->jpegquality = 75; /* Default IJG quality */
2290
+ sp->jpegcolormode = JPEGCOLORMODE_RAW;
2291
+ sp->jpegtablesmode = JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF;
2292
+ sp->ycbcrsampling_fetched = 0;
2293
+
2294
+ /*
2295
+ * Install codec methods.
2296
+ */
2297
+ tif->tif_fixuptags = JPEGFixupTags;
2298
+ tif->tif_setupdecode = JPEGSetupDecode;
2299
+ tif->tif_predecode = JPEGPreDecode;
2300
+ tif->tif_decoderow = JPEGDecode;
2301
+ tif->tif_decodestrip = JPEGDecode;
2302
+ tif->tif_decodetile = JPEGDecode;
2303
+ tif->tif_setupencode = JPEGSetupEncode;
2304
+ tif->tif_preencode = JPEGPreEncode;
2305
+ tif->tif_postencode = JPEGPostEncode;
2306
+ tif->tif_encoderow = JPEGEncode;
2307
+ tif->tif_encodestrip = JPEGEncode;
2308
+ tif->tif_encodetile = JPEGEncode;
2309
+ tif->tif_cleanup = JPEGCleanup;
2310
+ sp->defsparent = tif->tif_defstripsize;
2311
+ tif->tif_defstripsize = JPEGDefaultStripSize;
2312
+ sp->deftparent = tif->tif_deftilesize;
2313
+ tif->tif_deftilesize = JPEGDefaultTileSize;
2314
+ tif->tif_flags |= TIFF_NOBITREV; /* no bit reversal, please */
2315
+
2316
+ sp->cinfo_initialized = FALSE;
2317
+
2318
+ /*
2319
+ ** Create a JPEGTables field if no directory has yet been created.
2320
+ ** We do this just to ensure that sufficient space is reserved for
2321
+ ** the JPEGTables field. It will be properly created the right
2322
+ ** size later.
2323
+ */
2324
+ if( tif->tif_diroff == 0 )
2325
+ {
2326
+ #define SIZE_OF_JPEGTABLES 2000
2327
+ /*
2328
+ The following line assumes incorrectly that all JPEG-in-TIFF files will have
2329
+ a JPEGTABLES tag generated and causes null-filled JPEGTABLES tags to be written
2330
+ when the JPEG data is placed with TIFFWriteRawStrip. The field bit should be
2331
+ set, anyway, later when actual JPEGTABLES header is generated, so removing it
2332
+ here hopefully is harmless.
2333
+ TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
2334
+ */
2335
+ sp->jpegtables_length = SIZE_OF_JPEGTABLES;
2336
+ sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length);
2337
+ // FIXME: NULL-deref after malloc failure
2338
+ _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES);
2339
+ #undef SIZE_OF_JPEGTABLES
2340
+ }
2341
+
2342
+ return 1;
2343
+ }
2344
+ #endif /* JPEG_SUPPORT */
2345
+
2346
+ /* vim: set ts=8 sts=8 sw=8 noet: */
2347
+
2348
+ /*
2349
+ * Local Variables:
2350
+ * mode: c
2351
+ * c-basic-offset: 8
2352
+ * fill-column: 78
2353
+ * End:
2354
+ */