koffi 2.1.3 → 2.1.5

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 (374) hide show
  1. package/ChangeLog.md +17 -0
  2. package/doc/contribute.md +5 -5
  3. package/doc/index.rst +1 -1
  4. package/doc/memory.md +1 -0
  5. package/doc/templates/badges.html +1 -1
  6. package/package.json +44 -68
  7. package/src/cnoke/LICENSE.txt +661 -0
  8. package/src/cnoke/README.md +97 -0
  9. package/src/cnoke/assets/FindCNoke.cmake +71 -0
  10. package/src/cnoke/assets/win_delay_hook.c +34 -0
  11. package/src/cnoke/cnoke.js +968 -0
  12. package/src/cnoke/package.json +25 -0
  13. package/{vendor → src/core}/libcc/libcc.cc +38 -11
  14. package/{vendor → src/core}/libcc/libcc.hh +4 -2
  15. package/{CMakeLists.txt → src/koffi/CMakeLists.txt} +3 -3
  16. package/{benchmark → src/koffi/benchmark}/CMakeLists.txt +9 -6
  17. package/{benchmark → src/koffi/benchmark}/atoi_koffi.js +0 -0
  18. package/{benchmark → src/koffi/benchmark}/atoi_napi.cc +1 -1
  19. package/{benchmark → src/koffi/benchmark}/atoi_napi.js +0 -0
  20. package/{benchmark → src/koffi/benchmark}/atoi_node_ffi.js +0 -0
  21. package/src/koffi/benchmark/benchmark.js +118 -0
  22. package/src/koffi/benchmark/rand_koffi.js +52 -0
  23. package/src/koffi/benchmark/rand_napi.cc +69 -0
  24. package/src/koffi/benchmark/rand_napi.js +47 -0
  25. package/src/koffi/benchmark/rand_node_ffi.js +55 -0
  26. package/{benchmark → src/koffi/benchmark}/raylib_cc.cc +2 -2
  27. package/{benchmark → src/koffi/benchmark}/raylib_cc.js +0 -0
  28. package/{benchmark → src/koffi/benchmark}/raylib_koffi.js +0 -0
  29. package/{benchmark → src/koffi/benchmark}/raylib_node_ffi.js +0 -0
  30. package/{benchmark → src/koffi/benchmark}/raylib_node_raylib.js +0 -0
  31. package/src/koffi/build/2.1.5/koffi_darwin_arm64.tar.gz +0 -0
  32. package/src/koffi/build/2.1.5/koffi_darwin_x64.tar.gz +0 -0
  33. package/src/koffi/build/2.1.5/koffi_freebsd_arm64.tar.gz +0 -0
  34. package/src/koffi/build/2.1.5/koffi_freebsd_ia32.tar.gz +0 -0
  35. package/src/koffi/build/2.1.5/koffi_freebsd_x64.tar.gz +0 -0
  36. package/src/koffi/build/2.1.5/koffi_linux_arm32hf.tar.gz +0 -0
  37. package/src/koffi/build/2.1.5/koffi_linux_arm64.tar.gz +0 -0
  38. package/src/koffi/build/2.1.5/koffi_linux_ia32.tar.gz +0 -0
  39. package/src/koffi/build/2.1.5/koffi_linux_riscv64hf64.tar.gz +0 -0
  40. package/src/koffi/build/2.1.5/koffi_linux_x64.tar.gz +0 -0
  41. package/src/koffi/build/2.1.5/koffi_openbsd_ia32.tar.gz +0 -0
  42. package/src/koffi/build/2.1.5/koffi_openbsd_x64.tar.gz +0 -0
  43. package/src/koffi/build/2.1.5/koffi_win32_arm64.tar.gz +0 -0
  44. package/src/koffi/build/2.1.5/koffi_win32_ia32.tar.gz +0 -0
  45. package/src/koffi/build/2.1.5/koffi_win32_x64.tar.gz +0 -0
  46. package/src/koffi/qemu/qemu/.gitkeep +0 -0
  47. package/{qemu → src/koffi/qemu}/qemu.js +227 -133
  48. package/{qemu → src/koffi/qemu}/registry/machines.json +24 -0
  49. package/{qemu → src/koffi/qemu}/registry/sha256sum.txt +0 -0
  50. package/src/{abi_arm32.cc → koffi/src/abi_arm32.cc} +1 -1
  51. package/src/{abi_arm32_fwd.S → koffi/src/abi_arm32_fwd.S} +0 -0
  52. package/src/{abi_arm64.cc → koffi/src/abi_arm64.cc} +1 -1
  53. package/src/{abi_arm64_fwd.S → koffi/src/abi_arm64_fwd.S} +0 -0
  54. package/src/{abi_arm64_fwd.asm → koffi/src/abi_arm64_fwd.asm} +0 -0
  55. package/src/{abi_riscv64.cc → koffi/src/abi_riscv64.cc} +1 -1
  56. package/src/{abi_riscv64_fwd.S → koffi/src/abi_riscv64_fwd.S} +0 -0
  57. package/src/{abi_x64_sysv.cc → koffi/src/abi_x64_sysv.cc} +1 -1
  58. package/src/{abi_x64_sysv_fwd.S → koffi/src/abi_x64_sysv_fwd.S} +0 -0
  59. package/src/{abi_x64_win.cc → koffi/src/abi_x64_win.cc} +1 -1
  60. package/src/{abi_x64_win_fwd.asm → koffi/src/abi_x64_win_fwd.asm} +0 -0
  61. package/src/{abi_x86.cc → koffi/src/abi_x86.cc} +1 -1
  62. package/src/{abi_x86_fwd.S → koffi/src/abi_x86_fwd.S} +0 -0
  63. package/src/{abi_x86_fwd.asm → koffi/src/abi_x86_fwd.asm} +0 -0
  64. package/src/{call.cc → koffi/src/call.cc} +1 -1
  65. package/src/{call.hh → koffi/src/call.hh} +2 -2
  66. package/src/{ffi.cc → koffi/src/ffi.cc} +34 -18
  67. package/src/{ffi.hh → koffi/src/ffi.hh} +5 -3
  68. package/src/{index.js → koffi/src/index.js} +0 -0
  69. package/src/{parser.cc → koffi/src/parser.cc} +1 -1
  70. package/src/{parser.hh → koffi/src/parser.hh} +1 -1
  71. package/src/{util.cc → koffi/src/util.cc} +1 -1
  72. package/src/{util.hh → koffi/src/util.hh} +1 -1
  73. package/{test → src/koffi/test}/CMakeLists.txt +14 -15
  74. package/{test → src/koffi/test}/async.js +0 -0
  75. package/{test → src/koffi/test}/callbacks.js +0 -0
  76. package/{test → src/koffi/test}/misc.c +13 -0
  77. package/{test → src/koffi/test}/misc.def +0 -0
  78. package/{test → src/koffi/test}/raylib.js +0 -0
  79. package/{test → src/koffi/test}/sqlite.js +1 -1
  80. package/{test → src/koffi/test}/sync.js +17 -0
  81. package/vendor/brotli/BUILD +144 -0
  82. package/vendor/brotli/CMakeLists.txt +421 -0
  83. package/vendor/brotli/CONTRIBUTING.md +27 -0
  84. package/vendor/brotli/LICENSE +19 -0
  85. package/vendor/brotli/MANIFEST.in +17 -0
  86. package/vendor/brotli/Makefile +55 -0
  87. package/vendor/brotli/Makefile.am +38 -0
  88. package/vendor/brotli/README +15 -0
  89. package/vendor/brotli/README.md +104 -0
  90. package/vendor/brotli/WORKSPACE +21 -0
  91. package/vendor/brotli/bootstrap +35 -0
  92. package/vendor/brotli/c/common/constants.c +15 -0
  93. package/vendor/brotli/c/common/constants.h +200 -0
  94. package/vendor/brotli/c/common/context.c +156 -0
  95. package/vendor/brotli/c/common/context.h +113 -0
  96. package/vendor/brotli/c/common/dictionary.c +5914 -0
  97. package/vendor/brotli/c/common/dictionary.h +64 -0
  98. package/vendor/brotli/c/common/platform.c +22 -0
  99. package/vendor/brotli/c/common/platform.h +594 -0
  100. package/vendor/brotli/c/common/transform.c +291 -0
  101. package/vendor/brotli/c/common/transform.h +85 -0
  102. package/vendor/brotli/c/common/version.h +26 -0
  103. package/vendor/brotli/c/dec/bit_reader.c +76 -0
  104. package/vendor/brotli/c/dec/bit_reader.h +351 -0
  105. package/vendor/brotli/c/dec/decode.c +2608 -0
  106. package/vendor/brotli/c/dec/huffman.c +339 -0
  107. package/vendor/brotli/c/dec/huffman.h +121 -0
  108. package/vendor/brotli/c/dec/prefix.h +732 -0
  109. package/vendor/brotli/c/dec/state.c +159 -0
  110. package/vendor/brotli/c/dec/state.h +365 -0
  111. package/vendor/brotli/c/enc/backward_references.c +145 -0
  112. package/vendor/brotli/c/enc/backward_references.h +39 -0
  113. package/vendor/brotli/c/enc/backward_references_hq.c +843 -0
  114. package/vendor/brotli/c/enc/backward_references_hq.h +95 -0
  115. package/vendor/brotli/c/enc/backward_references_inc.h +163 -0
  116. package/vendor/brotli/c/enc/bit_cost.c +35 -0
  117. package/vendor/brotli/c/enc/bit_cost.h +63 -0
  118. package/vendor/brotli/c/enc/bit_cost_inc.h +127 -0
  119. package/vendor/brotli/c/enc/block_encoder_inc.h +34 -0
  120. package/vendor/brotli/c/enc/block_splitter.c +194 -0
  121. package/vendor/brotli/c/enc/block_splitter.h +51 -0
  122. package/vendor/brotli/c/enc/block_splitter_inc.h +440 -0
  123. package/vendor/brotli/c/enc/brotli_bit_stream.c +1314 -0
  124. package/vendor/brotli/c/enc/brotli_bit_stream.h +84 -0
  125. package/vendor/brotli/c/enc/cluster.c +56 -0
  126. package/vendor/brotli/c/enc/cluster.h +48 -0
  127. package/vendor/brotli/c/enc/cluster_inc.h +320 -0
  128. package/vendor/brotli/c/enc/command.c +28 -0
  129. package/vendor/brotli/c/enc/command.h +190 -0
  130. package/vendor/brotli/c/enc/compress_fragment.c +790 -0
  131. package/vendor/brotli/c/enc/compress_fragment.h +61 -0
  132. package/vendor/brotli/c/enc/compress_fragment_two_pass.c +645 -0
  133. package/vendor/brotli/c/enc/compress_fragment_two_pass.h +54 -0
  134. package/vendor/brotli/c/enc/dictionary_hash.c +1846 -0
  135. package/vendor/brotli/c/enc/dictionary_hash.h +25 -0
  136. package/vendor/brotli/c/enc/encode.c +1927 -0
  137. package/vendor/brotli/c/enc/encoder_dict.c +33 -0
  138. package/vendor/brotli/c/enc/encoder_dict.h +43 -0
  139. package/vendor/brotli/c/enc/entropy_encode.c +503 -0
  140. package/vendor/brotli/c/enc/entropy_encode.h +122 -0
  141. package/vendor/brotli/c/enc/entropy_encode_static.h +539 -0
  142. package/vendor/brotli/c/enc/fast_log.c +105 -0
  143. package/vendor/brotli/c/enc/fast_log.h +66 -0
  144. package/vendor/brotli/c/enc/find_match_length.h +79 -0
  145. package/vendor/brotli/c/enc/hash.h +488 -0
  146. package/vendor/brotli/c/enc/hash_composite_inc.h +125 -0
  147. package/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +293 -0
  148. package/vendor/brotli/c/enc/hash_longest_match64_inc.h +267 -0
  149. package/vendor/brotli/c/enc/hash_longest_match_inc.h +262 -0
  150. package/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +266 -0
  151. package/vendor/brotli/c/enc/hash_rolling_inc.h +212 -0
  152. package/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +329 -0
  153. package/vendor/brotli/c/enc/histogram.c +100 -0
  154. package/vendor/brotli/c/enc/histogram.h +63 -0
  155. package/vendor/brotli/c/enc/histogram_inc.h +51 -0
  156. package/vendor/brotli/c/enc/literal_cost.c +175 -0
  157. package/vendor/brotli/c/enc/literal_cost.h +30 -0
  158. package/vendor/brotli/c/enc/memory.c +170 -0
  159. package/vendor/brotli/c/enc/memory.h +114 -0
  160. package/vendor/brotli/c/enc/metablock.c +663 -0
  161. package/vendor/brotli/c/enc/metablock.h +105 -0
  162. package/vendor/brotli/c/enc/metablock_inc.h +183 -0
  163. package/vendor/brotli/c/enc/params.h +46 -0
  164. package/vendor/brotli/c/enc/prefix.h +53 -0
  165. package/vendor/brotli/c/enc/quality.h +165 -0
  166. package/vendor/brotli/c/enc/ringbuffer.h +167 -0
  167. package/vendor/brotli/c/enc/static_dict.c +486 -0
  168. package/vendor/brotli/c/enc/static_dict.h +40 -0
  169. package/vendor/brotli/c/enc/static_dict_lut.h +5864 -0
  170. package/vendor/brotli/c/enc/utf8_util.c +85 -0
  171. package/vendor/brotli/c/enc/utf8_util.h +32 -0
  172. package/vendor/brotli/c/enc/write_bits.h +87 -0
  173. package/vendor/brotli/c/include/brotli/decode.h +344 -0
  174. package/vendor/brotli/c/include/brotli/encode.h +448 -0
  175. package/vendor/brotli/c/include/brotli/port.h +288 -0
  176. package/vendor/brotli/c/include/brotli/types.h +83 -0
  177. package/vendor/brotli/c/tools/brotli.c +1116 -0
  178. package/vendor/brotli/c/tools/brotli.md +107 -0
  179. package/vendor/brotli/compiler_config_setting.bzl +28 -0
  180. package/vendor/brotli/configure +8 -0
  181. package/vendor/brotli/configure-cmake +318 -0
  182. package/vendor/brotli/configure.ac +14 -0
  183. package/vendor/brotli/docs/brotli.1 +132 -0
  184. package/vendor/brotli/docs/constants.h.3 +47 -0
  185. package/vendor/brotli/docs/decode.h.3 +415 -0
  186. package/vendor/brotli/docs/encode.h.3 +586 -0
  187. package/vendor/brotli/docs/types.h.3 +117 -0
  188. package/vendor/brotli/premake5.lua +78 -0
  189. package/vendor/brotli/python/Makefile +57 -0
  190. package/vendor/brotli/python/README.md +54 -0
  191. package/vendor/brotli/python/_brotli.cc +753 -0
  192. package/vendor/brotli/python/bro.py +160 -0
  193. package/vendor/brotli/python/brotli.py +56 -0
  194. package/vendor/brotli/python/tests/__init__.py +0 -0
  195. package/vendor/brotli/python/tests/_test_utils.py +112 -0
  196. package/vendor/brotli/python/tests/bro_test.py +102 -0
  197. package/vendor/brotli/python/tests/compress_test.py +41 -0
  198. package/vendor/brotli/python/tests/compressor_test.py +94 -0
  199. package/vendor/brotli/python/tests/decompress_test.py +42 -0
  200. package/vendor/brotli/python/tests/decompressor_test.py +59 -0
  201. package/vendor/brotli/scripts/libbrotlicommon.pc.in +11 -0
  202. package/vendor/brotli/scripts/libbrotlidec.pc.in +12 -0
  203. package/vendor/brotli/scripts/libbrotlienc.pc.in +12 -0
  204. package/vendor/brotli/scripts/sources.lst +104 -0
  205. package/vendor/brotli/setup.cfg +5 -0
  206. package/vendor/brotli/setup.py +293 -0
  207. package/vendor/brotli/tests/Makefile +17 -0
  208. package/vendor/brotli/tests/compatibility_test.sh +25 -0
  209. package/vendor/brotli/tests/roundtrip_test.sh +36 -0
  210. package/vendor/brotli/tests/run-compatibility-test.cmake +31 -0
  211. package/vendor/brotli/tests/run-roundtrip-test.cmake +36 -0
  212. package/vendor/brotli/tests/testdata/empty +0 -0
  213. package/vendor/brotli/tests/testdata/empty.compressed +1 -0
  214. package/vendor/brotli/tests/testdata/ukkonooa +1 -0
  215. package/vendor/brotli/tests/testdata/ukkonooa.compressed +0 -0
  216. package/vendor/miniz/ChangeLog.md +235 -0
  217. package/vendor/miniz/LICENSE +22 -0
  218. package/vendor/miniz/examples/example1.c +105 -0
  219. package/vendor/miniz/examples/example2.c +164 -0
  220. package/vendor/miniz/examples/example3.c +269 -0
  221. package/vendor/miniz/examples/example4.c +102 -0
  222. package/vendor/miniz/examples/example5.c +327 -0
  223. package/vendor/miniz/examples/example6.c +166 -0
  224. package/vendor/miniz/miniz.c +7835 -0
  225. package/vendor/miniz/miniz.h +1422 -0
  226. package/vendor/miniz/readme.md +46 -0
  227. package/vendor/{sqlite3 → sqlite3mc}/sqlite3ext.h +18 -2
  228. package/vendor/{sqlite3/sqlite3.c → sqlite3mc/sqlite3mc.c} +60872 -4890
  229. package/vendor/sqlite3mc/sqlite3mc.def +312 -0
  230. package/vendor/{sqlite3/sqlite3.h → sqlite3mc/sqlite3mc.h} +480 -36
  231. package/build/qemu/2.1.3/koffi_darwin_arm64.tar.gz +0 -0
  232. package/build/qemu/2.1.3/koffi_darwin_x64.tar.gz +0 -0
  233. package/build/qemu/2.1.3/koffi_freebsd_arm64.tar.gz +0 -0
  234. package/build/qemu/2.1.3/koffi_freebsd_ia32.tar.gz +0 -0
  235. package/build/qemu/2.1.3/koffi_freebsd_x64.tar.gz +0 -0
  236. package/build/qemu/2.1.3/koffi_linux_arm32hf.tar.gz +0 -0
  237. package/build/qemu/2.1.3/koffi_linux_arm64.tar.gz +0 -0
  238. package/build/qemu/2.1.3/koffi_linux_ia32.tar.gz +0 -0
  239. package/build/qemu/2.1.3/koffi_linux_riscv64hf64.tar.gz +0 -0
  240. package/build/qemu/2.1.3/koffi_linux_x64.tar.gz +0 -0
  241. package/build/qemu/2.1.3/koffi_openbsd_ia32.tar.gz +0 -0
  242. package/build/qemu/2.1.3/koffi_openbsd_x64.tar.gz +0 -0
  243. package/build/qemu/2.1.3/koffi_win32_arm64.tar.gz +0 -0
  244. package/build/qemu/2.1.3/koffi_win32_ia32.tar.gz +0 -0
  245. package/build/qemu/2.1.3/koffi_win32_x64.tar.gz +0 -0
  246. package/vendor/_patches/glfw_001_fix_openbsd_xlib_soname.patch +0 -145
  247. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj +0 -226
  248. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.filters +0 -10
  249. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.user +0 -4
  250. package/vendor/raylib/projects/VS2019-Android/raylib_android.sln +0 -75
  251. package/vendor/raylib/projects/VS2022/examples/audio_module_playing.vcxproj +0 -390
  252. package/vendor/raylib/projects/VS2022/examples/audio_multichannel_sound.vcxproj +0 -390
  253. package/vendor/raylib/projects/VS2022/examples/audio_music_stream.vcxproj +0 -390
  254. package/vendor/raylib/projects/VS2022/examples/audio_raw_stream.vcxproj +0 -390
  255. package/vendor/raylib/projects/VS2022/examples/audio_sound_loading.vcxproj +0 -390
  256. package/vendor/raylib/projects/VS2022/examples/audio_stream_effects.vcxproj +0 -390
  257. package/vendor/raylib/projects/VS2022/examples/core_2d_camera.vcxproj +0 -390
  258. package/vendor/raylib/projects/VS2022/examples/core_2d_camera_mouse_zoom.vcxproj +0 -390
  259. package/vendor/raylib/projects/VS2022/examples/core_2d_camera_platformer.vcxproj +0 -390
  260. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_first_person.vcxproj +0 -390
  261. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_free.vcxproj +0 -390
  262. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_mode.vcxproj +0 -390
  263. package/vendor/raylib/projects/VS2022/examples/core_3d_picking.vcxproj +0 -390
  264. package/vendor/raylib/projects/VS2022/examples/core_basic_screen_manager.vcxproj +0 -390
  265. package/vendor/raylib/projects/VS2022/examples/core_basic_window.vcxproj +0 -390
  266. package/vendor/raylib/projects/VS2022/examples/core_custom_frame_control.vcxproj +0 -390
  267. package/vendor/raylib/projects/VS2022/examples/core_custom_logging.vcxproj +0 -390
  268. package/vendor/raylib/projects/VS2022/examples/core_drop_files.vcxproj +0 -390
  269. package/vendor/raylib/projects/VS2022/examples/core_input_gamepad.vcxproj +0 -387
  270. package/vendor/raylib/projects/VS2022/examples/core_input_gestures.vcxproj +0 -387
  271. package/vendor/raylib/projects/VS2022/examples/core_input_keys.vcxproj +0 -387
  272. package/vendor/raylib/projects/VS2022/examples/core_input_mouse.vcxproj +0 -387
  273. package/vendor/raylib/projects/VS2022/examples/core_input_mouse_wheel.vcxproj +0 -387
  274. package/vendor/raylib/projects/VS2022/examples/core_input_multitouch.vcxproj +0 -387
  275. package/vendor/raylib/projects/VS2022/examples/core_loading_thread.vcxproj +0 -387
  276. package/vendor/raylib/projects/VS2022/examples/core_random_values.vcxproj +0 -387
  277. package/vendor/raylib/projects/VS2022/examples/core_scissor_test.vcxproj +0 -387
  278. package/vendor/raylib/projects/VS2022/examples/core_split_screen.vcxproj +0 -387
  279. package/vendor/raylib/projects/VS2022/examples/core_storage_values.vcxproj +0 -387
  280. package/vendor/raylib/projects/VS2022/examples/core_vr_simulator.vcxproj +0 -387
  281. package/vendor/raylib/projects/VS2022/examples/core_window_flags.vcxproj +0 -387
  282. package/vendor/raylib/projects/VS2022/examples/core_window_letterbox.vcxproj +0 -387
  283. package/vendor/raylib/projects/VS2022/examples/core_window_should_close.vcxproj +0 -390
  284. package/vendor/raylib/projects/VS2022/examples/core_world_screen.vcxproj +0 -387
  285. package/vendor/raylib/projects/VS2022/examples/easings_testbed.vcxproj +0 -387
  286. package/vendor/raylib/projects/VS2022/examples/embedded_files_loading.vcxproj +0 -387
  287. package/vendor/raylib/projects/VS2022/examples/models_animation.vcxproj +0 -387
  288. package/vendor/raylib/projects/VS2022/examples/models_billboard.vcxproj +0 -387
  289. package/vendor/raylib/projects/VS2022/examples/models_box_collisions.vcxproj +0 -387
  290. package/vendor/raylib/projects/VS2022/examples/models_cubicmap.vcxproj +0 -387
  291. package/vendor/raylib/projects/VS2022/examples/models_first_person_maze.vcxproj +0 -387
  292. package/vendor/raylib/projects/VS2022/examples/models_geometric_shapes.vcxproj +0 -387
  293. package/vendor/raylib/projects/VS2022/examples/models_heightmap.vcxproj +0 -387
  294. package/vendor/raylib/projects/VS2022/examples/models_loading.vcxproj +0 -387
  295. package/vendor/raylib/projects/VS2022/examples/models_loading_gltf.vcxproj +0 -387
  296. package/vendor/raylib/projects/VS2022/examples/models_loading_vox.vcxproj +0 -387
  297. package/vendor/raylib/projects/VS2022/examples/models_mesh_generation.vcxproj +0 -387
  298. package/vendor/raylib/projects/VS2022/examples/models_mesh_picking.vcxproj +0 -387
  299. package/vendor/raylib/projects/VS2022/examples/models_orthographic_projection.vcxproj +0 -387
  300. package/vendor/raylib/projects/VS2022/examples/models_rlgl_solar_system.vcxproj +0 -387
  301. package/vendor/raylib/projects/VS2022/examples/models_skybox.vcxproj +0 -387
  302. package/vendor/raylib/projects/VS2022/examples/models_waving_cubes.vcxproj +0 -387
  303. package/vendor/raylib/projects/VS2022/examples/models_yaw_pitch_roll.vcxproj +0 -387
  304. package/vendor/raylib/projects/VS2022/examples/rlgl_compute_shaders.vcxproj +0 -391
  305. package/vendor/raylib/projects/VS2022/examples/rlgl_standalone.vcxproj +0 -391
  306. package/vendor/raylib/projects/VS2022/examples/shaders_basic_lighting.vcxproj +0 -387
  307. package/vendor/raylib/projects/VS2022/examples/shaders_custom_uniform.vcxproj +0 -387
  308. package/vendor/raylib/projects/VS2022/examples/shaders_eratosthenes.vcxproj +0 -387
  309. package/vendor/raylib/projects/VS2022/examples/shaders_fog.vcxproj +0 -387
  310. package/vendor/raylib/projects/VS2022/examples/shaders_hot_reloading.vcxproj +0 -387
  311. package/vendor/raylib/projects/VS2022/examples/shaders_julia_set.vcxproj +0 -387
  312. package/vendor/raylib/projects/VS2022/examples/shaders_mesh_instancing.vcxproj +0 -387
  313. package/vendor/raylib/projects/VS2022/examples/shaders_model_shader.vcxproj +0 -387
  314. package/vendor/raylib/projects/VS2022/examples/shaders_multi_sample2d.vcxproj +0 -387
  315. package/vendor/raylib/projects/VS2022/examples/shaders_palette_switch.vcxproj +0 -387
  316. package/vendor/raylib/projects/VS2022/examples/shaders_postprocessing.vcxproj +0 -387
  317. package/vendor/raylib/projects/VS2022/examples/shaders_raymarching.vcxproj +0 -387
  318. package/vendor/raylib/projects/VS2022/examples/shaders_shapes_textures.vcxproj +0 -387
  319. package/vendor/raylib/projects/VS2022/examples/shaders_simple_mask.vcxproj +0 -387
  320. package/vendor/raylib/projects/VS2022/examples/shaders_spotlight.vcxproj +0 -387
  321. package/vendor/raylib/projects/VS2022/examples/shaders_texture_drawing.vcxproj +0 -387
  322. package/vendor/raylib/projects/VS2022/examples/shaders_texture_waves.vcxproj +0 -387
  323. package/vendor/raylib/projects/VS2022/examples/shapes_basic_shapes.vcxproj +0 -387
  324. package/vendor/raylib/projects/VS2022/examples/shapes_bouncing_ball.vcxproj +0 -387
  325. package/vendor/raylib/projects/VS2022/examples/shapes_collision_area.vcxproj +0 -387
  326. package/vendor/raylib/projects/VS2022/examples/shapes_colors_palette.vcxproj +0 -387
  327. package/vendor/raylib/projects/VS2022/examples/shapes_draw_circle_sector.vcxproj +0 -387
  328. package/vendor/raylib/projects/VS2022/examples/shapes_draw_rectangle_rounded.vcxproj +0 -387
  329. package/vendor/raylib/projects/VS2022/examples/shapes_draw_ring.vcxproj +0 -387
  330. package/vendor/raylib/projects/VS2022/examples/shapes_easings_ball_anim.vcxproj +0 -387
  331. package/vendor/raylib/projects/VS2022/examples/shapes_easings_box_anim.vcxproj +0 -387
  332. package/vendor/raylib/projects/VS2022/examples/shapes_easings_rectangle_array.vcxproj +0 -387
  333. package/vendor/raylib/projects/VS2022/examples/shapes_following_eyes.vcxproj +0 -387
  334. package/vendor/raylib/projects/VS2022/examples/shapes_lines_bezier.vcxproj +0 -387
  335. package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib.vcxproj +0 -387
  336. package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib_anim.vcxproj +0 -387
  337. package/vendor/raylib/projects/VS2022/examples/shapes_rectangle_scaling.vcxproj +0 -387
  338. package/vendor/raylib/projects/VS2022/examples/text_codepoints_loading.vcxproj +0 -387
  339. package/vendor/raylib/projects/VS2022/examples/text_draw_3d.vcxproj +0 -387
  340. package/vendor/raylib/projects/VS2022/examples/text_font_filters.vcxproj +0 -387
  341. package/vendor/raylib/projects/VS2022/examples/text_font_loading.vcxproj +0 -387
  342. package/vendor/raylib/projects/VS2022/examples/text_font_sdf.vcxproj +0 -387
  343. package/vendor/raylib/projects/VS2022/examples/text_font_spritefont.vcxproj +0 -387
  344. package/vendor/raylib/projects/VS2022/examples/text_format_text.vcxproj +0 -387
  345. package/vendor/raylib/projects/VS2022/examples/text_input_box.vcxproj +0 -387
  346. package/vendor/raylib/projects/VS2022/examples/text_raylib_fonts.vcxproj +0 -387
  347. package/vendor/raylib/projects/VS2022/examples/text_rectangle_bounds.vcxproj +0 -387
  348. package/vendor/raylib/projects/VS2022/examples/text_unicode.vcxproj +0 -387
  349. package/vendor/raylib/projects/VS2022/examples/text_writing_anim.vcxproj +0 -387
  350. package/vendor/raylib/projects/VS2022/examples/textures_background_scrolling.vcxproj +0 -387
  351. package/vendor/raylib/projects/VS2022/examples/textures_blend_modes.vcxproj +0 -387
  352. package/vendor/raylib/projects/VS2022/examples/textures_bunnymark.vcxproj +0 -387
  353. package/vendor/raylib/projects/VS2022/examples/textures_draw_tiled.vcxproj +0 -387
  354. package/vendor/raylib/projects/VS2022/examples/textures_fog_of_war.vcxproj +0 -387
  355. package/vendor/raylib/projects/VS2022/examples/textures_gif_player.vcxproj +0 -387
  356. package/vendor/raylib/projects/VS2022/examples/textures_image_drawing.vcxproj +0 -387
  357. package/vendor/raylib/projects/VS2022/examples/textures_image_generation.vcxproj +0 -387
  358. package/vendor/raylib/projects/VS2022/examples/textures_image_loading.vcxproj +0 -387
  359. package/vendor/raylib/projects/VS2022/examples/textures_image_processing.vcxproj +0 -387
  360. package/vendor/raylib/projects/VS2022/examples/textures_image_text.vcxproj +0 -387
  361. package/vendor/raylib/projects/VS2022/examples/textures_logo_raylib.vcxproj +0 -387
  362. package/vendor/raylib/projects/VS2022/examples/textures_mouse_painting.vcxproj +0 -387
  363. package/vendor/raylib/projects/VS2022/examples/textures_npatch_drawing.vcxproj +0 -387
  364. package/vendor/raylib/projects/VS2022/examples/textures_particles_blending.vcxproj +0 -387
  365. package/vendor/raylib/projects/VS2022/examples/textures_polygon.vcxproj +0 -387
  366. package/vendor/raylib/projects/VS2022/examples/textures_raw_data.vcxproj +0 -387
  367. package/vendor/raylib/projects/VS2022/examples/textures_sprite_anim.vcxproj +0 -387
  368. package/vendor/raylib/projects/VS2022/examples/textures_sprite_button.vcxproj +0 -387
  369. package/vendor/raylib/projects/VS2022/examples/textures_sprite_explosion.vcxproj +0 -387
  370. package/vendor/raylib/projects/VS2022/examples/textures_srcrec_dstrec.vcxproj +0 -387
  371. package/vendor/raylib/projects/VS2022/examples/textures_to_image.vcxproj +0 -387
  372. package/vendor/raylib/projects/VS2022/raylib/raylib.vcxproj +0 -340
  373. package/vendor/raylib/projects/VS2022/raylib.sln +0 -2347
  374. package/vendor/sqlite3/shell.c +0 -23496
@@ -0,0 +1,663 @@
1
+ /* Copyright 2015 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Algorithms for distributing the literals and commands of a metablock between
8
+ block types and contexts. */
9
+
10
+ #include "./metablock.h"
11
+
12
+ #include "../common/constants.h"
13
+ #include "../common/context.h"
14
+ #include "../common/platform.h"
15
+ #include <brotli/types.h>
16
+ #include "./bit_cost.h"
17
+ #include "./block_splitter.h"
18
+ #include "./cluster.h"
19
+ #include "./entropy_encode.h"
20
+ #include "./histogram.h"
21
+ #include "./memory.h"
22
+ #include "./quality.h"
23
+
24
+ #if defined(__cplusplus) || defined(c_plusplus)
25
+ extern "C" {
26
+ #endif
27
+
28
+ void BrotliInitDistanceParams(BrotliEncoderParams* params,
29
+ uint32_t npostfix, uint32_t ndirect) {
30
+ BrotliDistanceParams* dist_params = &params->dist;
31
+ uint32_t alphabet_size_max;
32
+ uint32_t alphabet_size_limit;
33
+ uint32_t max_distance;
34
+
35
+ dist_params->distance_postfix_bits = npostfix;
36
+ dist_params->num_direct_distance_codes = ndirect;
37
+
38
+ alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZE(
39
+ npostfix, ndirect, BROTLI_MAX_DISTANCE_BITS);
40
+ alphabet_size_limit = alphabet_size_max;
41
+ max_distance = ndirect + (1U << (BROTLI_MAX_DISTANCE_BITS + npostfix + 2)) -
42
+ (1U << (npostfix + 2));
43
+
44
+ if (params->large_window) {
45
+ BrotliDistanceCodeLimit limit = BrotliCalculateDistanceCodeLimit(
46
+ BROTLI_MAX_ALLOWED_DISTANCE, npostfix, ndirect);
47
+ alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZE(
48
+ npostfix, ndirect, BROTLI_LARGE_MAX_DISTANCE_BITS);
49
+ alphabet_size_limit = limit.max_alphabet_size;
50
+ max_distance = limit.max_distance;
51
+ }
52
+
53
+ dist_params->alphabet_size_max = alphabet_size_max;
54
+ dist_params->alphabet_size_limit = alphabet_size_limit;
55
+ dist_params->max_distance = max_distance;
56
+ }
57
+
58
+ static void RecomputeDistancePrefixes(Command* cmds,
59
+ size_t num_commands,
60
+ const BrotliDistanceParams* orig_params,
61
+ const BrotliDistanceParams* new_params) {
62
+ size_t i;
63
+
64
+ if (orig_params->distance_postfix_bits == new_params->distance_postfix_bits &&
65
+ orig_params->num_direct_distance_codes ==
66
+ new_params->num_direct_distance_codes) {
67
+ return;
68
+ }
69
+
70
+ for (i = 0; i < num_commands; ++i) {
71
+ Command* cmd = &cmds[i];
72
+ if (CommandCopyLen(cmd) && cmd->cmd_prefix_ >= 128) {
73
+ PrefixEncodeCopyDistance(CommandRestoreDistanceCode(cmd, orig_params),
74
+ new_params->num_direct_distance_codes,
75
+ new_params->distance_postfix_bits,
76
+ &cmd->dist_prefix_,
77
+ &cmd->dist_extra_);
78
+ }
79
+ }
80
+ }
81
+
82
+ static BROTLI_BOOL ComputeDistanceCost(const Command* cmds,
83
+ size_t num_commands,
84
+ const BrotliDistanceParams* orig_params,
85
+ const BrotliDistanceParams* new_params,
86
+ double* cost) {
87
+ size_t i;
88
+ BROTLI_BOOL equal_params = BROTLI_FALSE;
89
+ uint16_t dist_prefix;
90
+ uint32_t dist_extra;
91
+ double extra_bits = 0.0;
92
+ HistogramDistance histo;
93
+ HistogramClearDistance(&histo);
94
+
95
+ if (orig_params->distance_postfix_bits == new_params->distance_postfix_bits &&
96
+ orig_params->num_direct_distance_codes ==
97
+ new_params->num_direct_distance_codes) {
98
+ equal_params = BROTLI_TRUE;
99
+ }
100
+
101
+ for (i = 0; i < num_commands; i++) {
102
+ const Command* cmd = &cmds[i];
103
+ if (CommandCopyLen(cmd) && cmd->cmd_prefix_ >= 128) {
104
+ if (equal_params) {
105
+ dist_prefix = cmd->dist_prefix_;
106
+ } else {
107
+ uint32_t distance = CommandRestoreDistanceCode(cmd, orig_params);
108
+ if (distance > new_params->max_distance) {
109
+ return BROTLI_FALSE;
110
+ }
111
+ PrefixEncodeCopyDistance(distance,
112
+ new_params->num_direct_distance_codes,
113
+ new_params->distance_postfix_bits,
114
+ &dist_prefix,
115
+ &dist_extra);
116
+ }
117
+ HistogramAddDistance(&histo, dist_prefix & 0x3FF);
118
+ extra_bits += dist_prefix >> 10;
119
+ }
120
+ }
121
+
122
+ *cost = BrotliPopulationCostDistance(&histo) + extra_bits;
123
+ return BROTLI_TRUE;
124
+ }
125
+
126
+ void BrotliBuildMetaBlock(MemoryManager* m,
127
+ const uint8_t* ringbuffer,
128
+ const size_t pos,
129
+ const size_t mask,
130
+ BrotliEncoderParams* params,
131
+ uint8_t prev_byte,
132
+ uint8_t prev_byte2,
133
+ Command* cmds,
134
+ size_t num_commands,
135
+ ContextType literal_context_mode,
136
+ MetaBlockSplit* mb) {
137
+ /* Histogram ids need to fit in one byte. */
138
+ static const size_t kMaxNumberOfHistograms = 256;
139
+ HistogramDistance* distance_histograms;
140
+ HistogramLiteral* literal_histograms;
141
+ ContextType* literal_context_modes = NULL;
142
+ size_t literal_histograms_size;
143
+ size_t distance_histograms_size;
144
+ size_t i;
145
+ size_t literal_context_multiplier = 1;
146
+ uint32_t npostfix;
147
+ uint32_t ndirect_msb = 0;
148
+ BROTLI_BOOL check_orig = BROTLI_TRUE;
149
+ double best_dist_cost = 1e99;
150
+ BrotliEncoderParams orig_params = *params;
151
+ BrotliEncoderParams new_params = *params;
152
+
153
+ for (npostfix = 0; npostfix <= BROTLI_MAX_NPOSTFIX; npostfix++) {
154
+ for (; ndirect_msb < 16; ndirect_msb++) {
155
+ uint32_t ndirect = ndirect_msb << npostfix;
156
+ BROTLI_BOOL skip;
157
+ double dist_cost;
158
+ BrotliInitDistanceParams(&new_params, npostfix, ndirect);
159
+ if (npostfix == orig_params.dist.distance_postfix_bits &&
160
+ ndirect == orig_params.dist.num_direct_distance_codes) {
161
+ check_orig = BROTLI_FALSE;
162
+ }
163
+ skip = !ComputeDistanceCost(
164
+ cmds, num_commands,
165
+ &orig_params.dist, &new_params.dist, &dist_cost);
166
+ if (skip || (dist_cost > best_dist_cost)) {
167
+ break;
168
+ }
169
+ best_dist_cost = dist_cost;
170
+ params->dist = new_params.dist;
171
+ }
172
+ if (ndirect_msb > 0) ndirect_msb--;
173
+ ndirect_msb /= 2;
174
+ }
175
+ if (check_orig) {
176
+ double dist_cost;
177
+ ComputeDistanceCost(cmds, num_commands,
178
+ &orig_params.dist, &orig_params.dist, &dist_cost);
179
+ if (dist_cost < best_dist_cost) {
180
+ /* NB: currently unused; uncomment when more param tuning is added. */
181
+ /* best_dist_cost = dist_cost; */
182
+ params->dist = orig_params.dist;
183
+ }
184
+ }
185
+ RecomputeDistancePrefixes(cmds, num_commands,
186
+ &orig_params.dist, &params->dist);
187
+
188
+ BrotliSplitBlock(m, cmds, num_commands,
189
+ ringbuffer, pos, mask, params,
190
+ &mb->literal_split,
191
+ &mb->command_split,
192
+ &mb->distance_split);
193
+ if (BROTLI_IS_OOM(m)) return;
194
+
195
+ if (!params->disable_literal_context_modeling) {
196
+ literal_context_multiplier = 1 << BROTLI_LITERAL_CONTEXT_BITS;
197
+ literal_context_modes =
198
+ BROTLI_ALLOC(m, ContextType, mb->literal_split.num_types);
199
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(literal_context_modes)) return;
200
+ for (i = 0; i < mb->literal_split.num_types; ++i) {
201
+ literal_context_modes[i] = literal_context_mode;
202
+ }
203
+ }
204
+
205
+ literal_histograms_size =
206
+ mb->literal_split.num_types * literal_context_multiplier;
207
+ literal_histograms =
208
+ BROTLI_ALLOC(m, HistogramLiteral, literal_histograms_size);
209
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(literal_histograms)) return;
210
+ ClearHistogramsLiteral(literal_histograms, literal_histograms_size);
211
+
212
+ distance_histograms_size =
213
+ mb->distance_split.num_types << BROTLI_DISTANCE_CONTEXT_BITS;
214
+ distance_histograms =
215
+ BROTLI_ALLOC(m, HistogramDistance, distance_histograms_size);
216
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(distance_histograms)) return;
217
+ ClearHistogramsDistance(distance_histograms, distance_histograms_size);
218
+
219
+ BROTLI_DCHECK(mb->command_histograms == 0);
220
+ mb->command_histograms_size = mb->command_split.num_types;
221
+ mb->command_histograms =
222
+ BROTLI_ALLOC(m, HistogramCommand, mb->command_histograms_size);
223
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->command_histograms)) return;
224
+ ClearHistogramsCommand(mb->command_histograms, mb->command_histograms_size);
225
+
226
+ BrotliBuildHistogramsWithContext(cmds, num_commands,
227
+ &mb->literal_split, &mb->command_split, &mb->distance_split,
228
+ ringbuffer, pos, mask, prev_byte, prev_byte2, literal_context_modes,
229
+ literal_histograms, mb->command_histograms, distance_histograms);
230
+ BROTLI_FREE(m, literal_context_modes);
231
+
232
+ BROTLI_DCHECK(mb->literal_context_map == 0);
233
+ mb->literal_context_map_size =
234
+ mb->literal_split.num_types << BROTLI_LITERAL_CONTEXT_BITS;
235
+ mb->literal_context_map =
236
+ BROTLI_ALLOC(m, uint32_t, mb->literal_context_map_size);
237
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->literal_context_map)) return;
238
+
239
+ BROTLI_DCHECK(mb->literal_histograms == 0);
240
+ mb->literal_histograms_size = mb->literal_context_map_size;
241
+ mb->literal_histograms =
242
+ BROTLI_ALLOC(m, HistogramLiteral, mb->literal_histograms_size);
243
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->literal_histograms)) return;
244
+
245
+ BrotliClusterHistogramsLiteral(m, literal_histograms, literal_histograms_size,
246
+ kMaxNumberOfHistograms, mb->literal_histograms,
247
+ &mb->literal_histograms_size, mb->literal_context_map);
248
+ if (BROTLI_IS_OOM(m)) return;
249
+ BROTLI_FREE(m, literal_histograms);
250
+
251
+ if (params->disable_literal_context_modeling) {
252
+ /* Distribute assignment to all contexts. */
253
+ for (i = mb->literal_split.num_types; i != 0;) {
254
+ size_t j = 0;
255
+ i--;
256
+ for (; j < (1 << BROTLI_LITERAL_CONTEXT_BITS); j++) {
257
+ mb->literal_context_map[(i << BROTLI_LITERAL_CONTEXT_BITS) + j] =
258
+ mb->literal_context_map[i];
259
+ }
260
+ }
261
+ }
262
+
263
+ BROTLI_DCHECK(mb->distance_context_map == 0);
264
+ mb->distance_context_map_size =
265
+ mb->distance_split.num_types << BROTLI_DISTANCE_CONTEXT_BITS;
266
+ mb->distance_context_map =
267
+ BROTLI_ALLOC(m, uint32_t, mb->distance_context_map_size);
268
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->distance_context_map)) return;
269
+
270
+ BROTLI_DCHECK(mb->distance_histograms == 0);
271
+ mb->distance_histograms_size = mb->distance_context_map_size;
272
+ mb->distance_histograms =
273
+ BROTLI_ALLOC(m, HistogramDistance, mb->distance_histograms_size);
274
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->distance_histograms)) return;
275
+
276
+ BrotliClusterHistogramsDistance(m, distance_histograms,
277
+ mb->distance_context_map_size,
278
+ kMaxNumberOfHistograms,
279
+ mb->distance_histograms,
280
+ &mb->distance_histograms_size,
281
+ mb->distance_context_map);
282
+ if (BROTLI_IS_OOM(m)) return;
283
+ BROTLI_FREE(m, distance_histograms);
284
+ }
285
+
286
+ #define FN(X) X ## Literal
287
+ #include "./metablock_inc.h" /* NOLINT(build/include) */
288
+ #undef FN
289
+
290
+ #define FN(X) X ## Command
291
+ #include "./metablock_inc.h" /* NOLINT(build/include) */
292
+ #undef FN
293
+
294
+ #define FN(X) X ## Distance
295
+ #include "./metablock_inc.h" /* NOLINT(build/include) */
296
+ #undef FN
297
+
298
+ #define BROTLI_MAX_STATIC_CONTEXTS 13
299
+
300
+ /* Greedy block splitter for one block category (literal, command or distance).
301
+ Gathers histograms for all context buckets. */
302
+ typedef struct ContextBlockSplitter {
303
+ /* Alphabet size of particular block category. */
304
+ size_t alphabet_size_;
305
+ size_t num_contexts_;
306
+ size_t max_block_types_;
307
+ /* We collect at least this many symbols for each block. */
308
+ size_t min_block_size_;
309
+ /* We merge histograms A and B if
310
+ entropy(A+B) < entropy(A) + entropy(B) + split_threshold_,
311
+ where A is the current histogram and B is the histogram of the last or the
312
+ second last block type. */
313
+ double split_threshold_;
314
+
315
+ size_t num_blocks_;
316
+ BlockSplit* split_; /* not owned */
317
+ HistogramLiteral* histograms_; /* not owned */
318
+ size_t* histograms_size_; /* not owned */
319
+
320
+ /* The number of symbols that we want to collect before deciding on whether
321
+ or not to merge the block with a previous one or emit a new block. */
322
+ size_t target_block_size_;
323
+ /* The number of symbols in the current histogram. */
324
+ size_t block_size_;
325
+ /* Offset of the current histogram. */
326
+ size_t curr_histogram_ix_;
327
+ /* Offset of the histograms of the previous two block types. */
328
+ size_t last_histogram_ix_[2];
329
+ /* Entropy of the previous two block types. */
330
+ double last_entropy_[2 * BROTLI_MAX_STATIC_CONTEXTS];
331
+ /* The number of times we merged the current block with the last one. */
332
+ size_t merge_last_count_;
333
+ } ContextBlockSplitter;
334
+
335
+ static void InitContextBlockSplitter(
336
+ MemoryManager* m, ContextBlockSplitter* self, size_t alphabet_size,
337
+ size_t num_contexts, size_t min_block_size, double split_threshold,
338
+ size_t num_symbols, BlockSplit* split, HistogramLiteral** histograms,
339
+ size_t* histograms_size) {
340
+ size_t max_num_blocks = num_symbols / min_block_size + 1;
341
+ size_t max_num_types;
342
+ BROTLI_DCHECK(num_contexts <= BROTLI_MAX_STATIC_CONTEXTS);
343
+
344
+ self->alphabet_size_ = alphabet_size;
345
+ self->num_contexts_ = num_contexts;
346
+ self->max_block_types_ = BROTLI_MAX_NUMBER_OF_BLOCK_TYPES / num_contexts;
347
+ self->min_block_size_ = min_block_size;
348
+ self->split_threshold_ = split_threshold;
349
+ self->num_blocks_ = 0;
350
+ self->split_ = split;
351
+ self->histograms_size_ = histograms_size;
352
+ self->target_block_size_ = min_block_size;
353
+ self->block_size_ = 0;
354
+ self->curr_histogram_ix_ = 0;
355
+ self->merge_last_count_ = 0;
356
+
357
+ /* We have to allocate one more histogram than the maximum number of block
358
+ types for the current histogram when the meta-block is too big. */
359
+ max_num_types =
360
+ BROTLI_MIN(size_t, max_num_blocks, self->max_block_types_ + 1);
361
+ BROTLI_ENSURE_CAPACITY(m, uint8_t,
362
+ split->types, split->types_alloc_size, max_num_blocks);
363
+ BROTLI_ENSURE_CAPACITY(m, uint32_t,
364
+ split->lengths, split->lengths_alloc_size, max_num_blocks);
365
+ if (BROTLI_IS_OOM(m)) return;
366
+ split->num_blocks = max_num_blocks;
367
+ if (BROTLI_IS_OOM(m)) return;
368
+ BROTLI_DCHECK(*histograms == 0);
369
+ *histograms_size = max_num_types * num_contexts;
370
+ *histograms = BROTLI_ALLOC(m, HistogramLiteral, *histograms_size);
371
+ self->histograms_ = *histograms;
372
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(*histograms)) return;
373
+ /* Clear only current histogram. */
374
+ ClearHistogramsLiteral(&self->histograms_[0], num_contexts);
375
+ self->last_histogram_ix_[0] = self->last_histogram_ix_[1] = 0;
376
+ }
377
+
378
+ /* Does either of three things:
379
+ (1) emits the current block with a new block type;
380
+ (2) emits the current block with the type of the second last block;
381
+ (3) merges the current block with the last block. */
382
+ static void ContextBlockSplitterFinishBlock(
383
+ ContextBlockSplitter* self, MemoryManager* m, BROTLI_BOOL is_final) {
384
+ BlockSplit* split = self->split_;
385
+ const size_t num_contexts = self->num_contexts_;
386
+ double* last_entropy = self->last_entropy_;
387
+ HistogramLiteral* histograms = self->histograms_;
388
+
389
+ if (self->block_size_ < self->min_block_size_) {
390
+ self->block_size_ = self->min_block_size_;
391
+ }
392
+ if (self->num_blocks_ == 0) {
393
+ size_t i;
394
+ /* Create first block. */
395
+ split->lengths[0] = (uint32_t)self->block_size_;
396
+ split->types[0] = 0;
397
+
398
+ for (i = 0; i < num_contexts; ++i) {
399
+ last_entropy[i] =
400
+ BitsEntropy(histograms[i].data_, self->alphabet_size_);
401
+ last_entropy[num_contexts + i] = last_entropy[i];
402
+ }
403
+ ++self->num_blocks_;
404
+ ++split->num_types;
405
+ self->curr_histogram_ix_ += num_contexts;
406
+ if (self->curr_histogram_ix_ < *self->histograms_size_) {
407
+ ClearHistogramsLiteral(
408
+ &self->histograms_[self->curr_histogram_ix_], self->num_contexts_);
409
+ }
410
+ self->block_size_ = 0;
411
+ } else if (self->block_size_ > 0) {
412
+ /* Try merging the set of histograms for the current block type with the
413
+ respective set of histograms for the last and second last block types.
414
+ Decide over the split based on the total reduction of entropy across
415
+ all contexts. */
416
+ double entropy[BROTLI_MAX_STATIC_CONTEXTS];
417
+ HistogramLiteral* combined_histo =
418
+ BROTLI_ALLOC(m, HistogramLiteral, 2 * num_contexts);
419
+ double combined_entropy[2 * BROTLI_MAX_STATIC_CONTEXTS];
420
+ double diff[2] = { 0.0 };
421
+ size_t i;
422
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(combined_histo)) return;
423
+ for (i = 0; i < num_contexts; ++i) {
424
+ size_t curr_histo_ix = self->curr_histogram_ix_ + i;
425
+ size_t j;
426
+ entropy[i] = BitsEntropy(histograms[curr_histo_ix].data_,
427
+ self->alphabet_size_);
428
+ for (j = 0; j < 2; ++j) {
429
+ size_t jx = j * num_contexts + i;
430
+ size_t last_histogram_ix = self->last_histogram_ix_[j] + i;
431
+ combined_histo[jx] = histograms[curr_histo_ix];
432
+ HistogramAddHistogramLiteral(&combined_histo[jx],
433
+ &histograms[last_histogram_ix]);
434
+ combined_entropy[jx] = BitsEntropy(
435
+ &combined_histo[jx].data_[0], self->alphabet_size_);
436
+ diff[j] += combined_entropy[jx] - entropy[i] - last_entropy[jx];
437
+ }
438
+ }
439
+
440
+ if (split->num_types < self->max_block_types_ &&
441
+ diff[0] > self->split_threshold_ &&
442
+ diff[1] > self->split_threshold_) {
443
+ /* Create new block. */
444
+ split->lengths[self->num_blocks_] = (uint32_t)self->block_size_;
445
+ split->types[self->num_blocks_] = (uint8_t)split->num_types;
446
+ self->last_histogram_ix_[1] = self->last_histogram_ix_[0];
447
+ self->last_histogram_ix_[0] = split->num_types * num_contexts;
448
+ for (i = 0; i < num_contexts; ++i) {
449
+ last_entropy[num_contexts + i] = last_entropy[i];
450
+ last_entropy[i] = entropy[i];
451
+ }
452
+ ++self->num_blocks_;
453
+ ++split->num_types;
454
+ self->curr_histogram_ix_ += num_contexts;
455
+ if (self->curr_histogram_ix_ < *self->histograms_size_) {
456
+ ClearHistogramsLiteral(
457
+ &self->histograms_[self->curr_histogram_ix_], self->num_contexts_);
458
+ }
459
+ self->block_size_ = 0;
460
+ self->merge_last_count_ = 0;
461
+ self->target_block_size_ = self->min_block_size_;
462
+ } else if (diff[1] < diff[0] - 20.0) {
463
+ /* Combine this block with second last block. */
464
+ split->lengths[self->num_blocks_] = (uint32_t)self->block_size_;
465
+ split->types[self->num_blocks_] = split->types[self->num_blocks_ - 2];
466
+ BROTLI_SWAP(size_t, self->last_histogram_ix_, 0, 1);
467
+ for (i = 0; i < num_contexts; ++i) {
468
+ histograms[self->last_histogram_ix_[0] + i] =
469
+ combined_histo[num_contexts + i];
470
+ last_entropy[num_contexts + i] = last_entropy[i];
471
+ last_entropy[i] = combined_entropy[num_contexts + i];
472
+ HistogramClearLiteral(&histograms[self->curr_histogram_ix_ + i]);
473
+ }
474
+ ++self->num_blocks_;
475
+ self->block_size_ = 0;
476
+ self->merge_last_count_ = 0;
477
+ self->target_block_size_ = self->min_block_size_;
478
+ } else {
479
+ /* Combine this block with last block. */
480
+ split->lengths[self->num_blocks_ - 1] += (uint32_t)self->block_size_;
481
+ for (i = 0; i < num_contexts; ++i) {
482
+ histograms[self->last_histogram_ix_[0] + i] = combined_histo[i];
483
+ last_entropy[i] = combined_entropy[i];
484
+ if (split->num_types == 1) {
485
+ last_entropy[num_contexts + i] = last_entropy[i];
486
+ }
487
+ HistogramClearLiteral(&histograms[self->curr_histogram_ix_ + i]);
488
+ }
489
+ self->block_size_ = 0;
490
+ if (++self->merge_last_count_ > 1) {
491
+ self->target_block_size_ += self->min_block_size_;
492
+ }
493
+ }
494
+ BROTLI_FREE(m, combined_histo);
495
+ }
496
+ if (is_final) {
497
+ *self->histograms_size_ = split->num_types * num_contexts;
498
+ split->num_blocks = self->num_blocks_;
499
+ }
500
+ }
501
+
502
+ /* Adds the next symbol to the current block type and context. When the
503
+ current block reaches the target size, decides on merging the block. */
504
+ static void ContextBlockSplitterAddSymbol(
505
+ ContextBlockSplitter* self, MemoryManager* m,
506
+ size_t symbol, size_t context) {
507
+ HistogramAddLiteral(&self->histograms_[self->curr_histogram_ix_ + context],
508
+ symbol);
509
+ ++self->block_size_;
510
+ if (self->block_size_ == self->target_block_size_) {
511
+ ContextBlockSplitterFinishBlock(self, m, /* is_final = */ BROTLI_FALSE);
512
+ if (BROTLI_IS_OOM(m)) return;
513
+ }
514
+ }
515
+
516
+ static void MapStaticContexts(MemoryManager* m,
517
+ size_t num_contexts,
518
+ const uint32_t* static_context_map,
519
+ MetaBlockSplit* mb) {
520
+ size_t i;
521
+ BROTLI_DCHECK(mb->literal_context_map == 0);
522
+ mb->literal_context_map_size =
523
+ mb->literal_split.num_types << BROTLI_LITERAL_CONTEXT_BITS;
524
+ mb->literal_context_map =
525
+ BROTLI_ALLOC(m, uint32_t, mb->literal_context_map_size);
526
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->literal_context_map)) return;
527
+
528
+ for (i = 0; i < mb->literal_split.num_types; ++i) {
529
+ uint32_t offset = (uint32_t)(i * num_contexts);
530
+ size_t j;
531
+ for (j = 0; j < (1u << BROTLI_LITERAL_CONTEXT_BITS); ++j) {
532
+ mb->literal_context_map[(i << BROTLI_LITERAL_CONTEXT_BITS) + j] =
533
+ offset + static_context_map[j];
534
+ }
535
+ }
536
+ }
537
+
538
+ static BROTLI_INLINE void BrotliBuildMetaBlockGreedyInternal(
539
+ MemoryManager* m, const uint8_t* ringbuffer, size_t pos, size_t mask,
540
+ uint8_t prev_byte, uint8_t prev_byte2, ContextLut literal_context_lut,
541
+ const size_t num_contexts, const uint32_t* static_context_map,
542
+ const Command* commands, size_t n_commands, MetaBlockSplit* mb) {
543
+ union {
544
+ BlockSplitterLiteral plain;
545
+ ContextBlockSplitter ctx;
546
+ } lit_blocks;
547
+ BlockSplitterCommand cmd_blocks;
548
+ BlockSplitterDistance dist_blocks;
549
+ size_t num_literals = 0;
550
+ size_t i;
551
+ for (i = 0; i < n_commands; ++i) {
552
+ num_literals += commands[i].insert_len_;
553
+ }
554
+
555
+ if (num_contexts == 1) {
556
+ InitBlockSplitterLiteral(m, &lit_blocks.plain, 256, 512, 400.0,
557
+ num_literals, &mb->literal_split, &mb->literal_histograms,
558
+ &mb->literal_histograms_size);
559
+ } else {
560
+ InitContextBlockSplitter(m, &lit_blocks.ctx, 256, num_contexts, 512, 400.0,
561
+ num_literals, &mb->literal_split, &mb->literal_histograms,
562
+ &mb->literal_histograms_size);
563
+ }
564
+ if (BROTLI_IS_OOM(m)) return;
565
+ InitBlockSplitterCommand(m, &cmd_blocks, BROTLI_NUM_COMMAND_SYMBOLS, 1024,
566
+ 500.0, n_commands, &mb->command_split, &mb->command_histograms,
567
+ &mb->command_histograms_size);
568
+ if (BROTLI_IS_OOM(m)) return;
569
+ InitBlockSplitterDistance(m, &dist_blocks, 64, 512, 100.0, n_commands,
570
+ &mb->distance_split, &mb->distance_histograms,
571
+ &mb->distance_histograms_size);
572
+ if (BROTLI_IS_OOM(m)) return;
573
+
574
+ for (i = 0; i < n_commands; ++i) {
575
+ const Command cmd = commands[i];
576
+ size_t j;
577
+ BlockSplitterAddSymbolCommand(&cmd_blocks, cmd.cmd_prefix_);
578
+ for (j = cmd.insert_len_; j != 0; --j) {
579
+ uint8_t literal = ringbuffer[pos & mask];
580
+ if (num_contexts == 1) {
581
+ BlockSplitterAddSymbolLiteral(&lit_blocks.plain, literal);
582
+ } else {
583
+ size_t context =
584
+ BROTLI_CONTEXT(prev_byte, prev_byte2, literal_context_lut);
585
+ ContextBlockSplitterAddSymbol(&lit_blocks.ctx, m, literal,
586
+ static_context_map[context]);
587
+ if (BROTLI_IS_OOM(m)) return;
588
+ }
589
+ prev_byte2 = prev_byte;
590
+ prev_byte = literal;
591
+ ++pos;
592
+ }
593
+ pos += CommandCopyLen(&cmd);
594
+ if (CommandCopyLen(&cmd)) {
595
+ prev_byte2 = ringbuffer[(pos - 2) & mask];
596
+ prev_byte = ringbuffer[(pos - 1) & mask];
597
+ if (cmd.cmd_prefix_ >= 128) {
598
+ BlockSplitterAddSymbolDistance(&dist_blocks, cmd.dist_prefix_ & 0x3FF);
599
+ }
600
+ }
601
+ }
602
+
603
+ if (num_contexts == 1) {
604
+ BlockSplitterFinishBlockLiteral(
605
+ &lit_blocks.plain, /* is_final = */ BROTLI_TRUE);
606
+ } else {
607
+ ContextBlockSplitterFinishBlock(
608
+ &lit_blocks.ctx, m, /* is_final = */ BROTLI_TRUE);
609
+ if (BROTLI_IS_OOM(m)) return;
610
+ }
611
+ BlockSplitterFinishBlockCommand(&cmd_blocks, /* is_final = */ BROTLI_TRUE);
612
+ BlockSplitterFinishBlockDistance(&dist_blocks, /* is_final = */ BROTLI_TRUE);
613
+
614
+ if (num_contexts > 1) {
615
+ MapStaticContexts(m, num_contexts, static_context_map, mb);
616
+ }
617
+ }
618
+
619
+ void BrotliBuildMetaBlockGreedy(MemoryManager* m,
620
+ const uint8_t* ringbuffer,
621
+ size_t pos,
622
+ size_t mask,
623
+ uint8_t prev_byte,
624
+ uint8_t prev_byte2,
625
+ ContextLut literal_context_lut,
626
+ size_t num_contexts,
627
+ const uint32_t* static_context_map,
628
+ const Command* commands,
629
+ size_t n_commands,
630
+ MetaBlockSplit* mb) {
631
+ if (num_contexts == 1) {
632
+ BrotliBuildMetaBlockGreedyInternal(m, ringbuffer, pos, mask, prev_byte,
633
+ prev_byte2, literal_context_lut, 1, NULL, commands, n_commands, mb);
634
+ } else {
635
+ BrotliBuildMetaBlockGreedyInternal(m, ringbuffer, pos, mask, prev_byte,
636
+ prev_byte2, literal_context_lut, num_contexts, static_context_map,
637
+ commands, n_commands, mb);
638
+ }
639
+ }
640
+
641
+ void BrotliOptimizeHistograms(uint32_t num_distance_codes,
642
+ MetaBlockSplit* mb) {
643
+ uint8_t good_for_rle[BROTLI_NUM_COMMAND_SYMBOLS];
644
+ size_t i;
645
+ for (i = 0; i < mb->literal_histograms_size; ++i) {
646
+ BrotliOptimizeHuffmanCountsForRle(256, mb->literal_histograms[i].data_,
647
+ good_for_rle);
648
+ }
649
+ for (i = 0; i < mb->command_histograms_size; ++i) {
650
+ BrotliOptimizeHuffmanCountsForRle(BROTLI_NUM_COMMAND_SYMBOLS,
651
+ mb->command_histograms[i].data_,
652
+ good_for_rle);
653
+ }
654
+ for (i = 0; i < mb->distance_histograms_size; ++i) {
655
+ BrotliOptimizeHuffmanCountsForRle(num_distance_codes,
656
+ mb->distance_histograms[i].data_,
657
+ good_for_rle);
658
+ }
659
+ }
660
+
661
+ #if defined(__cplusplus) || defined(c_plusplus)
662
+ } /* extern "C" */
663
+ #endif