lightdrift-libraw 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (487) hide show
  1. package/CHANGELOG.md +374 -0
  2. package/LICENSE +21 -0
  3. package/README.md +757 -0
  4. package/binding.gyp +38 -0
  5. package/deps/LibRaw-Source/LibRaw-0.21.4/.clang-format +4 -0
  6. package/deps/LibRaw-Source/LibRaw-0.21.4/COPYRIGHT +27 -0
  7. package/deps/LibRaw-Source/LibRaw-0.21.4/Changelog.txt +2802 -0
  8. package/deps/LibRaw-Source/LibRaw-0.21.4/DEVELOPER-NOTES +20 -0
  9. package/deps/LibRaw-Source/LibRaw-0.21.4/GoPro/dng-sdk-1_4-allow-VC5-validate.diff +21 -0
  10. package/deps/LibRaw-Source/LibRaw-0.21.4/GoPro/dng-sdk-1_6-hide-ccVc5-definitiion.diff +15 -0
  11. package/deps/LibRaw-Source/LibRaw-0.21.4/GoPro/dng-sdk-allow-VC5-validate.diff +21 -0
  12. package/deps/LibRaw-Source/LibRaw-0.21.4/GoPro/gpr_read_image.cpp.diff +29 -0
  13. package/deps/LibRaw-Source/LibRaw-0.21.4/GoPro/gpr_read_image.h.diff +12 -0
  14. package/deps/LibRaw-Source/LibRaw-0.21.4/INSTALL +51 -0
  15. package/deps/LibRaw-Source/LibRaw-0.21.4/LICENSE.CDDL +340 -0
  16. package/deps/LibRaw-Source/LibRaw-0.21.4/LICENSE.LGPL +458 -0
  17. package/deps/LibRaw-Source/LibRaw-0.21.4/LibRaw.pro +19 -0
  18. package/deps/LibRaw-Source/LibRaw-0.21.4/LibRaw.sln +123 -0
  19. package/deps/LibRaw-Source/LibRaw-0.21.4/Makefile.am +140 -0
  20. package/deps/LibRaw-Source/LibRaw-0.21.4/Makefile.devel.nopp +230 -0
  21. package/deps/LibRaw-Source/LibRaw-0.21.4/Makefile.devel.noppr2i +227 -0
  22. package/deps/LibRaw-Source/LibRaw-0.21.4/Makefile.dist +501 -0
  23. package/deps/LibRaw-Source/LibRaw-0.21.4/Makefile.in +1849 -0
  24. package/deps/LibRaw-Source/LibRaw-0.21.4/Makefile.mingw +297 -0
  25. package/deps/LibRaw-Source/LibRaw-0.21.4/Makefile.msvc +628 -0
  26. package/deps/LibRaw-Source/LibRaw-0.21.4/README.DNGSDK.txt +43 -0
  27. package/deps/LibRaw-Source/LibRaw-0.21.4/README.GoPro.txt +112 -0
  28. package/deps/LibRaw-Source/LibRaw-0.21.4/README.RawSpeed.txt +62 -0
  29. package/deps/LibRaw-Source/LibRaw-0.21.4/README.cmake +9 -0
  30. package/deps/LibRaw-Source/LibRaw-0.21.4/README.demosaic-packs +17 -0
  31. package/deps/LibRaw-Source/LibRaw-0.21.4/README.md +106 -0
  32. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed/rawspeed.cpucount-unix.patch +15 -0
  33. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed/rawspeed.qmake-pro-files.patch +84 -0
  34. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed/rawspeed.samsung-decoder.patch +39 -0
  35. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed/rawspeed.uncompressed-color-dng.patch +13 -0
  36. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed/rawspeed.win32-dll.patch +186 -0
  37. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed/rawspeed_xmldata.cpp +4115 -0
  38. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/README.md +69 -0
  39. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/patches/01.CameraMeta-extensibility.patch +13 -0
  40. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/patches/02.Makernotes-processing.patch +36 -0
  41. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/patches/03.remove-limits-and-logging.patch +245 -0
  42. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/patches/04.clang-cl-compatibility.patch +37 -0
  43. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rawspeed3_capi.cpp +251 -0
  44. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rawspeed3_capi.h +83 -0
  45. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rawspeed3_capi_test.cpp +71 -0
  46. package/deps/LibRaw-Source/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rsxml2c.sh +5 -0
  47. package/deps/LibRaw-Source/LibRaw-0.21.4/aclocal.m4 +1446 -0
  48. package/deps/LibRaw-Source/LibRaw-0.21.4/autom4te.cache/output.0 +19332 -0
  49. package/deps/LibRaw-Source/LibRaw-0.21.4/autom4te.cache/output.1 +19332 -0
  50. package/deps/LibRaw-Source/LibRaw-0.21.4/autom4te.cache/output.2 +19332 -0
  51. package/deps/LibRaw-Source/LibRaw-0.21.4/autom4te.cache/requests +544 -0
  52. package/deps/LibRaw-Source/LibRaw-0.21.4/autom4te.cache/traces.0 +3028 -0
  53. package/deps/LibRaw-Source/LibRaw-0.21.4/autom4te.cache/traces.1 +665 -0
  54. package/deps/LibRaw-Source/LibRaw-0.21.4/autom4te.cache/traces.2 +3028 -0
  55. package/deps/LibRaw-Source/LibRaw-0.21.4/bin/.keep_me +2 -0
  56. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/4channels.pro +5 -0
  57. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/4channels.vcxproj +145 -0
  58. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/4channels.vcxproj.filters +18 -0
  59. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/dcraw_emu.pro +6 -0
  60. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/dcraw_emu.vcxproj +145 -0
  61. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/dcraw_emu.vcxproj.filters +18 -0
  62. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/dcraw_half.pro +6 -0
  63. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/dcraw_half.vcxproj +145 -0
  64. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/dcraw_half.vcxproj.filters +18 -0
  65. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/half_mt.pro +10 -0
  66. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/libraw-common-lib.pro +28 -0
  67. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/libraw-common.pro +8 -0
  68. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/libraw.pro +70 -0
  69. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/libraw.vcxproj +234 -0
  70. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/libraw.vcxproj.filters +295 -0
  71. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/mem_image.pro +6 -0
  72. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/mem_image.vcxproj +145 -0
  73. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/mem_image.vcxproj.filters +18 -0
  74. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/multirender_test.pro +6 -0
  75. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/multirender_test.vcxproj +145 -0
  76. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/multirender_test.vcxproj.filters +18 -0
  77. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/openbayer_sample.pro +6 -0
  78. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/openbayer_sample.vcxproj +145 -0
  79. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/openbayer_sample.vcxproj.filters +18 -0
  80. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/postprocessing_benchmark.pro +4 -0
  81. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/postprocessing_benchmark.vcxproj +145 -0
  82. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/postprocessing_benchmark.vcxproj.filters +18 -0
  83. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/raw-identify.pro +6 -0
  84. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/raw-identify.vcxproj +145 -0
  85. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/raw-identify.vcxproj.filters +18 -0
  86. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/rawtextdump.pro +6 -0
  87. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/rawtextdump.vcxproj +145 -0
  88. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/rawtextdump.vcxproj.filters +18 -0
  89. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/simple_dcraw.pro +6 -0
  90. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/simple_dcraw.vcxproj +145 -0
  91. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/simple_dcraw.vcxproj.filters +18 -0
  92. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/unprocessed_raw.pro +6 -0
  93. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/unprocessed_raw.vcxproj +145 -0
  94. package/deps/LibRaw-Source/LibRaw-0.21.4/buildfiles/unprocessed_raw.vcxproj.filters +18 -0
  95. package/deps/LibRaw-Source/LibRaw-0.21.4/compile +347 -0
  96. package/deps/LibRaw-Source/LibRaw-0.21.4/config.guess +1433 -0
  97. package/deps/LibRaw-Source/LibRaw-0.21.4/config.sub +1804 -0
  98. package/deps/LibRaw-Source/LibRaw-0.21.4/configure +19332 -0
  99. package/deps/LibRaw-Source/LibRaw-0.21.4/configure.ac +153 -0
  100. package/deps/LibRaw-Source/LibRaw-0.21.4/depcomp +791 -0
  101. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/API-C.html +187 -0
  102. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/API-CXX.html +881 -0
  103. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/API-datastruct.html +1341 -0
  104. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/API-notes.html +305 -0
  105. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/API-overview.html +66 -0
  106. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/Install-LibRaw.html +124 -0
  107. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/Samples-LibRaw.html +213 -0
  108. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/Why-LibRaw.html +65 -0
  109. package/deps/LibRaw-Source/LibRaw-0.21.4/doc/index.html +38 -0
  110. package/deps/LibRaw-Source/LibRaw-0.21.4/install-sh +501 -0
  111. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/dcraw_defs.h +66 -0
  112. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/dcraw_fileio_defs.h +25 -0
  113. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/defines.h +193 -0
  114. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/dmp_include.h +27 -0
  115. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/libraw_cameraids.h +320 -0
  116. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/libraw_cxx_defs.h +133 -0
  117. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/libraw_internal_funcs.h +412 -0
  118. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/var_defines.h +215 -0
  119. package/deps/LibRaw-Source/LibRaw-0.21.4/internal/x3f_tools.h +539 -0
  120. package/deps/LibRaw-Source/LibRaw-0.21.4/lib/Makefile +3 -0
  121. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw/libraw.h +534 -0
  122. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw/libraw_alloc.h +148 -0
  123. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw/libraw_const.h +814 -0
  124. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw/libraw_datastream.h +410 -0
  125. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw/libraw_internal.h +341 -0
  126. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw/libraw_types.h +1175 -0
  127. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw/libraw_version.h +63 -0
  128. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw.pc.in +12 -0
  129. package/deps/LibRaw-Source/LibRaw-0.21.4/libraw_r.pc.in +12 -0
  130. package/deps/LibRaw-Source/LibRaw-0.21.4/ltmain.sh +11147 -0
  131. package/deps/LibRaw-Source/LibRaw-0.21.4/m4/ax_openmp.m4 +99 -0
  132. package/deps/LibRaw-Source/LibRaw-0.21.4/m4/libtool.m4 +8369 -0
  133. package/deps/LibRaw-Source/LibRaw-0.21.4/m4/ltoptions.m4 +437 -0
  134. package/deps/LibRaw-Source/LibRaw-0.21.4/m4/ltsugar.m4 +124 -0
  135. package/deps/LibRaw-Source/LibRaw-0.21.4/m4/ltversion.m4 +23 -0
  136. package/deps/LibRaw-Source/LibRaw-0.21.4/m4/lt~obsolete.m4 +99 -0
  137. package/deps/LibRaw-Source/LibRaw-0.21.4/missing +215 -0
  138. package/deps/LibRaw-Source/LibRaw-0.21.4/object/.keep_me +0 -0
  139. package/deps/LibRaw-Source/LibRaw-0.21.4/rsxml2c.sh +6 -0
  140. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/4channels.cpp +174 -0
  141. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/Makefile +2 -0
  142. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/dcraw_emu.cpp +670 -0
  143. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/dcraw_half.c +78 -0
  144. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/half_mt.c +178 -0
  145. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/half_mt_win32.c +212 -0
  146. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/mem_image_sample.cpp +282 -0
  147. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/multirender_test.cpp +107 -0
  148. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/openbayer_sample.cpp +65 -0
  149. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/postprocessing_benchmark.cpp +223 -0
  150. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/raw-identify.cpp +743 -0
  151. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/rawtextdump.cpp +144 -0
  152. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/simple_dcraw.cpp +217 -0
  153. package/deps/LibRaw-Source/LibRaw-0.21.4/samples/unprocessed_raw.cpp +319 -0
  154. package/deps/LibRaw-Source/LibRaw-0.21.4/shlib-version.sh +11 -0
  155. package/deps/LibRaw-Source/LibRaw-0.21.4/src/Makefile +2 -0
  156. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/canon_600.cpp +225 -0
  157. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/crx.cpp +2781 -0
  158. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/decoders_dcraw.cpp +1816 -0
  159. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/decoders_libraw.cpp +873 -0
  160. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/decoders_libraw_dcrdefs.cpp +411 -0
  161. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/dng.cpp +284 -0
  162. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/fp_dng.cpp +689 -0
  163. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/fuji_compressed.cpp +1210 -0
  164. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/generic.cpp +101 -0
  165. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/kodak_decoders.cpp +524 -0
  166. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/load_mfbacks.cpp +936 -0
  167. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/smal.cpp +181 -0
  168. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/unpack.cpp +508 -0
  169. package/deps/LibRaw-Source/LibRaw-0.21.4/src/decoders/unpack_thumb.cpp +405 -0
  170. package/deps/LibRaw-Source/LibRaw-0.21.4/src/demosaic/aahd_demosaic.cpp +781 -0
  171. package/deps/LibRaw-Source/LibRaw-0.21.4/src/demosaic/ahd_demosaic.cpp +355 -0
  172. package/deps/LibRaw-Source/LibRaw-0.21.4/src/demosaic/dcb_demosaic.cpp +900 -0
  173. package/deps/LibRaw-Source/LibRaw-0.21.4/src/demosaic/dht_demosaic.cpp +1033 -0
  174. package/deps/LibRaw-Source/LibRaw-0.21.4/src/demosaic/misc_demosaic.cpp +420 -0
  175. package/deps/LibRaw-Source/LibRaw-0.21.4/src/demosaic/xtrans_demosaic.cpp +434 -0
  176. package/deps/LibRaw-Source/LibRaw-0.21.4/src/integration/dngsdk_glue.cpp +416 -0
  177. package/deps/LibRaw-Source/LibRaw-0.21.4/src/integration/rawspeed_glue.cpp +286 -0
  178. package/deps/LibRaw-Source/LibRaw-0.21.4/src/libraw_c_api.cpp +457 -0
  179. package/deps/LibRaw-Source/LibRaw-0.21.4/src/libraw_datastream.cpp +1046 -0
  180. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/adobepano.cpp +154 -0
  181. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/canon.cpp +1335 -0
  182. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/ciff.cpp +411 -0
  183. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/cr3_parser.cpp +896 -0
  184. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/epson.cpp +96 -0
  185. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/exif_gps.cpp +430 -0
  186. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/fuji.cpp +1427 -0
  187. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/hasselblad_model.cpp +538 -0
  188. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/identify.cpp +3167 -0
  189. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/identify_tools.cpp +140 -0
  190. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/kodak.cpp +363 -0
  191. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/leica.cpp +375 -0
  192. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/makernotes.cpp +786 -0
  193. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/mediumformat.cpp +521 -0
  194. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/minolta.cpp +110 -0
  195. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/misc_parsers.cpp +694 -0
  196. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/nikon.cpp +1051 -0
  197. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/normalize_model.cpp +1451 -0
  198. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/olympus.cpp +685 -0
  199. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/p1.cpp +192 -0
  200. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/pentax.cpp +675 -0
  201. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/samsung.cpp +182 -0
  202. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/sony.cpp +2320 -0
  203. package/deps/LibRaw-Source/LibRaw-0.21.4/src/metadata/tiff.cpp +2198 -0
  204. package/deps/LibRaw-Source/LibRaw-0.21.4/src/postprocessing/aspect_ratio.cpp +113 -0
  205. package/deps/LibRaw-Source/LibRaw-0.21.4/src/postprocessing/dcraw_process.cpp +259 -0
  206. package/deps/LibRaw-Source/LibRaw-0.21.4/src/postprocessing/mem_image.cpp +292 -0
  207. package/deps/LibRaw-Source/LibRaw-0.21.4/src/postprocessing/postprocessing_aux.cpp +413 -0
  208. package/deps/LibRaw-Source/LibRaw-0.21.4/src/postprocessing/postprocessing_ph.cpp +31 -0
  209. package/deps/LibRaw-Source/LibRaw-0.21.4/src/postprocessing/postprocessing_utils.cpp +190 -0
  210. package/deps/LibRaw-Source/LibRaw-0.21.4/src/postprocessing/postprocessing_utils_dcrdefs.cpp +308 -0
  211. package/deps/LibRaw-Source/LibRaw-0.21.4/src/preprocessing/ext_preprocess.cpp +127 -0
  212. package/deps/LibRaw-Source/LibRaw-0.21.4/src/preprocessing/preprocessing_ph.cpp +24 -0
  213. package/deps/LibRaw-Source/LibRaw-0.21.4/src/preprocessing/raw2image.cpp +560 -0
  214. package/deps/LibRaw-Source/LibRaw-0.21.4/src/preprocessing/subtract_black.cpp +91 -0
  215. package/deps/LibRaw-Source/LibRaw-0.21.4/src/tables/cameralist.cpp +1268 -0
  216. package/deps/LibRaw-Source/LibRaw-0.21.4/src/tables/colorconst.cpp +57 -0
  217. package/deps/LibRaw-Source/LibRaw-0.21.4/src/tables/colordata.cpp +1841 -0
  218. package/deps/LibRaw-Source/LibRaw-0.21.4/src/tables/wblists.cpp +217 -0
  219. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/curves.cpp +154 -0
  220. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/decoder_info.cpp +413 -0
  221. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/init_close_utils.cpp +340 -0
  222. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/open.cpp +1269 -0
  223. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/phaseone_processing.cpp +101 -0
  224. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/read_utils.cpp +176 -0
  225. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/thumb_utils.cpp +338 -0
  226. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/utils_dcraw.cpp +330 -0
  227. package/deps/LibRaw-Source/LibRaw-0.21.4/src/utils/utils_libraw.cpp +673 -0
  228. package/deps/LibRaw-Source/LibRaw-0.21.4/src/write/apply_profile.cpp +76 -0
  229. package/deps/LibRaw-Source/LibRaw-0.21.4/src/write/file_write.cpp +338 -0
  230. package/deps/LibRaw-Source/LibRaw-0.21.4/src/write/tiff_writer.cpp +73 -0
  231. package/deps/LibRaw-Source/LibRaw-0.21.4/src/write/write_ph.cpp +39 -0
  232. package/deps/LibRaw-Source/LibRaw-0.21.4/src/x3f/x3f_parse_process.cpp +708 -0
  233. package/deps/LibRaw-Source/LibRaw-0.21.4/src/x3f/x3f_utils_patched.cpp +2119 -0
  234. package/deps/LibRaw-Source/LibRaw-0.21.4/version.sh +16 -0
  235. package/deps/LibRaw-Win64/LibRaw-0.21.4/.clang-format +4 -0
  236. package/deps/LibRaw-Win64/LibRaw-0.21.4/COPYRIGHT +27 -0
  237. package/deps/LibRaw-Win64/LibRaw-0.21.4/Changelog.txt +2802 -0
  238. package/deps/LibRaw-Win64/LibRaw-0.21.4/DEVELOPER-NOTES +20 -0
  239. package/deps/LibRaw-Win64/LibRaw-0.21.4/GoPro/dng-sdk-1_4-allow-VC5-validate.diff +21 -0
  240. package/deps/LibRaw-Win64/LibRaw-0.21.4/GoPro/dng-sdk-1_6-hide-ccVc5-definitiion.diff +15 -0
  241. package/deps/LibRaw-Win64/LibRaw-0.21.4/GoPro/dng-sdk-allow-VC5-validate.diff +21 -0
  242. package/deps/LibRaw-Win64/LibRaw-0.21.4/GoPro/gpr_read_image.cpp.diff +29 -0
  243. package/deps/LibRaw-Win64/LibRaw-0.21.4/GoPro/gpr_read_image.h.diff +12 -0
  244. package/deps/LibRaw-Win64/LibRaw-0.21.4/INSTALL +51 -0
  245. package/deps/LibRaw-Win64/LibRaw-0.21.4/LICENSE.CDDL +340 -0
  246. package/deps/LibRaw-Win64/LibRaw-0.21.4/LICENSE.LGPL +458 -0
  247. package/deps/LibRaw-Win64/LibRaw-0.21.4/LibRaw.pro +19 -0
  248. package/deps/LibRaw-Win64/LibRaw-0.21.4/LibRaw.sln +123 -0
  249. package/deps/LibRaw-Win64/LibRaw-0.21.4/Makefile.am +140 -0
  250. package/deps/LibRaw-Win64/LibRaw-0.21.4/Makefile.devel.nopp +230 -0
  251. package/deps/LibRaw-Win64/LibRaw-0.21.4/Makefile.devel.noppr2i +227 -0
  252. package/deps/LibRaw-Win64/LibRaw-0.21.4/Makefile.dist +501 -0
  253. package/deps/LibRaw-Win64/LibRaw-0.21.4/Makefile.in +1849 -0
  254. package/deps/LibRaw-Win64/LibRaw-0.21.4/Makefile.mingw +297 -0
  255. package/deps/LibRaw-Win64/LibRaw-0.21.4/Makefile.msvc +628 -0
  256. package/deps/LibRaw-Win64/LibRaw-0.21.4/README.DNGSDK.txt +43 -0
  257. package/deps/LibRaw-Win64/LibRaw-0.21.4/README.GoPro.txt +112 -0
  258. package/deps/LibRaw-Win64/LibRaw-0.21.4/README.RawSpeed.txt +62 -0
  259. package/deps/LibRaw-Win64/LibRaw-0.21.4/README.cmake +9 -0
  260. package/deps/LibRaw-Win64/LibRaw-0.21.4/README.demosaic-packs +17 -0
  261. package/deps/LibRaw-Win64/LibRaw-0.21.4/README.md +106 -0
  262. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed/rawspeed.cpucount-unix.patch +15 -0
  263. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed/rawspeed.qmake-pro-files.patch +84 -0
  264. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed/rawspeed.samsung-decoder.patch +39 -0
  265. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed/rawspeed.uncompressed-color-dng.patch +13 -0
  266. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed/rawspeed.win32-dll.patch +186 -0
  267. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed/rawspeed_xmldata.cpp +4115 -0
  268. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/README.md +69 -0
  269. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/patches/01.CameraMeta-extensibility.patch +13 -0
  270. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/patches/02.Makernotes-processing.patch +36 -0
  271. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/patches/03.remove-limits-and-logging.patch +245 -0
  272. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/patches/04.clang-cl-compatibility.patch +37 -0
  273. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rawspeed3_capi.cpp +251 -0
  274. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rawspeed3_capi.h +83 -0
  275. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rawspeed3_capi_test.cpp +71 -0
  276. package/deps/LibRaw-Win64/LibRaw-0.21.4/RawSpeed3/rawspeed3_c_api/rsxml2c.sh +5 -0
  277. package/deps/LibRaw-Win64/LibRaw-0.21.4/aclocal.m4 +1446 -0
  278. package/deps/LibRaw-Win64/LibRaw-0.21.4/autom4te.cache/output.0 +19332 -0
  279. package/deps/LibRaw-Win64/LibRaw-0.21.4/autom4te.cache/output.1 +19332 -0
  280. package/deps/LibRaw-Win64/LibRaw-0.21.4/autom4te.cache/output.2 +19332 -0
  281. package/deps/LibRaw-Win64/LibRaw-0.21.4/autom4te.cache/requests +544 -0
  282. package/deps/LibRaw-Win64/LibRaw-0.21.4/autom4te.cache/traces.0 +3028 -0
  283. package/deps/LibRaw-Win64/LibRaw-0.21.4/autom4te.cache/traces.1 +665 -0
  284. package/deps/LibRaw-Win64/LibRaw-0.21.4/autom4te.cache/traces.2 +3028 -0
  285. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/.keep_me +2 -0
  286. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/4channels.exe +0 -0
  287. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/dcraw_emu.exe +0 -0
  288. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/dcraw_half.exe +0 -0
  289. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/half_mt.exe +0 -0
  290. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/libraw.dll +0 -0
  291. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/mem_image.exe +0 -0
  292. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/multirender_test.exe +0 -0
  293. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/openbayer_sample.exe +0 -0
  294. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/postprocessing_benchmark.exe +0 -0
  295. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/raw-identify.exe +0 -0
  296. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/rawtextdump.exe +0 -0
  297. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/simple_dcraw.exe +0 -0
  298. package/deps/LibRaw-Win64/LibRaw-0.21.4/bin/unprocessed_raw.exe +0 -0
  299. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/4channels.pro +5 -0
  300. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/4channels.vcxproj +145 -0
  301. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/4channels.vcxproj.filters +18 -0
  302. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/dcraw_emu.pro +6 -0
  303. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/dcraw_emu.vcxproj +145 -0
  304. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/dcraw_emu.vcxproj.filters +18 -0
  305. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/dcraw_half.pro +6 -0
  306. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/dcraw_half.vcxproj +145 -0
  307. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/dcraw_half.vcxproj.filters +18 -0
  308. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/half_mt.pro +10 -0
  309. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/libraw-common-lib.pro +28 -0
  310. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/libraw-common.pro +8 -0
  311. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/libraw.pro +70 -0
  312. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/libraw.vcxproj +234 -0
  313. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/libraw.vcxproj.filters +295 -0
  314. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/mem_image.pro +6 -0
  315. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/mem_image.vcxproj +145 -0
  316. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/mem_image.vcxproj.filters +18 -0
  317. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/multirender_test.pro +6 -0
  318. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/multirender_test.vcxproj +145 -0
  319. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/multirender_test.vcxproj.filters +18 -0
  320. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/openbayer_sample.pro +6 -0
  321. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/openbayer_sample.vcxproj +145 -0
  322. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/openbayer_sample.vcxproj.filters +18 -0
  323. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/postprocessing_benchmark.pro +4 -0
  324. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/postprocessing_benchmark.vcxproj +145 -0
  325. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/postprocessing_benchmark.vcxproj.filters +18 -0
  326. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/raw-identify.pro +6 -0
  327. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/raw-identify.vcxproj +145 -0
  328. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/raw-identify.vcxproj.filters +18 -0
  329. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/rawtextdump.pro +6 -0
  330. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/rawtextdump.vcxproj +145 -0
  331. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/rawtextdump.vcxproj.filters +18 -0
  332. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/simple_dcraw.pro +6 -0
  333. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/simple_dcraw.vcxproj +145 -0
  334. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/simple_dcraw.vcxproj.filters +18 -0
  335. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/unprocessed_raw.pro +6 -0
  336. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/unprocessed_raw.vcxproj +145 -0
  337. package/deps/LibRaw-Win64/LibRaw-0.21.4/buildfiles/unprocessed_raw.vcxproj.filters +18 -0
  338. package/deps/LibRaw-Win64/LibRaw-0.21.4/compile +347 -0
  339. package/deps/LibRaw-Win64/LibRaw-0.21.4/config.guess +1433 -0
  340. package/deps/LibRaw-Win64/LibRaw-0.21.4/config.sub +1804 -0
  341. package/deps/LibRaw-Win64/LibRaw-0.21.4/configure +19332 -0
  342. package/deps/LibRaw-Win64/LibRaw-0.21.4/configure.ac +153 -0
  343. package/deps/LibRaw-Win64/LibRaw-0.21.4/depcomp +791 -0
  344. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/API-C.html +187 -0
  345. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/API-CXX.html +881 -0
  346. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/API-datastruct.html +1341 -0
  347. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/API-notes.html +305 -0
  348. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/API-overview.html +66 -0
  349. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/Install-LibRaw.html +124 -0
  350. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/Samples-LibRaw.html +213 -0
  351. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/Why-LibRaw.html +65 -0
  352. package/deps/LibRaw-Win64/LibRaw-0.21.4/doc/index.html +38 -0
  353. package/deps/LibRaw-Win64/LibRaw-0.21.4/install-sh +501 -0
  354. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/dcraw_defs.h +66 -0
  355. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/dcraw_fileio_defs.h +25 -0
  356. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/defines.h +193 -0
  357. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/dmp_include.h +27 -0
  358. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/libraw_cameraids.h +320 -0
  359. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/libraw_cxx_defs.h +133 -0
  360. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/libraw_internal_funcs.h +412 -0
  361. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/var_defines.h +215 -0
  362. package/deps/LibRaw-Win64/LibRaw-0.21.4/internal/x3f_tools.h +539 -0
  363. package/deps/LibRaw-Win64/LibRaw-0.21.4/lib/Makefile +3 -0
  364. package/deps/LibRaw-Win64/LibRaw-0.21.4/lib/libraw.exp +0 -0
  365. package/deps/LibRaw-Win64/LibRaw-0.21.4/lib/libraw.lib +0 -0
  366. package/deps/LibRaw-Win64/LibRaw-0.21.4/lib/libraw_static.lib +0 -0
  367. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw/libraw.h +534 -0
  368. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw/libraw_alloc.h +148 -0
  369. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw/libraw_const.h +814 -0
  370. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw/libraw_datastream.h +410 -0
  371. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw/libraw_internal.h +341 -0
  372. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw/libraw_types.h +1175 -0
  373. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw/libraw_version.h +63 -0
  374. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw.pc.in +12 -0
  375. package/deps/LibRaw-Win64/LibRaw-0.21.4/libraw_r.pc.in +12 -0
  376. package/deps/LibRaw-Win64/LibRaw-0.21.4/ltmain.sh +11147 -0
  377. package/deps/LibRaw-Win64/LibRaw-0.21.4/m4/ax_openmp.m4 +99 -0
  378. package/deps/LibRaw-Win64/LibRaw-0.21.4/m4/libtool.m4 +8369 -0
  379. package/deps/LibRaw-Win64/LibRaw-0.21.4/m4/ltoptions.m4 +437 -0
  380. package/deps/LibRaw-Win64/LibRaw-0.21.4/m4/ltsugar.m4 +124 -0
  381. package/deps/LibRaw-Win64/LibRaw-0.21.4/m4/ltversion.m4 +23 -0
  382. package/deps/LibRaw-Win64/LibRaw-0.21.4/m4/lt~obsolete.m4 +99 -0
  383. package/deps/LibRaw-Win64/LibRaw-0.21.4/missing +215 -0
  384. package/deps/LibRaw-Win64/LibRaw-0.21.4/object/.keep_me +0 -0
  385. package/deps/LibRaw-Win64/LibRaw-0.21.4/rsxml2c.sh +6 -0
  386. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/4channels.cpp +174 -0
  387. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/Makefile +2 -0
  388. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/dcraw_emu.cpp +670 -0
  389. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/dcraw_half.c +78 -0
  390. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/half_mt.c +178 -0
  391. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/half_mt_win32.c +212 -0
  392. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/mem_image_sample.cpp +282 -0
  393. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/multirender_test.cpp +107 -0
  394. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/openbayer_sample.cpp +65 -0
  395. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/postprocessing_benchmark.cpp +223 -0
  396. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/raw-identify.cpp +743 -0
  397. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/rawtextdump.cpp +144 -0
  398. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/simple_dcraw.cpp +217 -0
  399. package/deps/LibRaw-Win64/LibRaw-0.21.4/samples/unprocessed_raw.cpp +319 -0
  400. package/deps/LibRaw-Win64/LibRaw-0.21.4/shlib-version.sh +11 -0
  401. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/Makefile +2 -0
  402. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/canon_600.cpp +225 -0
  403. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/crx.cpp +2781 -0
  404. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/decoders_dcraw.cpp +1816 -0
  405. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/decoders_libraw.cpp +873 -0
  406. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/decoders_libraw_dcrdefs.cpp +411 -0
  407. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/dng.cpp +284 -0
  408. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/fp_dng.cpp +689 -0
  409. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/fuji_compressed.cpp +1210 -0
  410. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/generic.cpp +101 -0
  411. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/kodak_decoders.cpp +524 -0
  412. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/load_mfbacks.cpp +936 -0
  413. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/smal.cpp +181 -0
  414. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/unpack.cpp +508 -0
  415. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/decoders/unpack_thumb.cpp +405 -0
  416. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/demosaic/aahd_demosaic.cpp +781 -0
  417. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/demosaic/ahd_demosaic.cpp +355 -0
  418. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/demosaic/dcb_demosaic.cpp +900 -0
  419. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/demosaic/dht_demosaic.cpp +1033 -0
  420. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/demosaic/misc_demosaic.cpp +420 -0
  421. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/demosaic/xtrans_demosaic.cpp +434 -0
  422. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/integration/dngsdk_glue.cpp +416 -0
  423. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/integration/rawspeed_glue.cpp +286 -0
  424. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/libraw_c_api.cpp +457 -0
  425. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/libraw_datastream.cpp +1046 -0
  426. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/adobepano.cpp +154 -0
  427. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/canon.cpp +1335 -0
  428. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/ciff.cpp +411 -0
  429. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/cr3_parser.cpp +896 -0
  430. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/epson.cpp +96 -0
  431. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/exif_gps.cpp +430 -0
  432. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/fuji.cpp +1427 -0
  433. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/hasselblad_model.cpp +538 -0
  434. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/identify.cpp +3167 -0
  435. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/identify_tools.cpp +140 -0
  436. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/kodak.cpp +363 -0
  437. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/leica.cpp +375 -0
  438. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/makernotes.cpp +786 -0
  439. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/mediumformat.cpp +521 -0
  440. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/minolta.cpp +110 -0
  441. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/misc_parsers.cpp +694 -0
  442. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/nikon.cpp +1051 -0
  443. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/normalize_model.cpp +1451 -0
  444. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/olympus.cpp +685 -0
  445. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/p1.cpp +192 -0
  446. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/pentax.cpp +675 -0
  447. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/samsung.cpp +182 -0
  448. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/sony.cpp +2320 -0
  449. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/metadata/tiff.cpp +2198 -0
  450. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/postprocessing/aspect_ratio.cpp +113 -0
  451. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/postprocessing/dcraw_process.cpp +259 -0
  452. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/postprocessing/mem_image.cpp +292 -0
  453. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/postprocessing/postprocessing_aux.cpp +413 -0
  454. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/postprocessing/postprocessing_ph.cpp +31 -0
  455. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/postprocessing/postprocessing_utils.cpp +190 -0
  456. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/postprocessing/postprocessing_utils_dcrdefs.cpp +308 -0
  457. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/preprocessing/ext_preprocess.cpp +127 -0
  458. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/preprocessing/preprocessing_ph.cpp +24 -0
  459. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/preprocessing/raw2image.cpp +560 -0
  460. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/preprocessing/subtract_black.cpp +91 -0
  461. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/tables/cameralist.cpp +1268 -0
  462. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/tables/colorconst.cpp +57 -0
  463. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/tables/colordata.cpp +1841 -0
  464. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/tables/wblists.cpp +217 -0
  465. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/curves.cpp +154 -0
  466. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/decoder_info.cpp +413 -0
  467. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/init_close_utils.cpp +340 -0
  468. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/open.cpp +1269 -0
  469. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/phaseone_processing.cpp +101 -0
  470. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/read_utils.cpp +176 -0
  471. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/thumb_utils.cpp +338 -0
  472. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/utils_dcraw.cpp +330 -0
  473. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/utils/utils_libraw.cpp +673 -0
  474. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/write/apply_profile.cpp +76 -0
  475. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/write/file_write.cpp +338 -0
  476. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/write/tiff_writer.cpp +73 -0
  477. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/write/write_ph.cpp +39 -0
  478. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/x3f/x3f_parse_process.cpp +708 -0
  479. package/deps/LibRaw-Win64/LibRaw-0.21.4/src/x3f/x3f_utils_patched.cpp +2119 -0
  480. package/deps/LibRaw-Win64/LibRaw-0.21.4/version.sh +16 -0
  481. package/lib/index.d.ts +324 -0
  482. package/lib/index.js +761 -0
  483. package/package.json +97 -0
  484. package/src/addon.cpp +8 -0
  485. package/src/libraw_wrapper.cpp +1223 -0
  486. package/src/libraw_wrapper.h +109 -0
  487. package/src/libraw_wrapper_new.cpp +853 -0
@@ -0,0 +1,2781 @@
1
+ /* -*- C++ -*-
2
+ * File: libraw_crxdec.cpp
3
+ * Copyright (C) 2018-2019 Alexey Danilchenko
4
+ * Copyright (C) 2019 Alex Tutubalin, LibRaw LLC
5
+ *
6
+ Canon CR3 file decoder
7
+
8
+ LibRaw is free software; you can redistribute it and/or modify
9
+ it under the terms of the one of two licenses as you choose:
10
+
11
+ 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
12
+ (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
13
+
14
+ 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
15
+ (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
16
+
17
+ */
18
+
19
+ #include "../../internal/libraw_cxx_defs.h"
20
+
21
+ #ifdef _abs
22
+ #undef _abs
23
+ #undef _min
24
+ #undef _constrain
25
+ #endif
26
+ #define _abs(x) (((x) ^ ((int32_t)(x) >> 31)) - ((int32_t)(x) >> 31))
27
+ #define _min(a, b) ((a) < (b) ? (a) : (b))
28
+ #define _constrain(x, l, u) ((x) < (l) ? (l) : ((x) > (u) ? (u) : (x)))
29
+
30
+ #if defined(__clang__) || defined(__GNUG__)
31
+ #define libraw_inline inline __attribute__((always_inline))
32
+ #elif defined(_MSC_VER) && _MSC_VER > 1400
33
+ #define libraw_inline __forceinline
34
+ #else
35
+ #define libraw_inline inline
36
+ #endif
37
+
38
+ // this should be divisible by 4
39
+ #define CRX_BUF_SIZE 0x10000
40
+ #if !defined(_WIN32) || (defined(__GNUC__) && !defined(__INTRINSIC_SPECIAL__BitScanReverse))
41
+ /* __INTRINSIC_SPECIAL__BitScanReverse found in MinGW32-W64 v7.30 headers, may be there is a better solution? */
42
+ typedef uint32_t DWORD;
43
+ libraw_inline void _BitScanReverse(DWORD *Index, unsigned long Mask)
44
+ {
45
+ *Index = sizeof(unsigned long) * 8 - 1 - __builtin_clzl(Mask);
46
+ }
47
+ #if LibRawBigEndian
48
+ #define _byteswap_ulong(x) (x)
49
+ #else
50
+ #define _byteswap_ulong(x) __builtin_bswap32(x)
51
+ #endif
52
+ #endif
53
+
54
+ struct CrxBitstream
55
+ {
56
+ uint8_t mdatBuf[CRX_BUF_SIZE];
57
+ uint64_t mdatSize;
58
+ uint64_t curBufOffset;
59
+ uint32_t curPos;
60
+ uint32_t curBufSize;
61
+ uint32_t bitData;
62
+ int32_t bitsLeft;
63
+ LibRaw_abstract_datastream *input;
64
+ };
65
+
66
+ struct CrxBandParam
67
+ {
68
+ CrxBitstream bitStream;
69
+ int16_t subbandWidth;
70
+ int16_t subbandHeight;
71
+ int32_t roundedBitsMask;
72
+ int32_t roundedBits;
73
+ int16_t curLine;
74
+ int32_t *lineBuf0;
75
+ int32_t *lineBuf1;
76
+ int32_t *lineBuf2;
77
+ int32_t sParam;
78
+ int32_t kParam;
79
+ int32_t *paramData;
80
+ int32_t *nonProgrData;
81
+ bool supportsPartial;
82
+ };
83
+
84
+ struct CrxWaveletTransform
85
+ {
86
+ int32_t *subband0Buf;
87
+ int32_t *subband1Buf;
88
+ int32_t *subband2Buf;
89
+ int32_t *subband3Buf;
90
+ int32_t *lineBuf[8];
91
+ int16_t curLine;
92
+ int16_t curH;
93
+ int8_t fltTapH;
94
+ int16_t height;
95
+ int16_t width;
96
+ };
97
+
98
+ struct CrxSubband
99
+ {
100
+ CrxBandParam *bandParam;
101
+ uint64_t mdatOffset;
102
+ uint8_t *bandBuf;
103
+ uint16_t width;
104
+ uint16_t height;
105
+ int32_t qParam;
106
+ int32_t kParam;
107
+ int32_t qStepBase;
108
+ uint32_t qStepMult;
109
+ bool supportsPartial;
110
+ int32_t bandSize;
111
+ uint64_t dataSize;
112
+ int64_t dataOffset;
113
+ short rowStartAddOn;
114
+ short rowEndAddOn;
115
+ short colStartAddOn;
116
+ short colEndAddOn;
117
+ short levelShift;
118
+ };
119
+
120
+ struct CrxPlaneComp
121
+ {
122
+ uint8_t *compBuf;
123
+ CrxSubband *subBands;
124
+ CrxWaveletTransform *wvltTransform;
125
+ int8_t compNumber;
126
+ int64_t dataOffset;
127
+ int32_t compSize;
128
+ bool supportsPartial;
129
+ int32_t roundedBitsMask;
130
+ int8_t tileFlag;
131
+ };
132
+
133
+ struct CrxQStep
134
+ {
135
+ uint32_t *qStepTbl;
136
+ int width;
137
+ int height;
138
+ };
139
+
140
+ struct CrxTile
141
+ {
142
+ CrxPlaneComp *comps;
143
+ int8_t tileFlag;
144
+ int8_t tileNumber;
145
+ int64_t dataOffset;
146
+ int32_t tileSize;
147
+ uint16_t width;
148
+ uint16_t height;
149
+ bool hasQPData;
150
+ CrxQStep *qStep;
151
+ uint32_t mdatQPDataSize;
152
+ uint16_t mdatExtraSize;
153
+ };
154
+
155
+ struct CrxImage
156
+ {
157
+ uint8_t nPlanes;
158
+ uint16_t planeWidth;
159
+ uint16_t planeHeight;
160
+ uint8_t samplePrecision;
161
+ uint8_t medianBits;
162
+ uint8_t subbandCount;
163
+ uint8_t levels;
164
+ uint8_t nBits;
165
+ uint8_t encType;
166
+ uint8_t tileCols;
167
+ uint8_t tileRows;
168
+ CrxTile *tiles;
169
+ uint64_t mdatOffset;
170
+ uint64_t mdatSize;
171
+ int16_t *outBufs[4]; // one per plane
172
+ int16_t *planeBuf;
173
+ LibRaw_abstract_datastream *input;
174
+ #ifdef LIBRAW_CR3_MEMPOOL
175
+ libraw_memmgr memmgr;
176
+ CrxImage() : memmgr(0) {}
177
+ #endif
178
+ };
179
+
180
+ enum TileFlags
181
+ {
182
+ E_HAS_TILES_ON_THE_RIGHT = 1,
183
+ E_HAS_TILES_ON_THE_LEFT = 2,
184
+ E_HAS_TILES_ON_THE_BOTTOM = 4,
185
+ E_HAS_TILES_ON_THE_TOP = 8
186
+ };
187
+
188
+ int32_t exCoefNumTbl[144] = {1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
189
+ 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0,
190
+ 0, 0, 1, 2, 2, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 2, 2,
191
+ 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 1, 1, 1,
192
+ 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 0, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1};
193
+
194
+ int32_t q_step_tbl[8] = {0x28, 0x2D, 0x33, 0x39, 0x40, 0x48};
195
+
196
+ uint32_t JS[32] = {1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4,
197
+ 4, 8, 8, 8, 8, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40,
198
+ 0x80, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000};
199
+
200
+ uint32_t J[32] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
201
+ 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
202
+
203
+ static inline void crxFillBuffer(CrxBitstream *bitStrm)
204
+ {
205
+ if (bitStrm->curPos >= bitStrm->curBufSize && bitStrm->mdatSize)
206
+ {
207
+ bitStrm->curPos = 0;
208
+ bitStrm->curBufOffset += bitStrm->curBufSize;
209
+ #ifdef LIBRAW_USE_OPENMP
210
+ #pragma omp critical
211
+ #endif
212
+ {
213
+ #ifndef LIBRAW_USE_OPENMP
214
+ bitStrm->input->lock();
215
+ #endif
216
+ bitStrm->input->seek(bitStrm->curBufOffset, SEEK_SET);
217
+ bitStrm->curBufSize = bitStrm->input->read(bitStrm->mdatBuf, 1, _min(bitStrm->mdatSize, CRX_BUF_SIZE));
218
+ #ifndef LIBRAW_USE_OPENMP
219
+ bitStrm->input->unlock();
220
+ #endif
221
+ }
222
+ if (bitStrm->curBufSize < 1) // nothing read
223
+ throw LIBRAW_EXCEPTION_IO_EOF;
224
+ bitStrm->mdatSize -= bitStrm->curBufSize;
225
+ }
226
+ }
227
+
228
+ libraw_inline int crxBitstreamGetZeros(CrxBitstream *bitStrm)
229
+ {
230
+ uint32_t nonZeroBit = 0;
231
+ uint64_t nextData = 0;
232
+ int32_t result = 0;
233
+
234
+ if (bitStrm->bitData)
235
+ {
236
+ _BitScanReverse((DWORD *)&nonZeroBit, (DWORD)bitStrm->bitData);
237
+ result = 31 - nonZeroBit;
238
+ bitStrm->bitData <<= 32 - nonZeroBit;
239
+ bitStrm->bitsLeft -= 32 - nonZeroBit;
240
+ }
241
+ else
242
+ {
243
+ uint32_t bitsLeft = bitStrm->bitsLeft;
244
+ while (1)
245
+ {
246
+ while (bitStrm->curPos + 4 <= bitStrm->curBufSize)
247
+ {
248
+ nextData = _byteswap_ulong(*(uint32_t *)(bitStrm->mdatBuf + bitStrm->curPos));
249
+ bitStrm->curPos += 4;
250
+ crxFillBuffer(bitStrm);
251
+ if (nextData)
252
+ {
253
+ _BitScanReverse((DWORD *)&nonZeroBit, (DWORD)nextData);
254
+ result = bitsLeft + 31 - nonZeroBit;
255
+ bitStrm->bitData = nextData << (32 - nonZeroBit);
256
+ bitStrm->bitsLeft = nonZeroBit;
257
+ return result;
258
+ }
259
+ bitsLeft += 32;
260
+ }
261
+ if (bitStrm->curBufSize < bitStrm->curPos + 1)
262
+ break; // error
263
+ nextData = bitStrm->mdatBuf[bitStrm->curPos++];
264
+ crxFillBuffer(bitStrm);
265
+ if (nextData)
266
+ break;
267
+ bitsLeft += 8;
268
+ }
269
+ _BitScanReverse((DWORD *)&nonZeroBit, (DWORD)nextData);
270
+ result = (uint32_t)(bitsLeft + 7 - nonZeroBit);
271
+ bitStrm->bitData = nextData << (32 - nonZeroBit);
272
+ bitStrm->bitsLeft = nonZeroBit;
273
+ }
274
+ return result;
275
+ }
276
+
277
+ libraw_inline uint32_t crxBitstreamGetBits(CrxBitstream *bitStrm, int bits)
278
+ {
279
+ int bitsLeft = bitStrm->bitsLeft;
280
+ uint32_t bitData = bitStrm->bitData;
281
+ uint32_t nextWord;
282
+ uint8_t nextByte;
283
+ uint32_t result;
284
+
285
+ if (bitsLeft < bits)
286
+ {
287
+ // get them from stream
288
+ if (bitStrm->curPos + 4 <= bitStrm->curBufSize)
289
+ {
290
+ nextWord = _byteswap_ulong(*(uint32_t *)(bitStrm->mdatBuf + bitStrm->curPos));
291
+ bitStrm->curPos += 4;
292
+ crxFillBuffer(bitStrm);
293
+ bitStrm->bitsLeft = 32 - (bits - bitsLeft);
294
+ result = ((nextWord >> bitsLeft) | bitData) >> (32 - bits);
295
+ bitStrm->bitData = nextWord << (bits - bitsLeft);
296
+ return result;
297
+ }
298
+ // less than a word left - read byte at a time
299
+ do
300
+ {
301
+ if (bitStrm->curPos >= bitStrm->curBufSize)
302
+ break; // error
303
+ bitsLeft += 8;
304
+ nextByte = bitStrm->mdatBuf[bitStrm->curPos++];
305
+ crxFillBuffer(bitStrm);
306
+ bitData |= nextByte << (32 - bitsLeft);
307
+ } while (bitsLeft < bits);
308
+ }
309
+ result = bitData >> (32 - bits); // 32-bits
310
+ bitStrm->bitData = bitData << bits;
311
+ bitStrm->bitsLeft = bitsLeft - bits;
312
+ return result;
313
+ }
314
+
315
+ libraw_inline int32_t crxPrediction(int32_t left, int32_t top, int32_t deltaH, int32_t deltaV)
316
+ {
317
+ int32_t symb[4] = {left + deltaH, left + deltaH, left, top};
318
+
319
+ return symb[(((deltaV < 0) ^ (deltaH < 0)) << 1) + ((left < top) ^ (deltaH < 0))];
320
+ }
321
+
322
+ libraw_inline int32_t crxPredictKParameter(int32_t prevK, int32_t bitCode, int32_t maxVal = 0)
323
+ {
324
+ int32_t newKParam = prevK - (bitCode < (1 << prevK >> 1)) + ((bitCode >> prevK) > 2) + ((bitCode >> prevK) > 5);
325
+
326
+ return !maxVal || newKParam < maxVal ? newKParam : maxVal;
327
+ }
328
+
329
+ libraw_inline void crxDecodeSymbolL1(CrxBandParam *param, int32_t doMedianPrediction, int32_t notEOL = 0)
330
+ {
331
+ if (doMedianPrediction)
332
+ {
333
+ int32_t symb[4];
334
+
335
+ int32_t delta = param->lineBuf0[1] - param->lineBuf0[0];
336
+ symb[2] = param->lineBuf1[0];
337
+ symb[0] = symb[1] = delta + symb[2];
338
+ symb[3] = param->lineBuf0[1];
339
+
340
+ param->lineBuf1[1] = symb[(((param->lineBuf0[0] < param->lineBuf1[0]) ^ (delta < 0)) << 1) +
341
+ ((param->lineBuf1[0] < param->lineBuf0[1]) ^ (delta < 0))];
342
+ }
343
+ else
344
+ param->lineBuf1[1] = param->lineBuf0[1];
345
+
346
+ // get next error symbol
347
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
348
+ if (bitCode >= 41)
349
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
350
+ else if (param->kParam)
351
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
352
+
353
+ // add converted (+/-) error code to predicted value
354
+ param->lineBuf1[1] += -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
355
+
356
+ // for not end of the line - use one symbol ahead to estimate next K
357
+ if (notEOL)
358
+ {
359
+ int32_t nextDelta = (param->lineBuf0[2] - param->lineBuf0[1]) << 1;
360
+ bitCode = (bitCode + _abs(nextDelta)) >> 1;
361
+ ++param->lineBuf0;
362
+ }
363
+
364
+ // update K parameter
365
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
366
+
367
+ ++param->lineBuf1;
368
+ }
369
+
370
+ int crxDecodeLine(CrxBandParam *param)
371
+ {
372
+ int length = param->subbandWidth;
373
+
374
+ param->lineBuf1[0] = param->lineBuf0[1];
375
+ for (; length > 1; --length)
376
+ {
377
+ if (param->lineBuf1[0] != param->lineBuf0[1] || param->lineBuf1[0] != param->lineBuf0[2])
378
+ {
379
+ crxDecodeSymbolL1(param, 1, 1);
380
+ }
381
+ else
382
+ {
383
+ int nSyms = 0;
384
+ if (crxBitstreamGetBits(&param->bitStream, 1))
385
+ {
386
+ nSyms = 1;
387
+ while (crxBitstreamGetBits(&param->bitStream, 1))
388
+ {
389
+ nSyms += JS[param->sParam];
390
+ if (nSyms > length)
391
+ {
392
+ nSyms = length;
393
+ break;
394
+ }
395
+ if (param->sParam < 31)
396
+ ++param->sParam;
397
+ if (nSyms == length)
398
+ break;
399
+ }
400
+
401
+ if (nSyms < length)
402
+ {
403
+ if (J[param->sParam])
404
+ nSyms += crxBitstreamGetBits(&param->bitStream, J[param->sParam]);
405
+ if (param->sParam > 0)
406
+ --param->sParam;
407
+ if (nSyms > length)
408
+ return -1;
409
+ }
410
+
411
+ length -= nSyms;
412
+
413
+ // copy symbol nSyms times
414
+ param->lineBuf0 += nSyms;
415
+
416
+ // copy symbol nSyms times
417
+ while (nSyms-- > 0)
418
+ {
419
+ param->lineBuf1[1] = param->lineBuf1[0];
420
+ ++param->lineBuf1;
421
+ }
422
+ }
423
+
424
+ if (length > 0)
425
+ crxDecodeSymbolL1(param, 0, (length > 1));
426
+ }
427
+ }
428
+
429
+ if (length == 1)
430
+ crxDecodeSymbolL1(param, 1, 0);
431
+
432
+ param->lineBuf1[1] = param->lineBuf1[0] + 1;
433
+
434
+ return 0;
435
+ }
436
+
437
+ libraw_inline void crxDecodeSymbolL1Rounded(CrxBandParam *param, int32_t doSym = 1, int32_t doCode = 1)
438
+ {
439
+ int32_t sym = param->lineBuf0[1];
440
+
441
+ if (doSym)
442
+ {
443
+ // calculate the next symbol gradient
444
+ int32_t symb[4];
445
+ int32_t deltaH = param->lineBuf0[1] - param->lineBuf0[0];
446
+ symb[2] = param->lineBuf1[0];
447
+ symb[0] = symb[1] = deltaH + symb[2];
448
+ symb[3] = param->lineBuf0[1];
449
+ sym = symb[(((param->lineBuf0[0] < param->lineBuf1[0]) ^ (deltaH < 0)) << 1) +
450
+ ((param->lineBuf1[0] < param->lineBuf0[1]) ^ (deltaH < 0))];
451
+ }
452
+
453
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
454
+ if (bitCode >= 41)
455
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
456
+ else if (param->kParam)
457
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
458
+ int32_t code = -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
459
+ param->lineBuf1[1] = param->roundedBitsMask * 2 * code + (code >> 31) + sym;
460
+
461
+ if (doCode)
462
+ {
463
+ if (param->lineBuf0[2] > param->lineBuf0[1])
464
+ code = (param->lineBuf0[2] - param->lineBuf0[1] + param->roundedBitsMask - 1) >> param->roundedBits;
465
+ else
466
+ code = -((param->lineBuf0[1] - param->lineBuf0[2] + param->roundedBitsMask) >> param->roundedBits);
467
+
468
+ param->kParam = crxPredictKParameter(param->kParam, (bitCode + 2 * _abs(code)) >> 1, 15);
469
+ }
470
+ else
471
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
472
+
473
+ ++param->lineBuf1;
474
+ }
475
+
476
+ int crxDecodeLineRounded(CrxBandParam *param)
477
+ {
478
+ int32_t valueReached = 0;
479
+
480
+ param->lineBuf0[0] = param->lineBuf0[1];
481
+ param->lineBuf1[0] = param->lineBuf0[1];
482
+ int32_t length = param->subbandWidth;
483
+
484
+ for (; length > 1; --length)
485
+ {
486
+ if (_abs(param->lineBuf0[2] - param->lineBuf0[1]) > param->roundedBitsMask)
487
+ {
488
+ crxDecodeSymbolL1Rounded(param);
489
+ ++param->lineBuf0;
490
+ valueReached = 1;
491
+ }
492
+ else if (valueReached || _abs(param->lineBuf0[0] - param->lineBuf1[0]) > param->roundedBitsMask)
493
+ {
494
+ crxDecodeSymbolL1Rounded(param);
495
+ ++param->lineBuf0;
496
+ valueReached = 0;
497
+ }
498
+ else
499
+ {
500
+ int nSyms = 0;
501
+ if (crxBitstreamGetBits(&param->bitStream, 1))
502
+ {
503
+ nSyms = 1;
504
+ while (crxBitstreamGetBits(&param->bitStream, 1))
505
+ {
506
+ nSyms += JS[param->sParam];
507
+ if (nSyms > length)
508
+ {
509
+ nSyms = length;
510
+ break;
511
+ }
512
+ if (param->sParam < 31)
513
+ ++param->sParam;
514
+ if (nSyms == length)
515
+ break;
516
+ }
517
+ if (nSyms < length)
518
+ {
519
+ if (J[param->sParam])
520
+ nSyms += crxBitstreamGetBits(&param->bitStream, J[param->sParam]);
521
+ if (param->sParam > 0)
522
+ --param->sParam;
523
+ }
524
+ if (nSyms > length)
525
+ return -1;
526
+ }
527
+ length -= nSyms;
528
+
529
+ // copy symbol nSyms times
530
+ param->lineBuf0 += nSyms;
531
+
532
+ // copy symbol nSyms times
533
+ while (nSyms-- > 0)
534
+ {
535
+ param->lineBuf1[1] = param->lineBuf1[0];
536
+ ++param->lineBuf1;
537
+ }
538
+
539
+ if (length > 1)
540
+ {
541
+ crxDecodeSymbolL1Rounded(param, 0);
542
+ ++param->lineBuf0;
543
+ valueReached = _abs(param->lineBuf0[1] - param->lineBuf0[0]) > param->roundedBitsMask;
544
+ }
545
+ else if (length == 1)
546
+ crxDecodeSymbolL1Rounded(param, 0, 0);
547
+ }
548
+ }
549
+ if (length == 1)
550
+ crxDecodeSymbolL1Rounded(param, 1, 0);
551
+
552
+ param->lineBuf1[1] = param->lineBuf1[0] + 1;
553
+
554
+ return 0;
555
+ }
556
+
557
+ int crxDecodeLineNoRefPrevLine(CrxBandParam *param)
558
+ {
559
+ int32_t i = 0;
560
+
561
+ for (; i < param->subbandWidth - 1; i++)
562
+ {
563
+ if (param->lineBuf0[i + 2] | param->lineBuf0[i + 1] | param->lineBuf1[i])
564
+ {
565
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
566
+ if (bitCode >= 41)
567
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
568
+ else if (param->kParam)
569
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
570
+ param->lineBuf1[i + 1] = -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
571
+ param->kParam = crxPredictKParameter(param->kParam, bitCode);
572
+ if (param->lineBuf2[i + 1] - param->kParam <= 1)
573
+ {
574
+ if (param->kParam >= 15)
575
+ param->kParam = 15;
576
+ }
577
+ else
578
+ ++param->kParam;
579
+ }
580
+ else
581
+ {
582
+ int nSyms = 0;
583
+ if (crxBitstreamGetBits(&param->bitStream, 1))
584
+ {
585
+ nSyms = 1;
586
+ if (i != param->subbandWidth - 1)
587
+ {
588
+ while (crxBitstreamGetBits(&param->bitStream, 1))
589
+ {
590
+ nSyms += JS[param->sParam];
591
+ if (i + nSyms > param->subbandWidth)
592
+ {
593
+ nSyms = param->subbandWidth - i;
594
+ break;
595
+ }
596
+ if (param->sParam < 31)
597
+ ++param->sParam;
598
+ if (i + nSyms == param->subbandWidth)
599
+ break;
600
+ }
601
+ if (i + nSyms < param->subbandWidth)
602
+ {
603
+ if (J[param->sParam])
604
+ nSyms += crxBitstreamGetBits(&param->bitStream, J[param->sParam]);
605
+ if (param->sParam > 0)
606
+ --param->sParam;
607
+ }
608
+ if (i + nSyms > param->subbandWidth)
609
+ return -1;
610
+ }
611
+ }
612
+ else if (i > param->subbandWidth)
613
+ return -1;
614
+
615
+ if (nSyms > 0)
616
+ {
617
+ memset(param->lineBuf1 + i + 1, 0, nSyms * sizeof(int32_t));
618
+ memset(param->lineBuf2 + i, 0, nSyms * sizeof(int32_t));
619
+ i += nSyms;
620
+ }
621
+
622
+ if (i >= param->subbandWidth - 1)
623
+ {
624
+ if (i == param->subbandWidth - 1)
625
+ {
626
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
627
+ if (bitCode >= 41)
628
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
629
+ else if (param->kParam)
630
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
631
+ param->lineBuf1[i + 1] = -(int32_t)((bitCode + 1) & 1) ^ (int32_t)((bitCode + 1) >> 1);
632
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
633
+ param->lineBuf2[i] = param->kParam;
634
+ }
635
+ continue;
636
+ }
637
+ else
638
+ {
639
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
640
+ if (bitCode >= 41)
641
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
642
+ else if (param->kParam)
643
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
644
+ param->lineBuf1[i + 1] = -(int32_t)((bitCode + 1) & 1) ^ (int32_t)((bitCode + 1) >> 1);
645
+ param->kParam = crxPredictKParameter(param->kParam, bitCode);
646
+ if (param->lineBuf2[i + 1] - param->kParam <= 1)
647
+ {
648
+ if (param->kParam >= 15)
649
+ param->kParam = 15;
650
+ }
651
+ else
652
+ ++param->kParam;
653
+ }
654
+ }
655
+ param->lineBuf2[i] = param->kParam;
656
+ }
657
+ if (i == param->subbandWidth - 1)
658
+ {
659
+ int32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
660
+ if (bitCode >= 41)
661
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
662
+ else if (param->kParam)
663
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
664
+ param->lineBuf1[i + 1] = -(bitCode & 1) ^ (bitCode >> 1);
665
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
666
+ param->lineBuf2[i] = param->kParam;
667
+ }
668
+
669
+ return 0;
670
+ }
671
+
672
+ int crxDecodeTopLine(CrxBandParam *param)
673
+ {
674
+ param->lineBuf1[0] = 0;
675
+
676
+ int32_t length = param->subbandWidth;
677
+
678
+ // read the line from bitstream
679
+ for (; length > 1; --length)
680
+ {
681
+ if (param->lineBuf1[0])
682
+ param->lineBuf1[1] = param->lineBuf1[0];
683
+ else
684
+ {
685
+ int nSyms = 0;
686
+ if (crxBitstreamGetBits(&param->bitStream, 1))
687
+ {
688
+ nSyms = 1;
689
+ while (crxBitstreamGetBits(&param->bitStream, 1))
690
+ {
691
+ nSyms += JS[param->sParam];
692
+ if (nSyms > length)
693
+ {
694
+ nSyms = length;
695
+ break;
696
+ }
697
+ if (param->sParam < 31)
698
+ ++param->sParam;
699
+ if (nSyms == length)
700
+ break;
701
+ }
702
+ if (nSyms < length)
703
+ {
704
+ if (J[param->sParam])
705
+ nSyms += crxBitstreamGetBits(&param->bitStream, J[param->sParam]);
706
+ if (param->sParam > 0)
707
+ --param->sParam;
708
+ if (nSyms > length)
709
+ return -1;
710
+ }
711
+
712
+ length -= nSyms;
713
+
714
+ // copy symbol nSyms times
715
+ while (nSyms-- > 0)
716
+ {
717
+ param->lineBuf1[1] = param->lineBuf1[0];
718
+ ++param->lineBuf1;
719
+ }
720
+
721
+ if (length <= 0)
722
+ break;
723
+ }
724
+
725
+ param->lineBuf1[1] = 0;
726
+ }
727
+
728
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
729
+ if (bitCode >= 41)
730
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
731
+ else if (param->kParam)
732
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
733
+ param->lineBuf1[1] += -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
734
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
735
+ ++param->lineBuf1;
736
+ }
737
+
738
+ if (length == 1)
739
+ {
740
+ param->lineBuf1[1] = param->lineBuf1[0];
741
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
742
+ if (bitCode >= 41)
743
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
744
+ else if (param->kParam)
745
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
746
+ param->lineBuf1[1] += -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
747
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
748
+ ++param->lineBuf1;
749
+ }
750
+
751
+ param->lineBuf1[1] = param->lineBuf1[0] + 1;
752
+
753
+ return 0;
754
+ }
755
+
756
+ int crxDecodeTopLineRounded(CrxBandParam *param)
757
+ {
758
+ param->lineBuf1[0] = 0;
759
+
760
+ int32_t length = param->subbandWidth;
761
+
762
+ // read the line from bitstream
763
+ for (; length > 1; --length)
764
+ {
765
+ if (_abs(param->lineBuf1[0]) > param->roundedBitsMask)
766
+ param->lineBuf1[1] = param->lineBuf1[0];
767
+ else
768
+ {
769
+ int nSyms = 0;
770
+ if (crxBitstreamGetBits(&param->bitStream, 1))
771
+ {
772
+ nSyms = 1;
773
+ while (crxBitstreamGetBits(&param->bitStream, 1))
774
+ {
775
+ nSyms += JS[param->sParam];
776
+ if (nSyms > length)
777
+ {
778
+ nSyms = length;
779
+ break;
780
+ }
781
+ if (param->sParam < 31)
782
+ ++param->sParam;
783
+ if (nSyms == length)
784
+ break;
785
+ }
786
+ if (nSyms < length)
787
+ {
788
+ if (J[param->sParam])
789
+ nSyms += crxBitstreamGetBits(&param->bitStream, J[param->sParam]);
790
+ if (param->sParam > 0)
791
+ --param->sParam;
792
+ if (nSyms > length)
793
+ return -1;
794
+ }
795
+ }
796
+
797
+ length -= nSyms;
798
+
799
+ // copy symbol nSyms times
800
+ while (nSyms-- > 0)
801
+ {
802
+ param->lineBuf1[1] = param->lineBuf1[0];
803
+ ++param->lineBuf1;
804
+ }
805
+
806
+ if (length <= 0)
807
+ break;
808
+
809
+ param->lineBuf1[1] = 0;
810
+ }
811
+
812
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
813
+ if (bitCode >= 41)
814
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
815
+ else if (param->kParam)
816
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
817
+
818
+ int32_t sVal = -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
819
+ param->lineBuf1[1] += param->roundedBitsMask * 2 * sVal + (sVal >> 31);
820
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
821
+ ++param->lineBuf1;
822
+ }
823
+
824
+ if (length == 1)
825
+ {
826
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
827
+ if (bitCode >= 41)
828
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
829
+ else if (param->kParam)
830
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
831
+ int32_t sVal = -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
832
+ param->lineBuf1[1] += param->roundedBitsMask * 2 * sVal + (sVal >> 31);
833
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
834
+ ++param->lineBuf1;
835
+ }
836
+
837
+ param->lineBuf1[1] = param->lineBuf1[0] + 1;
838
+
839
+ return 0;
840
+ }
841
+
842
+ int crxDecodeTopLineNoRefPrevLine(CrxBandParam *param)
843
+ {
844
+ param->lineBuf0[0] = 0;
845
+ param->lineBuf1[0] = 0;
846
+ int32_t length = param->subbandWidth;
847
+ for (; length > 1; --length)
848
+ {
849
+ if (param->lineBuf1[0])
850
+ {
851
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
852
+ if (bitCode >= 41)
853
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
854
+ else if (param->kParam)
855
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
856
+ param->lineBuf1[1] = -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
857
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
858
+ }
859
+ else
860
+ {
861
+ int nSyms = 0;
862
+ if (crxBitstreamGetBits(&param->bitStream, 1))
863
+ {
864
+ nSyms = 1;
865
+ while (crxBitstreamGetBits(&param->bitStream, 1))
866
+ {
867
+ nSyms += JS[param->sParam];
868
+ if (nSyms > length)
869
+ {
870
+ nSyms = length;
871
+ break;
872
+ }
873
+ if (param->sParam < 31)
874
+ ++param->sParam;
875
+ if (nSyms == length)
876
+ break;
877
+ }
878
+ if (nSyms < length)
879
+ {
880
+ if (J[param->sParam])
881
+ nSyms += crxBitstreamGetBits(&param->bitStream, J[param->sParam]);
882
+ if (param->sParam > 0)
883
+ --param->sParam;
884
+ if (nSyms > length)
885
+ return -1;
886
+ }
887
+ }
888
+
889
+ length -= nSyms;
890
+
891
+ // copy symbol nSyms times
892
+ while (nSyms-- > 0)
893
+ {
894
+ param->lineBuf2[0] = 0;
895
+ param->lineBuf1[1] = 0;
896
+ ++param->lineBuf1;
897
+ ++param->lineBuf2;
898
+ }
899
+
900
+ if (length <= 0)
901
+ break;
902
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
903
+ if (bitCode >= 41)
904
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
905
+ else if (param->kParam)
906
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
907
+ param->lineBuf1[1] = -(int32_t)((bitCode + 1) & 1) ^ (int32_t)((bitCode + 1) >> 1);
908
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
909
+ }
910
+ param->lineBuf2[0] = param->kParam;
911
+ ++param->lineBuf2;
912
+ ++param->lineBuf1;
913
+ }
914
+
915
+ if (length == 1)
916
+ {
917
+ uint32_t bitCode = crxBitstreamGetZeros(&param->bitStream);
918
+ if (bitCode >= 41)
919
+ bitCode = crxBitstreamGetBits(&param->bitStream, 21);
920
+ else if (param->kParam)
921
+ bitCode = crxBitstreamGetBits(&param->bitStream, param->kParam) | (bitCode << param->kParam);
922
+ param->lineBuf1[1] = -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1);
923
+ param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
924
+ param->lineBuf2[0] = param->kParam;
925
+ ++param->lineBuf1;
926
+ }
927
+
928
+ param->lineBuf1[1] = 0;
929
+
930
+ return 0;
931
+ }
932
+
933
+ int crxDecodeLine(CrxBandParam *param, uint8_t *bandBuf)
934
+ {
935
+ if (!param || !bandBuf)
936
+ return -1;
937
+ if (param->curLine >= param->subbandHeight)
938
+ return -1;
939
+
940
+ if (param->curLine == 0)
941
+ {
942
+ int32_t lineLength = param->subbandWidth + 2;
943
+
944
+ param->sParam = 0;
945
+ param->kParam = 0;
946
+ if (param->supportsPartial)
947
+ {
948
+ if (param->roundedBitsMask <= 0)
949
+ {
950
+ param->lineBuf0 = (int32_t *)param->paramData;
951
+ param->lineBuf1 = param->lineBuf0 + lineLength;
952
+ int32_t *lineBuf = param->lineBuf1 + 1;
953
+ if (crxDecodeTopLine(param))
954
+ return -1;
955
+ memcpy(bandBuf, lineBuf, param->subbandWidth * sizeof(int32_t));
956
+ ++param->curLine;
957
+ }
958
+ else
959
+ {
960
+ param->roundedBits = 1;
961
+ if (param->roundedBitsMask & ~1)
962
+ {
963
+ while (param->roundedBitsMask >> param->roundedBits)
964
+ ++param->roundedBits;
965
+ }
966
+ param->lineBuf0 = (int32_t *)param->paramData;
967
+ param->lineBuf1 = param->lineBuf0 + lineLength;
968
+ int32_t *lineBuf = param->lineBuf1 + 1;
969
+ if (crxDecodeTopLineRounded(param))
970
+ return -1;
971
+ memcpy(bandBuf, lineBuf, param->subbandWidth * sizeof(int32_t));
972
+ ++param->curLine;
973
+ }
974
+ }
975
+ else
976
+ {
977
+ param->lineBuf2 = (int32_t *)param->nonProgrData;
978
+ param->lineBuf0 = (int32_t *)param->paramData;
979
+ param->lineBuf1 = param->lineBuf0 + lineLength;
980
+ int32_t *lineBuf = param->lineBuf1 + 1;
981
+ if (crxDecodeTopLineNoRefPrevLine(param))
982
+ return -1;
983
+ memcpy(bandBuf, lineBuf, param->subbandWidth * sizeof(int32_t));
984
+ ++param->curLine;
985
+ }
986
+ }
987
+ else if (!param->supportsPartial)
988
+ {
989
+ int32_t lineLength = param->subbandWidth + 2;
990
+ param->lineBuf2 = (int32_t *)param->nonProgrData;
991
+ if (param->curLine & 1)
992
+ {
993
+ param->lineBuf1 = (int32_t *)param->paramData;
994
+ param->lineBuf0 = param->lineBuf1 + lineLength;
995
+ }
996
+ else
997
+ {
998
+ param->lineBuf0 = (int32_t *)param->paramData;
999
+ param->lineBuf1 = param->lineBuf0 + lineLength;
1000
+ }
1001
+ int32_t *lineBuf = param->lineBuf1 + 1;
1002
+ if (crxDecodeLineNoRefPrevLine(param))
1003
+ return -1;
1004
+ memcpy(bandBuf, lineBuf, param->subbandWidth * sizeof(int32_t));
1005
+ ++param->curLine;
1006
+ }
1007
+ else if (param->roundedBitsMask <= 0)
1008
+ {
1009
+ int32_t lineLength = param->subbandWidth + 2;
1010
+ if (param->curLine & 1)
1011
+ {
1012
+ param->lineBuf1 = (int32_t *)param->paramData;
1013
+ param->lineBuf0 = param->lineBuf1 + lineLength;
1014
+ }
1015
+ else
1016
+ {
1017
+ param->lineBuf0 = (int32_t *)param->paramData;
1018
+ param->lineBuf1 = param->lineBuf0 + lineLength;
1019
+ }
1020
+ int32_t *lineBuf = param->lineBuf1 + 1;
1021
+ if (crxDecodeLine(param))
1022
+ return -1;
1023
+ memcpy(bandBuf, lineBuf, param->subbandWidth * sizeof(int32_t));
1024
+ ++param->curLine;
1025
+ }
1026
+ else
1027
+ {
1028
+ int32_t lineLength = param->subbandWidth + 2;
1029
+ if (param->curLine & 1)
1030
+ {
1031
+ param->lineBuf1 = (int32_t *)param->paramData;
1032
+ param->lineBuf0 = param->lineBuf1 + lineLength;
1033
+ }
1034
+ else
1035
+ {
1036
+ param->lineBuf0 = (int32_t *)param->paramData;
1037
+ param->lineBuf1 = param->lineBuf0 + lineLength;
1038
+ }
1039
+ int32_t *lineBuf = param->lineBuf1 + 1;
1040
+ if (crxDecodeLineRounded(param))
1041
+ return -1;
1042
+ memcpy(bandBuf, lineBuf, param->subbandWidth * sizeof(int32_t));
1043
+ ++param->curLine;
1044
+ }
1045
+ return 0;
1046
+ }
1047
+
1048
+ int crxUpdateQparam(CrxSubband *subband)
1049
+ {
1050
+ uint32_t bitCode = crxBitstreamGetZeros(&subband->bandParam->bitStream);
1051
+ if (bitCode >= 23)
1052
+ bitCode = crxBitstreamGetBits(&subband->bandParam->bitStream, 8);
1053
+ else if (subband->kParam)
1054
+ bitCode = crxBitstreamGetBits(&subband->bandParam->bitStream, subband->kParam) | (bitCode << subband->kParam);
1055
+
1056
+ subband->qParam += -(int32_t)(bitCode & 1) ^ (int32_t)(bitCode >> 1); // converting encoded to signed integer
1057
+ subband->kParam = crxPredictKParameter(subband->kParam, bitCode);
1058
+ if (subband->kParam > 7)
1059
+ return -1;
1060
+ return 0;
1061
+ }
1062
+
1063
+ libraw_inline int getSubbandRow(CrxSubband *band, int row)
1064
+ {
1065
+ return row < band->rowStartAddOn
1066
+ ? 0
1067
+ : (row < band->height - band->rowEndAddOn ? row - band->rowEndAddOn
1068
+ : band->height - band->rowEndAddOn - band->rowStartAddOn - 1);
1069
+ }
1070
+ int crxDecodeLineWithIQuantization(CrxSubband *band, CrxQStep *qStep)
1071
+ {
1072
+ if (!band->dataSize)
1073
+ {
1074
+ memset(band->bandBuf, 0, band->bandSize);
1075
+ return 0;
1076
+ }
1077
+
1078
+ if (band->supportsPartial && !qStep && crxUpdateQparam(band))
1079
+ return -1;
1080
+ if (crxDecodeLine(band->bandParam, band->bandBuf))
1081
+ return -1;
1082
+
1083
+ if (band->width <= 0)
1084
+ return 0;
1085
+
1086
+ // update band buffers
1087
+ int32_t *bandBuf = (int32_t *)band->bandBuf;
1088
+ if (qStep)
1089
+ {
1090
+ // new version
1091
+ uint32_t *qStepTblPtr = &qStep->qStepTbl[qStep->width * getSubbandRow(band, band->bandParam->curLine - 1)];
1092
+
1093
+ for (int i = 0; i < band->colStartAddOn; ++i)
1094
+ {
1095
+ int32_t quantVal = band->qStepBase + ((qStepTblPtr[0] * band->qStepMult) >> 3);
1096
+ bandBuf[i] *= _constrain(quantVal, 1, 0x168000);
1097
+ }
1098
+
1099
+ for (int i = band->colStartAddOn; i < band->width - band->colEndAddOn; ++i)
1100
+ {
1101
+ int32_t quantVal =
1102
+ band->qStepBase + ((qStepTblPtr[(i - band->colStartAddOn) >> band->levelShift] * band->qStepMult) >> 3);
1103
+ bandBuf[i] *= _constrain(quantVal, 1, 0x168000);
1104
+ }
1105
+ int lastIdx = (band->width - band->colEndAddOn - band->colStartAddOn - 1) >> band->levelShift;
1106
+ for (int i = band->width - band->colEndAddOn; i < band->width; ++i)
1107
+ {
1108
+ int32_t quantVal = band->qStepBase + ((qStepTblPtr[lastIdx] * band->qStepMult) >> 3);
1109
+ bandBuf[i] *= _constrain(quantVal, 1, 0x168000);
1110
+ }
1111
+ }
1112
+ else
1113
+ {
1114
+ // prev. version
1115
+ int32_t qScale = q_step_tbl[band->qParam % 6] >> (6 - band->qParam / 6);
1116
+ if (band->qParam / 6 >= 6)
1117
+ qScale = q_step_tbl[band->qParam % 6] * (1 << (band->qParam / 6 + 26));
1118
+
1119
+ if (qScale != 1)
1120
+ for (int32_t i = 0; i < band->width; ++i)
1121
+ bandBuf[i] *= qScale;
1122
+ }
1123
+
1124
+ return 0;
1125
+ }
1126
+
1127
+ void crxHorizontal53(int32_t *lineBufLA, int32_t *lineBufLB, CrxWaveletTransform *wavelet, uint32_t tileFlag)
1128
+ {
1129
+ int32_t *band0Buf = wavelet->subband0Buf;
1130
+ int32_t *band1Buf = wavelet->subband1Buf;
1131
+ int32_t *band2Buf = wavelet->subband2Buf;
1132
+ int32_t *band3Buf = wavelet->subband3Buf;
1133
+
1134
+ if (wavelet->width <= 1)
1135
+ {
1136
+ lineBufLA[0] = band0Buf[0];
1137
+ lineBufLB[0] = band2Buf[0];
1138
+ }
1139
+ else
1140
+ {
1141
+ if (tileFlag & E_HAS_TILES_ON_THE_LEFT)
1142
+ {
1143
+ lineBufLA[0] = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1144
+ lineBufLB[0] = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1145
+ ++band1Buf;
1146
+ ++band3Buf;
1147
+ }
1148
+ else
1149
+ {
1150
+ lineBufLA[0] = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1151
+ lineBufLB[0] = band2Buf[0] - ((band3Buf[0] + 1) >> 1);
1152
+ }
1153
+ ++band0Buf;
1154
+ ++band2Buf;
1155
+
1156
+ for (int i = 0; i < wavelet->width - 3; i += 2)
1157
+ {
1158
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1159
+ lineBufLA[1] = band1Buf[0] + ((delta + lineBufLA[0]) >> 1);
1160
+ lineBufLA[2] = delta;
1161
+
1162
+ delta = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1163
+ lineBufLB[1] = band3Buf[0] + ((delta + lineBufLB[0]) >> 1);
1164
+ lineBufLB[2] = delta;
1165
+
1166
+ ++band0Buf;
1167
+ ++band1Buf;
1168
+ ++band2Buf;
1169
+ ++band3Buf;
1170
+ lineBufLA += 2;
1171
+ lineBufLB += 2;
1172
+ }
1173
+ if (tileFlag & E_HAS_TILES_ON_THE_RIGHT)
1174
+ {
1175
+ int32_t deltaA = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1176
+ lineBufLA[1] = band1Buf[0] + ((deltaA + lineBufLA[0]) >> 1);
1177
+
1178
+ int32_t deltaB = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1179
+ lineBufLB[1] = band3Buf[0] + ((deltaB + lineBufLB[0]) >> 1);
1180
+
1181
+ if (wavelet->width & 1)
1182
+ {
1183
+ lineBufLA[2] = deltaA;
1184
+ lineBufLB[2] = deltaB;
1185
+ }
1186
+ }
1187
+ else if (wavelet->width & 1)
1188
+ {
1189
+ lineBufLA[1] = band1Buf[0] + ((lineBufLA[0] + band0Buf[0] - ((band1Buf[0] + 1) >> 1)) >> 1);
1190
+ lineBufLA[2] = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1191
+
1192
+ lineBufLB[1] = band3Buf[0] + ((lineBufLB[0] + band2Buf[0] - ((band3Buf[0] + 1) >> 1)) >> 1);
1193
+ lineBufLB[2] = band2Buf[0] - ((band3Buf[0] + 1) >> 1);
1194
+ }
1195
+ else
1196
+ {
1197
+ lineBufLA[1] = lineBufLA[0] + band1Buf[0];
1198
+ lineBufLB[1] = lineBufLB[0] + band3Buf[0];
1199
+ }
1200
+ }
1201
+ }
1202
+
1203
+ int32_t *crxIdwt53FilterGetLine(CrxPlaneComp *comp, int32_t level)
1204
+ {
1205
+ int32_t *result = comp->wvltTransform[level]
1206
+ .lineBuf[(comp->wvltTransform[level].fltTapH - comp->wvltTransform[level].curH + 5) % 5 + 3];
1207
+ comp->wvltTransform[level].curH--;
1208
+ return result;
1209
+ }
1210
+
1211
+ int crxIdwt53FilterDecode(CrxPlaneComp *comp, int32_t level, CrxQStep *qStep)
1212
+ {
1213
+ if (comp->wvltTransform[level].curH)
1214
+ return 0;
1215
+
1216
+ CrxSubband *sband = comp->subBands + 3 * level;
1217
+ CrxQStep *qStepLevel = qStep ? qStep + level : 0;
1218
+
1219
+ if (comp->wvltTransform[level].height - 3 <= comp->wvltTransform[level].curLine &&
1220
+ !(comp->tileFlag & E_HAS_TILES_ON_THE_BOTTOM))
1221
+ {
1222
+ if (comp->wvltTransform[level].height & 1)
1223
+ {
1224
+ if (level)
1225
+ {
1226
+ if (crxIdwt53FilterDecode(comp, level - 1, qStep))
1227
+ return -1;
1228
+ }
1229
+ else if (crxDecodeLineWithIQuantization(sband, qStepLevel))
1230
+ return -1;
1231
+
1232
+ if (crxDecodeLineWithIQuantization(sband + 1, qStepLevel))
1233
+ return -1;
1234
+ }
1235
+ }
1236
+ else
1237
+ {
1238
+ if (level)
1239
+ {
1240
+ if (crxIdwt53FilterDecode(comp, level - 1, qStep))
1241
+ return -1;
1242
+ }
1243
+ else if (crxDecodeLineWithIQuantization(sband, qStepLevel)) // LL band
1244
+ return -1;
1245
+
1246
+ if (crxDecodeLineWithIQuantization(sband + 1, qStepLevel) || // HL band
1247
+ crxDecodeLineWithIQuantization(sband + 2, qStepLevel) || // LH band
1248
+ crxDecodeLineWithIQuantization(sband + 3, qStepLevel)) // HH band
1249
+ return -1;
1250
+ }
1251
+
1252
+ return 0;
1253
+ }
1254
+
1255
+ int crxIdwt53FilterTransform(CrxPlaneComp *comp, uint32_t level)
1256
+ {
1257
+ CrxWaveletTransform *wavelet = comp->wvltTransform + level;
1258
+
1259
+ if (wavelet->curH)
1260
+ return 0;
1261
+
1262
+ if (wavelet->curLine >= wavelet->height - 3)
1263
+ {
1264
+ if (!(comp->tileFlag & E_HAS_TILES_ON_THE_BOTTOM))
1265
+ {
1266
+ if (wavelet->height & 1)
1267
+ {
1268
+ if (level)
1269
+ {
1270
+ if (!wavelet[-1].curH)
1271
+ if (crxIdwt53FilterTransform(comp, level - 1))
1272
+ return -1;
1273
+ wavelet->subband0Buf = crxIdwt53FilterGetLine(comp, level - 1);
1274
+ }
1275
+ int32_t *band0Buf = wavelet->subband0Buf;
1276
+ int32_t *band1Buf = wavelet->subband1Buf;
1277
+ int32_t *lineBufH0 = wavelet->lineBuf[wavelet->fltTapH + 3];
1278
+ int32_t *lineBufH1 = wavelet->lineBuf[(wavelet->fltTapH + 1) % 5 + 3];
1279
+ int32_t *lineBufH2 = wavelet->lineBuf[(wavelet->fltTapH + 2) % 5 + 3];
1280
+
1281
+ int32_t *lineBufL0 = wavelet->lineBuf[0];
1282
+ int32_t *lineBufL1 = wavelet->lineBuf[1];
1283
+ wavelet->lineBuf[1] = wavelet->lineBuf[2];
1284
+ wavelet->lineBuf[2] = lineBufL1;
1285
+
1286
+ // process L bands
1287
+ if (wavelet->width <= 1)
1288
+ {
1289
+ lineBufL0[0] = band0Buf[0];
1290
+ }
1291
+ else
1292
+ {
1293
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_LEFT)
1294
+ {
1295
+ lineBufL0[0] = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1296
+ ++band1Buf;
1297
+ }
1298
+ else
1299
+ {
1300
+ lineBufL0[0] = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1301
+ }
1302
+ ++band0Buf;
1303
+ for (int i = 0; i < wavelet->width - 3; i += 2)
1304
+ {
1305
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1306
+ lineBufL0[1] = band1Buf[0] + ((lineBufL0[0] + delta) >> 1);
1307
+ lineBufL0[2] = delta;
1308
+ ++band0Buf;
1309
+ ++band1Buf;
1310
+ lineBufL0 += 2;
1311
+ }
1312
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_RIGHT)
1313
+ {
1314
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1315
+ lineBufL0[1] = band1Buf[0] + ((lineBufL0[0] + delta) >> 1);
1316
+ if (wavelet->width & 1)
1317
+ lineBufL0[2] = delta;
1318
+ }
1319
+ else if (wavelet->width & 1)
1320
+ {
1321
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1322
+ lineBufL0[1] = band1Buf[0] + ((lineBufL0[0] + delta) >> 1);
1323
+ lineBufL0[2] = delta;
1324
+ }
1325
+ else
1326
+ lineBufL0[1] = band1Buf[0] + lineBufL0[0];
1327
+ }
1328
+
1329
+ // process H bands
1330
+ lineBufL0 = wavelet->lineBuf[0];
1331
+ lineBufL1 = wavelet->lineBuf[1];
1332
+ for (int32_t i = 0; i < wavelet->width; i++)
1333
+ {
1334
+ int32_t delta = lineBufL0[i] - ((lineBufL1[i] + 1) >> 1);
1335
+ lineBufH1[i] = lineBufL1[i] + ((delta + lineBufH0[i]) >> 1);
1336
+ lineBufH2[i] = delta;
1337
+ }
1338
+ wavelet->curH += 3;
1339
+ wavelet->curLine += 3;
1340
+ wavelet->fltTapH = (wavelet->fltTapH + 3) % 5;
1341
+ }
1342
+ else
1343
+ {
1344
+ int32_t *lineBufL2 = wavelet->lineBuf[2];
1345
+ int32_t *lineBufH0 = wavelet->lineBuf[wavelet->fltTapH + 3];
1346
+ int32_t *lineBufH1 = wavelet->lineBuf[(wavelet->fltTapH + 1) % 5 + 3];
1347
+ wavelet->lineBuf[1] = lineBufL2;
1348
+ wavelet->lineBuf[2] = wavelet->lineBuf[1];
1349
+
1350
+ for (int32_t i = 0; i < wavelet->width; i++)
1351
+ lineBufH1[i] = lineBufH0[i] + lineBufL2[i];
1352
+
1353
+ wavelet->curH += 2;
1354
+ wavelet->curLine += 2;
1355
+ wavelet->fltTapH = (wavelet->fltTapH + 2) % 5;
1356
+ }
1357
+ }
1358
+ }
1359
+ else
1360
+ {
1361
+ if (level)
1362
+ {
1363
+ if (!wavelet[-1].curH && crxIdwt53FilterTransform(comp, level - 1))
1364
+ return -1;
1365
+ wavelet->subband0Buf = crxIdwt53FilterGetLine(comp, level - 1);
1366
+ }
1367
+
1368
+ int32_t *band0Buf = wavelet->subband0Buf;
1369
+ int32_t *band1Buf = wavelet->subband1Buf;
1370
+ int32_t *band2Buf = wavelet->subband2Buf;
1371
+ int32_t *band3Buf = wavelet->subband3Buf;
1372
+
1373
+ int32_t *lineBufL0 = wavelet->lineBuf[0];
1374
+ int32_t *lineBufL1 = wavelet->lineBuf[1];
1375
+ int32_t *lineBufL2 = wavelet->lineBuf[2];
1376
+ int32_t *lineBufH0 = wavelet->lineBuf[wavelet->fltTapH + 3];
1377
+ int32_t *lineBufH1 = wavelet->lineBuf[(wavelet->fltTapH + 1) % 5 + 3];
1378
+ int32_t *lineBufH2 = wavelet->lineBuf[(wavelet->fltTapH + 2) % 5 + 3];
1379
+
1380
+ wavelet->lineBuf[1] = wavelet->lineBuf[2];
1381
+ wavelet->lineBuf[2] = lineBufL1;
1382
+
1383
+ // process L bands
1384
+ if (wavelet->width <= 1)
1385
+ {
1386
+ lineBufL0[0] = band0Buf[0];
1387
+ lineBufL1[0] = band2Buf[0];
1388
+ }
1389
+ else
1390
+ {
1391
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_LEFT)
1392
+ {
1393
+ lineBufL0[0] = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1394
+ lineBufL1[0] = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1395
+ ++band1Buf;
1396
+ ++band3Buf;
1397
+ }
1398
+ else
1399
+ {
1400
+ lineBufL0[0] = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1401
+ lineBufL1[0] = band2Buf[0] - ((band3Buf[0] + 1) >> 1);
1402
+ }
1403
+ ++band0Buf;
1404
+ ++band2Buf;
1405
+ for (int i = 0; i < wavelet->width - 3; i += 2)
1406
+ {
1407
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1408
+ lineBufL0[1] = band1Buf[0] + ((delta + lineBufL0[0]) >> 1);
1409
+ lineBufL0[2] = delta;
1410
+
1411
+ delta = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1412
+ lineBufL1[1] = band3Buf[0] + ((delta + lineBufL1[0]) >> 1);
1413
+ lineBufL1[2] = delta;
1414
+
1415
+ ++band0Buf;
1416
+ ++band1Buf;
1417
+ ++band2Buf;
1418
+ ++band3Buf;
1419
+ lineBufL0 += 2;
1420
+ lineBufL1 += 2;
1421
+ }
1422
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_RIGHT)
1423
+ {
1424
+ int32_t deltaA = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1425
+ lineBufL0[1] = band1Buf[0] + ((deltaA + lineBufL0[0]) >> 1);
1426
+
1427
+ int32_t deltaB = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1428
+ lineBufL1[1] = band3Buf[0] + ((deltaB + lineBufL1[0]) >> 1);
1429
+
1430
+ if (wavelet->width & 1)
1431
+ {
1432
+ lineBufL0[2] = deltaA;
1433
+ lineBufL1[2] = deltaB;
1434
+ }
1435
+ }
1436
+ else if (wavelet->width & 1)
1437
+ {
1438
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1439
+ lineBufL0[1] = band1Buf[0] + ((delta + lineBufL0[0]) >> 1);
1440
+ lineBufL0[2] = delta;
1441
+
1442
+ delta = band2Buf[0] - ((band3Buf[0] + 1) >> 1);
1443
+ lineBufL1[1] = band3Buf[0] + ((delta + lineBufL1[0]) >> 1);
1444
+ lineBufL1[2] = delta;
1445
+ }
1446
+ else
1447
+ {
1448
+ lineBufL0[1] = lineBufL0[0] + band1Buf[0];
1449
+ lineBufL1[1] = lineBufL1[0] + band3Buf[0];
1450
+ }
1451
+ }
1452
+
1453
+ // process H bands
1454
+ lineBufL0 = wavelet->lineBuf[0];
1455
+ lineBufL1 = wavelet->lineBuf[1];
1456
+ lineBufL2 = wavelet->lineBuf[2];
1457
+ for (int32_t i = 0; i < wavelet->width; i++)
1458
+ {
1459
+ int32_t delta = lineBufL0[i] - ((lineBufL2[i] + lineBufL1[i] + 2) >> 2);
1460
+ lineBufH1[i] = lineBufL1[i] + ((delta + lineBufH0[i]) >> 1);
1461
+ lineBufH2[i] = delta;
1462
+ }
1463
+ if (wavelet->curLine >= wavelet->height - 3 && wavelet->height & 1)
1464
+ {
1465
+ wavelet->curH += 3;
1466
+ wavelet->curLine += 3;
1467
+ wavelet->fltTapH = (wavelet->fltTapH + 3) % 5;
1468
+ }
1469
+ else
1470
+ {
1471
+ wavelet->curH += 2;
1472
+ wavelet->curLine += 2;
1473
+ wavelet->fltTapH = (wavelet->fltTapH + 2) % 5;
1474
+ }
1475
+ }
1476
+
1477
+ return 0;
1478
+ }
1479
+
1480
+ int crxIdwt53FilterInitialize(CrxPlaneComp *comp, int32_t level, CrxQStep *qStep)
1481
+ {
1482
+ if (level == 0)
1483
+ return 0;
1484
+
1485
+ for (int curLevel = 0, curBand = 0; curLevel < level; curLevel++, curBand += 3)
1486
+ {
1487
+ CrxQStep *qStepLevel = qStep ? qStep + curLevel : 0;
1488
+ CrxWaveletTransform *wavelet = comp->wvltTransform + curLevel;
1489
+ if (curLevel)
1490
+ wavelet[0].subband0Buf = crxIdwt53FilterGetLine(comp, curLevel - 1);
1491
+ else if (crxDecodeLineWithIQuantization(comp->subBands + curBand, qStepLevel))
1492
+ return -1;
1493
+
1494
+ int32_t *lineBufH0 = wavelet->lineBuf[wavelet->fltTapH + 3];
1495
+ if (wavelet->height > 1)
1496
+ {
1497
+ if (crxDecodeLineWithIQuantization(comp->subBands + curBand + 1, qStepLevel) ||
1498
+ crxDecodeLineWithIQuantization(comp->subBands + curBand + 2, qStepLevel) ||
1499
+ crxDecodeLineWithIQuantization(comp->subBands + curBand + 3, qStepLevel))
1500
+ return -1;
1501
+
1502
+ int32_t *lineBufL0 = wavelet->lineBuf[0];
1503
+ int32_t *lineBufL1 = wavelet->lineBuf[1];
1504
+ int32_t *lineBufL2 = wavelet->lineBuf[2];
1505
+
1506
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_TOP)
1507
+ {
1508
+ crxHorizontal53(lineBufL0, wavelet->lineBuf[1], wavelet, comp->tileFlag);
1509
+ if (crxDecodeLineWithIQuantization(comp->subBands + curBand + 3, qStepLevel) ||
1510
+ crxDecodeLineWithIQuantization(comp->subBands + curBand + 2, qStepLevel))
1511
+ return -1;
1512
+
1513
+ int32_t *band2Buf = wavelet->subband2Buf;
1514
+ int32_t *band3Buf = wavelet->subband3Buf;
1515
+
1516
+ // process L band
1517
+ if (wavelet->width <= 1)
1518
+ lineBufL2[0] = band2Buf[0];
1519
+ else
1520
+ {
1521
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_LEFT)
1522
+ {
1523
+ lineBufL2[0] = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1524
+ ++band3Buf;
1525
+ }
1526
+ else
1527
+ lineBufL2[0] = band2Buf[0] - ((band3Buf[0] + 1) >> 1);
1528
+
1529
+ ++band2Buf;
1530
+
1531
+ for (int i = 0; i < wavelet->width - 3; i += 2)
1532
+ {
1533
+ int32_t delta = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1534
+ lineBufL2[1] = band3Buf[0] + ((lineBufL2[0] + delta) >> 1);
1535
+ lineBufL2[2] = delta;
1536
+
1537
+ ++band2Buf;
1538
+ ++band3Buf;
1539
+ lineBufL2 += 2;
1540
+ }
1541
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_RIGHT)
1542
+ {
1543
+ int32_t delta = band2Buf[0] - ((band3Buf[0] + band3Buf[1] + 2) >> 2);
1544
+ lineBufL2[1] = band3Buf[0] + ((lineBufL2[0] + delta) >> 1);
1545
+ if (wavelet->width & 1)
1546
+ lineBufL2[2] = delta;
1547
+ }
1548
+ else if (wavelet->width & 1)
1549
+ {
1550
+ int32_t delta = band2Buf[0] - ((band3Buf[0] + 1) >> 1);
1551
+
1552
+ lineBufL2[1] = band3Buf[0] + ((lineBufL2[0] + delta) >> 1);
1553
+ lineBufL2[2] = delta;
1554
+ }
1555
+ else
1556
+ {
1557
+ lineBufL2[1] = band3Buf[0] + lineBufL2[0];
1558
+ }
1559
+ }
1560
+
1561
+ // process H band
1562
+ for (int32_t i = 0; i < wavelet->width; i++)
1563
+ lineBufH0[i] = lineBufL0[i] - ((lineBufL1[i] + lineBufL2[i] + 2) >> 2);
1564
+ }
1565
+ else
1566
+ {
1567
+ crxHorizontal53(lineBufL0, wavelet->lineBuf[2], wavelet, comp->tileFlag);
1568
+ for (int i = 0; i < wavelet->width; i++)
1569
+ lineBufH0[i] = lineBufL0[i] - ((lineBufL2[i] + 1) >> 1);
1570
+ }
1571
+
1572
+ if (crxIdwt53FilterDecode(comp, curLevel, qStep) || crxIdwt53FilterTransform(comp, curLevel))
1573
+ return -1;
1574
+ }
1575
+ else
1576
+ {
1577
+ if (crxDecodeLineWithIQuantization(comp->subBands + curBand + 1, qStepLevel))
1578
+ return -1;
1579
+
1580
+ int32_t *band0Buf = wavelet->subband0Buf;
1581
+ int32_t *band1Buf = wavelet->subband1Buf;
1582
+
1583
+ // process H band
1584
+ if (wavelet->width <= 1)
1585
+ lineBufH0[0] = band0Buf[0];
1586
+ else
1587
+ {
1588
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_LEFT)
1589
+ {
1590
+ lineBufH0[0] = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1591
+ ++band1Buf;
1592
+ }
1593
+ else
1594
+ lineBufH0[0] = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1595
+
1596
+ ++band0Buf;
1597
+
1598
+ for (int i = 0; i < wavelet->width - 3; i += 2)
1599
+ {
1600
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1601
+ lineBufH0[1] = band1Buf[0] + ((lineBufH0[0] + delta) >> 1);
1602
+ lineBufH0[2] = delta;
1603
+
1604
+ ++band0Buf;
1605
+ ++band1Buf;
1606
+ lineBufH0 += 2;
1607
+ }
1608
+
1609
+ if (comp->tileFlag & E_HAS_TILES_ON_THE_RIGHT)
1610
+ {
1611
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + band1Buf[1] + 2) >> 2);
1612
+ lineBufH0[1] = band1Buf[0] + ((lineBufH0[0] + delta) >> 1);
1613
+ lineBufH0[2] = delta;
1614
+ }
1615
+ else if (wavelet->width & 1)
1616
+ {
1617
+ int32_t delta = band0Buf[0] - ((band1Buf[0] + 1) >> 1);
1618
+ lineBufH0[1] = band1Buf[0] + ((lineBufH0[0] + delta) >> 1);
1619
+ lineBufH0[2] = delta;
1620
+ }
1621
+ else
1622
+ {
1623
+ lineBufH0[1] = band1Buf[0] + lineBufH0[0];
1624
+ }
1625
+ }
1626
+ ++wavelet->curLine;
1627
+ ++wavelet->curH;
1628
+ wavelet->fltTapH = (wavelet->fltTapH + 1) % 5;
1629
+ }
1630
+ }
1631
+
1632
+ return 0;
1633
+ }
1634
+
1635
+ void crxFreeSubbandData(CrxImage *image, CrxPlaneComp *comp)
1636
+ {
1637
+ if (comp->compBuf)
1638
+ {
1639
+ free(comp->compBuf);
1640
+ comp->compBuf = 0;
1641
+ }
1642
+
1643
+ if (!comp->subBands)
1644
+ return;
1645
+
1646
+ for (int32_t i = 0; i < image->subbandCount; i++)
1647
+ {
1648
+ if (comp->subBands[i].bandParam)
1649
+ {
1650
+ free(comp->subBands[i].bandParam);
1651
+ comp->subBands[i].bandParam = 0LL;
1652
+ }
1653
+
1654
+ comp->subBands[i].bandBuf = 0;
1655
+ comp->subBands[i].bandSize = 0;
1656
+ }
1657
+ }
1658
+
1659
+ void crxConvertPlaneLine(CrxImage *img, int imageRow, int imageCol = 0, int plane = 0, int32_t *lineData = 0,
1660
+ int lineLength = 0)
1661
+ {
1662
+ if (lineData)
1663
+ {
1664
+ uint64_t rawOffset = 4 * img->planeWidth * imageRow + 2 * imageCol;
1665
+ if (img->encType == 1)
1666
+ {
1667
+ int32_t maxVal = 1 << (img->nBits - 1);
1668
+ int32_t minVal = -maxVal;
1669
+ --maxVal;
1670
+ for (int i = 0; i < lineLength; i++)
1671
+ img->outBufs[plane][rawOffset + 2 * i] = _constrain(lineData[i], minVal, maxVal);
1672
+ }
1673
+ else if (img->encType == 3)
1674
+ {
1675
+ // copy to intermediate planeBuf
1676
+ rawOffset = plane * img->planeWidth * img->planeHeight + img->planeWidth * imageRow + imageCol;
1677
+ for (int i = 0; i < lineLength; i++)
1678
+ img->planeBuf[rawOffset + i] = lineData[i];
1679
+ }
1680
+ else if (img->nPlanes == 4)
1681
+ {
1682
+ int32_t median = 1 << (img->nBits - 1);
1683
+ int32_t maxVal = (1 << img->nBits) - 1;
1684
+ for (int i = 0; i < lineLength; i++)
1685
+ img->outBufs[plane][rawOffset + 2 * i] = _constrain(median + lineData[i], 0, maxVal);
1686
+ }
1687
+ else if (img->nPlanes == 1)
1688
+ {
1689
+ int32_t maxVal = (1 << img->nBits) - 1;
1690
+ int32_t median = 1 << (img->nBits - 1);
1691
+ rawOffset = img->planeWidth * imageRow + imageCol;
1692
+ for (int i = 0; i < lineLength; i++)
1693
+ img->outBufs[0][rawOffset + i] = _constrain(median + lineData[i], 0, maxVal);
1694
+ }
1695
+ }
1696
+ else if (img->encType == 3 && img->planeBuf)
1697
+ {
1698
+ int32_t planeSize = img->planeWidth * img->planeHeight;
1699
+ int16_t *plane0 = img->planeBuf + imageRow * img->planeWidth;
1700
+ int16_t *plane1 = plane0 + planeSize;
1701
+ int16_t *plane2 = plane1 + planeSize;
1702
+ int16_t *plane3 = plane2 + planeSize;
1703
+
1704
+ int32_t median = (1 << (img->medianBits - 1)) << 10;
1705
+ int32_t maxVal = (1 << img->medianBits) - 1;
1706
+ uint32_t rawLineOffset = 4 * img->planeWidth * imageRow;
1707
+
1708
+ // for this stage - all except imageRow is ignored
1709
+ for (int i = 0; i < img->planeWidth; i++)
1710
+ {
1711
+ int32_t gr = median + (plane0[i] << 10) - 168 * plane1[i] - 585 * plane3[i];
1712
+ int32_t val = 0;
1713
+ if (gr < 0)
1714
+ gr = -(((_abs(gr) + 512) >> 9) & ~1);
1715
+ else
1716
+ gr = ((_abs(gr) + 512) >> 9) & ~1;
1717
+
1718
+ // Essentially R = round(median + P0 + 1.474*P3)
1719
+ val = (median + (plane0[i] << 10) + 1510 * plane3[i] + 512) >> 10;
1720
+ img->outBufs[0][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1721
+ // Essentially G1 = round(median + P0 + P2 - 0.164*P1 - 0.571*P3)
1722
+ val = (plane2[i] + gr + 1) >> 1;
1723
+ img->outBufs[1][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1724
+ // Essentially G2 = round(median + P0 - P2 - 0.164*P1 - 0.571*P3)
1725
+ val = (gr - plane2[i] + 1) >> 1;
1726
+ img->outBufs[2][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1727
+ // Essentially B = round(median + P0 + 1.881*P1)
1728
+ val = (median + (plane0[i] << 10) + 1927 * plane1[i] + 512) >> 10;
1729
+ img->outBufs[3][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1730
+ }
1731
+ }
1732
+ }
1733
+
1734
+ int crxParamInit(CrxImage *img, CrxBandParam **param, uint64_t subbandMdatOffset, uint64_t subbandDataSize,
1735
+ uint32_t subbandWidth, uint32_t subbandHeight, bool supportsPartial, uint32_t roundedBitsMask)
1736
+ {
1737
+ int32_t progrDataSize = supportsPartial ? 0 : sizeof(int32_t) * subbandWidth;
1738
+ int32_t paramLength = 2 * subbandWidth + 4;
1739
+ uint8_t *paramBuf = 0;
1740
+ paramBuf = (uint8_t *)
1741
+ #ifdef LIBRAW_CR3_MEMPOOL
1742
+ img->memmgr.
1743
+ #endif
1744
+ calloc(1, sizeof(CrxBandParam) + sizeof(int32_t) * paramLength + progrDataSize);
1745
+
1746
+ if (!paramBuf)
1747
+ return -1;
1748
+
1749
+ *param = (CrxBandParam *)paramBuf;
1750
+
1751
+ paramBuf += sizeof(CrxBandParam);
1752
+
1753
+ (*param)->paramData = (int32_t *)paramBuf;
1754
+ (*param)->nonProgrData = progrDataSize ? (*param)->paramData + paramLength : 0;
1755
+ (*param)->subbandWidth = subbandWidth;
1756
+ (*param)->subbandHeight = subbandHeight;
1757
+ (*param)->roundedBits = 0;
1758
+ (*param)->curLine = 0;
1759
+ (*param)->roundedBitsMask = roundedBitsMask;
1760
+ (*param)->supportsPartial = supportsPartial;
1761
+ (*param)->bitStream.bitData = 0;
1762
+ (*param)->bitStream.bitsLeft = 0;
1763
+ (*param)->bitStream.mdatSize = subbandDataSize;
1764
+ (*param)->bitStream.curPos = 0;
1765
+ (*param)->bitStream.curBufSize = 0;
1766
+ (*param)->bitStream.curBufOffset = subbandMdatOffset;
1767
+ (*param)->bitStream.input = img->input;
1768
+
1769
+ crxFillBuffer(&(*param)->bitStream);
1770
+
1771
+ return 0;
1772
+ }
1773
+
1774
+ int crxSetupSubbandData(CrxImage *img, CrxPlaneComp *planeComp, const CrxTile *tile, uint32_t mdatOffset)
1775
+ {
1776
+ long compDataSize = 0;
1777
+ long waveletDataOffset = 0;
1778
+ long compCoeffDataOffset = 0;
1779
+ int32_t toSubbands = 3 * img->levels + 1;
1780
+ int32_t transformWidth = 0;
1781
+
1782
+ CrxSubband *subbands = planeComp->subBands;
1783
+
1784
+ // calculate sizes
1785
+ for (int32_t subbandNum = 0; subbandNum < toSubbands; subbandNum++)
1786
+ {
1787
+ subbands[subbandNum].bandSize = subbands[subbandNum].width * sizeof(int32_t); // 4bytes
1788
+ compDataSize += subbands[subbandNum].bandSize;
1789
+ }
1790
+
1791
+ if (img->levels)
1792
+ {
1793
+ int32_t encLevels = img->levels ? img->levels : 1;
1794
+ waveletDataOffset = (compDataSize + 7) & ~7;
1795
+ compDataSize = (sizeof(CrxWaveletTransform) * encLevels + waveletDataOffset + 7) & ~7;
1796
+ compCoeffDataOffset = compDataSize;
1797
+
1798
+ // calc wavelet line buffer sizes (always at one level up from current)
1799
+ for (int level = 0; level < img->levels; ++level)
1800
+ if (level < img->levels - 1)
1801
+ compDataSize += 8 * sizeof(int32_t) * planeComp->subBands[3 * (level + 1) + 2].width;
1802
+ else
1803
+ compDataSize += 8 * sizeof(int32_t) * tile->width;
1804
+ }
1805
+ // buffer allocation
1806
+ planeComp->compBuf = (uint8_t *)
1807
+ #ifdef LIBRAW_CR3_MEMPOOL
1808
+ img->memmgr.
1809
+ #endif
1810
+ malloc(compDataSize);
1811
+ if (!planeComp->compBuf)
1812
+ return -1;
1813
+
1814
+ // subbands buffer and sizes initialisation
1815
+ uint64_t subbandMdatOffset = img->mdatOffset + mdatOffset;
1816
+ uint8_t *subbandBuf = planeComp->compBuf;
1817
+
1818
+ for (int32_t subbandNum = 0; subbandNum < toSubbands; subbandNum++)
1819
+ {
1820
+ subbands[subbandNum].bandBuf = subbandBuf;
1821
+ subbandBuf += subbands[subbandNum].bandSize;
1822
+ subbands[subbandNum].mdatOffset = subbandMdatOffset + subbands[subbandNum].dataOffset;
1823
+ }
1824
+
1825
+ // wavelet data initialisation
1826
+ if (img->levels)
1827
+ {
1828
+ CrxWaveletTransform *waveletTransforms = (CrxWaveletTransform *)(planeComp->compBuf + waveletDataOffset);
1829
+ int32_t *paramData = (int32_t *)(planeComp->compBuf + compCoeffDataOffset);
1830
+
1831
+ planeComp->wvltTransform = waveletTransforms;
1832
+ waveletTransforms[0].subband0Buf = (int32_t *)subbands->bandBuf;
1833
+
1834
+ for (int level = 0; level < img->levels; ++level)
1835
+ {
1836
+ int32_t band = 3 * level + 1;
1837
+
1838
+ if (level >= img->levels - 1)
1839
+ {
1840
+ waveletTransforms[level].height = tile->height;
1841
+ transformWidth = tile->width;
1842
+ }
1843
+ else
1844
+ {
1845
+ waveletTransforms[level].height = subbands[band + 3].height;
1846
+ transformWidth = subbands[band + 4].width;
1847
+ }
1848
+ waveletTransforms[level].width = transformWidth;
1849
+ waveletTransforms[level].lineBuf[0] = paramData;
1850
+ waveletTransforms[level].lineBuf[1] = waveletTransforms[level].lineBuf[0] + transformWidth;
1851
+ waveletTransforms[level].lineBuf[2] = waveletTransforms[level].lineBuf[1] + transformWidth;
1852
+ waveletTransforms[level].lineBuf[3] = waveletTransforms[level].lineBuf[2] + transformWidth;
1853
+ waveletTransforms[level].lineBuf[4] = waveletTransforms[level].lineBuf[3] + transformWidth;
1854
+ waveletTransforms[level].lineBuf[5] = waveletTransforms[level].lineBuf[4] + transformWidth;
1855
+ waveletTransforms[level].lineBuf[6] = waveletTransforms[level].lineBuf[5] + transformWidth;
1856
+ waveletTransforms[level].lineBuf[7] = waveletTransforms[level].lineBuf[6] + transformWidth;
1857
+ waveletTransforms[level].curLine = 0;
1858
+ waveletTransforms[level].curH = 0;
1859
+ waveletTransforms[level].fltTapH = 0;
1860
+ waveletTransforms[level].subband1Buf = (int32_t *)subbands[band].bandBuf;
1861
+ waveletTransforms[level].subband2Buf = (int32_t *)subbands[band + 1].bandBuf;
1862
+ waveletTransforms[level].subband3Buf = (int32_t *)subbands[band + 2].bandBuf;
1863
+
1864
+ paramData = waveletTransforms[level].lineBuf[7] + transformWidth;
1865
+ }
1866
+ }
1867
+
1868
+ // decoding params and bitstream initialisation
1869
+ for (int32_t subbandNum = 0; subbandNum < toSubbands; subbandNum++)
1870
+ {
1871
+ if (subbands[subbandNum].dataSize)
1872
+ {
1873
+ bool supportsPartial = false;
1874
+ uint32_t roundedBitsMask = 0;
1875
+
1876
+ if (planeComp->supportsPartial && subbandNum == 0)
1877
+ {
1878
+ roundedBitsMask = planeComp->roundedBitsMask;
1879
+ supportsPartial = true;
1880
+ }
1881
+ if (crxParamInit(img, &subbands[subbandNum].bandParam, subbands[subbandNum].mdatOffset,
1882
+ subbands[subbandNum].dataSize, subbands[subbandNum].width, subbands[subbandNum].height,
1883
+ supportsPartial, roundedBitsMask))
1884
+ return -1;
1885
+ }
1886
+ }
1887
+
1888
+ return 0;
1889
+ }
1890
+
1891
+ int LibRaw::crxDecodePlane(void *p, uint32_t planeNumber)
1892
+ {
1893
+ CrxImage *img = (CrxImage *)p;
1894
+ int imageRow = 0;
1895
+ for (int tRow = 0; tRow < img->tileRows; tRow++)
1896
+ {
1897
+ int imageCol = 0;
1898
+ for (int tCol = 0; tCol < img->tileCols; tCol++)
1899
+ {
1900
+ CrxTile *tile = img->tiles + tRow * img->tileCols + tCol;
1901
+ CrxPlaneComp *planeComp = tile->comps + planeNumber;
1902
+ uint64_t tileMdatOffset = tile->dataOffset + tile->mdatQPDataSize + tile->mdatExtraSize + planeComp->dataOffset;
1903
+
1904
+ // decode single tile
1905
+ if (crxSetupSubbandData(img, planeComp, tile, tileMdatOffset))
1906
+ return -1;
1907
+
1908
+ if (img->levels)
1909
+ {
1910
+ if (crxIdwt53FilterInitialize(planeComp, img->levels, tile->qStep))
1911
+ return -1;
1912
+ for (int i = 0; i < tile->height; ++i)
1913
+ {
1914
+ if (crxIdwt53FilterDecode(planeComp, img->levels - 1, tile->qStep) ||
1915
+ crxIdwt53FilterTransform(planeComp, img->levels - 1))
1916
+ return -1;
1917
+ int32_t *lineData = crxIdwt53FilterGetLine(planeComp, img->levels - 1);
1918
+ crxConvertPlaneLine(img, imageRow + i, imageCol, planeNumber, lineData, tile->width);
1919
+ }
1920
+ }
1921
+ else
1922
+ {
1923
+ // we have the only subband in this case
1924
+ if (!planeComp->subBands->dataSize)
1925
+ {
1926
+ memset(planeComp->subBands->bandBuf, 0, planeComp->subBands->bandSize);
1927
+ return 0;
1928
+ }
1929
+
1930
+ for (int i = 0; i < tile->height; ++i)
1931
+ {
1932
+ if (crxDecodeLine(planeComp->subBands->bandParam, planeComp->subBands->bandBuf))
1933
+ return -1;
1934
+ int32_t *lineData = (int32_t *)planeComp->subBands->bandBuf;
1935
+ crxConvertPlaneLine(img, imageRow + i, imageCol, planeNumber, lineData, tile->width);
1936
+ }
1937
+ }
1938
+ imageCol += tile->width;
1939
+ }
1940
+ imageRow += img->tiles[tRow * img->tileCols].height;
1941
+ }
1942
+
1943
+ return 0;
1944
+ }
1945
+
1946
+ uint32_t crxReadQP(CrxBitstream *bitStrm, int32_t kParam)
1947
+ {
1948
+ uint32_t qp = crxBitstreamGetZeros(bitStrm);
1949
+ if (qp >= 23)
1950
+ qp = crxBitstreamGetBits(bitStrm, 8);
1951
+ else if (kParam)
1952
+ qp = crxBitstreamGetBits(bitStrm, kParam) | (qp << kParam);
1953
+
1954
+ return qp;
1955
+ }
1956
+
1957
+ void crxDecodeGolombTop(CrxBitstream *bitStrm, int32_t width, int32_t *lineBuf, int32_t *kParam)
1958
+ {
1959
+ lineBuf[0] = 0;
1960
+ while (width-- > 0)
1961
+ {
1962
+ lineBuf[1] = lineBuf[0];
1963
+ uint32_t qp = crxReadQP(bitStrm, *kParam);
1964
+ lineBuf[1] += -(int32_t)(qp & 1) ^ (int32_t)(qp >> 1);
1965
+ *kParam = crxPredictKParameter(*kParam, qp, 7);
1966
+ ++lineBuf;
1967
+ }
1968
+ lineBuf[1] = lineBuf[0] + 1;
1969
+ }
1970
+
1971
+ void crxDecodeGolombNormal(CrxBitstream *bitStrm, int32_t width, int32_t *lineBuf0, int32_t *lineBuf1, int32_t *kParam)
1972
+ {
1973
+ lineBuf1[0] = lineBuf0[1];
1974
+ int32_t deltaH = lineBuf0[1] - lineBuf0[0];
1975
+ while (width-- > 0)
1976
+ {
1977
+ lineBuf1[1] = crxPrediction(lineBuf1[0], lineBuf0[1], deltaH, lineBuf0[0] - lineBuf1[0]);
1978
+ uint32_t qp = crxReadQP(bitStrm, *kParam);
1979
+ lineBuf1[1] += -(int32_t)(qp & 1) ^ (int32_t)(qp >> 1);
1980
+ if (width)
1981
+ {
1982
+ deltaH = lineBuf0[2] - lineBuf0[1];
1983
+ *kParam = crxPredictKParameter(*kParam, (qp + 2 * _abs(deltaH)) >> 1, 7);
1984
+ ++lineBuf0;
1985
+ }
1986
+ else
1987
+ *kParam = crxPredictKParameter(*kParam, qp, 7);
1988
+ ++lineBuf1;
1989
+ }
1990
+ lineBuf1[1] = lineBuf1[0] + 1;
1991
+ }
1992
+
1993
+ int crxMakeQStep(CrxImage *img, CrxTile *tile, int32_t *qpTable, uint32_t /*totalQP*/)
1994
+ {
1995
+ if (img->levels > 3 || img->levels < 1)
1996
+ return -1;
1997
+ int qpWidth = (tile->width >> 3) + ((tile->width & 7) != 0);
1998
+ int qpHeight = (tile->height >> 1) + (tile->height & 1);
1999
+ int qpHeight4 = (tile->height >> 2) + ((tile->height & 3) != 0);
2000
+ int qpHeight8 = (tile->height >> 3) + ((tile->height & 7) != 0);
2001
+ uint32_t totalHeight = qpHeight;
2002
+ if (img->levels > 1)
2003
+ totalHeight += qpHeight4;
2004
+ if (img->levels > 2)
2005
+ totalHeight += qpHeight8;
2006
+ tile->qStep = (CrxQStep *)
2007
+ #ifdef LIBRAW_CR3_MEMPOOL
2008
+ img->memmgr.
2009
+ #endif
2010
+ malloc(totalHeight * qpWidth * sizeof(uint32_t) + img->levels * sizeof(CrxQStep));
2011
+
2012
+ if (!tile->qStep)
2013
+ return -1;
2014
+ uint32_t *qStepTbl = (uint32_t *)(tile->qStep + img->levels);
2015
+ CrxQStep *qStep = tile->qStep;
2016
+ switch (img->levels)
2017
+ {
2018
+ case 3:
2019
+ qStep->qStepTbl = qStepTbl;
2020
+ qStep->width = qpWidth;
2021
+ qStep->height = qpHeight8;
2022
+ for (int qpRow = 0; qpRow < qpHeight8; ++qpRow)
2023
+ {
2024
+ int row0Idx = qpWidth * _min(4 * qpRow, qpHeight - 1);
2025
+ int row1Idx = qpWidth * _min(4 * qpRow + 1, qpHeight - 1);
2026
+ int row2Idx = qpWidth * _min(4 * qpRow + 2, qpHeight - 1);
2027
+ int row3Idx = qpWidth * _min(4 * qpRow + 3, qpHeight - 1);
2028
+
2029
+ for (int qpCol = 0; qpCol < qpWidth; ++qpCol, ++qStepTbl)
2030
+ {
2031
+ int32_t quantVal = qpTable[row0Idx++] + qpTable[row1Idx++] + qpTable[row2Idx++] + qpTable[row3Idx++];
2032
+ // not sure about this nonsense - why is it not just avg like with 2 levels?
2033
+ quantVal = ((quantVal < 0) * 3 + quantVal) >> 2;
2034
+ if (quantVal / 6 >= 6)
2035
+ *qStepTbl = q_step_tbl[quantVal % 6] << ((quantVal / 6 - 6 ) & 0x1f);
2036
+ else
2037
+ *qStepTbl = q_step_tbl[quantVal % 6] >> (6 - quantVal / 6);
2038
+ }
2039
+ }
2040
+ // continue to the next level - we always decode all levels
2041
+ ++qStep;
2042
+ case 2:
2043
+ qStep->qStepTbl = qStepTbl;
2044
+ qStep->width = qpWidth;
2045
+ qStep->height = qpHeight4;
2046
+ for (int qpRow = 0; qpRow < qpHeight4; ++qpRow)
2047
+ {
2048
+ int row0Idx = qpWidth * _min(2 * qpRow, qpHeight - 1);
2049
+ int row1Idx = qpWidth * _min(2 * qpRow + 1, qpHeight - 1);
2050
+
2051
+ for (int qpCol = 0; qpCol < qpWidth; ++qpCol, ++qStepTbl)
2052
+ {
2053
+ int32_t quantVal = (qpTable[row0Idx++] + qpTable[row1Idx++]) / 2;
2054
+ if (quantVal / 6 >= 6)
2055
+ *qStepTbl = q_step_tbl[quantVal % 6] << ((quantVal / 6 - 6) & 0x1f);
2056
+ else
2057
+ *qStepTbl = q_step_tbl[quantVal % 6] >> (6 - quantVal / 6);
2058
+ }
2059
+ }
2060
+ // continue to the next level - we always decode all levels
2061
+ ++qStep;
2062
+ case 1:
2063
+ qStep->qStepTbl = qStepTbl;
2064
+ qStep->width = qpWidth;
2065
+ qStep->height = qpHeight;
2066
+ for (int qpRow = 0; qpRow < qpHeight; ++qpRow)
2067
+ for (int qpCol = 0; qpCol < qpWidth; ++qpCol, ++qStepTbl, ++qpTable)
2068
+ if (*qpTable / 6 >= 6)
2069
+ *qStepTbl = q_step_tbl[*qpTable % 6] << ((*qpTable / 6 - 6) & 0x1f);
2070
+ else
2071
+ *qStepTbl = q_step_tbl[*qpTable % 6] >> (6 - *qpTable / 6);
2072
+
2073
+ break;
2074
+ }
2075
+ return 0;
2076
+ }
2077
+
2078
+ libraw_inline void crxSetupSubbandIdx(crx_data_header_t *hdr, CrxImage * /*img*/, CrxSubband *band, int level,
2079
+ short colStartIdx, short bandWidthExCoef, short rowStartIdx,
2080
+ short bandHeightExCoef)
2081
+ {
2082
+ if (hdr->version == 0x200)
2083
+ {
2084
+ band->rowStartAddOn = rowStartIdx;
2085
+ band->rowEndAddOn = bandHeightExCoef;
2086
+ band->colStartAddOn = colStartIdx;
2087
+ band->colEndAddOn = bandWidthExCoef;
2088
+ band->levelShift = 3 - level;
2089
+ }
2090
+ else
2091
+ {
2092
+ band->rowStartAddOn = 0;
2093
+ band->rowEndAddOn = 0;
2094
+ band->colStartAddOn = 0;
2095
+ band->colEndAddOn = 0;
2096
+ band->levelShift = 0;
2097
+ }
2098
+ }
2099
+
2100
+ int crxProcessSubbands(crx_data_header_t *hdr, CrxImage *img, CrxTile *tile, CrxPlaneComp *comp)
2101
+ {
2102
+ CrxSubband *band = comp->subBands + img->subbandCount - 1; // set to last band
2103
+ uint32_t bandHeight = tile->height;
2104
+ uint32_t bandWidth = tile->width;
2105
+ int32_t bandWidthExCoef = 0;
2106
+ int32_t bandHeightExCoef = 0;
2107
+ if (img->levels)
2108
+ {
2109
+ // Build up subband sequences to crxDecode to a level in a header
2110
+
2111
+ // Coefficient structure is a bit unclear and convoluted:
2112
+ // 3 levels max - 8 groups (for tile width rounded to 8 bytes)
2113
+ // of 3 band per level 4 sets of coefficients for each
2114
+ int32_t *rowExCoef = exCoefNumTbl + 0x30 * (img->levels - 1) + 6 * (tile->width & 7);
2115
+ int32_t *colExCoef = exCoefNumTbl + 0x30 * (img->levels - 1) + 6 * (tile->height & 7);
2116
+ for (int level = 0; level < img->levels; ++level)
2117
+ {
2118
+ int32_t widthOddPixel = bandWidth & 1;
2119
+ int32_t heightOddPixel = bandHeight & 1;
2120
+ bandWidth = (widthOddPixel + bandWidth) >> 1;
2121
+ bandHeight = (heightOddPixel + bandHeight) >> 1;
2122
+
2123
+ int32_t bandWidthExCoef0 = 0;
2124
+ int32_t bandWidthExCoef1 = 0;
2125
+ int32_t bandHeightExCoef0 = 0;
2126
+ int32_t bandHeightExCoef1 = 0;
2127
+ int32_t colStartIdx = 0;
2128
+ int32_t rowStartIdx = 0;
2129
+ if (tile->tileFlag & E_HAS_TILES_ON_THE_RIGHT)
2130
+ {
2131
+ bandWidthExCoef0 = rowExCoef[2 * level];
2132
+ bandWidthExCoef1 = rowExCoef[2 * level + 1];
2133
+ }
2134
+ if (tile->tileFlag & E_HAS_TILES_ON_THE_LEFT)
2135
+ {
2136
+ ++bandWidthExCoef0;
2137
+ colStartIdx = 1;
2138
+ }
2139
+
2140
+ if (tile->tileFlag & E_HAS_TILES_ON_THE_BOTTOM)
2141
+ {
2142
+ bandHeightExCoef0 = colExCoef[2 * level];
2143
+ bandHeightExCoef1 = colExCoef[2 * level + 1];
2144
+ }
2145
+ if (tile->tileFlag & E_HAS_TILES_ON_THE_TOP)
2146
+ {
2147
+ ++bandHeightExCoef0;
2148
+ rowStartIdx = 1;
2149
+ }
2150
+
2151
+ band[0].width = bandWidth + bandWidthExCoef0 - widthOddPixel;
2152
+ band[0].height = bandHeight + bandHeightExCoef0 - heightOddPixel;
2153
+ crxSetupSubbandIdx(hdr, img, band, level + 1, colStartIdx, bandWidthExCoef0 - colStartIdx, rowStartIdx,
2154
+ bandHeightExCoef0 - rowStartIdx);
2155
+
2156
+ band[-1].width = bandWidth + bandWidthExCoef1;
2157
+ band[-1].height = bandHeight + bandHeightExCoef0 - heightOddPixel;
2158
+
2159
+ crxSetupSubbandIdx(hdr, img, band - 1, level + 1, 0, bandWidthExCoef1, rowStartIdx,
2160
+ bandHeightExCoef0 - rowStartIdx);
2161
+
2162
+ band[-2].width = bandWidth + bandWidthExCoef0 - widthOddPixel;
2163
+ band[-2].height = bandHeight + bandHeightExCoef1;
2164
+ crxSetupSubbandIdx(hdr, img, band - 2, level + 1, colStartIdx, bandWidthExCoef0 - colStartIdx, 0,
2165
+ bandHeightExCoef1);
2166
+
2167
+ band -= 3;
2168
+ }
2169
+ bandWidthExCoef = bandHeightExCoef = 0;
2170
+ if (tile->tileFlag & E_HAS_TILES_ON_THE_RIGHT)
2171
+ bandWidthExCoef = rowExCoef[2 * img->levels - 1];
2172
+ if (tile->tileFlag & E_HAS_TILES_ON_THE_BOTTOM)
2173
+ bandHeightExCoef = colExCoef[2 * img->levels - 1];
2174
+ }
2175
+ band->width = bandWidthExCoef + bandWidth;
2176
+ band->height = bandHeightExCoef + bandHeight;
2177
+ if (img->levels)
2178
+ crxSetupSubbandIdx(hdr, img, band, img->levels, 0, bandWidthExCoef, 0, bandHeightExCoef);
2179
+
2180
+ return 0;
2181
+ }
2182
+
2183
+ int crxReadSubbandHeaders(crx_data_header_t * /*hdr*/, CrxImage *img, CrxTile * /*tile*/, CrxPlaneComp *comp,
2184
+ uint8_t **subbandMdatPtr, int32_t *mdatSize)
2185
+ {
2186
+ if (!img->subbandCount)
2187
+ return 0;
2188
+ int32_t subbandOffset = 0;
2189
+ CrxSubband *band = comp->subBands;
2190
+ for (int curSubband = 0; curSubband < img->subbandCount; curSubband++, band++)
2191
+ {
2192
+ if (*mdatSize < 4)
2193
+ return -1;
2194
+
2195
+ int hdrSign = LibRaw::sgetn(2, *subbandMdatPtr);
2196
+ int hdrSize = LibRaw::sgetn(2, *subbandMdatPtr + 2);
2197
+ if (*mdatSize < hdrSize + 4)
2198
+ return -1;
2199
+ if ((hdrSign != 0xFF03 || hdrSize != 8) && (hdrSign != 0xFF13 || hdrSize != 16))
2200
+ return -1;
2201
+
2202
+ int32_t subbandSize = LibRaw::sgetn(4, *subbandMdatPtr + 4);
2203
+
2204
+ if (curSubband != ((*subbandMdatPtr)[8] & 0xF0) >> 4)
2205
+ {
2206
+ band->dataSize = subbandSize;
2207
+ return -1;
2208
+ }
2209
+
2210
+ band->dataOffset = subbandOffset;
2211
+ band->kParam = 0;
2212
+ band->bandParam = 0;
2213
+ band->bandBuf = 0;
2214
+ band->bandSize = 0;
2215
+
2216
+ if (hdrSign == 0xFF03)
2217
+ {
2218
+ // old header
2219
+ uint32_t bitData = LibRaw::sgetn(4, *subbandMdatPtr + 8);
2220
+ band->dataSize = subbandSize - (bitData & 0x7FFFF);
2221
+ band->supportsPartial = bitData & 0x8000000;
2222
+ band->qParam = (bitData >> 19) & 0xFF;
2223
+ band->qStepBase = 0;
2224
+ band->qStepMult = 0;
2225
+ }
2226
+ else
2227
+ {
2228
+ // new header
2229
+ if (LibRaw::sgetn(2, *subbandMdatPtr + 8) & 0xFFF)
2230
+ // partial and qParam are not supported
2231
+ return -1;
2232
+ if (LibRaw::sgetn(2, *subbandMdatPtr + 18))
2233
+ // new header terninated by 2 zero bytes
2234
+ return -1;
2235
+ band->supportsPartial = false;
2236
+ band->qParam = 0;
2237
+ band->dataSize = subbandSize - LibRaw::sgetn(2, *subbandMdatPtr + 16);
2238
+ band->qStepBase = LibRaw::sgetn(4, *subbandMdatPtr + 12);
2239
+ ;
2240
+ band->qStepMult = LibRaw::sgetn(2, *subbandMdatPtr + 10);
2241
+ ;
2242
+ }
2243
+
2244
+ subbandOffset += subbandSize;
2245
+
2246
+ *subbandMdatPtr += hdrSize + 4;
2247
+ *mdatSize -= hdrSize + 4;
2248
+ }
2249
+
2250
+ return 0;
2251
+ }
2252
+
2253
+ int crxReadImageHeaders(crx_data_header_t *hdr, CrxImage *img, uint8_t *mdatPtr, int32_t mdatHdrSize)
2254
+ {
2255
+ int nTiles = img->tileRows * img->tileCols;
2256
+
2257
+ if (!nTiles)
2258
+ return -1;
2259
+
2260
+ if (!img->tiles)
2261
+ {
2262
+ img->tiles = (CrxTile *)
2263
+ #ifdef LIBRAW_CR3_MEMPOOL
2264
+ img->memmgr.
2265
+ #endif
2266
+ calloc(sizeof(CrxTile) * nTiles + sizeof(CrxPlaneComp) * nTiles * img->nPlanes +
2267
+ sizeof(CrxSubband) * nTiles * img->nPlanes * img->subbandCount,
2268
+ 1);
2269
+ if (!img->tiles)
2270
+ return -1;
2271
+
2272
+ // memory areas in allocated chunk
2273
+ CrxTile *tile = img->tiles;
2274
+ CrxPlaneComp *comps = (CrxPlaneComp *)(tile + nTiles);
2275
+ CrxSubband *bands = (CrxSubband *)(comps + img->nPlanes * nTiles);
2276
+
2277
+ for (int curTile = 0; curTile < nTiles; curTile++, tile++)
2278
+ {
2279
+ tile->tileFlag = 0; // tile neighbouring flags
2280
+ tile->tileNumber = curTile;
2281
+ tile->tileSize = 0;
2282
+ tile->comps = comps + curTile * img->nPlanes;
2283
+
2284
+ if ((curTile + 1) % img->tileCols)
2285
+ {
2286
+ // not the last tile in a tile row
2287
+ tile->width = hdr->tileWidth;
2288
+ if (img->tileCols > 1)
2289
+ {
2290
+ tile->tileFlag = E_HAS_TILES_ON_THE_RIGHT;
2291
+ if (curTile % img->tileCols)
2292
+ // not the first tile in tile row
2293
+ tile->tileFlag |= E_HAS_TILES_ON_THE_LEFT;
2294
+ }
2295
+ }
2296
+ else
2297
+ {
2298
+ // last tile in a tile row
2299
+ tile->width = img->planeWidth - hdr->tileWidth * (img->tileCols - 1);
2300
+ if (img->tileCols > 1)
2301
+ tile->tileFlag = E_HAS_TILES_ON_THE_LEFT;
2302
+ }
2303
+ if (curTile < nTiles - img->tileCols)
2304
+ {
2305
+ // in first tile row
2306
+ tile->height = hdr->tileHeight;
2307
+ if (img->tileRows > 1)
2308
+ {
2309
+ tile->tileFlag |= E_HAS_TILES_ON_THE_BOTTOM;
2310
+ if (curTile >= img->tileCols)
2311
+ tile->tileFlag |= E_HAS_TILES_ON_THE_TOP;
2312
+ }
2313
+ }
2314
+ else
2315
+ {
2316
+ // non first tile row
2317
+ tile->height = img->planeHeight - hdr->tileHeight * (img->tileRows - 1);
2318
+ if (img->tileRows > 1)
2319
+ tile->tileFlag |= E_HAS_TILES_ON_THE_TOP;
2320
+ }
2321
+ if (img->nPlanes)
2322
+ {
2323
+ CrxPlaneComp *comp = tile->comps;
2324
+ CrxSubband *band = bands + curTile * img->nPlanes * img->subbandCount;
2325
+
2326
+ for (int curComp = 0; curComp < img->nPlanes; curComp++, comp++)
2327
+ {
2328
+ comp->compNumber = curComp;
2329
+ comp->supportsPartial = true;
2330
+ comp->tileFlag = tile->tileFlag;
2331
+ comp->subBands = band;
2332
+ comp->compBuf = 0;
2333
+ comp->wvltTransform = 0;
2334
+ if (img->subbandCount)
2335
+ {
2336
+ for (int curBand = 0; curBand < img->subbandCount; curBand++, band++)
2337
+ {
2338
+ band->supportsPartial = false;
2339
+ band->qParam = 4;
2340
+ band->bandParam = 0;
2341
+ band->dataSize = 0;
2342
+ }
2343
+ }
2344
+ }
2345
+ }
2346
+ }
2347
+ }
2348
+
2349
+ uint32_t tileOffset = 0;
2350
+ int32_t dataSize = mdatHdrSize;
2351
+ uint8_t *dataPtr = mdatPtr;
2352
+ CrxTile *tile = img->tiles;
2353
+
2354
+ for (int curTile = 0; curTile < nTiles; ++curTile, ++tile)
2355
+ {
2356
+ if (dataSize < 4)
2357
+ return -1;
2358
+
2359
+ int hdrSign = LibRaw::sgetn(2, dataPtr);
2360
+ int hdrSize = LibRaw::sgetn(2, dataPtr + 2);
2361
+ if ((hdrSign != 0xFF01 || hdrSize != 8) && (hdrSign != 0xFF11 || (hdrSize != 8 && hdrSize != 16)))
2362
+ return -1;
2363
+ if (dataSize < hdrSize + 4)
2364
+ return -1;
2365
+ int tailSign = LibRaw::sgetn(2, dataPtr + 10);
2366
+ if ((hdrSize == 8 && tailSign) || (hdrSize == 16 && tailSign != 0x4000))
2367
+ return -1;
2368
+ if (LibRaw::sgetn(2, dataPtr + 8) != (unsigned)curTile)
2369
+ return -1;
2370
+
2371
+ dataSize -= hdrSize + 4;
2372
+
2373
+ tile->tileSize = LibRaw::sgetn(4, dataPtr + 4);
2374
+ tile->dataOffset = tileOffset;
2375
+ tile->qStep = 0;
2376
+ if (hdrSize == 16)
2377
+ {
2378
+ // extended header data - terminated by 0 bytes
2379
+ if (LibRaw::sgetn(2, dataPtr + 18) != 0)
2380
+ return -1;
2381
+ tile->hasQPData = true;
2382
+ tile->mdatQPDataSize = LibRaw::sgetn(4, dataPtr + 12);
2383
+ tile->mdatExtraSize = LibRaw::sgetn(2, dataPtr + 16);
2384
+ }
2385
+ else
2386
+ {
2387
+ tile->hasQPData = false;
2388
+ tile->mdatQPDataSize = 0;
2389
+ tile->mdatExtraSize = 0;
2390
+ }
2391
+
2392
+ dataPtr += hdrSize + 4;
2393
+ tileOffset += tile->tileSize;
2394
+
2395
+ uint32_t compOffset = 0;
2396
+ CrxPlaneComp *comp = tile->comps;
2397
+
2398
+ for (int compNum = 0; compNum < img->nPlanes; ++compNum, ++comp)
2399
+ {
2400
+ if (dataSize < 0xC)
2401
+ return -1;
2402
+ hdrSign = LibRaw::sgetn(2, dataPtr);
2403
+ hdrSize = LibRaw::sgetn(2, dataPtr + 2);
2404
+ if ((hdrSign != 0xFF02 && hdrSign != 0xFF12) || hdrSize != 8)
2405
+ return -1;
2406
+ if (compNum != dataPtr[8] >> 4)
2407
+ return -1;
2408
+ if (LibRaw::sgetn(3, dataPtr + 9) != 0)
2409
+ return -1;
2410
+
2411
+ comp->compSize = LibRaw::sgetn(4, dataPtr + 4);
2412
+
2413
+ int32_t compHdrRoundedBits = (dataPtr[8] >> 1) & 3;
2414
+ comp->supportsPartial = (dataPtr[8] & 8) != 0;
2415
+
2416
+ comp->dataOffset = compOffset;
2417
+ comp->tileFlag = tile->tileFlag;
2418
+
2419
+ compOffset += comp->compSize;
2420
+ dataSize -= 0xC;
2421
+ dataPtr += 0xC;
2422
+
2423
+ comp->roundedBitsMask = 0;
2424
+
2425
+ if (compHdrRoundedBits)
2426
+ {
2427
+ if (img->levels || !comp->supportsPartial)
2428
+ return -1;
2429
+
2430
+ comp->roundedBitsMask = 1 << (compHdrRoundedBits - 1);
2431
+ }
2432
+
2433
+ if (crxReadSubbandHeaders(hdr, img, tile, comp, &dataPtr, &dataSize) || crxProcessSubbands(hdr, img, tile, comp))
2434
+ return -1;
2435
+ }
2436
+ }
2437
+
2438
+ if (hdr->version != 0x200)
2439
+ return 0;
2440
+
2441
+ tile = img->tiles;
2442
+ for (int curTile = 0; curTile < nTiles; ++curTile, ++tile)
2443
+ {
2444
+ if (tile->hasQPData)
2445
+ {
2446
+ CrxBitstream bitStrm;
2447
+ bitStrm.bitData = 0;
2448
+ bitStrm.bitsLeft = 0;
2449
+ bitStrm.curPos = 0;
2450
+ bitStrm.curBufSize = 0;
2451
+ bitStrm.mdatSize = tile->mdatQPDataSize;
2452
+ bitStrm.curBufOffset = img->mdatOffset + tile->dataOffset;
2453
+ bitStrm.input = img->input;
2454
+
2455
+ crxFillBuffer(&bitStrm);
2456
+
2457
+ unsigned int qpWidth = (tile->width >> 3) + ((tile->width & 7) != 0);
2458
+ unsigned int qpHeight = (tile->height >> 1) + (tile->height & 1);
2459
+ unsigned long totalQP = qpHeight * qpWidth;
2460
+
2461
+ try
2462
+ {
2463
+ std::vector<int32_t> qpTable(totalQP + 2 * (qpWidth + 2));
2464
+ int32_t *qpCurElem = qpTable.data();
2465
+ // 2 lines padded with extra pixels at the start and at the end
2466
+ int32_t *qpLineBuf = qpTable.data() + totalQP;
2467
+ int32_t kParam = 0;
2468
+ for (unsigned qpRow = 0; qpRow < qpHeight; ++qpRow)
2469
+ {
2470
+ int32_t *qpLine0 = qpRow & 1 ? qpLineBuf + qpWidth + 2 : qpLineBuf;
2471
+ int32_t *qpLine1 = qpRow & 1 ? qpLineBuf : qpLineBuf + qpWidth + 2;
2472
+
2473
+ if (qpRow)
2474
+ crxDecodeGolombNormal(&bitStrm, qpWidth, qpLine0, qpLine1, &kParam);
2475
+ else
2476
+ crxDecodeGolombTop(&bitStrm, qpWidth, qpLine1, &kParam);
2477
+
2478
+ for (unsigned qpCol = 0; qpCol < qpWidth; ++qpCol)
2479
+ *qpCurElem++ = qpLine1[qpCol + 1] + 4;
2480
+ }
2481
+
2482
+ // now we read QP data - build tile QStep
2483
+ if (crxMakeQStep(img, tile, qpTable.data(), totalQP))
2484
+ return -1;
2485
+ }
2486
+ catch (...)
2487
+ {
2488
+ return -1;
2489
+ }
2490
+ }
2491
+ }
2492
+
2493
+ return 0;
2494
+ }
2495
+
2496
+ int crxSetupImageData(crx_data_header_t *hdr, CrxImage *img, int16_t *outBuf, uint64_t mdatOffset, uint32_t mdatSize,
2497
+ uint8_t *mdatHdrPtr, int32_t mdatHdrSize)
2498
+ {
2499
+ int IncrBitTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0};
2500
+
2501
+ img->planeWidth = hdr->f_width;
2502
+ img->planeHeight = hdr->f_height;
2503
+
2504
+ if (hdr->tileWidth < 0x16 || hdr->tileHeight < 0x16 || img->planeWidth > 0x7FFF || img->planeHeight > 0x7FFF)
2505
+ return -1;
2506
+
2507
+ img->tileCols = (img->planeWidth + hdr->tileWidth - 1) / hdr->tileWidth;
2508
+ img->tileRows = (img->planeHeight + hdr->tileHeight - 1) / hdr->tileHeight;
2509
+
2510
+ if (img->tileCols > 0xFF || img->tileRows > 0xFF || img->planeWidth - hdr->tileWidth * (img->tileCols - 1) < 0x16 ||
2511
+ img->planeHeight - hdr->tileHeight * (img->tileRows - 1) < 0x16)
2512
+ return -1;
2513
+
2514
+ img->tiles = 0;
2515
+ img->levels = hdr->imageLevels;
2516
+ img->subbandCount = 3 * img->levels + 1; // 3 bands per level + one last LL
2517
+ img->nPlanes = hdr->nPlanes;
2518
+ img->nBits = hdr->nBits;
2519
+ img->encType = hdr->encType;
2520
+ img->samplePrecision = hdr->nBits + IncrBitTable[4 * hdr->encType + 2] + 1;
2521
+ img->mdatOffset = mdatOffset + hdr->mdatHdrSize;
2522
+ img->mdatSize = mdatSize;
2523
+ img->planeBuf = 0;
2524
+ img->outBufs[0] = img->outBufs[1] = img->outBufs[2] = img->outBufs[3] = 0;
2525
+ img->medianBits = hdr->medianBits;
2526
+
2527
+ // The encoding type 3 needs all 4 planes to be decoded to generate row of
2528
+ // RGGB values. It seems to be using some other colour space for raw encoding
2529
+ // It is a massive buffer so ideallly it will need a different approach:
2530
+ // decode planes line by line and convert single line then without
2531
+ // intermediate plane buffer. At the moment though it's too many changes so
2532
+ // left as is.
2533
+ if (img->encType == 3 && img->nPlanes == 4 && img->nBits > 8)
2534
+ {
2535
+ img->planeBuf = (int16_t *)
2536
+ #ifdef LIBRAW_CR3_MEMPOOL
2537
+ img->memmgr.
2538
+ #endif
2539
+ malloc(img->planeHeight * img->planeWidth * img->nPlanes * ((img->samplePrecision + 7) >> 3));
2540
+ if (!img->planeBuf)
2541
+ return -1;
2542
+ }
2543
+
2544
+ int32_t rowSize = 2 * img->planeWidth;
2545
+
2546
+ if (img->nPlanes == 1)
2547
+ img->outBufs[0] = outBuf;
2548
+ else
2549
+ switch (hdr->cfaLayout)
2550
+ {
2551
+ case 0:
2552
+ // R G
2553
+ // G B
2554
+ img->outBufs[0] = outBuf;
2555
+ img->outBufs[1] = outBuf + 1;
2556
+ img->outBufs[2] = outBuf + rowSize;
2557
+ img->outBufs[3] = img->outBufs[2] + 1;
2558
+ break;
2559
+ case 1:
2560
+ // G R
2561
+ // B G
2562
+ img->outBufs[1] = outBuf;
2563
+ img->outBufs[0] = outBuf + 1;
2564
+ img->outBufs[3] = outBuf + rowSize;
2565
+ img->outBufs[2] = img->outBufs[3] + 1;
2566
+ break;
2567
+ case 2:
2568
+ // G B
2569
+ // R G
2570
+ img->outBufs[2] = outBuf;
2571
+ img->outBufs[3] = outBuf + 1;
2572
+ img->outBufs[0] = outBuf + rowSize;
2573
+ img->outBufs[1] = img->outBufs[0] + 1;
2574
+ break;
2575
+ case 3:
2576
+ // B G
2577
+ // G R
2578
+ img->outBufs[3] = outBuf;
2579
+ img->outBufs[2] = outBuf + 1;
2580
+ img->outBufs[1] = outBuf + rowSize;
2581
+ img->outBufs[0] = img->outBufs[1] + 1;
2582
+ break;
2583
+ }
2584
+
2585
+ // read header
2586
+ return crxReadImageHeaders(hdr, img, mdatHdrPtr, mdatHdrSize);
2587
+ }
2588
+
2589
+ int crxFreeImageData(CrxImage *img)
2590
+ {
2591
+ #ifdef LIBRAW_CR3_MEMPOOL
2592
+ img->memmgr.cleanup();
2593
+ #else
2594
+ CrxTile *tile = img->tiles;
2595
+ int nTiles = img->tileRows * img->tileCols;
2596
+
2597
+ if (img->tiles)
2598
+ {
2599
+ for (int32_t curTile = 0; curTile < nTiles; curTile++)
2600
+ {
2601
+ if (tile[curTile].comps)
2602
+ for (int32_t curPlane = 0; curPlane < img->nPlanes; curPlane++)
2603
+ crxFreeSubbandData(img, tile[curTile].comps + curPlane);
2604
+ if (tile[curTile].qStep)
2605
+ free(tile[curTile].qStep);
2606
+ }
2607
+ free(img->tiles);
2608
+ img->tiles = 0;
2609
+ }
2610
+
2611
+ if (img->planeBuf)
2612
+ {
2613
+ free(img->planeBuf);
2614
+ img->planeBuf = 0;
2615
+ }
2616
+ #endif
2617
+ return 0;
2618
+ }
2619
+ void LibRaw::crxLoadDecodeLoop(void *img, int nPlanes)
2620
+ {
2621
+ #ifdef LIBRAW_USE_OPENMP
2622
+ int results[4] ={0,0,0,0}; // nPlanes is always <= 4
2623
+ #pragma omp parallel for
2624
+ for (int32_t plane = 0; plane < nPlanes; ++plane)
2625
+ try {
2626
+ results[plane] = crxDecodePlane(img, plane);
2627
+ } catch (...) {
2628
+ results[plane] = 1;
2629
+ }
2630
+
2631
+ for (int32_t plane = 0; plane < nPlanes; ++plane)
2632
+ if (results[plane])
2633
+ derror();
2634
+ #else
2635
+ for (int32_t plane = 0; plane < nPlanes; ++plane)
2636
+ if (crxDecodePlane(img, plane))
2637
+ derror();
2638
+ #endif
2639
+ }
2640
+
2641
+ void LibRaw::crxConvertPlaneLineDf(void *p, int imageRow) { crxConvertPlaneLine((CrxImage *)p, imageRow); }
2642
+
2643
+ void LibRaw::crxLoadFinalizeLoopE3(void *p, int planeHeight)
2644
+ {
2645
+ #ifdef LIBRAW_USE_OPENMP
2646
+ #pragma omp parallel for
2647
+ #endif
2648
+ for (int i = 0; i < planeHeight; ++i)
2649
+ crxConvertPlaneLineDf(p, i);
2650
+ }
2651
+
2652
+ void LibRaw::crxLoadRaw()
2653
+ {
2654
+ CrxImage img;
2655
+ if (libraw_internal_data.unpacker_data.crx_track_selected < 0 ||
2656
+ libraw_internal_data.unpacker_data.crx_track_selected >= LIBRAW_CRXTRACKS_MAXCOUNT)
2657
+ derror();
2658
+
2659
+ crx_data_header_t hdr =
2660
+ libraw_internal_data.unpacker_data.crx_header[libraw_internal_data.unpacker_data.crx_track_selected];
2661
+
2662
+ if (libraw_internal_data.unpacker_data.data_size < (unsigned)hdr.mdatHdrSize)
2663
+ derror();
2664
+
2665
+ img.input = libraw_internal_data.internal_data.input;
2666
+
2667
+ // update sizes for the planes
2668
+ if (hdr.nPlanes == 4)
2669
+ {
2670
+ hdr.f_width >>= 1;
2671
+ hdr.f_height >>= 1;
2672
+ hdr.tileWidth >>= 1;
2673
+ hdr.tileHeight >>= 1;
2674
+ }
2675
+
2676
+ imgdata.color.maximum = (1 << hdr.nBits) - 1;
2677
+
2678
+ std::vector<uint8_t> hdrBuf(hdr.mdatHdrSize);
2679
+
2680
+ unsigned bytes = 0;
2681
+ // read image header
2682
+ #ifdef LIBRAW_USE_OPENMP
2683
+ #pragma omp critical
2684
+ #endif
2685
+ {
2686
+ #ifndef LIBRAW_USE_OPENMP
2687
+ libraw_internal_data.internal_data.input->lock();
2688
+ #endif
2689
+ libraw_internal_data.internal_data.input->seek(libraw_internal_data.unpacker_data.data_offset, SEEK_SET);
2690
+ bytes = libraw_internal_data.internal_data.input->read(hdrBuf.data(), 1, hdr.mdatHdrSize);
2691
+ #ifndef LIBRAW_USE_OPENMP
2692
+ libraw_internal_data.internal_data.input->unlock();
2693
+ #endif
2694
+ }
2695
+
2696
+ if (bytes != hdr.mdatHdrSize)
2697
+ throw LIBRAW_EXCEPTION_IO_EOF;
2698
+
2699
+ // parse and setup the image data
2700
+ if (crxSetupImageData(&hdr, &img, (int16_t *)imgdata.rawdata.raw_image,
2701
+ libraw_internal_data.unpacker_data.data_offset, libraw_internal_data.unpacker_data.data_size,
2702
+ hdrBuf.data(), hdr.mdatHdrSize))
2703
+ throw LIBRAW_EXCEPTION_IO_CORRUPT;
2704
+
2705
+ crxLoadDecodeLoop(&img, hdr.nPlanes);
2706
+
2707
+ if (img.encType == 3)
2708
+ crxLoadFinalizeLoopE3(&img, img.planeHeight);
2709
+
2710
+ crxFreeImageData(&img);
2711
+ }
2712
+
2713
+ int LibRaw::crxParseImageHeader(uchar *cmp1TagData, int nTrack, int size)
2714
+ {
2715
+ if (nTrack < 0 || nTrack >= LIBRAW_CRXTRACKS_MAXCOUNT)
2716
+ return -1;
2717
+ if (!cmp1TagData)
2718
+ return -1;
2719
+
2720
+ crx_data_header_t *hdr = &libraw_internal_data.unpacker_data.crx_header[nTrack];
2721
+
2722
+ hdr->version = sgetn(2, cmp1TagData + 4);
2723
+ hdr->f_width = sgetn(4, cmp1TagData + 8);
2724
+ hdr->f_height = sgetn(4, cmp1TagData + 12);
2725
+ hdr->tileWidth = sgetn(4, cmp1TagData + 16);
2726
+ hdr->tileHeight = sgetn(4, cmp1TagData + 20);
2727
+ hdr->nBits = cmp1TagData[24];
2728
+ hdr->nPlanes = cmp1TagData[25] >> 4;
2729
+ hdr->cfaLayout = cmp1TagData[25] & 0xF;
2730
+ hdr->encType = cmp1TagData[26] >> 4;
2731
+ hdr->imageLevels = cmp1TagData[26] & 0xF;
2732
+ hdr->hasTileCols = cmp1TagData[27] >> 7;
2733
+ hdr->hasTileRows = (cmp1TagData[27] >> 6) & 1;
2734
+ hdr->mdatHdrSize = sgetn(4, cmp1TagData + 28);
2735
+ int extHeader = cmp1TagData[32] >> 7;
2736
+ int useMedianBits = 0;
2737
+ hdr->medianBits = hdr->nBits;
2738
+
2739
+ if (extHeader && size >= 56 && hdr->nPlanes == 4)
2740
+ useMedianBits = cmp1TagData[56] >> 6 & 1;
2741
+
2742
+ if (useMedianBits && size >= 84)
2743
+ hdr->medianBits = cmp1TagData[84];
2744
+
2745
+ // validation
2746
+ if ((hdr->version != 0x100 && hdr->version != 0x200) || !hdr->mdatHdrSize)
2747
+ return -1;
2748
+ if (hdr->encType == 1)
2749
+ {
2750
+ if (hdr->nBits > 15)
2751
+ return -1;
2752
+ }
2753
+ else
2754
+ {
2755
+ if (hdr->encType && hdr->encType != 3)
2756
+ return -1;
2757
+ if (hdr->nBits > 14)
2758
+ return -1;
2759
+ }
2760
+
2761
+ if (hdr->nPlanes == 1)
2762
+ {
2763
+ if (hdr->cfaLayout || hdr->encType || hdr->nBits != 8)
2764
+ return -1;
2765
+ }
2766
+ else if (hdr->nPlanes != 4 || hdr->f_width & 1 || hdr->f_height & 1 || hdr->tileWidth & 1 || hdr->tileHeight & 1 ||
2767
+ hdr->cfaLayout > 3 || hdr->nBits == 8)
2768
+ return -1;
2769
+
2770
+ if (hdr->tileWidth > hdr->f_width || hdr->tileHeight > hdr->f_height)
2771
+ return -1;
2772
+
2773
+ if (hdr->imageLevels > 3 || hdr->hasTileCols > 1 || hdr->hasTileRows > 1)
2774
+ return -1;
2775
+ return 0;
2776
+ }
2777
+
2778
+ #undef _abs
2779
+ #undef _min
2780
+ #undef _constrain
2781
+ #undef libraw_inline