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,2776 @@
1
+ /*
2
+ * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3
+ * Copyright (c) 2002-2007, Professor Benoit Macq
4
+ * Copyright (c) 2001-2003, David Janssens
5
+ * Copyright (c) 2002-2003, Yannick Verschueren
6
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
7
+ * Copyright (c) 2005, Herve Drolon, FreeImage Team
8
+ * Copyright (c) 2010-2011, Kaori Hagihara
9
+ * Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France
10
+ * Copyright (c) 2012, CS Systemes d'Information, France
11
+ * All rights reserved.
12
+ *
13
+ * Redistribution and use in source and binary forms, with or without
14
+ * modification, are permitted provided that the following conditions
15
+ * are met:
16
+ * 1. Redistributions of source code must retain the above copyright
17
+ * notice, this list of conditions and the following disclaimer.
18
+ * 2. Redistributions in binary form must reproduce the above copyright
19
+ * notice, this list of conditions and the following disclaimer in the
20
+ * documentation and/or other materials provided with the distribution.
21
+ *
22
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
23
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ * POSSIBILITY OF SUCH DAMAGE.
33
+ */
34
+ #include "opj_includes.h"
35
+
36
+ /** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
37
+ /*@{*/
38
+
39
+ #define OPJ_BOX_SIZE 1024
40
+
41
+ /** @name Local static functions */
42
+ /*@{*/
43
+
44
+ /*static void jp2_write_url(opj_cio_t *cio, char *Idx_file);*/
45
+
46
+ /**
47
+ * Reads a IHDR box - Image Header box
48
+ *
49
+ * @param p_image_header_data pointer to actual data (already read from file)
50
+ * @param jp2 the jpeg2000 file codec.
51
+ * @param p_image_header_size the size of the image header
52
+ * @param p_manager the user event manager.
53
+ *
54
+ * @return true if the image header is valid, false else.
55
+ */
56
+ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
57
+ OPJ_BYTE *p_image_header_data,
58
+ OPJ_UINT32 p_image_header_size,
59
+ opj_event_mgr_t * p_manager );
60
+
61
+ /**
62
+ * Writes the Image Header box - Image Header box.
63
+ *
64
+ * @param jp2 jpeg2000 file codec.
65
+ * @param p_nb_bytes_written pointer to store the nb of bytes written by the function.
66
+ *
67
+ * @return the data being copied.
68
+ */
69
+ static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
70
+ OPJ_UINT32 * p_nb_bytes_written );
71
+
72
+ /**
73
+ * Writes the Bit per Component box.
74
+ *
75
+ * @param jp2 jpeg2000 file codec.
76
+ * @param p_nb_bytes_written pointer to store the nb of bytes written by the function.
77
+ *
78
+ * @return the data being copied.
79
+ */
80
+ static OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2,
81
+ OPJ_UINT32 * p_nb_bytes_written );
82
+
83
+ /**
84
+ * Reads a Bit per Component box.
85
+ *
86
+ * @param p_bpc_header_data pointer to actual data (already read from file)
87
+ * @param jp2 the jpeg2000 file codec.
88
+ * @param p_bpc_header_size the size of the bpc header
89
+ * @param p_manager the user event manager.
90
+ *
91
+ * @return true if the bpc header is valid, fale else.
92
+ */
93
+ static OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2,
94
+ OPJ_BYTE * p_bpc_header_data,
95
+ OPJ_UINT32 p_bpc_header_size,
96
+ opj_event_mgr_t * p_manager );
97
+
98
+ static OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2,
99
+ OPJ_BYTE * p_cdef_header_data,
100
+ OPJ_UINT32 p_cdef_header_size,
101
+ opj_event_mgr_t * p_manager );
102
+
103
+ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color);
104
+
105
+ /**
106
+ * Writes the Colour Specification box.
107
+ *
108
+ * @param jp2 jpeg2000 file codec.
109
+ * @param p_nb_bytes_written pointer to store the nb of bytes written by the function.
110
+ *
111
+ * @return the data being copied.
112
+ */
113
+ static OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2,
114
+ OPJ_UINT32 * p_nb_bytes_written );
115
+
116
+ /**
117
+ * Writes a FTYP box - File type box
118
+ *
119
+ * @param cio the stream to write data to.
120
+ * @param jp2 the jpeg2000 file codec.
121
+ * @param p_manager the user event manager.
122
+ *
123
+ * @return true if writing was successful.
124
+ */
125
+ static OPJ_BOOL opj_jp2_write_ftyp( opj_jp2_t *jp2,
126
+ opj_stream_private_t *cio,
127
+ opj_event_mgr_t * p_manager );
128
+
129
+ /**
130
+ * Reads a a FTYP box - File type box
131
+ *
132
+ * @param p_header_data the data contained in the FTYP box.
133
+ * @param jp2 the jpeg2000 file codec.
134
+ * @param p_header_size the size of the data contained in the FTYP box.
135
+ * @param p_manager the user event manager.
136
+ *
137
+ * @return true if the FTYP box is valid.
138
+ */
139
+ static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2,
140
+ OPJ_BYTE * p_header_data,
141
+ OPJ_UINT32 p_header_size,
142
+ opj_event_mgr_t * p_manager );
143
+
144
+ OPJ_BOOL opj_jp2_skip_jp2c( opj_jp2_t *jp2,
145
+ opj_stream_private_t *cio,
146
+ opj_event_mgr_t * p_manager );
147
+
148
+ /**
149
+ * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
150
+ *
151
+ * @param p_header_data the data contained in the file header box.
152
+ * @param jp2 the jpeg2000 file codec.
153
+ * @param p_header_size the size of the data contained in the file header box.
154
+ * @param p_manager the user event manager.
155
+ *
156
+ * @return true if the JP2 Header box was successfully reconized.
157
+ */
158
+ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
159
+ OPJ_BYTE *p_header_data,
160
+ OPJ_UINT32 p_header_size,
161
+ opj_event_mgr_t * p_manager );
162
+
163
+ /**
164
+ * Writes the Jpeg2000 codestream Header box - JP2C Header box. This function must be called AFTER the coding has been done.
165
+ *
166
+ * @param cio the stream to write data to.
167
+ * @param jp2 the jpeg2000 file codec.
168
+ * @param p_manager user event manager.
169
+ *
170
+ * @return true if writing was successful.
171
+ */
172
+ static OPJ_BOOL opj_jp2_write_jp2c( opj_jp2_t *jp2,
173
+ opj_stream_private_t *cio,
174
+ opj_event_mgr_t * p_manager );
175
+
176
+ #ifdef USE_JPIP
177
+ /**
178
+ * Write index Finder box
179
+ * @param cio the stream to write to.
180
+ * @param jp2 the jpeg2000 file codec.
181
+ * @param p_manager user event manager.
182
+ */
183
+ static OPJ_BOOL opj_jpip_write_iptr( opj_jp2_t *jp2,
184
+ opj_stream_private_t *cio,
185
+ opj_event_mgr_t * p_manager );
186
+
187
+ /**
188
+ * Write index Finder box
189
+ * @param cio the stream to write to.
190
+ * @param jp2 the jpeg2000 file codec.
191
+ * @param p_manager user event manager.
192
+ */
193
+ static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2,
194
+ opj_stream_private_t *cio,
195
+ opj_event_mgr_t * p_manager );
196
+
197
+ /**
198
+ * Write file Index (superbox)
199
+ * @param cio the stream to write to.
200
+ * @param jp2 the jpeg2000 file codec.
201
+ * @param p_manager user event manager.
202
+ */
203
+ static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2,
204
+ opj_stream_private_t *cio,
205
+ opj_event_mgr_t * p_manager );
206
+ #endif /* USE_JPIP */
207
+
208
+ /**
209
+ * Reads a jpeg2000 file signature box.
210
+ *
211
+ * @param p_header_data the data contained in the signature box.
212
+ * @param jp2 the jpeg2000 file codec.
213
+ * @param p_header_size the size of the data contained in the signature box.
214
+ * @param p_manager the user event manager.
215
+ *
216
+ * @return true if the file signature box is valid.
217
+ */
218
+ static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2,
219
+ OPJ_BYTE * p_header_data,
220
+ OPJ_UINT32 p_header_size,
221
+ opj_event_mgr_t * p_manager);
222
+
223
+ /**
224
+ * Writes a jpeg2000 file signature box.
225
+ *
226
+ * @param cio the stream to write data to.
227
+ * @param jp2 the jpeg2000 file codec.
228
+ * @param p_manager the user event manager.
229
+ *
230
+ * @return true if writing was successful.
231
+ */
232
+ static OPJ_BOOL opj_jp2_write_jp( opj_jp2_t *jp2,
233
+ opj_stream_private_t *cio,
234
+ opj_event_mgr_t * p_manager );
235
+
236
+ /**
237
+ Apply collected palette data
238
+ @param color Collector for profile, cdef and pclr data
239
+ @param image
240
+ */
241
+ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color);
242
+
243
+ static void opj_jp2_free_pclr(opj_jp2_color_t *color);
244
+
245
+ /**
246
+ * Collect palette data
247
+ *
248
+ * @param jp2 JP2 handle
249
+ * @param p_pclr_header_data FIXME DOC
250
+ * @param p_pclr_header_size FIXME DOC
251
+ * @param p_manager
252
+ *
253
+ * @return Returns true if successful, returns false otherwise
254
+ */
255
+ static OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
256
+ OPJ_BYTE * p_pclr_header_data,
257
+ OPJ_UINT32 p_pclr_header_size,
258
+ opj_event_mgr_t * p_manager );
259
+
260
+ /**
261
+ * Collect component mapping data
262
+ *
263
+ * @param jp2 JP2 handle
264
+ * @param p_cmap_header_data FIXME DOC
265
+ * @param p_cmap_header_size FIXME DOC
266
+ * @param p_manager FIXME DOC
267
+ *
268
+ * @return Returns true if successful, returns false otherwise
269
+ */
270
+
271
+ static OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2,
272
+ OPJ_BYTE * p_cmap_header_data,
273
+ OPJ_UINT32 p_cmap_header_size,
274
+ opj_event_mgr_t * p_manager );
275
+
276
+ /**
277
+ * Reads the Color Specification box.
278
+ *
279
+ * @param p_colr_header_data pointer to actual data (already read from file)
280
+ * @param jp2 the jpeg2000 file codec.
281
+ * @param p_colr_header_size the size of the color header
282
+ * @param p_manager the user event manager.
283
+ *
284
+ * @return true if the bpc header is valid, fale else.
285
+ */
286
+ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
287
+ OPJ_BYTE * p_colr_header_data,
288
+ OPJ_UINT32 p_colr_header_size,
289
+ opj_event_mgr_t * p_manager );
290
+
291
+ /*@}*/
292
+
293
+ /*@}*/
294
+
295
+ /**
296
+ * Sets up the procedures to do on writing header after the codestream.
297
+ * Developpers wanting to extend the library can add their own writing procedures.
298
+ */
299
+ static void opj_jp2_setup_end_header_writing (opj_jp2_t *jp2);
300
+
301
+ /**
302
+ * Sets up the procedures to do on reading header after the codestream.
303
+ * Developpers wanting to extend the library can add their own writing procedures.
304
+ */
305
+ static void opj_jp2_setup_end_header_reading (opj_jp2_t *jp2);
306
+
307
+ /**
308
+ * Reads a jpeg2000 file header structure.
309
+ *
310
+ * @param jp2 the jpeg2000 file header structure.
311
+ * @param stream the stream to read data from.
312
+ * @param p_manager the user event manager.
313
+ *
314
+ * @return true if the box is valid.
315
+ */
316
+ static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
317
+ opj_stream_private_t *stream,
318
+ opj_event_mgr_t * p_manager );
319
+
320
+ /**
321
+ * Excutes the given procedures on the given codec.
322
+ *
323
+ * @param p_procedure_list the list of procedures to execute
324
+ * @param jp2 the jpeg2000 file codec to execute the procedures on.
325
+ * @param stream the stream to execute the procedures on.
326
+ * @param p_manager the user manager.
327
+ *
328
+ * @return true if all the procedures were successfully executed.
329
+ */
330
+ static OPJ_BOOL opj_jp2_exec ( opj_jp2_t * jp2,
331
+ opj_procedure_list_t * p_procedure_list,
332
+ opj_stream_private_t *stream,
333
+ opj_event_mgr_t * p_manager );
334
+
335
+ /**
336
+ * Reads a box header. The box is the way data is packed inside a jpeg2000 file structure.
337
+ *
338
+ * @param cio the input stream to read data from.
339
+ * @param box the box structure to fill.
340
+ * @param p_number_bytes_read pointer to an int that will store the number of bytes read from the stream (shoul usually be 2).
341
+ * @param p_manager user event manager.
342
+ *
343
+ * @return true if the box is reconized, false otherwise
344
+ */
345
+ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
346
+ OPJ_UINT32 * p_number_bytes_read,
347
+ opj_stream_private_t *cio,
348
+ opj_event_mgr_t * p_manager);
349
+
350
+ /**
351
+ * Sets up the validation ,i.e. adds the procedures to lauch to make sure the codec parameters
352
+ * are valid. Developpers wanting to extend the library can add their own validation procedures.
353
+ */
354
+ static void opj_jp2_setup_encoding_validation (opj_jp2_t *jp2);
355
+
356
+ /**
357
+ * Sets up the procedures to do on writing header. Developpers wanting to extend the library can add their own writing procedures.
358
+ */
359
+ static void opj_jp2_setup_header_writing (opj_jp2_t *jp2);
360
+
361
+ OPJ_BOOL opj_jp2_default_validation ( opj_jp2_t * jp2,
362
+ opj_stream_private_t *cio,
363
+ opj_event_mgr_t * p_manager );
364
+
365
+ /**
366
+ * Finds the image execution function related to the given box id.
367
+ *
368
+ * @param p_id the id of the handler to fetch.
369
+ *
370
+ * @return the given handler or NULL if it could not be found.
371
+ */
372
+ static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_id);
373
+
374
+ /**
375
+ * Finds the execution function related to the given box id.
376
+ *
377
+ * @param p_id the id of the handler to fetch.
378
+ *
379
+ * @return the given handler or NULL if it could not be found.
380
+ */
381
+ static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id );
382
+
383
+ const opj_jp2_header_handler_t jp2_header [] =
384
+ {
385
+ {JP2_JP,opj_jp2_read_jp},
386
+ {JP2_FTYP,opj_jp2_read_ftyp},
387
+ {JP2_JP2H,opj_jp2_read_jp2h}
388
+ };
389
+
390
+ const opj_jp2_header_handler_t jp2_img_header [] =
391
+ {
392
+ {JP2_IHDR,opj_jp2_read_ihdr},
393
+ {JP2_COLR,opj_jp2_read_colr},
394
+ {JP2_BPCC,opj_jp2_read_bpcc},
395
+ {JP2_PCLR,opj_jp2_read_pclr},
396
+ {JP2_CMAP,opj_jp2_read_cmap},
397
+ {JP2_CDEF,opj_jp2_read_cdef}
398
+
399
+ };
400
+
401
+ /**
402
+ * Reads a box header. The box is the way data is packed inside a jpeg2000 file structure. Data is read from a character string
403
+ *
404
+ * @param box the box structure to fill.
405
+ * @param p_data the character string to read data from.
406
+ * @param p_number_bytes_read pointer to an int that will store the number of bytes read from the stream (shoul usually be 2).
407
+ * @param p_box_max_size the maximum number of bytes in the box.
408
+ * @param p_manager FIXME DOC
409
+ *
410
+ * @return true if the box is reconized, false otherwise
411
+ */
412
+ static OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
413
+ OPJ_BYTE * p_data,
414
+ OPJ_UINT32 * p_number_bytes_read,
415
+ OPJ_UINT32 p_box_max_size,
416
+ opj_event_mgr_t * p_manager );
417
+
418
+ /**
419
+ * Sets up the validation ,i.e. adds the procedures to lauch to make sure the codec parameters
420
+ * are valid. Developpers wanting to extend the library can add their own validation procedures.
421
+ */
422
+ static void opj_jp2_setup_decoding_validation (opj_jp2_t *jp2);
423
+
424
+ /**
425
+ * Sets up the procedures to do on reading header.
426
+ * Developpers wanting to extend the library can add their own writing procedures.
427
+ */
428
+ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2);
429
+
430
+ /* ----------------------------------------------------------------------- */
431
+ OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
432
+ OPJ_UINT32 * p_number_bytes_read,
433
+ opj_stream_private_t *cio,
434
+ opj_event_mgr_t * p_manager )
435
+ {
436
+ /* read header from file */
437
+ OPJ_BYTE l_data_header [8];
438
+
439
+ /* preconditions */
440
+ assert(cio != 00);
441
+ assert(box != 00);
442
+ assert(p_number_bytes_read != 00);
443
+ assert(p_manager != 00);
444
+
445
+ *p_number_bytes_read = (OPJ_UINT32)opj_stream_read_data(cio,l_data_header,8,p_manager);
446
+ if (*p_number_bytes_read != 8) {
447
+ return OPJ_FALSE;
448
+ }
449
+
450
+ /* process read data */
451
+ opj_read_bytes(l_data_header,&(box->length), 4);
452
+ opj_read_bytes(l_data_header+4,&(box->type), 4);
453
+
454
+ if(box->length == 0)/* last box */
455
+ {
456
+ const OPJ_OFF_T bleft = opj_stream_get_number_byte_left(cio);
457
+ box->length = (OPJ_UINT32)bleft;
458
+ assert( (OPJ_OFF_T)box->length == bleft );
459
+ return OPJ_TRUE;
460
+ }
461
+
462
+ /* do we have a "special very large box ?" */
463
+ /* read then the XLBox */
464
+ if (box->length == 1) {
465
+ OPJ_UINT32 l_xl_part_size;
466
+
467
+ OPJ_UINT32 l_nb_bytes_read = (OPJ_UINT32)opj_stream_read_data(cio,l_data_header,8,p_manager);
468
+ if (l_nb_bytes_read != 8) {
469
+ if (l_nb_bytes_read > 0) {
470
+ *p_number_bytes_read += l_nb_bytes_read;
471
+ }
472
+
473
+ return OPJ_FALSE;
474
+ }
475
+
476
+ *p_number_bytes_read = 16;
477
+ opj_read_bytes(l_data_header,&l_xl_part_size, 4);
478
+ if (l_xl_part_size != 0) {
479
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
480
+ return OPJ_FALSE;
481
+ }
482
+ opj_read_bytes(l_data_header+4,&(box->length), 4);
483
+ }
484
+ return OPJ_TRUE;
485
+ }
486
+
487
+ #if 0
488
+ static void jp2_write_url(opj_cio_t *cio, char *Idx_file) {
489
+ OPJ_UINT32 i;
490
+ opj_jp2_box_t box;
491
+
492
+ box.init_pos = cio_tell(cio);
493
+ cio_skip(cio, 4);
494
+ cio_write(cio, JP2_URL, 4); /* DBTL */
495
+ cio_write(cio, 0, 1); /* VERS */
496
+ cio_write(cio, 0, 3); /* FLAG */
497
+
498
+ if(Idx_file) {
499
+ for (i = 0; i < strlen(Idx_file); i++) {
500
+ cio_write(cio, Idx_file[i], 1);
501
+ }
502
+ }
503
+
504
+ box.length = cio_tell(cio) - box.init_pos;
505
+ cio_seek(cio, box.init_pos);
506
+ cio_write(cio, box.length, 4); /* L */
507
+ cio_seek(cio, box.init_pos + box.length);
508
+ }
509
+ #endif
510
+
511
+ OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
512
+ OPJ_BYTE *p_image_header_data,
513
+ OPJ_UINT32 p_image_header_size,
514
+ opj_event_mgr_t * p_manager )
515
+ {
516
+ /* preconditions */
517
+ assert(p_image_header_data != 00);
518
+ assert(jp2 != 00);
519
+ assert(p_manager != 00);
520
+
521
+ if (p_image_header_size != 14) {
522
+ opj_event_msg(p_manager, EVT_ERROR, "Bad image header box (bad size)\n");
523
+ return OPJ_FALSE;
524
+ }
525
+
526
+ opj_read_bytes(p_image_header_data,&(jp2->h),4); /* HEIGHT */
527
+ p_image_header_data += 4;
528
+ opj_read_bytes(p_image_header_data,&(jp2->w),4); /* WIDTH */
529
+ p_image_header_data += 4;
530
+ opj_read_bytes(p_image_header_data,&(jp2->numcomps),2); /* NC */
531
+ p_image_header_data += 2;
532
+
533
+ /* allocate memory for components */
534
+ jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
535
+ if (jp2->comps == 0) {
536
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n");
537
+ return OPJ_FALSE;
538
+ }
539
+ memset(jp2->comps,0,jp2->numcomps * sizeof(opj_jp2_comps_t));
540
+
541
+ opj_read_bytes(p_image_header_data,&(jp2->bpc),1); /* BPC */
542
+ ++ p_image_header_data;
543
+
544
+ opj_read_bytes(p_image_header_data,&(jp2->C),1); /* C */
545
+ ++ p_image_header_data;
546
+
547
+ /* Should be equal to 7 cf. chapter about image header box of the norm */
548
+ if (jp2->C != 7){
549
+ opj_event_msg(p_manager, EVT_INFO, "JP2 IHDR box: compression type indicate that the file is not a conforming JP2 file (%d) \n", jp2->C);
550
+ }
551
+
552
+ opj_read_bytes(p_image_header_data,&(jp2->UnkC),1); /* UnkC */
553
+ ++ p_image_header_data;
554
+ opj_read_bytes(p_image_header_data,&(jp2->IPR),1); /* IPR */
555
+ ++ p_image_header_data;
556
+
557
+ return OPJ_TRUE;
558
+ }
559
+
560
+ OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
561
+ OPJ_UINT32 * p_nb_bytes_written
562
+ )
563
+ {
564
+ OPJ_BYTE * l_ihdr_data,* l_current_ihdr_ptr;
565
+
566
+ /* preconditions */
567
+ assert(jp2 != 00);
568
+ assert(p_nb_bytes_written != 00);
569
+
570
+ /* default image header is 22 bytes wide */
571
+ l_ihdr_data = (OPJ_BYTE *) opj_malloc(22);
572
+ if (l_ihdr_data == 00) {
573
+ return 00;
574
+ }
575
+ memset(l_ihdr_data,0,22);
576
+
577
+ l_current_ihdr_ptr = l_ihdr_data;
578
+
579
+ opj_write_bytes(l_current_ihdr_ptr,22,4); /* write box size */
580
+ l_current_ihdr_ptr+=4;
581
+
582
+ opj_write_bytes(l_current_ihdr_ptr,JP2_IHDR, 4); /* IHDR */
583
+ l_current_ihdr_ptr+=4;
584
+
585
+ opj_write_bytes(l_current_ihdr_ptr,jp2->h, 4); /* HEIGHT */
586
+ l_current_ihdr_ptr+=4;
587
+
588
+ opj_write_bytes(l_current_ihdr_ptr, jp2->w, 4); /* WIDTH */
589
+ l_current_ihdr_ptr+=4;
590
+
591
+ opj_write_bytes(l_current_ihdr_ptr, jp2->numcomps, 2); /* NC */
592
+ l_current_ihdr_ptr+=2;
593
+
594
+ opj_write_bytes(l_current_ihdr_ptr, jp2->bpc, 1); /* BPC */
595
+ ++l_current_ihdr_ptr;
596
+
597
+ opj_write_bytes(l_current_ihdr_ptr, jp2->C, 1); /* C : Always 7 */
598
+ ++l_current_ihdr_ptr;
599
+
600
+ opj_write_bytes(l_current_ihdr_ptr, jp2->UnkC, 1); /* UnkC, colorspace unknown */
601
+ ++l_current_ihdr_ptr;
602
+
603
+ opj_write_bytes(l_current_ihdr_ptr, jp2->IPR, 1); /* IPR, no intellectual property */
604
+ ++l_current_ihdr_ptr;
605
+
606
+ *p_nb_bytes_written = 22;
607
+
608
+ return l_ihdr_data;
609
+ }
610
+
611
+ OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2,
612
+ OPJ_UINT32 * p_nb_bytes_written
613
+ )
614
+ {
615
+ OPJ_UINT32 i;
616
+ /* room for 8 bytes for box and 1 byte for each component */
617
+ OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps;
618
+ OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr;
619
+
620
+ /* preconditions */
621
+ assert(jp2 != 00);
622
+ assert(p_nb_bytes_written != 00);
623
+
624
+ l_bpcc_data = (OPJ_BYTE *) opj_malloc(l_bpcc_size);
625
+ if (l_bpcc_data == 00) {
626
+ return 00;
627
+ }
628
+ memset(l_bpcc_data,0,l_bpcc_size);
629
+
630
+ l_current_bpcc_ptr = l_bpcc_data;
631
+
632
+ opj_write_bytes(l_current_bpcc_ptr,l_bpcc_size,4); /* write box size */
633
+ l_current_bpcc_ptr += 4;
634
+
635
+ opj_write_bytes(l_current_bpcc_ptr,JP2_BPCC,4); /* BPCC */
636
+ l_current_bpcc_ptr += 4;
637
+
638
+ for (i = 0; i < jp2->numcomps; ++i) {
639
+ opj_write_bytes(l_current_bpcc_ptr, jp2->comps[i].bpcc, 1); /* write each component information */
640
+ ++l_current_bpcc_ptr;
641
+ }
642
+
643
+ *p_nb_bytes_written = l_bpcc_size;
644
+
645
+ return l_bpcc_data;
646
+ }
647
+
648
+ OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2,
649
+ OPJ_BYTE * p_bpc_header_data,
650
+ OPJ_UINT32 p_bpc_header_size,
651
+ opj_event_mgr_t * p_manager
652
+ )
653
+ {
654
+ OPJ_UINT32 i;
655
+
656
+ /* preconditions */
657
+ assert(p_bpc_header_data != 00);
658
+ assert(jp2 != 00);
659
+ assert(p_manager != 00);
660
+
661
+
662
+ if (jp2->bpc != 255 ){
663
+ opj_event_msg(p_manager, EVT_WARNING, "A BPCC header box is available although BPC given by the IHDR box (%d) indicate components bit depth is constant\n",jp2->bpc);
664
+ }
665
+
666
+ /* and length is relevant */
667
+ if (p_bpc_header_size != jp2->numcomps) {
668
+ opj_event_msg(p_manager, EVT_ERROR, "Bad BPCC header box (bad size)\n");
669
+ return OPJ_FALSE;
670
+ }
671
+
672
+ /* read info for each component */
673
+ for (i = 0; i < jp2->numcomps; ++i) {
674
+ opj_read_bytes(p_bpc_header_data,&jp2->comps[i].bpcc ,1); /* read each BPCC component */
675
+ ++p_bpc_header_data;
676
+ }
677
+
678
+ return OPJ_TRUE;
679
+ }
680
+
681
+ OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2,
682
+ OPJ_UINT32 * p_nb_bytes_written
683
+ )
684
+ {
685
+ /* room for 8 bytes for box 3 for common data and variable upon profile*/
686
+ OPJ_UINT32 l_colr_size = 11;
687
+ OPJ_BYTE * l_colr_data,* l_current_colr_ptr;
688
+
689
+ /* preconditions */
690
+ assert(jp2 != 00);
691
+ assert(p_nb_bytes_written != 00);
692
+ assert(jp2->meth == 1 || jp2->meth == 2);
693
+
694
+ switch (jp2->meth) {
695
+ case 1 :
696
+ l_colr_size += 4; /* EnumCS */
697
+ break;
698
+ case 2 :
699
+ assert(jp2->color.icc_profile_len); /* ICC profile */
700
+ l_colr_size += jp2->color.icc_profile_len;
701
+ break;
702
+ default :
703
+ return 00;
704
+ }
705
+
706
+ l_colr_data = (OPJ_BYTE *) opj_malloc(l_colr_size);
707
+ if (l_colr_data == 00) {
708
+ return 00;
709
+ }
710
+ memset(l_colr_data,0,l_colr_size);
711
+
712
+ l_current_colr_ptr = l_colr_data;
713
+
714
+ opj_write_bytes(l_current_colr_ptr,l_colr_size,4); /* write box size */
715
+ l_current_colr_ptr += 4;
716
+
717
+ opj_write_bytes(l_current_colr_ptr,JP2_COLR,4); /* BPCC */
718
+ l_current_colr_ptr += 4;
719
+
720
+ opj_write_bytes(l_current_colr_ptr, jp2->meth,1); /* METH */
721
+ ++l_current_colr_ptr;
722
+
723
+ opj_write_bytes(l_current_colr_ptr, jp2->precedence,1); /* PRECEDENCE */
724
+ ++l_current_colr_ptr;
725
+
726
+ opj_write_bytes(l_current_colr_ptr, jp2->approx,1); /* APPROX */
727
+ ++l_current_colr_ptr;
728
+
729
+ if (jp2->meth == 1) { /* Meth value is restricted to 1 or 2 (Table I.9 of part 1) */
730
+ opj_write_bytes(l_current_colr_ptr, jp2->enumcs,4); } /* EnumCS */
731
+ else {
732
+ if (jp2->meth == 2) { /* ICC profile */
733
+ OPJ_UINT32 i;
734
+ for(i = 0; i < jp2->color.icc_profile_len; ++i) {
735
+ opj_write_bytes(l_current_colr_ptr, jp2->color.icc_profile_buf[i], 1);
736
+ ++l_current_colr_ptr;
737
+ }
738
+ }
739
+ }
740
+
741
+ *p_nb_bytes_written = l_colr_size;
742
+
743
+ return l_colr_data;
744
+ }
745
+
746
+ void opj_jp2_free_pclr(opj_jp2_color_t *color)
747
+ {
748
+ opj_free(color->jp2_pclr->channel_sign);
749
+ opj_free(color->jp2_pclr->channel_size);
750
+ opj_free(color->jp2_pclr->entries);
751
+
752
+ if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap);
753
+
754
+ opj_free(color->jp2_pclr); color->jp2_pclr = NULL;
755
+ }
756
+
757
+ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, opj_event_mgr_t *p_manager)
758
+ {
759
+ OPJ_UINT16 i;
760
+
761
+ /* testcase 4149.pdf.SIGSEGV.cf7.3501 */
762
+ if (color->jp2_cdef) {
763
+ opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
764
+ OPJ_UINT16 n = color->jp2_cdef->n;
765
+
766
+ for (i = 0; i < n; i++) {
767
+ if (info[i].cn >= image->numcomps) {
768
+ opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, image->numcomps);
769
+ return OPJ_FALSE;
770
+ }
771
+ if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >= image->numcomps) {
772
+ opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].asoc - 1, image->numcomps);
773
+ return OPJ_FALSE;
774
+ }
775
+ }
776
+ }
777
+
778
+ /* testcases 451.pdf.SIGSEGV.f4c.3723, 451.pdf.SIGSEGV.5b5.3723 and
779
+ 66ea31acbb0f23a2bbc91f64d69a03f5_signal_sigsegv_13937c0_7030_5725.pdf */
780
+ if (color->jp2_pclr && color->jp2_pclr->cmap) {
781
+ OPJ_UINT16 nr_channels = color->jp2_pclr->nr_channels;
782
+ opj_jp2_cmap_comp_t *cmap = color->jp2_pclr->cmap;
783
+ OPJ_BOOL *pcol_usage, is_sane = OPJ_TRUE;
784
+
785
+ /* verify that all original components match an existing one */
786
+ for (i = 0; i < nr_channels; i++) {
787
+ if (cmap[i].cmp >= image->numcomps) {
788
+ opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", cmap[i].cmp, image->numcomps);
789
+ is_sane = OPJ_FALSE;
790
+ }
791
+ }
792
+
793
+ pcol_usage = opj_calloc(nr_channels, sizeof(OPJ_BOOL));
794
+ if (!pcol_usage) {
795
+ opj_event_msg(p_manager, EVT_ERROR, "Unexpected OOM.\n");
796
+ return OPJ_FALSE;
797
+ }
798
+ /* verify that no component is targeted more than once */
799
+ for (i = 0; i < nr_channels; i++) {
800
+ OPJ_UINT16 pcol = cmap[i].pcol;
801
+ assert(cmap[i].mtyp == 0 || cmap[i].mtyp == 1);
802
+ if (pcol >= nr_channels) {
803
+ opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol);
804
+ is_sane = OPJ_FALSE;
805
+ }
806
+ else if (pcol_usage[pcol] && cmap[i].mtyp == 1) {
807
+ opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol);
808
+ is_sane = OPJ_FALSE;
809
+ }
810
+ else if (cmap[i].mtyp == 0 && cmap[i].pcol != 0) {
811
+ /* I.5.3.5 PCOL: If the value of the MTYP field for this channel is 0, then
812
+ * the value of this field shall be 0. */
813
+ opj_event_msg(p_manager, EVT_ERROR, "Direct use at #%d however pcol=%d.\n", i, pcol);
814
+ is_sane = OPJ_FALSE;
815
+ }
816
+ else
817
+ pcol_usage[pcol] = OPJ_TRUE;
818
+ }
819
+ /* verify that all components are targeted at least once */
820
+ for (i = 0; i < nr_channels; i++) {
821
+ if (!pcol_usage[i] && cmap[i].mtyp != 0) {
822
+ opj_event_msg(p_manager, EVT_ERROR, "Component %d doesn't have a mapping.\n", i);
823
+ is_sane = OPJ_FALSE;
824
+ }
825
+ }
826
+ opj_free(pcol_usage);
827
+ if (!is_sane) {
828
+ return OPJ_FALSE;
829
+ }
830
+ }
831
+
832
+ return OPJ_TRUE;
833
+ }
834
+
835
+ /* file9.jp2 */
836
+ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
837
+ {
838
+ opj_image_comp_t *old_comps, *new_comps;
839
+ OPJ_BYTE *channel_size, *channel_sign;
840
+ OPJ_UINT32 *entries;
841
+ opj_jp2_cmap_comp_t *cmap;
842
+ OPJ_INT32 *src, *dst;
843
+ OPJ_UINT32 j, max;
844
+ OPJ_UINT16 i, nr_channels, cmp, pcol;
845
+ OPJ_INT32 k, top_k;
846
+
847
+ channel_size = color->jp2_pclr->channel_size;
848
+ channel_sign = color->jp2_pclr->channel_sign;
849
+ entries = color->jp2_pclr->entries;
850
+ cmap = color->jp2_pclr->cmap;
851
+ nr_channels = color->jp2_pclr->nr_channels;
852
+
853
+ old_comps = image->comps;
854
+ new_comps = (opj_image_comp_t*)
855
+ opj_malloc(nr_channels * sizeof(opj_image_comp_t));
856
+
857
+ for(i = 0; i < nr_channels; ++i) {
858
+ pcol = cmap[i].pcol; cmp = cmap[i].cmp;
859
+
860
+ /* Direct use */
861
+ if(cmap[i].mtyp == 0){
862
+ assert( pcol == 0 );
863
+ new_comps[i] = old_comps[cmp];
864
+ } else {
865
+ assert( i == pcol );
866
+ new_comps[pcol] = old_comps[cmp];
867
+ }
868
+
869
+ /* Palette mapping: */
870
+ new_comps[i].data = (OPJ_INT32*)
871
+ opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32));
872
+ new_comps[i].prec = channel_size[i];
873
+ new_comps[i].sgnd = channel_sign[i];
874
+ }
875
+
876
+ top_k = color->jp2_pclr->nr_entries - 1;
877
+
878
+ for(i = 0; i < nr_channels; ++i) {
879
+ /* Palette mapping: */
880
+ cmp = cmap[i].cmp; pcol = cmap[i].pcol;
881
+ src = old_comps[cmp].data;
882
+ assert( src );
883
+ max = new_comps[pcol].w * new_comps[pcol].h;
884
+
885
+ /* Direct use: */
886
+ if(cmap[i].mtyp == 0) {
887
+ assert( cmp == 0 );
888
+ dst = new_comps[i].data;
889
+ assert( dst );
890
+ for(j = 0; j < max; ++j) {
891
+ dst[j] = src[j];
892
+ }
893
+ }
894
+ else {
895
+ assert( i == pcol );
896
+ dst = new_comps[pcol].data;
897
+ assert( dst );
898
+ for(j = 0; j < max; ++j) {
899
+ /* The index */
900
+ if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
901
+
902
+ /* The colour */
903
+ dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol];
904
+ }
905
+ }
906
+ }
907
+
908
+ max = image->numcomps;
909
+ for(i = 0; i < max; ++i) {
910
+ if(old_comps[i].data) opj_free(old_comps[i].data);
911
+ }
912
+
913
+ opj_free(old_comps);
914
+ image->comps = new_comps;
915
+ image->numcomps = nr_channels;
916
+
917
+ opj_jp2_free_pclr(color);
918
+
919
+ }/* apply_pclr() */
920
+
921
+ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
922
+ OPJ_BYTE * p_pclr_header_data,
923
+ OPJ_UINT32 p_pclr_header_size,
924
+ opj_event_mgr_t * p_manager
925
+ )
926
+ {
927
+ opj_jp2_pclr_t *jp2_pclr;
928
+ OPJ_BYTE *channel_size, *channel_sign;
929
+ OPJ_UINT32 *entries;
930
+ OPJ_UINT16 nr_entries,nr_channels;
931
+ OPJ_UINT16 i, j;
932
+ OPJ_UINT32 l_value;
933
+ OPJ_BYTE *orig_header_data = p_pclr_header_data;
934
+
935
+ /* preconditions */
936
+ assert(p_pclr_header_data != 00);
937
+ assert(jp2 != 00);
938
+ assert(p_manager != 00);
939
+ (void)p_pclr_header_size;
940
+
941
+ if(jp2->color.jp2_pclr)
942
+ return OPJ_FALSE;
943
+
944
+ if (p_pclr_header_size < 3)
945
+ return OPJ_FALSE;
946
+
947
+ opj_read_bytes(p_pclr_header_data, &l_value , 2); /* NE */
948
+ p_pclr_header_data += 2;
949
+ nr_entries = (OPJ_UINT16) l_value;
950
+
951
+ opj_read_bytes(p_pclr_header_data, &l_value , 1); /* NPC */
952
+ ++p_pclr_header_data;
953
+ nr_channels = (OPJ_UINT16) l_value;
954
+
955
+ if (p_pclr_header_size < 3 + (OPJ_UINT32)nr_channels || nr_channels == 0 || nr_entries >= (OPJ_UINT32)-1 / nr_channels)
956
+ return OPJ_FALSE;
957
+
958
+ entries = (OPJ_UINT32*) opj_malloc((size_t)nr_channels * nr_entries * sizeof(OPJ_UINT32));
959
+ if (!entries)
960
+ return OPJ_FALSE;
961
+ channel_size = (OPJ_BYTE*) opj_malloc(nr_channels);
962
+ if (!channel_size)
963
+ {
964
+ opj_free(entries);
965
+ return OPJ_FALSE;
966
+ }
967
+ channel_sign = (OPJ_BYTE*) opj_malloc(nr_channels);
968
+ if (!channel_sign)
969
+ {
970
+ opj_free(entries);
971
+ opj_free(channel_size);
972
+ return OPJ_FALSE;
973
+ }
974
+
975
+ jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t));
976
+ if (!jp2_pclr)
977
+ {
978
+ opj_free(entries);
979
+ opj_free(channel_size);
980
+ opj_free(channel_sign);
981
+ return OPJ_FALSE;
982
+ }
983
+
984
+ jp2_pclr->channel_sign = channel_sign;
985
+ jp2_pclr->channel_size = channel_size;
986
+ jp2_pclr->entries = entries;
987
+ jp2_pclr->nr_entries = nr_entries;
988
+ jp2_pclr->nr_channels = (OPJ_BYTE) l_value;
989
+ jp2_pclr->cmap = NULL;
990
+
991
+ jp2->color.jp2_pclr = jp2_pclr;
992
+
993
+ for(i = 0; i < nr_channels; ++i) {
994
+ opj_read_bytes(p_pclr_header_data, &l_value , 1); /* Bi */
995
+ ++p_pclr_header_data;
996
+
997
+ channel_size[i] = (OPJ_BYTE)((l_value & 0x7f) + 1);
998
+ channel_sign[i] = (l_value & 0x80) ? 1 : 0;
999
+ }
1000
+
1001
+ for(j = 0; j < nr_entries; ++j) {
1002
+ for(i = 0; i < nr_channels; ++i) {
1003
+ OPJ_UINT32 bytes_to_read = (OPJ_UINT32)((channel_size[i]+7)>>3);
1004
+
1005
+ if (bytes_to_read > sizeof(OPJ_UINT32))
1006
+ bytes_to_read = sizeof(OPJ_UINT32);
1007
+ if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read)
1008
+ return OPJ_FALSE;
1009
+
1010
+ opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */
1011
+ p_pclr_header_data += bytes_to_read;
1012
+ *entries = (OPJ_UINT32) l_value;
1013
+ entries++;
1014
+ }
1015
+ }
1016
+
1017
+ return OPJ_TRUE;
1018
+ }
1019
+
1020
+ OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2,
1021
+ OPJ_BYTE * p_cmap_header_data,
1022
+ OPJ_UINT32 p_cmap_header_size,
1023
+ opj_event_mgr_t * p_manager
1024
+ )
1025
+ {
1026
+ opj_jp2_cmap_comp_t *cmap;
1027
+ OPJ_BYTE i, nr_channels;
1028
+ OPJ_UINT32 l_value;
1029
+
1030
+ /* preconditions */
1031
+ assert(jp2 != 00);
1032
+ assert(p_cmap_header_data != 00);
1033
+ assert(p_manager != 00);
1034
+ (void)p_cmap_header_size;
1035
+
1036
+ /* Need nr_channels: */
1037
+ if(jp2->color.jp2_pclr == NULL) {
1038
+ opj_event_msg(p_manager, EVT_ERROR, "Need to read a PCLR box before the CMAP box.\n");
1039
+ return OPJ_FALSE;
1040
+ }
1041
+
1042
+ /* Part 1, I.5.3.5: 'There shall be at most one Component Mapping box
1043
+ * inside a JP2 Header box' :
1044
+ */
1045
+ if(jp2->color.jp2_pclr->cmap) {
1046
+ opj_event_msg(p_manager, EVT_ERROR, "Only one CMAP box is allowed.\n");
1047
+ return OPJ_FALSE;
1048
+ }
1049
+
1050
+ nr_channels = jp2->color.jp2_pclr->nr_channels;
1051
+ if (p_cmap_header_size < (OPJ_UINT32)nr_channels * 4) {
1052
+ opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CMAP box.\n");
1053
+ return OPJ_FALSE;
1054
+ }
1055
+
1056
+ cmap = (opj_jp2_cmap_comp_t*) opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t));
1057
+ if (!cmap)
1058
+ return OPJ_FALSE;
1059
+
1060
+
1061
+ for(i = 0; i < nr_channels; ++i) {
1062
+ opj_read_bytes(p_cmap_header_data, &l_value, 2); /* CMP^i */
1063
+ p_cmap_header_data +=2;
1064
+ cmap[i].cmp = (OPJ_UINT16) l_value;
1065
+
1066
+ opj_read_bytes(p_cmap_header_data, &l_value, 1); /* MTYP^i */
1067
+ ++p_cmap_header_data;
1068
+ cmap[i].mtyp = (OPJ_BYTE) l_value;
1069
+
1070
+ opj_read_bytes(p_cmap_header_data, &l_value, 1); /* PCOL^i */
1071
+ ++p_cmap_header_data;
1072
+ cmap[i].pcol = (OPJ_BYTE) l_value;
1073
+ }
1074
+
1075
+ jp2->color.jp2_pclr->cmap = cmap;
1076
+
1077
+ return OPJ_TRUE;
1078
+ }
1079
+
1080
+ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
1081
+ {
1082
+ opj_jp2_cdef_info_t *info;
1083
+ OPJ_UINT16 i, n, cn, asoc, acn;
1084
+
1085
+ info = color->jp2_cdef->info;
1086
+ n = color->jp2_cdef->n;
1087
+
1088
+ for(i = 0; i < n; ++i)
1089
+ {
1090
+ /* WATCH: acn = asoc - 1 ! */
1091
+ asoc = info[i].asoc;
1092
+ if(asoc == 0 || asoc == 65535)
1093
+ {
1094
+ if (i < image->numcomps)
1095
+ image->comps[i].alpha = info[i].typ;
1096
+ continue;
1097
+ }
1098
+
1099
+ cn = info[i].cn;
1100
+ acn = (OPJ_UINT16)(asoc - 1);
1101
+ if( cn >= image->numcomps || acn >= image->numcomps )
1102
+ {
1103
+ fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps);
1104
+ continue;
1105
+ }
1106
+
1107
+ if(cn != acn)
1108
+ {
1109
+ opj_image_comp_t saved;
1110
+
1111
+ memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
1112
+ memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
1113
+ memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
1114
+
1115
+ info[i].asoc = (OPJ_UINT16)(cn + 1);
1116
+ info[acn].asoc = (OPJ_UINT16)(info[acn].cn + 1);
1117
+ }
1118
+
1119
+ image->comps[cn].alpha = info[i].typ;
1120
+ }
1121
+
1122
+ if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
1123
+
1124
+ opj_free(color->jp2_cdef); color->jp2_cdef = NULL;
1125
+
1126
+ }/* jp2_apply_cdef() */
1127
+
1128
+ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2,
1129
+ OPJ_BYTE * p_cdef_header_data,
1130
+ OPJ_UINT32 p_cdef_header_size,
1131
+ opj_event_mgr_t * p_manager
1132
+ )
1133
+ {
1134
+ opj_jp2_cdef_info_t *cdef_info;
1135
+ OPJ_UINT16 i;
1136
+ OPJ_UINT32 l_value;
1137
+
1138
+ /* preconditions */
1139
+ assert(jp2 != 00);
1140
+ assert(p_cdef_header_data != 00);
1141
+ assert(p_manager != 00);
1142
+ (void)p_cdef_header_size;
1143
+
1144
+ /* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box
1145
+ * inside a JP2 Header box.'*/
1146
+ if(jp2->color.jp2_cdef) return OPJ_FALSE;
1147
+
1148
+ if (p_cdef_header_size < 2) {
1149
+ opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n");
1150
+ return OPJ_FALSE;
1151
+ }
1152
+
1153
+ opj_read_bytes(p_cdef_header_data,&l_value ,2); /* N */
1154
+ p_cdef_header_data+= 2;
1155
+
1156
+ if ( (OPJ_UINT16)l_value == 0){ /* szukw000: FIXME */
1157
+ opj_event_msg(p_manager, EVT_ERROR, "Number of channel description is equal to zero in CDEF box.\n");
1158
+ return OPJ_FALSE;
1159
+ }
1160
+
1161
+ if (p_cdef_header_size < 2 + (OPJ_UINT32)(OPJ_UINT16)l_value * 6) {
1162
+ opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n");
1163
+ return OPJ_FALSE;
1164
+ }
1165
+
1166
+ cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_cdef_info_t));
1167
+ if (!cdef_info)
1168
+ return OPJ_FALSE;
1169
+
1170
+ jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
1171
+ if(!jp2->color.jp2_cdef)
1172
+ {
1173
+ opj_free(cdef_info);
1174
+ return OPJ_FALSE;
1175
+ }
1176
+ jp2->color.jp2_cdef->info = cdef_info;
1177
+ jp2->color.jp2_cdef->n = (OPJ_UINT16) l_value;
1178
+
1179
+ for(i = 0; i < jp2->color.jp2_cdef->n; ++i) {
1180
+ opj_read_bytes(p_cdef_header_data, &l_value, 2); /* Cn^i */
1181
+ p_cdef_header_data +=2;
1182
+ cdef_info[i].cn = (OPJ_UINT16) l_value;
1183
+
1184
+ opj_read_bytes(p_cdef_header_data, &l_value, 2); /* Typ^i */
1185
+ p_cdef_header_data +=2;
1186
+ cdef_info[i].typ = (OPJ_UINT16) l_value;
1187
+
1188
+ opj_read_bytes(p_cdef_header_data, &l_value, 2); /* Asoc^i */
1189
+ p_cdef_header_data +=2;
1190
+ cdef_info[i].asoc = (OPJ_UINT16) l_value;
1191
+ }
1192
+
1193
+ return OPJ_TRUE;
1194
+ }
1195
+
1196
+ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
1197
+ OPJ_BYTE * p_colr_header_data,
1198
+ OPJ_UINT32 p_colr_header_size,
1199
+ opj_event_mgr_t * p_manager
1200
+ )
1201
+ {
1202
+ OPJ_UINT32 l_value;
1203
+
1204
+ /* preconditions */
1205
+ assert(jp2 != 00);
1206
+ assert(p_colr_header_data != 00);
1207
+ assert(p_manager != 00);
1208
+
1209
+ if (p_colr_header_size < 3) {
1210
+ opj_event_msg(p_manager, EVT_ERROR, "Bad COLR header box (bad size)\n");
1211
+ return OPJ_FALSE;
1212
+ }
1213
+
1214
+ /* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour
1215
+ * Specification boxes after the first.'
1216
+ */
1217
+ if(jp2->color.jp2_has_colr) {
1218
+ opj_event_msg(p_manager, EVT_INFO, "A conforming JP2 reader shall ignore all Colour Specification boxes after the first, so we ignore this one.\n");
1219
+ p_colr_header_data += p_colr_header_size;
1220
+ return OPJ_TRUE;
1221
+ }
1222
+
1223
+ opj_read_bytes(p_colr_header_data,&jp2->meth ,1); /* METH */
1224
+ ++p_colr_header_data;
1225
+
1226
+ opj_read_bytes(p_colr_header_data,&jp2->precedence ,1); /* PRECEDENCE */
1227
+ ++p_colr_header_data;
1228
+
1229
+ opj_read_bytes(p_colr_header_data,&jp2->approx ,1); /* APPROX */
1230
+ ++p_colr_header_data;
1231
+
1232
+ if (jp2->meth == 1) {
1233
+ if (p_colr_header_size < 7) {
1234
+ opj_event_msg(p_manager, EVT_ERROR, "Bad COLR header box (bad size: %d)\n", p_colr_header_size);
1235
+ return OPJ_FALSE;
1236
+ }
1237
+ if (p_colr_header_size > 7) {
1238
+ /* testcase Altona_Technical_v20_x4.pdf */
1239
+ opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (bad size: %d)\n", p_colr_header_size);
1240
+ }
1241
+
1242
+ opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4); /* EnumCS */
1243
+
1244
+ jp2->color.jp2_has_colr = 1;
1245
+ }
1246
+ else if (jp2->meth == 2) {
1247
+ /* ICC profile */
1248
+ OPJ_INT32 it_icc_value = 0;
1249
+ OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
1250
+
1251
+ jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
1252
+ jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc((size_t)icc_len);
1253
+ if (!jp2->color.icc_profile_buf)
1254
+ {
1255
+ jp2->color.icc_profile_len = 0;
1256
+ return OPJ_FALSE;
1257
+ }
1258
+ memset(jp2->color.icc_profile_buf, 0, (size_t)icc_len * sizeof(OPJ_BYTE));
1259
+
1260
+ for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
1261
+ {
1262
+ opj_read_bytes(p_colr_header_data,&l_value,1); /* icc values */
1263
+ ++p_colr_header_data;
1264
+ jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value;
1265
+ }
1266
+
1267
+ jp2->color.jp2_has_colr = 1;
1268
+ }
1269
+ else if (jp2->meth > 2)
1270
+ {
1271
+ /* ISO/IEC 15444-1:2004 (E), Table I.9 � Legal METH values:
1272
+ conforming JP2 reader shall ignore the entire Colour Specification box.*/
1273
+ opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
1274
+ "so we will ignore the entire Colour Specification box. \n", jp2->meth);
1275
+ }
1276
+ return OPJ_TRUE;
1277
+ }
1278
+
1279
+ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
1280
+ opj_stream_private_t *p_stream,
1281
+ opj_image_t* p_image,
1282
+ opj_event_mgr_t * p_manager)
1283
+ {
1284
+ if (!p_image)
1285
+ return OPJ_FALSE;
1286
+
1287
+ /* J2K decoding */
1288
+ if( ! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager) ) {
1289
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to decode the codestream in the JP2 file\n");
1290
+ return OPJ_FALSE;
1291
+ }
1292
+
1293
+ if (!jp2->ignore_pclr_cmap_cdef){
1294
+ if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) {
1295
+ return OPJ_FALSE;
1296
+ }
1297
+
1298
+ /* Set Image Color Space */
1299
+ if (jp2->enumcs == 16)
1300
+ p_image->color_space = OPJ_CLRSPC_SRGB;
1301
+ else if (jp2->enumcs == 17)
1302
+ p_image->color_space = OPJ_CLRSPC_GRAY;
1303
+ else if (jp2->enumcs == 18)
1304
+ p_image->color_space = OPJ_CLRSPC_SYCC;
1305
+ else if (jp2->enumcs == 24)
1306
+ p_image->color_space = OPJ_CLRSPC_EYCC;
1307
+ else
1308
+ p_image->color_space = OPJ_CLRSPC_UNKNOWN;
1309
+
1310
+ /* Apply the color space if needed */
1311
+ if(jp2->color.jp2_cdef) {
1312
+ opj_jp2_apply_cdef(p_image, &(jp2->color));
1313
+ }
1314
+
1315
+ if(jp2->color.jp2_pclr) {
1316
+ /* Part 1, I.5.3.4: Either both or none : */
1317
+ if( !jp2->color.jp2_pclr->cmap)
1318
+ opj_jp2_free_pclr(&(jp2->color));
1319
+ else
1320
+ opj_jp2_apply_pclr(p_image, &(jp2->color));
1321
+ }
1322
+
1323
+ if(jp2->color.icc_profile_buf) {
1324
+ p_image->icc_profile_buf = jp2->color.icc_profile_buf;
1325
+ p_image->icc_profile_len = jp2->color.icc_profile_len;
1326
+ jp2->color.icc_profile_buf = NULL;
1327
+ }
1328
+ }
1329
+
1330
+ return OPJ_TRUE;
1331
+ }
1332
+
1333
+ OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
1334
+ opj_stream_private_t *stream,
1335
+ opj_event_mgr_t * p_manager
1336
+ )
1337
+ {
1338
+ opj_jp2_img_header_writer_handler_t l_writers [3];
1339
+ opj_jp2_img_header_writer_handler_t * l_current_writer;
1340
+
1341
+ OPJ_INT32 i, l_nb_pass;
1342
+ /* size of data for super box*/
1343
+ OPJ_UINT32 l_jp2h_size = 8;
1344
+ OPJ_BOOL l_result = OPJ_TRUE;
1345
+
1346
+ /* to store the data of the super box */
1347
+ OPJ_BYTE l_jp2h_data [8];
1348
+
1349
+ /* preconditions */
1350
+ assert(stream != 00);
1351
+ assert(jp2 != 00);
1352
+ assert(p_manager != 00);
1353
+
1354
+ memset(l_writers,0,sizeof(l_writers));
1355
+
1356
+ if (jp2->bpc == 255) {
1357
+ l_nb_pass = 3;
1358
+ l_writers[0].handler = opj_jp2_write_ihdr;
1359
+ l_writers[1].handler = opj_jp2_write_bpcc;
1360
+ l_writers[2].handler = opj_jp2_write_colr;
1361
+ }
1362
+ else {
1363
+ l_nb_pass = 2;
1364
+ l_writers[0].handler = opj_jp2_write_ihdr;
1365
+ l_writers[1].handler = opj_jp2_write_colr;
1366
+ }
1367
+
1368
+ /* write box header */
1369
+ /* write JP2H type */
1370
+ opj_write_bytes(l_jp2h_data+4,JP2_JP2H,4);
1371
+
1372
+ l_current_writer = l_writers;
1373
+ for (i=0;i<l_nb_pass;++i) {
1374
+ l_current_writer->m_data = l_current_writer->handler(jp2,&(l_current_writer->m_size));
1375
+ if (l_current_writer->m_data == 00) {
1376
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to hold JP2 Header data\n");
1377
+ l_result = OPJ_FALSE;
1378
+ break;
1379
+ }
1380
+
1381
+ l_jp2h_size += l_current_writer->m_size;
1382
+ ++l_current_writer;
1383
+ }
1384
+
1385
+ if (! l_result) {
1386
+ l_current_writer = l_writers;
1387
+ for (i=0;i<l_nb_pass;++i) {
1388
+ if (l_current_writer->m_data != 00) {
1389
+ opj_free(l_current_writer->m_data );
1390
+ }
1391
+ ++l_current_writer;
1392
+ }
1393
+
1394
+ return OPJ_FALSE;
1395
+ }
1396
+
1397
+ /* write super box size */
1398
+ opj_write_bytes(l_jp2h_data,l_jp2h_size,4);
1399
+
1400
+ /* write super box data on stream */
1401
+ if (opj_stream_write_data(stream,l_jp2h_data,8,p_manager) != 8) {
1402
+ opj_event_msg(p_manager, EVT_ERROR, "Stream error while writing JP2 Header box\n");
1403
+ l_result = OPJ_FALSE;
1404
+ }
1405
+
1406
+ if (l_result) {
1407
+ l_current_writer = l_writers;
1408
+ for (i=0;i<l_nb_pass;++i) {
1409
+ if (opj_stream_write_data(stream,l_current_writer->m_data,l_current_writer->m_size,p_manager) != l_current_writer->m_size) {
1410
+ opj_event_msg(p_manager, EVT_ERROR, "Stream error while writing JP2 Header box\n");
1411
+ l_result = OPJ_FALSE;
1412
+ break;
1413
+ }
1414
+ ++l_current_writer;
1415
+ }
1416
+ }
1417
+
1418
+ l_current_writer = l_writers;
1419
+
1420
+ /* cleanup */
1421
+ for (i=0;i<l_nb_pass;++i) {
1422
+ if (l_current_writer->m_data != 00) {
1423
+ opj_free(l_current_writer->m_data );
1424
+ }
1425
+ ++l_current_writer;
1426
+ }
1427
+
1428
+ return l_result;
1429
+ }
1430
+
1431
+ OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
1432
+ opj_stream_private_t *cio,
1433
+ opj_event_mgr_t * p_manager )
1434
+ {
1435
+ OPJ_UINT32 i;
1436
+ OPJ_UINT32 l_ftyp_size = 16 + 4 * jp2->numcl;
1437
+ OPJ_BYTE * l_ftyp_data, * l_current_data_ptr;
1438
+ OPJ_BOOL l_result;
1439
+
1440
+ /* preconditions */
1441
+ assert(cio != 00);
1442
+ assert(jp2 != 00);
1443
+ assert(p_manager != 00);
1444
+
1445
+ l_ftyp_data = (OPJ_BYTE *) opj_malloc(l_ftyp_size);
1446
+
1447
+ if (l_ftyp_data == 00) {
1448
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n");
1449
+ return OPJ_FALSE;
1450
+ }
1451
+
1452
+ memset(l_ftyp_data,0,l_ftyp_size);
1453
+
1454
+ l_current_data_ptr = l_ftyp_data;
1455
+
1456
+ opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */
1457
+ l_current_data_ptr += 4;
1458
+
1459
+ opj_write_bytes(l_current_data_ptr, JP2_FTYP,4); /* FTYP */
1460
+ l_current_data_ptr += 4;
1461
+
1462
+ opj_write_bytes(l_current_data_ptr, jp2->brand,4); /* BR */
1463
+ l_current_data_ptr += 4;
1464
+
1465
+ opj_write_bytes(l_current_data_ptr, jp2->minversion,4); /* MinV */
1466
+ l_current_data_ptr += 4;
1467
+
1468
+ for (i = 0; i < jp2->numcl; i++) {
1469
+ opj_write_bytes(l_current_data_ptr, jp2->cl[i],4); /* CL */
1470
+ }
1471
+
1472
+ l_result = (opj_stream_write_data(cio,l_ftyp_data,l_ftyp_size,p_manager) == l_ftyp_size);
1473
+ if (! l_result)
1474
+ {
1475
+ opj_event_msg(p_manager, EVT_ERROR, "Error while writing ftyp data to stream\n");
1476
+ }
1477
+
1478
+ opj_free(l_ftyp_data);
1479
+
1480
+ return l_result;
1481
+ }
1482
+
1483
+ OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2,
1484
+ opj_stream_private_t *cio,
1485
+ opj_event_mgr_t * p_manager )
1486
+ {
1487
+ OPJ_OFF_T j2k_codestream_exit;
1488
+ OPJ_BYTE l_data_header [8];
1489
+
1490
+ /* preconditions */
1491
+ assert(jp2 != 00);
1492
+ assert(cio != 00);
1493
+ assert(p_manager != 00);
1494
+ assert(opj_stream_has_seek(cio));
1495
+
1496
+ j2k_codestream_exit = opj_stream_tell(cio);
1497
+ opj_write_bytes(l_data_header,
1498
+ (OPJ_UINT32) (j2k_codestream_exit - jp2->j2k_codestream_offset),
1499
+ 4); /* size of codestream */
1500
+ opj_write_bytes(l_data_header + 4,JP2_JP2C,4); /* JP2C */
1501
+
1502
+ if (! opj_stream_seek(cio,jp2->j2k_codestream_offset,p_manager)) {
1503
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
1504
+ return OPJ_FALSE;
1505
+ }
1506
+
1507
+ if (opj_stream_write_data(cio,l_data_header,8,p_manager) != 8) {
1508
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
1509
+ return OPJ_FALSE;
1510
+ }
1511
+
1512
+ if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
1513
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
1514
+ return OPJ_FALSE;
1515
+ }
1516
+
1517
+ return OPJ_TRUE;
1518
+ }
1519
+
1520
+ OPJ_BOOL opj_jp2_write_jp( opj_jp2_t *jp2,
1521
+ opj_stream_private_t *cio,
1522
+ opj_event_mgr_t * p_manager )
1523
+ {
1524
+ /* 12 bytes will be read */
1525
+ OPJ_BYTE l_signature_data [12];
1526
+
1527
+ /* preconditions */
1528
+ assert(cio != 00);
1529
+ assert(jp2 != 00);
1530
+ assert(p_manager != 00);
1531
+
1532
+ /* write box length */
1533
+ opj_write_bytes(l_signature_data,12,4);
1534
+ /* writes box type */
1535
+ opj_write_bytes(l_signature_data+4,JP2_JP,4);
1536
+ /* writes magic number*/
1537
+ opj_write_bytes(l_signature_data+8,0x0d0a870a,4);
1538
+
1539
+ if (opj_stream_write_data(cio,l_signature_data,12,p_manager) != 12) {
1540
+ return OPJ_FALSE;
1541
+ }
1542
+
1543
+ return OPJ_TRUE;
1544
+ }
1545
+
1546
+ /* ----------------------------------------------------------------------- */
1547
+ /* JP2 decoder interface */
1548
+ /* ----------------------------------------------------------------------- */
1549
+
1550
+ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)
1551
+ {
1552
+ /* setup the J2K codec */
1553
+ opj_j2k_setup_decoder(jp2->j2k, parameters);
1554
+
1555
+ /* further JP2 initializations go here */
1556
+ jp2->color.jp2_has_colr = 0;
1557
+ jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
1558
+ }
1559
+
1560
+ /* ----------------------------------------------------------------------- */
1561
+ /* JP2 encoder interface */
1562
+ /* ----------------------------------------------------------------------- */
1563
+
1564
+ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
1565
+ opj_cparameters_t *parameters,
1566
+ opj_image_t *image,
1567
+ opj_event_mgr_t * p_manager)
1568
+ {
1569
+ OPJ_UINT32 i;
1570
+ OPJ_UINT32 depth_0;
1571
+ OPJ_UINT32 sign;
1572
+
1573
+ if(!jp2 || !parameters || !image)
1574
+ return;
1575
+
1576
+ /* setup the J2K codec */
1577
+ /* ------------------- */
1578
+
1579
+ /* Check if number of components respects standard */
1580
+ if (image->numcomps < 1 || image->numcomps > 16384) {
1581
+ opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components specified while setting up JP2 encoder\n");
1582
+ return;
1583
+ }
1584
+
1585
+ opj_j2k_setup_encoder(jp2->j2k, parameters, image, p_manager );
1586
+
1587
+ /* setup the JP2 codec */
1588
+ /* ------------------- */
1589
+
1590
+ /* Profile box */
1591
+
1592
+ jp2->brand = JP2_JP2; /* BR */
1593
+ jp2->minversion = 0; /* MinV */
1594
+ jp2->numcl = 1;
1595
+ jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
1596
+ if (!jp2->cl){
1597
+ jp2->cl = NULL;
1598
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
1599
+ return;
1600
+ }
1601
+ jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
1602
+
1603
+ /* Image Header box */
1604
+
1605
+ jp2->numcomps = image->numcomps; /* NC */
1606
+ jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
1607
+ if (!jp2->comps) {
1608
+ jp2->comps = NULL;
1609
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
1610
+ return;
1611
+ }
1612
+
1613
+ jp2->h = image->y1 - image->y0; /* HEIGHT */
1614
+ jp2->w = image->x1 - image->x0; /* WIDTH */
1615
+ /* BPC */
1616
+ depth_0 = image->comps[0].prec - 1;
1617
+ sign = image->comps[0].sgnd;
1618
+ jp2->bpc = depth_0 + (sign << 7);
1619
+ for (i = 1; i < image->numcomps; i++) {
1620
+ OPJ_UINT32 depth = image->comps[i].prec - 1;
1621
+ sign = image->comps[i].sgnd;
1622
+ if (depth_0 != depth)
1623
+ jp2->bpc = 255;
1624
+ }
1625
+ jp2->C = 7; /* C : Always 7 */
1626
+ jp2->UnkC = 0; /* UnkC, colorspace specified in colr box */
1627
+ jp2->IPR = 0; /* IPR, no intellectual property */
1628
+
1629
+ /* BitsPerComponent box */
1630
+ for (i = 0; i < image->numcomps; i++) {
1631
+ jp2->comps[i].bpcc = image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
1632
+ }
1633
+
1634
+ /* Colour Specification box */
1635
+ if(image->icc_profile_len) {
1636
+ jp2->meth = 2;
1637
+ jp2->enumcs = 0;
1638
+ }
1639
+ else {
1640
+ jp2->meth = 1;
1641
+ if (image->color_space == 1)
1642
+ jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */
1643
+ else if (image->color_space == 2)
1644
+ jp2->enumcs = 17; /* greyscale */
1645
+ else if (image->color_space == 3)
1646
+ jp2->enumcs = 18; /* YUV */
1647
+ }
1648
+
1649
+
1650
+ jp2->precedence = 0; /* PRECEDENCE */
1651
+ jp2->approx = 0; /* APPROX */
1652
+
1653
+ jp2->jpip_on = parameters->jpip_on;
1654
+ }
1655
+
1656
+ OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2,
1657
+ opj_stream_private_t *stream,
1658
+ opj_event_mgr_t * p_manager)
1659
+ {
1660
+ return opj_j2k_encode(jp2->j2k, stream, p_manager);
1661
+ }
1662
+
1663
+ OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
1664
+ opj_stream_private_t *cio,
1665
+ opj_event_mgr_t * p_manager
1666
+ )
1667
+ {
1668
+ /* preconditions */
1669
+ assert(jp2 != 00);
1670
+ assert(cio != 00);
1671
+ assert(p_manager != 00);
1672
+
1673
+ /* customization of the end encoding */
1674
+ opj_jp2_setup_end_header_reading(jp2);
1675
+
1676
+ /* write header */
1677
+ if (! opj_jp2_exec (jp2,jp2->m_procedure_list,cio,p_manager)) {
1678
+ return OPJ_FALSE;
1679
+ }
1680
+
1681
+ return opj_j2k_end_decompress(jp2->j2k, cio, p_manager);
1682
+ }
1683
+
1684
+ OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
1685
+ opj_stream_private_t *cio,
1686
+ opj_event_mgr_t * p_manager
1687
+ )
1688
+ {
1689
+ /* preconditions */
1690
+ assert(jp2 != 00);
1691
+ assert(cio != 00);
1692
+ assert(p_manager != 00);
1693
+
1694
+ /* customization of the end encoding */
1695
+ opj_jp2_setup_end_header_writing(jp2);
1696
+
1697
+ if (! opj_j2k_end_compress(jp2->j2k,cio,p_manager)) {
1698
+ return OPJ_FALSE;
1699
+ }
1700
+
1701
+ /* write header */
1702
+ return opj_jp2_exec(jp2,jp2->m_procedure_list,cio,p_manager);
1703
+ }
1704
+
1705
+ void opj_jp2_setup_end_header_writing (opj_jp2_t *jp2)
1706
+ {
1707
+ /* preconditions */
1708
+ assert(jp2 != 00);
1709
+
1710
+ #ifdef USE_JPIP
1711
+ if( jp2->jpip_on )
1712
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_iptr );
1713
+ #endif
1714
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp2c );
1715
+ /* DEVELOPER CORNER, add your custom procedures */
1716
+ #ifdef USE_JPIP
1717
+ if( jp2->jpip_on )
1718
+ {
1719
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_cidx );
1720
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_fidx );
1721
+ }
1722
+ #endif
1723
+ }
1724
+
1725
+ void opj_jp2_setup_end_header_reading (opj_jp2_t *jp2)
1726
+ {
1727
+ /* preconditions */
1728
+ assert(jp2 != 00);
1729
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_read_header_procedure );
1730
+ /* DEVELOPER CORNER, add your custom procedures */
1731
+ }
1732
+
1733
+ OPJ_BOOL opj_jp2_default_validation ( opj_jp2_t * jp2,
1734
+ opj_stream_private_t *cio,
1735
+ opj_event_mgr_t * p_manager
1736
+ )
1737
+ {
1738
+ OPJ_BOOL l_is_valid = OPJ_TRUE;
1739
+ OPJ_UINT32 i;
1740
+
1741
+ /* preconditions */
1742
+ assert(jp2 != 00);
1743
+ assert(cio != 00);
1744
+ assert(p_manager != 00);
1745
+
1746
+ /* JPEG2000 codec validation */
1747
+
1748
+ /* STATE checking */
1749
+ /* make sure the state is at 0 */
1750
+ l_is_valid &= (jp2->jp2_state == JP2_STATE_NONE);
1751
+
1752
+ /* make sure not reading a jp2h ???? WEIRD */
1753
+ l_is_valid &= (jp2->jp2_img_state == JP2_IMG_STATE_NONE);
1754
+
1755
+ /* POINTER validation */
1756
+ /* make sure a j2k codec is present */
1757
+ l_is_valid &= (jp2->j2k != 00);
1758
+
1759
+ /* make sure a procedure list is present */
1760
+ l_is_valid &= (jp2->m_procedure_list != 00);
1761
+
1762
+ /* make sure a validation list is present */
1763
+ l_is_valid &= (jp2->m_validation_list != 00);
1764
+
1765
+ /* PARAMETER VALIDATION */
1766
+ /* number of components */
1767
+ l_is_valid &= (jp2->numcl > 0);
1768
+ /* width */
1769
+ l_is_valid &= (jp2->h > 0);
1770
+ /* height */
1771
+ l_is_valid &= (jp2->w > 0);
1772
+ /* precision */
1773
+ for (i = 0; i < jp2->numcomps; ++i) {
1774
+ l_is_valid &= (jp2->comps[i].bpcc > 0);
1775
+ }
1776
+
1777
+ /* METH */
1778
+ l_is_valid &= ((jp2->meth > 0) && (jp2->meth < 3));
1779
+
1780
+ /* stream validation */
1781
+ /* back and forth is needed */
1782
+ l_is_valid &= opj_stream_has_seek(cio);
1783
+
1784
+ return l_is_valid;
1785
+ }
1786
+
1787
+ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
1788
+ opj_stream_private_t *stream,
1789
+ opj_event_mgr_t * p_manager
1790
+ )
1791
+ {
1792
+ opj_jp2_box_t box;
1793
+ OPJ_UINT32 l_nb_bytes_read;
1794
+ const opj_jp2_header_handler_t * l_current_handler;
1795
+ OPJ_UINT32 l_last_data_size = OPJ_BOX_SIZE;
1796
+ OPJ_UINT32 l_current_data_size;
1797
+ OPJ_BYTE * l_current_data = 00;
1798
+
1799
+ /* preconditions */
1800
+ assert(stream != 00);
1801
+ assert(jp2 != 00);
1802
+ assert(p_manager != 00);
1803
+
1804
+ l_current_data = (OPJ_BYTE*)opj_malloc(l_last_data_size);
1805
+
1806
+ if (l_current_data == 00) {
1807
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 file header\n");
1808
+ return OPJ_FALSE;
1809
+ }
1810
+ memset(l_current_data, 0 , l_last_data_size);
1811
+
1812
+ while (opj_jp2_read_boxhdr(&box,&l_nb_bytes_read,stream,p_manager)) {
1813
+ /* is it the codestream box ? */
1814
+ if (box.type == JP2_JP2C) {
1815
+ if (jp2->jp2_state & JP2_STATE_HEADER) {
1816
+ jp2->jp2_state |= JP2_STATE_CODESTREAM;
1817
+ opj_free(l_current_data);
1818
+ return OPJ_TRUE;
1819
+ }
1820
+ else {
1821
+ opj_event_msg(p_manager, EVT_ERROR, "bad placed jpeg codestream\n");
1822
+ opj_free(l_current_data);
1823
+ return OPJ_FALSE;
1824
+ }
1825
+ }
1826
+ else if (box.length == 0) {
1827
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
1828
+ opj_free(l_current_data);
1829
+ return OPJ_FALSE;
1830
+ }
1831
+ /* testcase 1851.pdf.SIGSEGV.ce9.948 */
1832
+ else if (box.length < l_nb_bytes_read) {
1833
+ opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d (%x)\n", box.length, box.type);
1834
+ opj_free(l_current_data);
1835
+ return OPJ_FALSE;
1836
+ }
1837
+
1838
+ l_current_handler = opj_jp2_find_handler(box.type);
1839
+ l_current_data_size = box.length - l_nb_bytes_read;
1840
+
1841
+ if (l_current_handler != 00) {
1842
+ if (l_current_data_size > l_last_data_size) {
1843
+ OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_data_size);
1844
+ if (!new_current_data) {
1845
+ opj_free(l_current_data);
1846
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 box\n");
1847
+ return OPJ_FALSE;
1848
+ }
1849
+ l_current_data = new_current_data;
1850
+ l_last_data_size = l_current_data_size;
1851
+ }
1852
+
1853
+ l_nb_bytes_read = (OPJ_UINT32)opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager);
1854
+ if (l_nb_bytes_read != l_current_data_size) {
1855
+ opj_event_msg(p_manager, EVT_ERROR, "Problem with reading JPEG2000 box, stream error\n");
1856
+ opj_free(l_current_data);
1857
+ return OPJ_FALSE;
1858
+ }
1859
+
1860
+ if (! l_current_handler->handler(jp2,l_current_data,l_current_data_size,p_manager)) {
1861
+ opj_free(l_current_data);
1862
+ return OPJ_FALSE;
1863
+ }
1864
+ }
1865
+ else {
1866
+ jp2->jp2_state |= JP2_STATE_UNKNOWN;
1867
+ if (opj_stream_skip(stream,l_current_data_size,p_manager) != l_current_data_size) {
1868
+ opj_event_msg(p_manager, EVT_ERROR, "Problem with skipping JPEG2000 box, stream error\n");
1869
+ opj_free(l_current_data);
1870
+ return OPJ_FALSE;
1871
+ }
1872
+ }
1873
+ }
1874
+
1875
+ opj_free(l_current_data);
1876
+
1877
+ return OPJ_TRUE;
1878
+ }
1879
+
1880
+ /**
1881
+ * Excutes the given procedures on the given codec.
1882
+ *
1883
+ * @param p_procedure_list the list of procedures to execute
1884
+ * @param jp2 the jpeg2000 file codec to execute the procedures on.
1885
+ * @param stream the stream to execute the procedures on.
1886
+ * @param p_manager the user manager.
1887
+ *
1888
+ * @return true if all the procedures were successfully executed.
1889
+ */
1890
+ static OPJ_BOOL opj_jp2_exec ( opj_jp2_t * jp2,
1891
+ opj_procedure_list_t * p_procedure_list,
1892
+ opj_stream_private_t *stream,
1893
+ opj_event_mgr_t * p_manager
1894
+ )
1895
+
1896
+ {
1897
+ OPJ_BOOL (** l_procedure) (opj_jp2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *) = 00;
1898
+ OPJ_BOOL l_result = OPJ_TRUE;
1899
+ OPJ_UINT32 l_nb_proc, i;
1900
+
1901
+ /* preconditions */
1902
+ assert(p_procedure_list != 00);
1903
+ assert(jp2 != 00);
1904
+ assert(stream != 00);
1905
+ assert(p_manager != 00);
1906
+
1907
+ l_nb_proc = opj_procedure_list_get_nb_procedures(p_procedure_list);
1908
+ l_procedure = (OPJ_BOOL (**) (opj_jp2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list);
1909
+
1910
+ for (i=0;i<l_nb_proc;++i) {
1911
+ l_result = l_result && (*l_procedure) (jp2,stream,p_manager);
1912
+ ++l_procedure;
1913
+ }
1914
+
1915
+ /* and clear the procedure list at the end. */
1916
+ opj_procedure_list_clear(p_procedure_list);
1917
+ return l_result;
1918
+ }
1919
+
1920
+ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
1921
+ opj_stream_private_t *stream,
1922
+ opj_image_t * p_image,
1923
+ opj_event_mgr_t * p_manager
1924
+ )
1925
+ {
1926
+ /* preconditions */
1927
+ assert(jp2 != 00);
1928
+ assert(stream != 00);
1929
+ assert(p_manager != 00);
1930
+
1931
+ /* customization of the validation */
1932
+ opj_jp2_setup_encoding_validation (jp2);
1933
+
1934
+ /* validation of the parameters codec */
1935
+ if (! opj_jp2_exec(jp2,jp2->m_validation_list,stream,p_manager)) {
1936
+ return OPJ_FALSE;
1937
+ }
1938
+
1939
+ /* customization of the encoding */
1940
+ opj_jp2_setup_header_writing(jp2);
1941
+
1942
+ /* write header */
1943
+ if (! opj_jp2_exec (jp2,jp2->m_procedure_list,stream,p_manager)) {
1944
+ return OPJ_FALSE;
1945
+ }
1946
+
1947
+ return opj_j2k_start_compress(jp2->j2k,stream,p_image,p_manager);
1948
+ }
1949
+
1950
+ const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id)
1951
+ {
1952
+ OPJ_UINT32 i, l_handler_size = sizeof(jp2_header) / sizeof(opj_jp2_header_handler_t);
1953
+
1954
+ for (i=0;i<l_handler_size;++i) {
1955
+ if (jp2_header[i].id == p_id) {
1956
+ return &jp2_header[i];
1957
+ }
1958
+ }
1959
+ return NULL;
1960
+ }
1961
+
1962
+ /**
1963
+ * Finds the image execution function related to the given box id.
1964
+ *
1965
+ * @param p_id the id of the handler to fetch.
1966
+ *
1967
+ * @return the given handler or 00 if it could not be found.
1968
+ */
1969
+ static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_id)
1970
+ {
1971
+ OPJ_UINT32 i, l_handler_size = sizeof(jp2_img_header) / sizeof(opj_jp2_header_handler_t);
1972
+ for (i=0;i<l_handler_size;++i)
1973
+ {
1974
+ if (jp2_img_header[i].id == p_id) {
1975
+ return &jp2_img_header[i];
1976
+ }
1977
+ }
1978
+
1979
+ return NULL;
1980
+ }
1981
+
1982
+ /**
1983
+ * Reads a jpeg2000 file signature box.
1984
+ *
1985
+ * @param p_header_data the data contained in the signature box.
1986
+ * @param jp2 the jpeg2000 file codec.
1987
+ * @param p_header_size the size of the data contained in the signature box.
1988
+ * @param p_manager the user event manager.
1989
+ *
1990
+ * @return true if the file signature box is valid.
1991
+ */
1992
+ static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2,
1993
+ OPJ_BYTE * p_header_data,
1994
+ OPJ_UINT32 p_header_size,
1995
+ opj_event_mgr_t * p_manager
1996
+ )
1997
+
1998
+ {
1999
+ OPJ_UINT32 l_magic_number;
2000
+
2001
+ /* preconditions */
2002
+ assert(p_header_data != 00);
2003
+ assert(jp2 != 00);
2004
+ assert(p_manager != 00);
2005
+
2006
+ if (jp2->jp2_state != JP2_STATE_NONE) {
2007
+ opj_event_msg(p_manager, EVT_ERROR, "The signature box must be the first box in the file.\n");
2008
+ return OPJ_FALSE;
2009
+ }
2010
+
2011
+ /* assure length of data is correct (4 -> magic number) */
2012
+ if (p_header_size != 4) {
2013
+ opj_event_msg(p_manager, EVT_ERROR, "Error with JP signature Box size\n");
2014
+ return OPJ_FALSE;
2015
+ }
2016
+
2017
+ /* rearrange data */
2018
+ opj_read_bytes(p_header_data,&l_magic_number,4);
2019
+ if (l_magic_number != 0x0d0a870a ) {
2020
+ opj_event_msg(p_manager, EVT_ERROR, "Error with JP Signature : bad magic number\n");
2021
+ return OPJ_FALSE;
2022
+ }
2023
+
2024
+ jp2->jp2_state |= JP2_STATE_SIGNATURE;
2025
+
2026
+ return OPJ_TRUE;
2027
+ }
2028
+
2029
+ /**
2030
+ * Reads a a FTYP box - File type box
2031
+ *
2032
+ * @param p_header_data the data contained in the FTYP box.
2033
+ * @param jp2 the jpeg2000 file codec.
2034
+ * @param p_header_size the size of the data contained in the FTYP box.
2035
+ * @param p_manager the user event manager.
2036
+ *
2037
+ * @return true if the FTYP box is valid.
2038
+ */
2039
+ static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2,
2040
+ OPJ_BYTE * p_header_data,
2041
+ OPJ_UINT32 p_header_size,
2042
+ opj_event_mgr_t * p_manager
2043
+ )
2044
+ {
2045
+ OPJ_UINT32 i, l_remaining_bytes;
2046
+
2047
+ /* preconditions */
2048
+ assert(p_header_data != 00);
2049
+ assert(jp2 != 00);
2050
+ assert(p_manager != 00);
2051
+
2052
+ if (jp2->jp2_state != JP2_STATE_SIGNATURE) {
2053
+ opj_event_msg(p_manager, EVT_ERROR, "The ftyp box must be the second box in the file.\n");
2054
+ return OPJ_FALSE;
2055
+ }
2056
+
2057
+ /* assure length of data is correct */
2058
+ if (p_header_size < 8) {
2059
+ opj_event_msg(p_manager, EVT_ERROR, "Error with FTYP signature Box size\n");
2060
+ return OPJ_FALSE;
2061
+ }
2062
+
2063
+ opj_read_bytes(p_header_data,&jp2->brand,4); /* BR */
2064
+ p_header_data += 4;
2065
+
2066
+ opj_read_bytes(p_header_data,&jp2->minversion,4); /* MinV */
2067
+ p_header_data += 4;
2068
+
2069
+ l_remaining_bytes = p_header_size - 8;
2070
+
2071
+ /* the number of remaining bytes should be a multiple of 4 */
2072
+ if ((l_remaining_bytes & 0x3) != 0) {
2073
+ opj_event_msg(p_manager, EVT_ERROR, "Error with FTYP signature Box size\n");
2074
+ return OPJ_FALSE;
2075
+ }
2076
+
2077
+ /* div by 4 */
2078
+ jp2->numcl = l_remaining_bytes >> 2;
2079
+ if (jp2->numcl) {
2080
+ jp2->cl = (OPJ_UINT32 *) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
2081
+ if (jp2->cl == 00) {
2082
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory with FTYP Box\n");
2083
+ return OPJ_FALSE;
2084
+ }
2085
+ memset(jp2->cl,0,jp2->numcl * sizeof(OPJ_UINT32));
2086
+ }
2087
+
2088
+ for (i = 0; i < jp2->numcl; ++i)
2089
+ {
2090
+ opj_read_bytes(p_header_data,&jp2->cl[i],4); /* CLi */
2091
+ p_header_data += 4;
2092
+ }
2093
+
2094
+ jp2->jp2_state |= JP2_STATE_FILE_TYPE;
2095
+
2096
+ return OPJ_TRUE;
2097
+ }
2098
+
2099
+ OPJ_BOOL opj_jp2_skip_jp2c( opj_jp2_t *jp2,
2100
+ opj_stream_private_t *stream,
2101
+ opj_event_mgr_t * p_manager )
2102
+ {
2103
+ /* preconditions */
2104
+ assert(jp2 != 00);
2105
+ assert(stream != 00);
2106
+ assert(p_manager != 00);
2107
+
2108
+ jp2->j2k_codestream_offset = opj_stream_tell(stream);
2109
+
2110
+ if (opj_stream_skip(stream,8,p_manager) != 8) {
2111
+ return OPJ_FALSE;
2112
+ }
2113
+
2114
+ return OPJ_TRUE;
2115
+ }
2116
+
2117
+ static OPJ_BOOL opj_jpip_skip_iptr( opj_jp2_t *jp2,
2118
+ opj_stream_private_t *stream,
2119
+ opj_event_mgr_t * p_manager )
2120
+ {
2121
+ /* preconditions */
2122
+ assert(jp2 != 00);
2123
+ assert(stream != 00);
2124
+ assert(p_manager != 00);
2125
+
2126
+ jp2->jpip_iptr_offset = opj_stream_tell(stream);
2127
+
2128
+ if (opj_stream_skip(stream,24,p_manager) != 24) {
2129
+ return OPJ_FALSE;
2130
+ }
2131
+
2132
+ return OPJ_TRUE;
2133
+ }
2134
+
2135
+ /**
2136
+ * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
2137
+ *
2138
+ * @param p_header_data the data contained in the file header box.
2139
+ * @param jp2 the jpeg2000 file codec.
2140
+ * @param p_header_size the size of the data contained in the file header box.
2141
+ * @param p_manager the user event manager.
2142
+ *
2143
+ * @return true if the JP2 Header box was successfully reconized.
2144
+ */
2145
+ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
2146
+ OPJ_BYTE *p_header_data,
2147
+ OPJ_UINT32 p_header_size,
2148
+ opj_event_mgr_t * p_manager
2149
+ )
2150
+ {
2151
+ OPJ_UINT32 l_box_size=0, l_current_data_size = 0;
2152
+ opj_jp2_box_t box;
2153
+ const opj_jp2_header_handler_t * l_current_handler;
2154
+
2155
+ /* preconditions */
2156
+ assert(p_header_data != 00);
2157
+ assert(jp2 != 00);
2158
+ assert(p_manager != 00);
2159
+
2160
+ /* make sure the box is well placed */
2161
+ if ((jp2->jp2_state & JP2_STATE_FILE_TYPE) != JP2_STATE_FILE_TYPE ) {
2162
+ opj_event_msg(p_manager, EVT_ERROR, "The box must be the first box in the file.\n");
2163
+ return OPJ_FALSE;
2164
+ }
2165
+
2166
+ jp2->jp2_img_state = JP2_IMG_STATE_NONE;
2167
+
2168
+ /* iterate while remaining data */
2169
+ while (p_header_size > 0) {
2170
+
2171
+ if (! opj_jp2_read_boxhdr_char(&box,p_header_data,&l_box_size,p_header_size, p_manager)) {
2172
+ opj_event_msg(p_manager, EVT_ERROR, "Stream error while reading JP2 Header box\n");
2173
+ return OPJ_FALSE;
2174
+ }
2175
+
2176
+ if (box.length > p_header_size) {
2177
+ opj_event_msg(p_manager, EVT_ERROR, "Stream error while reading JP2 Header box: box length is inconsistent.\n");
2178
+ return OPJ_FALSE;
2179
+ }
2180
+
2181
+ l_current_handler = opj_jp2_img_find_handler(box.type);
2182
+ l_current_data_size = box.length - l_box_size;
2183
+ p_header_data += l_box_size;
2184
+
2185
+ if (l_current_handler != 00) {
2186
+ if (! l_current_handler->handler(jp2,p_header_data,l_current_data_size,p_manager)) {
2187
+ return OPJ_FALSE;
2188
+ }
2189
+ }
2190
+ else {
2191
+ jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN;
2192
+ }
2193
+
2194
+ p_header_data += l_current_data_size;
2195
+ p_header_size -= box.length;
2196
+ }
2197
+
2198
+ jp2->jp2_state |= JP2_STATE_HEADER;
2199
+
2200
+ return OPJ_TRUE;
2201
+ }
2202
+
2203
+ OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
2204
+ OPJ_BYTE * p_data,
2205
+ OPJ_UINT32 * p_number_bytes_read,
2206
+ OPJ_UINT32 p_box_max_size,
2207
+ opj_event_mgr_t * p_manager
2208
+ )
2209
+ {
2210
+ OPJ_UINT32 l_value;
2211
+
2212
+ /* preconditions */
2213
+ assert(p_data != 00);
2214
+ assert(box != 00);
2215
+ assert(p_number_bytes_read != 00);
2216
+ assert(p_manager != 00);
2217
+
2218
+ if (p_box_max_size < 8) {
2219
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of less than 8 bytes\n");
2220
+ return OPJ_FALSE;
2221
+ }
2222
+
2223
+ /* process read data */
2224
+ opj_read_bytes(p_data, &l_value, 4);
2225
+ p_data += 4;
2226
+ box->length = (OPJ_UINT32)(l_value);
2227
+
2228
+ opj_read_bytes(p_data, &l_value, 4);
2229
+ p_data += 4;
2230
+ box->type = (OPJ_UINT32)(l_value);
2231
+
2232
+ *p_number_bytes_read = 8;
2233
+
2234
+ /* do we have a "special very large box ?" */
2235
+ /* read then the XLBox */
2236
+ if (box->length == 1) {
2237
+ OPJ_UINT32 l_xl_part_size;
2238
+
2239
+ if (p_box_max_size < 16) {
2240
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle XL box of less than 16 bytes\n");
2241
+ return OPJ_FALSE;
2242
+ }
2243
+
2244
+ opj_read_bytes(p_data,&l_xl_part_size, 4);
2245
+ p_data += 4;
2246
+ *p_number_bytes_read += 4;
2247
+
2248
+ if (l_xl_part_size != 0) {
2249
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
2250
+ return OPJ_FALSE;
2251
+ }
2252
+
2253
+ opj_read_bytes(p_data, &l_value, 4);
2254
+ *p_number_bytes_read += 4;
2255
+ box->length = (OPJ_UINT32)(l_value);
2256
+
2257
+ if (box->length == 0) {
2258
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
2259
+ return OPJ_FALSE;
2260
+ }
2261
+ }
2262
+ else if (box->length == 0) {
2263
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
2264
+ return OPJ_FALSE;
2265
+ }
2266
+
2267
+ return OPJ_TRUE;
2268
+ }
2269
+
2270
+ OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream,
2271
+ opj_jp2_t *jp2,
2272
+ opj_image_t ** p_image,
2273
+ opj_event_mgr_t * p_manager
2274
+ )
2275
+ {
2276
+ /* preconditions */
2277
+ assert(jp2 != 00);
2278
+ assert(p_stream != 00);
2279
+ assert(p_manager != 00);
2280
+
2281
+ /* customization of the validation */
2282
+ opj_jp2_setup_decoding_validation (jp2);
2283
+
2284
+ /* customization of the encoding */
2285
+ opj_jp2_setup_header_reading(jp2);
2286
+
2287
+ /* validation of the parameters codec */
2288
+ if (! opj_jp2_exec(jp2,jp2->m_validation_list,p_stream,p_manager)) {
2289
+ return OPJ_FALSE;
2290
+ }
2291
+
2292
+ /* read header */
2293
+ if (! opj_jp2_exec (jp2,jp2->m_procedure_list,p_stream,p_manager)) {
2294
+ return OPJ_FALSE;
2295
+ }
2296
+
2297
+ return opj_j2k_read_header( p_stream,
2298
+ jp2->j2k,
2299
+ p_image,
2300
+ p_manager);
2301
+ }
2302
+
2303
+ void opj_jp2_setup_encoding_validation (opj_jp2_t *jp2)
2304
+ {
2305
+ /* preconditions */
2306
+ assert(jp2 != 00);
2307
+
2308
+ opj_procedure_list_add_procedure(jp2->m_validation_list, (opj_procedure)opj_jp2_default_validation);
2309
+ /* DEVELOPER CORNER, add your custom validation procedure */
2310
+ }
2311
+
2312
+ void opj_jp2_setup_decoding_validation (opj_jp2_t *jp2)
2313
+ {
2314
+ /* preconditions */
2315
+ assert(jp2 != 00);
2316
+ /* DEVELOPER CORNER, add your custom validation procedure */
2317
+ }
2318
+
2319
+ void opj_jp2_setup_header_writing (opj_jp2_t *jp2)
2320
+ {
2321
+ /* preconditions */
2322
+ assert(jp2 != 00);
2323
+
2324
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp );
2325
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_ftyp );
2326
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp2h );
2327
+ if( jp2->jpip_on )
2328
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_skip_iptr );
2329
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_skip_jp2c );
2330
+
2331
+ /* DEVELOPER CORNER, insert your custom procedures */
2332
+
2333
+ }
2334
+
2335
+ void opj_jp2_setup_header_reading (opj_jp2_t *jp2)
2336
+ {
2337
+ /* preconditions */
2338
+ assert(jp2 != 00);
2339
+
2340
+ opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_read_header_procedure );
2341
+ /* DEVELOPER CORNER, add your custom procedures */
2342
+ }
2343
+
2344
+ OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
2345
+ OPJ_UINT32 * p_tile_index,
2346
+ OPJ_UINT32 * p_data_size,
2347
+ OPJ_INT32 * p_tile_x0,
2348
+ OPJ_INT32 * p_tile_y0,
2349
+ OPJ_INT32 * p_tile_x1,
2350
+ OPJ_INT32 * p_tile_y1,
2351
+ OPJ_UINT32 * p_nb_comps,
2352
+ OPJ_BOOL * p_go_on,
2353
+ opj_stream_private_t *p_stream,
2354
+ opj_event_mgr_t * p_manager
2355
+ )
2356
+ {
2357
+ return opj_j2k_read_tile_header(p_jp2->j2k,
2358
+ p_tile_index,
2359
+ p_data_size,
2360
+ p_tile_x0, p_tile_y0,
2361
+ p_tile_x1, p_tile_y1,
2362
+ p_nb_comps,
2363
+ p_go_on,
2364
+ p_stream,
2365
+ p_manager);
2366
+ }
2367
+
2368
+ OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2,
2369
+ OPJ_UINT32 p_tile_index,
2370
+ OPJ_BYTE * p_data,
2371
+ OPJ_UINT32 p_data_size,
2372
+ opj_stream_private_t *p_stream,
2373
+ opj_event_mgr_t * p_manager
2374
+ )
2375
+
2376
+ {
2377
+ return opj_j2k_write_tile (p_jp2->j2k,p_tile_index,p_data,p_data_size,p_stream,p_manager);
2378
+ }
2379
+
2380
+ OPJ_BOOL opj_jp2_decode_tile ( opj_jp2_t * p_jp2,
2381
+ OPJ_UINT32 p_tile_index,
2382
+ OPJ_BYTE * p_data,
2383
+ OPJ_UINT32 p_data_size,
2384
+ opj_stream_private_t *p_stream,
2385
+ opj_event_mgr_t * p_manager
2386
+ )
2387
+ {
2388
+ return opj_j2k_decode_tile (p_jp2->j2k,p_tile_index,p_data,p_data_size,p_stream,p_manager);
2389
+ }
2390
+
2391
+ void opj_jp2_destroy(opj_jp2_t *jp2)
2392
+ {
2393
+ if (jp2) {
2394
+ /* destroy the J2K codec */
2395
+ opj_j2k_destroy(jp2->j2k);
2396
+ jp2->j2k = 00;
2397
+
2398
+ if (jp2->comps) {
2399
+ opj_free(jp2->comps);
2400
+ jp2->comps = 00;
2401
+ }
2402
+
2403
+ if (jp2->cl) {
2404
+ opj_free(jp2->cl);
2405
+ jp2->cl = 00;
2406
+ }
2407
+
2408
+ if (jp2->color.icc_profile_buf) {
2409
+ opj_free(jp2->color.icc_profile_buf);
2410
+ jp2->color.icc_profile_buf = 00;
2411
+ }
2412
+
2413
+ if (jp2->color.jp2_cdef) {
2414
+ if (jp2->color.jp2_cdef->info) {
2415
+ opj_free(jp2->color.jp2_cdef->info);
2416
+ jp2->color.jp2_cdef->info = NULL;
2417
+ }
2418
+
2419
+ opj_free(jp2->color.jp2_cdef);
2420
+ jp2->color.jp2_cdef = 00;
2421
+ }
2422
+
2423
+ if (jp2->color.jp2_pclr) {
2424
+ if (jp2->color.jp2_pclr->cmap) {
2425
+ opj_free(jp2->color.jp2_pclr->cmap);
2426
+ jp2->color.jp2_pclr->cmap = NULL;
2427
+ }
2428
+ if (jp2->color.jp2_pclr->channel_sign) {
2429
+ opj_free(jp2->color.jp2_pclr->channel_sign);
2430
+ jp2->color.jp2_pclr->channel_sign = NULL;
2431
+ }
2432
+ if (jp2->color.jp2_pclr->channel_size) {
2433
+ opj_free(jp2->color.jp2_pclr->channel_size);
2434
+ jp2->color.jp2_pclr->channel_size = NULL;
2435
+ }
2436
+ if (jp2->color.jp2_pclr->entries) {
2437
+ opj_free(jp2->color.jp2_pclr->entries);
2438
+ jp2->color.jp2_pclr->entries = NULL;
2439
+ }
2440
+
2441
+ opj_free(jp2->color.jp2_pclr);
2442
+ jp2->color.jp2_pclr = 00;
2443
+ }
2444
+
2445
+ if (jp2->m_validation_list) {
2446
+ opj_procedure_list_destroy(jp2->m_validation_list);
2447
+ jp2->m_validation_list = 00;
2448
+ }
2449
+
2450
+ if (jp2->m_procedure_list) {
2451
+ opj_procedure_list_destroy(jp2->m_procedure_list);
2452
+ jp2->m_procedure_list = 00;
2453
+ }
2454
+
2455
+ opj_free(jp2);
2456
+ }
2457
+ }
2458
+
2459
+ OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2,
2460
+ opj_image_t* p_image,
2461
+ OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
2462
+ OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
2463
+ opj_event_mgr_t * p_manager
2464
+ )
2465
+ {
2466
+ return opj_j2k_set_decode_area(p_jp2->j2k, p_image, p_start_x, p_start_y, p_end_x, p_end_y, p_manager);
2467
+ }
2468
+
2469
+ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
2470
+ opj_stream_private_t *p_stream,
2471
+ opj_image_t* p_image,
2472
+ opj_event_mgr_t * p_manager,
2473
+ OPJ_UINT32 tile_index
2474
+ )
2475
+ {
2476
+ if (!p_image)
2477
+ return OPJ_FALSE;
2478
+
2479
+ opj_event_msg(p_manager, EVT_WARNING, "JP2 box which are after the codestream will not be read by this function.\n");
2480
+
2481
+ if (! opj_j2k_get_tile(p_jp2->j2k, p_stream, p_image, p_manager, tile_index) ){
2482
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to decode the codestream in the JP2 file\n");
2483
+ return OPJ_FALSE;
2484
+ }
2485
+
2486
+ if (!opj_jp2_check_color(p_image, &(p_jp2->color), p_manager)) {
2487
+ return OPJ_FALSE;
2488
+ }
2489
+
2490
+ /* Set Image Color Space */
2491
+ if (p_jp2->enumcs == 16)
2492
+ p_image->color_space = OPJ_CLRSPC_SRGB;
2493
+ else if (p_jp2->enumcs == 17)
2494
+ p_image->color_space = OPJ_CLRSPC_GRAY;
2495
+ else if (p_jp2->enumcs == 18)
2496
+ p_image->color_space = OPJ_CLRSPC_SYCC;
2497
+ else
2498
+ p_image->color_space = OPJ_CLRSPC_UNKNOWN;
2499
+
2500
+ /* Apply the color space if needed */
2501
+ if(p_jp2->color.jp2_cdef) {
2502
+ opj_jp2_apply_cdef(p_image, &(p_jp2->color));
2503
+ }
2504
+
2505
+ if(p_jp2->color.jp2_pclr) {
2506
+ /* Part 1, I.5.3.4: Either both or none : */
2507
+ if( !p_jp2->color.jp2_pclr->cmap)
2508
+ opj_jp2_free_pclr(&(p_jp2->color));
2509
+ else
2510
+ opj_jp2_apply_pclr(p_image, &(p_jp2->color));
2511
+ }
2512
+
2513
+ if(p_jp2->color.icc_profile_buf) {
2514
+ p_image->icc_profile_buf = p_jp2->color.icc_profile_buf;
2515
+ p_image->icc_profile_len = p_jp2->color.icc_profile_len;
2516
+ p_jp2->color.icc_profile_buf = NULL;
2517
+ }
2518
+
2519
+ return OPJ_TRUE;
2520
+ }
2521
+
2522
+ /* ----------------------------------------------------------------------- */
2523
+ /* JP2 encoder interface */
2524
+ /* ----------------------------------------------------------------------- */
2525
+
2526
+ opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder)
2527
+ {
2528
+ opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
2529
+ if (jp2) {
2530
+ memset(jp2,0,sizeof(opj_jp2_t));
2531
+
2532
+ /* create the J2K codec */
2533
+ if (! p_is_decoder) {
2534
+ jp2->j2k = opj_j2k_create_compress();
2535
+ }
2536
+ else {
2537
+ jp2->j2k = opj_j2k_create_decompress();
2538
+ }
2539
+
2540
+ if (jp2->j2k == 00) {
2541
+ opj_jp2_destroy(jp2);
2542
+ return 00;
2543
+ }
2544
+
2545
+ /* Color structure */
2546
+ jp2->color.icc_profile_buf = NULL;
2547
+ jp2->color.icc_profile_len = 0;
2548
+ jp2->color.jp2_cdef = NULL;
2549
+ jp2->color.jp2_pclr = NULL;
2550
+ jp2->color.jp2_has_colr = 0;
2551
+
2552
+ /* validation list creation */
2553
+ jp2->m_validation_list = opj_procedure_list_create();
2554
+ if (! jp2->m_validation_list) {
2555
+ opj_jp2_destroy(jp2);
2556
+ return 00;
2557
+ }
2558
+
2559
+ /* execution list creation */
2560
+ jp2->m_procedure_list = opj_procedure_list_create();
2561
+ if (! jp2->m_procedure_list) {
2562
+ opj_jp2_destroy(jp2);
2563
+ return 00;
2564
+ }
2565
+ }
2566
+
2567
+ return jp2;
2568
+ }
2569
+
2570
+ void jp2_dump(opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream)
2571
+ {
2572
+ /* preconditions */
2573
+ assert(p_jp2 != 00);
2574
+
2575
+ j2k_dump(p_jp2->j2k,
2576
+ flag,
2577
+ out_stream);
2578
+ }
2579
+
2580
+ opj_codestream_index_t* jp2_get_cstr_index(opj_jp2_t* p_jp2)
2581
+ {
2582
+ return j2k_get_cstr_index(p_jp2->j2k);
2583
+ }
2584
+
2585
+ opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_t* p_jp2)
2586
+ {
2587
+ return j2k_get_cstr_info(p_jp2->j2k);
2588
+ }
2589
+
2590
+ OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2,
2591
+ OPJ_UINT32 res_factor,
2592
+ opj_event_mgr_t * p_manager)
2593
+ {
2594
+ return opj_j2k_set_decoded_resolution_factor(p_jp2->j2k, res_factor, p_manager);
2595
+ }
2596
+
2597
+ /* JPIP specific */
2598
+
2599
+ #ifdef USE_JPIP
2600
+ static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2,
2601
+ opj_stream_private_t *cio,
2602
+ opj_event_mgr_t * p_manager )
2603
+ {
2604
+ OPJ_OFF_T j2k_codestream_exit;
2605
+ OPJ_BYTE l_data_header [24];
2606
+
2607
+ /* preconditions */
2608
+ assert(jp2 != 00);
2609
+ assert(cio != 00);
2610
+ assert(p_manager != 00);
2611
+ assert(opj_stream_has_seek(cio));
2612
+
2613
+ j2k_codestream_exit = opj_stream_tell(cio);
2614
+ opj_write_bytes(l_data_header, 24, 4); /* size of iptr */
2615
+ opj_write_bytes(l_data_header + 4,JPIP_IPTR,4); /* IPTR */
2616
+ #if 0
2617
+ opj_write_bytes(l_data_header + 4 + 4, 0, 8); /* offset */
2618
+ opj_write_bytes(l_data_header + 8 + 8, 0, 8); /* length */
2619
+ #else
2620
+ opj_write_double(l_data_header + 4 + 4, 0); /* offset */
2621
+ opj_write_double(l_data_header + 8 + 8, 0); /* length */
2622
+ #endif
2623
+
2624
+ if (! opj_stream_seek(cio,jp2->jpip_iptr_offset,p_manager)) {
2625
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2626
+ return OPJ_FALSE;
2627
+ }
2628
+
2629
+ if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) {
2630
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2631
+ return OPJ_FALSE;
2632
+ }
2633
+
2634
+ if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
2635
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2636
+ return OPJ_FALSE;
2637
+ }
2638
+
2639
+ return OPJ_TRUE;
2640
+ }
2641
+
2642
+ static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2,
2643
+ opj_stream_private_t *cio,
2644
+ opj_event_mgr_t * p_manager )
2645
+ {
2646
+ OPJ_OFF_T j2k_codestream_exit;
2647
+ OPJ_BYTE l_data_header [24];
2648
+
2649
+ /* preconditions */
2650
+ assert(jp2 != 00);
2651
+ assert(cio != 00);
2652
+ assert(p_manager != 00);
2653
+ assert(opj_stream_has_seek(cio));
2654
+
2655
+ opj_write_bytes(l_data_header, 24, 4); /* size of iptr */
2656
+ opj_write_bytes(l_data_header + 4,JPIP_FIDX,4); /* IPTR */
2657
+ opj_write_double(l_data_header + 4 + 4, 0); /* offset */
2658
+ opj_write_double(l_data_header + 8 + 8, 0); /* length */
2659
+
2660
+ if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) {
2661
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2662
+ return OPJ_FALSE;
2663
+ }
2664
+
2665
+ j2k_codestream_exit = opj_stream_tell(cio);
2666
+ if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
2667
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2668
+ return OPJ_FALSE;
2669
+ }
2670
+
2671
+ return OPJ_TRUE;
2672
+ }
2673
+
2674
+ static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2,
2675
+ opj_stream_private_t *cio,
2676
+ opj_event_mgr_t * p_manager )
2677
+ {
2678
+ OPJ_OFF_T j2k_codestream_exit;
2679
+ OPJ_BYTE l_data_header [24];
2680
+
2681
+ /* preconditions */
2682
+ assert(jp2 != 00);
2683
+ assert(cio != 00);
2684
+ assert(p_manager != 00);
2685
+ assert(opj_stream_has_seek(cio));
2686
+
2687
+ j2k_codestream_exit = opj_stream_tell(cio);
2688
+ opj_write_bytes(l_data_header, 24, 4); /* size of iptr */
2689
+ opj_write_bytes(l_data_header + 4,JPIP_CIDX,4); /* IPTR */
2690
+ #if 0
2691
+ opj_write_bytes(l_data_header + 4 + 4, 0, 8); /* offset */
2692
+ opj_write_bytes(l_data_header + 8 + 8, 0, 8); /* length */
2693
+ #else
2694
+ opj_write_double(l_data_header + 4 + 4, 0); /* offset */
2695
+ opj_write_double(l_data_header + 8 + 8, 0); /* length */
2696
+ #endif
2697
+
2698
+ if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
2699
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2700
+ return OPJ_FALSE;
2701
+ }
2702
+
2703
+ if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) {
2704
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2705
+ return OPJ_FALSE;
2706
+ }
2707
+
2708
+ j2k_codestream_exit = opj_stream_tell(cio);
2709
+ if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
2710
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
2711
+ return OPJ_FALSE;
2712
+ }
2713
+
2714
+ return OPJ_TRUE;
2715
+ }
2716
+
2717
+ #if 0
2718
+ static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio,
2719
+ opj_event_mgr_t * p_manager )
2720
+ {
2721
+ OPJ_BYTE l_data_header [8];
2722
+ OPJ_OFF_T len, lenp;
2723
+
2724
+ lenp = opj_stream_tell(cio);
2725
+ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
2726
+ opj_write_bytes(l_data_header,JPIP_PRXY,4); /* IPTR */
2727
+ opj_stream_write_data(cio,l_data_header,4,p_manager);
2728
+
2729
+ opj_write_bytes( l_data_header, offset_jp2c, 8); /* OOFF */
2730
+ opj_stream_write_data(cio,l_data_header,8,p_manager);
2731
+ opj_write_bytes( l_data_header, length_jp2c, 4); /* OBH part 1 */
2732
+ opj_write_bytes( l_data_header+4, JP2_JP2C, 4); /* OBH part 2 */
2733
+ opj_stream_write_data(cio,l_data_header,8,p_manager);
2734
+
2735
+ opj_write_bytes( l_data_header, 1, 1);/* NI */
2736
+ opj_stream_write_data(cio,l_data_header,1,p_manager);
2737
+
2738
+ opj_write_bytes( l_data_header, offset_idx, 8); /* IOFF */
2739
+ opj_stream_write_data(cio,l_data_header,8,p_manager);
2740
+ opj_write_bytes( l_data_header, length_idx, 4); /* IBH part 1 */
2741
+ opj_write_bytes( l_data_header+4, JPIP_CIDX, 4); /* IBH part 2 */
2742
+ opj_stream_write_data(cio,l_data_header,8,p_manager);
2743
+
2744
+ len = opj_stream_tell(cio)-lenp;
2745
+ opj_stream_skip(cio, lenp, p_manager);
2746
+ opj_write_bytes(l_data_header,len,4);/* L */
2747
+ opj_stream_write_data(cio,l_data_header,4,p_manager);
2748
+ opj_stream_seek(cio, lenp+len,p_manager);
2749
+ }
2750
+ #endif
2751
+
2752
+
2753
+ #if 0
2754
+ static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio,
2755
+ opj_event_mgr_t * p_manager )
2756
+ {
2757
+ OPJ_BYTE l_data_header [4];
2758
+ OPJ_OFF_T len, lenp;
2759
+
2760
+ lenp = opj_stream_tell(cio);
2761
+ opj_stream_skip(cio, 4, p_manager);
2762
+ opj_write_bytes(l_data_header,JPIP_FIDX,4); /* FIDX */
2763
+ opj_stream_write_data(cio,l_data_header,4,p_manager);
2764
+
2765
+ write_prxy( offset_jp2c, length_jp2c, offset_idx, length_idx, cio,p_manager);
2766
+
2767
+ len = opj_stream_tell(cio)-lenp;
2768
+ opj_stream_skip(cio, lenp, p_manager);
2769
+ opj_write_bytes(l_data_header,len,4);/* L */
2770
+ opj_stream_write_data(cio,l_data_header,4,p_manager);
2771
+ opj_stream_seek(cio, lenp+len,p_manager);
2772
+
2773
+ return len;
2774
+ }
2775
+ #endif
2776
+ #endif /* USE_JPIP */