@patleeman/pi-boy 0.1.0

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 (1361) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +189 -0
  3. package/index.ts +1 -0
  4. package/mgba-bridge/build.sh +31 -0
  5. package/mgba-bridge/src/main.c +740 -0
  6. package/mgba-bridge/vendor/mgba/.clang-format +34 -0
  7. package/mgba-bridge/vendor/mgba/.gitlab-ci.yml +267 -0
  8. package/mgba-bridge/vendor/mgba/CHANGES +2094 -0
  9. package/mgba-bridge/vendor/mgba/CMakeLists.txt +1373 -0
  10. package/mgba-bridge/vendor/mgba/CMakePresets.json +21 -0
  11. package/mgba-bridge/vendor/mgba/CONTRIBUTING.md +196 -0
  12. package/mgba-bridge/vendor/mgba/LICENSE +373 -0
  13. package/mgba-bridge/vendor/mgba/Makefile +1 -0
  14. package/mgba-bridge/vendor/mgba/Makefile.libretro +490 -0
  15. package/mgba-bridge/vendor/mgba/PORTING.md +21 -0
  16. package/mgba-bridge/vendor/mgba/README.md +270 -0
  17. package/mgba-bridge/vendor/mgba/README_DE.md +255 -0
  18. package/mgba-bridge/vendor/mgba/README_ES.md +255 -0
  19. package/mgba-bridge/vendor/mgba/README_JP.md +268 -0
  20. package/mgba-bridge/vendor/mgba/README_ZH_CN.md +268 -0
  21. package/mgba-bridge/vendor/mgba/Tupfile +3 -0
  22. package/mgba-bridge/vendor/mgba/include/mgba/core/bitmap-cache.h +64 -0
  23. package/mgba-bridge/vendor/mgba/include/mgba/core/cache-set.h +38 -0
  24. package/mgba-bridge/vendor/mgba/include/mgba/core/cheats.h +130 -0
  25. package/mgba-bridge/vendor/mgba/include/mgba/core/config.h +118 -0
  26. package/mgba-bridge/vendor/mgba/include/mgba/core/core.h +232 -0
  27. package/mgba-bridge/vendor/mgba/include/mgba/core/cpu.h +40 -0
  28. package/mgba-bridge/vendor/mgba/include/mgba/core/directories.h +42 -0
  29. package/mgba-bridge/vendor/mgba/include/mgba/core/input.h +91 -0
  30. package/mgba-bridge/vendor/mgba/include/mgba/core/interface.h +199 -0
  31. package/mgba-bridge/vendor/mgba/include/mgba/core/library.h +62 -0
  32. package/mgba-bridge/vendor/mgba/include/mgba/core/lockstep.h +77 -0
  33. package/mgba-bridge/vendor/mgba/include/mgba/core/log.h +88 -0
  34. package/mgba-bridge/vendor/mgba/include/mgba/core/map-cache.h +82 -0
  35. package/mgba-bridge/vendor/mgba/include/mgba/core/mem-search.h +62 -0
  36. package/mgba-bridge/vendor/mgba/include/mgba/core/rewind.h +47 -0
  37. package/mgba-bridge/vendor/mgba/include/mgba/core/scripting.h +65 -0
  38. package/mgba-bridge/vendor/mgba/include/mgba/core/serialize.h +61 -0
  39. package/mgba-bridge/vendor/mgba/include/mgba/core/sync.h +44 -0
  40. package/mgba-bridge/vendor/mgba/include/mgba/core/thread.h +135 -0
  41. package/mgba-bridge/vendor/mgba/include/mgba/core/tile-cache.h +63 -0
  42. package/mgba-bridge/vendor/mgba/include/mgba/core/timing.h +55 -0
  43. package/mgba-bridge/vendor/mgba/include/mgba/core/version.h +27 -0
  44. package/mgba-bridge/vendor/mgba/include/mgba/debugger/debugger.h +267 -0
  45. package/mgba-bridge/vendor/mgba/include/mgba/feature/commandline.h +71 -0
  46. package/mgba-bridge/vendor/mgba/include/mgba/feature/proxy-backend.h +83 -0
  47. package/mgba-bridge/vendor/mgba/include/mgba/feature/thread-proxy.h +41 -0
  48. package/mgba-bridge/vendor/mgba/include/mgba/feature/updater.h +51 -0
  49. package/mgba-bridge/vendor/mgba/include/mgba/feature/video-backend.h +81 -0
  50. package/mgba-bridge/vendor/mgba/include/mgba/feature/video-logger.h +145 -0
  51. package/mgba-bridge/vendor/mgba/include/mgba/gb/core.h +21 -0
  52. package/mgba-bridge/vendor/mgba/include/mgba/gb/interface.h +112 -0
  53. package/mgba-bridge/vendor/mgba/include/mgba/gba/core.h +21 -0
  54. package/mgba-bridge/vendor/mgba/include/mgba/gba/interface.h +168 -0
  55. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/arm.h +217 -0
  56. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/debugger/cli-debugger.h +18 -0
  57. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/debugger/debugger.h +52 -0
  58. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/debugger/memory-debugger.h +20 -0
  59. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/decoder-inlines.h +37 -0
  60. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/decoder.h +231 -0
  61. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/emitter-arm.h +336 -0
  62. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/emitter-inlines.h +32 -0
  63. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/emitter-thumb.h +113 -0
  64. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/isa-arm.h +22 -0
  65. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/isa-inlines.h +186 -0
  66. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/isa-thumb.h +20 -0
  67. package/mgba-bridge/vendor/mgba/include/mgba/internal/arm/macros.h +18 -0
  68. package/mgba-bridge/vendor/mgba/include/mgba/internal/debugger/access-logger.h +57 -0
  69. package/mgba-bridge/vendor/mgba/include/mgba/internal/debugger/cli-debugger.h +108 -0
  70. package/mgba-bridge/vendor/mgba/include/mgba/internal/debugger/cli-el-backend.h +21 -0
  71. package/mgba-bridge/vendor/mgba/include/mgba/internal/debugger/gdb-stub.h +62 -0
  72. package/mgba-bridge/vendor/mgba/include/mgba/internal/debugger/parser.h +81 -0
  73. package/mgba-bridge/vendor/mgba/include/mgba/internal/debugger/stack-trace.h +32 -0
  74. package/mgba-bridge/vendor/mgba/include/mgba/internal/debugger/symbols.h +29 -0
  75. package/mgba-bridge/vendor/mgba/include/mgba/internal/defines.h +31 -0
  76. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/audio.h +257 -0
  77. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/cheats.h +26 -0
  78. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/debugger/cli.h +28 -0
  79. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/debugger/debugger.h +20 -0
  80. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/debugger/symbols.h +19 -0
  81. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/gb.h +202 -0
  82. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/input.h +31 -0
  83. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/io.h +127 -0
  84. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/mbc.h +72 -0
  85. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/memory.h +385 -0
  86. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/overrides.h +21 -0
  87. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/renderers/cache-set.h +23 -0
  88. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/renderers/proxy.h +29 -0
  89. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/renderers/software.h +72 -0
  90. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/serialize.h +536 -0
  91. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/sio/lockstep.h +49 -0
  92. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/sio/printer.h +74 -0
  93. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/sio.h +52 -0
  94. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/timer.h +45 -0
  95. package/mgba-bridge/vendor/mgba/include/mgba/internal/gb/video.h +201 -0
  96. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/audio.h +291 -0
  97. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/bios.h +73 -0
  98. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/cart/ereader.h +127 -0
  99. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/cart/gpio.h +110 -0
  100. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/cart/matrix.h +35 -0
  101. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/cart/unlicensed.h +77 -0
  102. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/cheats.h +175 -0
  103. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/debugger/cli.h +30 -0
  104. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/dma.h +73 -0
  105. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/gba.h +194 -0
  106. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/input.h +34 -0
  107. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/io.h +190 -0
  108. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/memory.h +184 -0
  109. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/overrides.h +21 -0
  110. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/renderers/cache-set.h +22 -0
  111. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/renderers/common.h +27 -0
  112. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/renderers/gl.h +218 -0
  113. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/renderers/proxy.h +29 -0
  114. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/renderers/video-software.h +160 -0
  115. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/savedata.h +130 -0
  116. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/serialize.h +496 -0
  117. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/sharkport.h +27 -0
  118. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/sio/dolphin.h +41 -0
  119. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/sio/gbp.h +38 -0
  120. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/sio/lockstep.h +95 -0
  121. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/sio.h +98 -0
  122. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/timer.h +36 -0
  123. package/mgba-bridge/vendor/mgba/include/mgba/internal/gba/video.h +251 -0
  124. package/mgba-bridge/vendor/mgba/include/mgba/internal/script/lua.h +12 -0
  125. package/mgba-bridge/vendor/mgba/include/mgba/internal/script/socket.h +31 -0
  126. package/mgba-bridge/vendor/mgba/include/mgba/internal/script/types.h +20 -0
  127. package/mgba-bridge/vendor/mgba/include/mgba/internal/sm83/debugger/cli-debugger.h +18 -0
  128. package/mgba-bridge/vendor/mgba/include/mgba/internal/sm83/debugger/debugger.h +43 -0
  129. package/mgba-bridge/vendor/mgba/include/mgba/internal/sm83/debugger/memory-debugger.h +20 -0
  130. package/mgba-bridge/vendor/mgba/include/mgba/internal/sm83/decoder.h +113 -0
  131. package/mgba-bridge/vendor/mgba/include/mgba/internal/sm83/emitter-sm83.h +528 -0
  132. package/mgba-bridge/vendor/mgba/include/mgba/internal/sm83/isa-sm83.h +20 -0
  133. package/mgba-bridge/vendor/mgba/include/mgba/internal/sm83/sm83.h +174 -0
  134. package/mgba-bridge/vendor/mgba/include/mgba/script/base.h +28 -0
  135. package/mgba-bridge/vendor/mgba/include/mgba/script/canvas.h +24 -0
  136. package/mgba-bridge/vendor/mgba/include/mgba/script/console.h +51 -0
  137. package/mgba-bridge/vendor/mgba/include/mgba/script/context.h +126 -0
  138. package/mgba-bridge/vendor/mgba/include/mgba/script/input.h +272 -0
  139. package/mgba-bridge/vendor/mgba/include/mgba/script/macros.h +680 -0
  140. package/mgba-bridge/vendor/mgba/include/mgba/script/storage.h +28 -0
  141. package/mgba-bridge/vendor/mgba/include/mgba/script/types.h +400 -0
  142. package/mgba-bridge/vendor/mgba/include/mgba/script.h +18 -0
  143. package/mgba-bridge/vendor/mgba/include/mgba-util/audio-buffer.h +34 -0
  144. package/mgba-bridge/vendor/mgba/include/mgba-util/audio-resampler.h +42 -0
  145. package/mgba-bridge/vendor/mgba/include/mgba-util/circle-buffer.h +39 -0
  146. package/mgba-bridge/vendor/mgba/include/mgba-util/common.h +352 -0
  147. package/mgba-bridge/vendor/mgba/include/mgba-util/configuration.h +50 -0
  148. package/mgba-bridge/vendor/mgba/include/mgba-util/convolve.h +33 -0
  149. package/mgba-bridge/vendor/mgba/include/mgba-util/crc32.h +26 -0
  150. package/mgba-bridge/vendor/mgba/include/mgba-util/dllexports.h +19 -0
  151. package/mgba-bridge/vendor/mgba/include/mgba-util/elf-read.h +45 -0
  152. package/mgba-bridge/vendor/mgba/include/mgba-util/formatting.h +36 -0
  153. package/mgba-bridge/vendor/mgba/include/mgba-util/geometry.h +31 -0
  154. package/mgba-bridge/vendor/mgba/include/mgba-util/gui/file-select.h +21 -0
  155. package/mgba-bridge/vendor/mgba/include/mgba-util/gui/font-metrics.h +15 -0
  156. package/mgba-bridge/vendor/mgba/include/mgba-util/gui/font.h +149 -0
  157. package/mgba-bridge/vendor/mgba/include/mgba-util/gui/menu.h +126 -0
  158. package/mgba-bridge/vendor/mgba/include/mgba-util/gui.h +136 -0
  159. package/mgba-bridge/vendor/mgba/include/mgba-util/hash.h +17 -0
  160. package/mgba-bridge/vendor/mgba/include/mgba-util/image/export.h +20 -0
  161. package/mgba-bridge/vendor/mgba/include/mgba-util/image/png-io.h +54 -0
  162. package/mgba-bridge/vendor/mgba/include/mgba-util/image.h +442 -0
  163. package/mgba-bridge/vendor/mgba/include/mgba-util/interpolator.h +51 -0
  164. package/mgba-bridge/vendor/mgba/include/mgba-util/macros.h +92 -0
  165. package/mgba-bridge/vendor/mgba/include/mgba-util/math.h +145 -0
  166. package/mgba-bridge/vendor/mgba/include/mgba-util/md5.h +34 -0
  167. package/mgba-bridge/vendor/mgba/include/mgba-util/memory.h +18 -0
  168. package/mgba-bridge/vendor/mgba/include/mgba-util/patch/fast.h +38 -0
  169. package/mgba-bridge/vendor/mgba/include/mgba-util/patch/ips.h +19 -0
  170. package/mgba-bridge/vendor/mgba/include/mgba-util/patch/ups.h +19 -0
  171. package/mgba-bridge/vendor/mgba/include/mgba-util/patch.h +26 -0
  172. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/3ds/3ds-vfs.h +17 -0
  173. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/3ds/threading.h +88 -0
  174. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/posix/threading.h +125 -0
  175. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/psp2/sce-vfs.h +18 -0
  176. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/psp2/threading.h +161 -0
  177. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/switch/threading.h +88 -0
  178. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/windows/getopt.h +609 -0
  179. package/mgba-bridge/vendor/mgba/include/mgba-util/platform/windows/threading.h +106 -0
  180. package/mgba-bridge/vendor/mgba/include/mgba-util/ring-fifo.h +30 -0
  181. package/mgba-bridge/vendor/mgba/include/mgba-util/sfo.h +30 -0
  182. package/mgba-bridge/vendor/mgba/include/mgba-util/sha1.h +33 -0
  183. package/mgba-bridge/vendor/mgba/include/mgba-util/socket.h +542 -0
  184. package/mgba-bridge/vendor/mgba/include/mgba-util/string.h +55 -0
  185. package/mgba-bridge/vendor/mgba/include/mgba-util/table.h +93 -0
  186. package/mgba-bridge/vendor/mgba/include/mgba-util/text-codec.h +36 -0
  187. package/mgba-bridge/vendor/mgba/include/mgba-util/threading.h +123 -0
  188. package/mgba-bridge/vendor/mgba/include/mgba-util/vector.h +128 -0
  189. package/mgba-bridge/vendor/mgba/include/mgba-util/vfs.h +125 -0
  190. package/mgba-bridge/vendor/mgba/intl/activate.py +70 -0
  191. package/mgba-bridge/vendor/mgba/intl/core_option_regex.py +95 -0
  192. package/mgba-bridge/vendor/mgba/intl/core_option_translation.py +633 -0
  193. package/mgba-bridge/vendor/mgba/intl/crowdin.yaml +13 -0
  194. package/mgba-bridge/vendor/mgba/intl/crowdin_prep.py +30 -0
  195. package/mgba-bridge/vendor/mgba/intl/crowdin_source_upload.py +93 -0
  196. package/mgba-bridge/vendor/mgba/intl/crowdin_translate.py +39 -0
  197. package/mgba-bridge/vendor/mgba/intl/crowdin_translation_download.py +93 -0
  198. package/mgba-bridge/vendor/mgba/intl/download_workflow.py +16 -0
  199. package/mgba-bridge/vendor/mgba/intl/initial_sync.py +125 -0
  200. package/mgba-bridge/vendor/mgba/intl/remove_initial_cycle.py +30 -0
  201. package/mgba-bridge/vendor/mgba/intl/upload_workflow.py +15 -0
  202. package/mgba-bridge/vendor/mgba/intl/v1_to_v2_converter.py +483 -0
  203. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.android_arm64-v8a +96 -0
  204. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.android_armeabi +96 -0
  205. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.android_armeabi-v7a +96 -0
  206. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.android_mips +96 -0
  207. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.android_mips64 +96 -0
  208. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.android_x86 +96 -0
  209. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.android_x86_64 +96 -0
  210. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.common +156 -0
  211. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.linux-portable_x86 +96 -0
  212. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.linux-portable_x86_64 +96 -0
  213. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.linux_x86 +96 -0
  214. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.linux_x86_64 +96 -0
  215. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.mingw_x86 +96 -0
  216. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.mingw_x86_64 +96 -0
  217. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.osx_x86 +96 -0
  218. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.osx_x86_64 +96 -0
  219. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.rules +45 -0
  220. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.vita_arm +96 -0
  221. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.wii_ppc +96 -0
  222. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.windows_x86 +96 -0
  223. package/mgba-bridge/vendor/mgba/libretro-build/Makefile.windows_x86_64 +96 -0
  224. package/mgba-bridge/vendor/mgba/libretro-build/include/libz/zconf.h +511 -0
  225. package/mgba-bridge/vendor/mgba/libretro-build/jni/Android.mk +23 -0
  226. package/mgba-bridge/vendor/mgba/libretro-build/jni/Application.mk +2 -0
  227. package/mgba-bridge/vendor/mgba/libretro-build/link.T +5 -0
  228. package/mgba-bridge/vendor/mgba/link.T +4 -0
  229. package/mgba-bridge/vendor/mgba/opt/libgba/mgba.c +94 -0
  230. package/mgba-bridge/vendor/mgba/opt/libgba/mgba.h +46 -0
  231. package/mgba-bridge/vendor/mgba/src/arm/CMakeLists.txt +19 -0
  232. package/mgba-bridge/vendor/mgba/src/arm/arm.c +264 -0
  233. package/mgba-bridge/vendor/mgba/src/arm/debugger/cli-debugger.c +187 -0
  234. package/mgba-bridge/vendor/mgba/src/arm/debugger/debugger.c +588 -0
  235. package/mgba-bridge/vendor/mgba/src/arm/debugger/memory-debugger.c +158 -0
  236. package/mgba-bridge/vendor/mgba/src/arm/decoder-arm.c +466 -0
  237. package/mgba-bridge/vendor/mgba/src/arm/decoder-thumb.c +344 -0
  238. package/mgba-bridge/vendor/mgba/src/arm/decoder.c +601 -0
  239. package/mgba-bridge/vendor/mgba/src/arm/isa-arm.c +784 -0
  240. package/mgba-bridge/vendor/mgba/src/arm/isa-thumb.c +417 -0
  241. package/mgba-bridge/vendor/mgba/src/core/CMakeLists.txt +47 -0
  242. package/mgba-bridge/vendor/mgba/src/core/bitmap-cache.c +187 -0
  243. package/mgba-bridge/vendor/mgba/src/core/cache-set.c +83 -0
  244. package/mgba-bridge/vendor/mgba/src/core/cheats.c +807 -0
  245. package/mgba-bridge/vendor/mgba/src/core/config.c +548 -0
  246. package/mgba-bridge/vendor/mgba/src/core/core-serialize.c +585 -0
  247. package/mgba-bridge/vendor/mgba/src/core/core.c +539 -0
  248. package/mgba-bridge/vendor/mgba/src/core/directories.c +196 -0
  249. package/mgba-bridge/vendor/mgba/src/core/flags.h.in +204 -0
  250. package/mgba-bridge/vendor/mgba/src/core/input.c +677 -0
  251. package/mgba-bridge/vendor/mgba/src/core/interface.c +154 -0
  252. package/mgba-bridge/vendor/mgba/src/core/library.c +584 -0
  253. package/mgba-bridge/vendor/mgba/src/core/lockstep.c +43 -0
  254. package/mgba-bridge/vendor/mgba/src/core/log.c +294 -0
  255. package/mgba-bridge/vendor/mgba/src/core/map-cache.c +219 -0
  256. package/mgba-bridge/vendor/mgba/src/core/mem-search.c +342 -0
  257. package/mgba-bridge/vendor/mgba/src/core/rewind.c +186 -0
  258. package/mgba-bridge/vendor/mgba/src/core/scripting.c +1481 -0
  259. package/mgba-bridge/vendor/mgba/src/core/sync.c +121 -0
  260. package/mgba-bridge/vendor/mgba/src/core/thread.c +726 -0
  261. package/mgba-bridge/vendor/mgba/src/core/tile-cache.c +283 -0
  262. package/mgba-bridge/vendor/mgba/src/core/timing.c +137 -0
  263. package/mgba-bridge/vendor/mgba/src/core/version.c.in +14 -0
  264. package/mgba-bridge/vendor/mgba/src/debugger/CMakeLists.txt +30 -0
  265. package/mgba-bridge/vendor/mgba/src/debugger/access-logger.c +592 -0
  266. package/mgba-bridge/vendor/mgba/src/debugger/cli-debugger-scripting.c +137 -0
  267. package/mgba-bridge/vendor/mgba/src/debugger/cli-debugger.c +1482 -0
  268. package/mgba-bridge/vendor/mgba/src/debugger/cli-el-backend.c +248 -0
  269. package/mgba-bridge/vendor/mgba/src/debugger/debugger.c +327 -0
  270. package/mgba-bridge/vendor/mgba/src/debugger/gdb-stub.c +918 -0
  271. package/mgba-bridge/vendor/mgba/src/debugger/parser.c +902 -0
  272. package/mgba-bridge/vendor/mgba/src/debugger/stack-trace.c +133 -0
  273. package/mgba-bridge/vendor/mgba/src/debugger/symbols.c +109 -0
  274. package/mgba-bridge/vendor/mgba/src/feature/CMakeLists.txt +24 -0
  275. package/mgba-bridge/vendor/mgba/src/feature/commandline.c +404 -0
  276. package/mgba-bridge/vendor/mgba/src/feature/ffmpeg/ffmpeg-common.h +95 -0
  277. package/mgba-bridge/vendor/mgba/src/feature/ffmpeg/ffmpeg-decoder.c +204 -0
  278. package/mgba-bridge/vendor/mgba/src/feature/ffmpeg/ffmpeg-decoder.h +45 -0
  279. package/mgba-bridge/vendor/mgba/src/feature/ffmpeg/ffmpeg-encoder.c +960 -0
  280. package/mgba-bridge/vendor/mgba/src/feature/ffmpeg/ffmpeg-encoder.h +91 -0
  281. package/mgba-bridge/vendor/mgba/src/feature/ffmpeg/ffmpeg-scale.c +36 -0
  282. package/mgba-bridge/vendor/mgba/src/feature/ffmpeg/ffmpeg-scale.h +21 -0
  283. package/mgba-bridge/vendor/mgba/src/feature/gui/cheats.c +195 -0
  284. package/mgba-bridge/vendor/mgba/src/feature/gui/cheats.h +18 -0
  285. package/mgba-bridge/vendor/mgba/src/feature/gui/gui-config.c +438 -0
  286. package/mgba-bridge/vendor/mgba/src/feature/gui/gui-config.h +19 -0
  287. package/mgba-bridge/vendor/mgba/src/feature/gui/gui-runner.c +853 -0
  288. package/mgba-bridge/vendor/mgba/src/feature/gui/gui-runner.h +114 -0
  289. package/mgba-bridge/vendor/mgba/src/feature/gui/remap.c +88 -0
  290. package/mgba-bridge/vendor/mgba/src/feature/gui/remap.h +27 -0
  291. package/mgba-bridge/vendor/mgba/src/feature/proxy-backend.c +286 -0
  292. package/mgba-bridge/vendor/mgba/src/feature/thread-proxy.c +213 -0
  293. package/mgba-bridge/vendor/mgba/src/feature/updater.c +227 -0
  294. package/mgba-bridge/vendor/mgba/src/feature/video-backend.c +45 -0
  295. package/mgba-bridge/vendor/mgba/src/feature/video-logger.c +1092 -0
  296. package/mgba-bridge/vendor/mgba/src/gb/CMakeLists.txt +53 -0
  297. package/mgba-bridge/vendor/mgba/src/gb/audio.c +1149 -0
  298. package/mgba-bridge/vendor/mgba/src/gb/cheats.c +190 -0
  299. package/mgba-bridge/vendor/mgba/src/gb/core.c +1539 -0
  300. package/mgba-bridge/vendor/mgba/src/gb/debugger/cli.c +115 -0
  301. package/mgba-bridge/vendor/mgba/src/gb/debugger/debugger.c +46 -0
  302. package/mgba-bridge/vendor/mgba/src/gb/debugger/symbols.c +61 -0
  303. package/mgba-bridge/vendor/mgba/src/gb/extra/proxy.c +328 -0
  304. package/mgba-bridge/vendor/mgba/src/gb/gb.c +1261 -0
  305. package/mgba-bridge/vendor/mgba/src/gb/input.c +29 -0
  306. package/mgba-bridge/vendor/mgba/src/gb/io.c +735 -0
  307. package/mgba-bridge/vendor/mgba/src/gb/mbc/huc-3.c +218 -0
  308. package/mgba-bridge/vendor/mgba/src/gb/mbc/licensed.c +84 -0
  309. package/mgba-bridge/vendor/mgba/src/gb/mbc/mbc-private.h +66 -0
  310. package/mgba-bridge/vendor/mgba/src/gb/mbc/mbc.c +583 -0
  311. package/mgba-bridge/vendor/mgba/src/gb/mbc/pocket-cam.c +142 -0
  312. package/mgba-bridge/vendor/mgba/src/gb/mbc/tama5.c +433 -0
  313. package/mgba-bridge/vendor/mgba/src/gb/mbc/unlicensed.c +601 -0
  314. package/mgba-bridge/vendor/mgba/src/gb/mbc.c +650 -0
  315. package/mgba-bridge/vendor/mgba/src/gb/memory.c +1079 -0
  316. package/mgba-bridge/vendor/mgba/src/gb/overrides.c +939 -0
  317. package/mgba-bridge/vendor/mgba/src/gb/renderers/cache-set.c +129 -0
  318. package/mgba-bridge/vendor/mgba/src/gb/renderers/software.c +1169 -0
  319. package/mgba-bridge/vendor/mgba/src/gb/serialize.c +310 -0
  320. package/mgba-bridge/vendor/mgba/src/gb/sio/lockstep.c +284 -0
  321. package/mgba-bridge/vendor/mgba/src/gb/sio/printer.c +237 -0
  322. package/mgba-bridge/vendor/mgba/src/gb/sio.c +106 -0
  323. package/mgba-bridge/vendor/mgba/src/gb/timer.c +150 -0
  324. package/mgba-bridge/vendor/mgba/src/gb/video.c +1216 -0
  325. package/mgba-bridge/vendor/mgba/src/gba/CMakeLists.txt +62 -0
  326. package/mgba-bridge/vendor/mgba/src/gba/audio.c +555 -0
  327. package/mgba-bridge/vendor/mgba/src/gba/bios.c +981 -0
  328. package/mgba-bridge/vendor/mgba/src/gba/cart/ereader.c +1639 -0
  329. package/mgba-bridge/vendor/mgba/src/gba/cart/gpio.c +584 -0
  330. package/mgba-bridge/vendor/mgba/src/gba/cart/matrix.c +134 -0
  331. package/mgba-bridge/vendor/mgba/src/gba/cart/unlicensed.c +255 -0
  332. package/mgba-bridge/vendor/mgba/src/gba/cart/vfame.c +320 -0
  333. package/mgba-bridge/vendor/mgba/src/gba/cheats/codebreaker.c +323 -0
  334. package/mgba-bridge/vendor/mgba/src/gba/cheats/gameshark.c +318 -0
  335. package/mgba-bridge/vendor/mgba/src/gba/cheats/gameshark.h +32 -0
  336. package/mgba-bridge/vendor/mgba/src/gba/cheats/parv3.c +442 -0
  337. package/mgba-bridge/vendor/mgba/src/gba/cheats/parv3.h +21 -0
  338. package/mgba-bridge/vendor/mgba/src/gba/cheats.c +386 -0
  339. package/mgba-bridge/vendor/mgba/src/gba/core.c +1822 -0
  340. package/mgba-bridge/vendor/mgba/src/gba/debugger/cli.c +116 -0
  341. package/mgba-bridge/vendor/mgba/src/gba/dma.c +363 -0
  342. package/mgba-bridge/vendor/mgba/src/gba/extra/battlechip.c +171 -0
  343. package/mgba-bridge/vendor/mgba/src/gba/extra/proxy.c +408 -0
  344. package/mgba-bridge/vendor/mgba/src/gba/gba.c +1095 -0
  345. package/mgba-bridge/vendor/mgba/src/gba/hle-bios-src.s +400 -0
  346. package/mgba-bridge/vendor/mgba/src/gba/hle-bios.c +103 -0
  347. package/mgba-bridge/vendor/mgba/src/gba/hle-bios.h +17 -0
  348. package/mgba-bridge/vendor/mgba/src/gba/hle-bios.make +18 -0
  349. package/mgba-bridge/vendor/mgba/src/gba/input.c +31 -0
  350. package/mgba-bridge/vendor/mgba/src/gba/io.c +1085 -0
  351. package/mgba-bridge/vendor/mgba/src/gba/memory.c +1974 -0
  352. package/mgba-bridge/vendor/mgba/src/gba/overrides.c +435 -0
  353. package/mgba-bridge/vendor/mgba/src/gba/renderers/cache-set.c +219 -0
  354. package/mgba-bridge/vendor/mgba/src/gba/renderers/common.c +59 -0
  355. package/mgba-bridge/vendor/mgba/src/gba/renderers/gl.c +2137 -0
  356. package/mgba-bridge/vendor/mgba/src/gba/renderers/software-bg.c +228 -0
  357. package/mgba-bridge/vendor/mgba/src/gba/renderers/software-mode0.c +576 -0
  358. package/mgba-bridge/vendor/mgba/src/gba/renderers/software-obj.c +431 -0
  359. package/mgba-bridge/vendor/mgba/src/gba/renderers/software-private.h +283 -0
  360. package/mgba-bridge/vendor/mgba/src/gba/renderers/video-software.c +1117 -0
  361. package/mgba-bridge/vendor/mgba/src/gba/savedata.c +792 -0
  362. package/mgba-bridge/vendor/mgba/src/gba/serialize.c +242 -0
  363. package/mgba-bridge/vendor/mgba/src/gba/sharkport.c +389 -0
  364. package/mgba-bridge/vendor/mgba/src/gba/sio/dolphin.c +217 -0
  365. package/mgba-bridge/vendor/mgba/src/gba/sio/gbp.c +150 -0
  366. package/mgba-bridge/vendor/mgba/src/gba/sio/lockstep.c +1063 -0
  367. package/mgba-bridge/vendor/mgba/src/gba/sio.c +493 -0
  368. package/mgba-bridge/vendor/mgba/src/gba/timer.c +153 -0
  369. package/mgba-bridge/vendor/mgba/src/gba/video.c +470 -0
  370. package/mgba-bridge/vendor/mgba/src/platform/cmake/DMGOverrides.cmake.in +6 -0
  371. package/mgba-bridge/vendor/mgba/src/platform/cmake/DebugStrip.cmake +12 -0
  372. package/mgba-bridge/vendor/mgba/src/platform/cmake/ExportDirectory.cmake +7 -0
  373. package/mgba-bridge/vendor/mgba/src/platform/cmake/FindFeature.cmake +88 -0
  374. package/mgba-bridge/vendor/mgba/src/platform/cmake/FindFunction.cmake +14 -0
  375. package/mgba-bridge/vendor/mgba/src/platform/cmake/FindSDL2.cmake +164 -0
  376. package/mgba-bridge/vendor/mgba/src/platform/cmake/Findepoxy.cmake +10 -0
  377. package/mgba-bridge/vendor/mgba/src/platform/cmake/devkitPro.cmake +44 -0
  378. package/mgba-bridge/vendor/mgba/src/platform/example/client-server/client.c +160 -0
  379. package/mgba-bridge/vendor/mgba/src/platform/example/client-server/server.c +168 -0
  380. package/mgba-bridge/vendor/mgba/src/platform/headless-main.c +379 -0
  381. package/mgba-bridge/vendor/mgba/src/platform/libretro/libretro.c +2611 -0
  382. package/mgba-bridge/vendor/mgba/src/platform/libretro/libretro.h +7846 -0
  383. package/mgba-bridge/vendor/mgba/src/platform/libretro/libretro_core_options.h +721 -0
  384. package/mgba-bridge/vendor/mgba/src/platform/libretro/libretro_core_options_intl.h +17798 -0
  385. package/mgba-bridge/vendor/mgba/src/platform/libretro/memory.c +22 -0
  386. package/mgba-bridge/vendor/mgba/src/platform/libretro/retro_inline.h +39 -0
  387. package/mgba-bridge/vendor/mgba/src/platform/opengl/gl.c +304 -0
  388. package/mgba-bridge/vendor/mgba/src/platform/opengl/gl.h +40 -0
  389. package/mgba-bridge/vendor/mgba/src/platform/opengl/gles2.c +1230 -0
  390. package/mgba-bridge/vendor/mgba/src/platform/opengl/gles2.h +117 -0
  391. package/mgba-bridge/vendor/mgba/src/platform/posix/memory.c +37 -0
  392. package/mgba-bridge/vendor/mgba/src/script/CMakeLists.txt +38 -0
  393. package/mgba-bridge/vendor/mgba/src/script/canvas.c +292 -0
  394. package/mgba-bridge/vendor/mgba/src/script/console.c +141 -0
  395. package/mgba-bridge/vendor/mgba/src/script/context.c +492 -0
  396. package/mgba-bridge/vendor/mgba/src/script/engines/lua.c +1617 -0
  397. package/mgba-bridge/vendor/mgba/src/script/image.c +338 -0
  398. package/mgba-bridge/vendor/mgba/src/script/input.c +612 -0
  399. package/mgba-bridge/vendor/mgba/src/script/socket.c +284 -0
  400. package/mgba-bridge/vendor/mgba/src/script/stdlib.c +306 -0
  401. package/mgba-bridge/vendor/mgba/src/script/storage.c +557 -0
  402. package/mgba-bridge/vendor/mgba/src/script/test.h +29 -0
  403. package/mgba-bridge/vendor/mgba/src/script/types.c +1886 -0
  404. package/mgba-bridge/vendor/mgba/src/sm83/CMakeLists.txt +16 -0
  405. package/mgba-bridge/vendor/mgba/src/sm83/debugger/cli-debugger.c +110 -0
  406. package/mgba-bridge/vendor/mgba/src/sm83/debugger/debugger.c +266 -0
  407. package/mgba-bridge/vendor/mgba/src/sm83/debugger/memory-debugger.c +84 -0
  408. package/mgba-bridge/vendor/mgba/src/sm83/decoder.c +608 -0
  409. package/mgba-bridge/vendor/mgba/src/sm83/isa-sm83.c +817 -0
  410. package/mgba-bridge/vendor/mgba/src/sm83/sm83.c +199 -0
  411. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/.clang-format +92 -0
  412. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/CMakeLists.txt +18 -0
  413. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/LICENSE +19 -0
  414. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/README.md +152 -0
  415. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/discord_register.h +26 -0
  416. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/discord_rpc.h +87 -0
  417. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/mingw-std-threads/LICENSE +24 -0
  418. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/mingw-std-threads/README.md +41 -0
  419. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/mingw-std-threads/condition_variable +549 -0
  420. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/mingw-std-threads/mutex +474 -0
  421. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/mingw-std-threads/shared_mutex +497 -0
  422. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/mingw-std-threads/thread +410 -0
  423. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/allocators.h +271 -0
  424. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/document.h +2573 -0
  425. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/encodedstream.h +299 -0
  426. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/encodings.h +716 -0
  427. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/error/en.h +74 -0
  428. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/error/error.h +155 -0
  429. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/filereadstream.h +99 -0
  430. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/filewritestream.h +104 -0
  431. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/fwd.h +151 -0
  432. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/biginteger.h +290 -0
  433. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/diyfp.h +258 -0
  434. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/dtoa.h +245 -0
  435. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/ieee754.h +78 -0
  436. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/itoa.h +304 -0
  437. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/meta.h +181 -0
  438. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/pow10.h +55 -0
  439. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/regex.h +701 -0
  440. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/stack.h +230 -0
  441. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/strfunc.h +55 -0
  442. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/strtod.h +269 -0
  443. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/internal/swap.h +46 -0
  444. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/istreamwrapper.h +115 -0
  445. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/license.txt +57 -0
  446. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/memorybuffer.h +70 -0
  447. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/memorystream.h +71 -0
  448. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/msinttypes/inttypes.h +316 -0
  449. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/msinttypes/stdint.h +300 -0
  450. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/ostreamwrapper.h +81 -0
  451. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/pointer.h +1358 -0
  452. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/prettywriter.h +255 -0
  453. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/rapidjson.h +615 -0
  454. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/reader.h +1879 -0
  455. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/schema.h +2006 -0
  456. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/stream.h +179 -0
  457. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/stringbuffer.h +117 -0
  458. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/include/rapidjson/writer.h +610 -0
  459. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/CMakeLists.txt +90 -0
  460. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/backoff.h +40 -0
  461. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/connection.h +19 -0
  462. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/connection_unix.cpp +125 -0
  463. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/connection_win.cpp +128 -0
  464. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/discord_register_linux.cpp +102 -0
  465. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/discord_register_osx.m +80 -0
  466. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/discord_register_win.cpp +185 -0
  467. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/discord_rpc.cpp +504 -0
  468. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/dllmain.cpp +8 -0
  469. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/msg_queue.h +36 -0
  470. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/rpc_connection.cpp +137 -0
  471. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/rpc_connection.h +59 -0
  472. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/serialization.cpp +245 -0
  473. package/mgba-bridge/vendor/mgba/src/third-party/discord-rpc/src/serialization.h +215 -0
  474. package/mgba-bridge/vendor/mgba/src/third-party/inih/LICENSE.txt +27 -0
  475. package/mgba-bridge/vendor/mgba/src/third-party/inih/README.md +157 -0
  476. package/mgba-bridge/vendor/mgba/src/third-party/inih/ini.c +288 -0
  477. package/mgba-bridge/vendor/mgba/src/third-party/inih/ini.h +148 -0
  478. package/mgba-bridge/vendor/mgba/src/third-party/libpng/ANNOUNCE +47 -0
  479. package/mgba-bridge/vendor/mgba/src/third-party/libpng/AUTHORS +45 -0
  480. package/mgba-bridge/vendor/mgba/src/third-party/libpng/CHANGES +6109 -0
  481. package/mgba-bridge/vendor/mgba/src/third-party/libpng/CMakeLists.txt +931 -0
  482. package/mgba-bridge/vendor/mgba/src/third-party/libpng/INSTALL +465 -0
  483. package/mgba-bridge/vendor/mgba/src/third-party/libpng/LICENSE +134 -0
  484. package/mgba-bridge/vendor/mgba/src/third-party/libpng/Makefile.am +393 -0
  485. package/mgba-bridge/vendor/mgba/src/third-party/libpng/Makefile.in +2428 -0
  486. package/mgba-bridge/vendor/mgba/src/third-party/libpng/README +183 -0
  487. package/mgba-bridge/vendor/mgba/src/third-party/libpng/TODO +23 -0
  488. package/mgba-bridge/vendor/mgba/src/third-party/libpng/TRADEMARK +8 -0
  489. package/mgba-bridge/vendor/mgba/src/third-party/libpng/aclocal.m4 +1196 -0
  490. package/mgba-bridge/vendor/mgba/src/third-party/libpng/arm/arm_init.c +136 -0
  491. package/mgba-bridge/vendor/mgba/src/third-party/libpng/arm/filter_neon.S +253 -0
  492. package/mgba-bridge/vendor/mgba/src/third-party/libpng/arm/filter_neon_intrinsics.c +402 -0
  493. package/mgba-bridge/vendor/mgba/src/third-party/libpng/arm/palette_neon_intrinsics.c +149 -0
  494. package/mgba-bridge/vendor/mgba/src/third-party/libpng/autogen.sh +225 -0
  495. package/mgba-bridge/vendor/mgba/src/third-party/libpng/compile +348 -0
  496. package/mgba-bridge/vendor/mgba/src/third-party/libpng/config.guess +1476 -0
  497. package/mgba-bridge/vendor/mgba/src/third-party/libpng/config.h.in +126 -0
  498. package/mgba-bridge/vendor/mgba/src/third-party/libpng/config.sub +1801 -0
  499. package/mgba-bridge/vendor/mgba/src/third-party/libpng/configure +16116 -0
  500. package/mgba-bridge/vendor/mgba/src/third-party/libpng/configure.ac +532 -0
  501. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/README.txt +5 -0
  502. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/arm-neon/README +83 -0
  503. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/arm-neon/android-ndk.c +39 -0
  504. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/arm-neon/linux-auxv.c +120 -0
  505. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/arm-neon/linux.c +161 -0
  506. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/conftest/README +49 -0
  507. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/conftest/pngcp.dfa +57 -0
  508. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/conftest/read.dfa +58 -0
  509. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/conftest/s_read.dfa +35 -0
  510. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/conftest/s_write.dfa +33 -0
  511. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/conftest/simple.dfa +36 -0
  512. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/conftest/write.dfa +45 -0
  513. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/examples/README.txt +24 -0
  514. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/examples/iccfrompng.c +185 -0
  515. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/examples/pngpixel.c +371 -0
  516. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/examples/pngtopng.c +98 -0
  517. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/examples/simpleover.c +648 -0
  518. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/COPYING +340 -0
  519. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/LICENSE +50 -0
  520. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/Makefile.mingw32 +131 -0
  521. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/Makefile.sgi +105 -0
  522. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/Makefile.unx +134 -0
  523. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/Makefile.w32 +114 -0
  524. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/README +186 -0
  525. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/makevms.com +132 -0
  526. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/readpng.c +323 -0
  527. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/readpng.h +88 -0
  528. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/readpng2.c +521 -0
  529. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/readpng2.h +116 -0
  530. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/readppm.c +188 -0
  531. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/rpng-win.c +735 -0
  532. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/rpng-x.c +911 -0
  533. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/rpng2-win.c +1261 -0
  534. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/rpng2-x.c +2143 -0
  535. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/toucan.png +0 -0
  536. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/wpng.c +865 -0
  537. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/writepng.c +401 -0
  538. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/gregbook/writepng.h +133 -0
  539. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/fakepng.c +65 -0
  540. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/gentests.sh +102 -0
  541. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/makepng.c +1941 -0
  542. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/pngimage.c +1712 -0
  543. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/pngstest-errors.h +165 -0
  544. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/pngstest.c +3828 -0
  545. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/pngunknown.c +1294 -0
  546. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/pngvalid.c +12230 -0
  547. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/readpng.c +115 -0
  548. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/tarith.c +999 -0
  549. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/libtests/timepng.c +608 -0
  550. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/mips-msa/README +83 -0
  551. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/mips-msa/linux.c +64 -0
  552. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/oss-fuzz/Dockerfile +25 -0
  553. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/oss-fuzz/README.txt +37 -0
  554. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/oss-fuzz/build.sh +51 -0
  555. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc +190 -0
  556. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/oss-fuzz/libpng_read_fuzzer.options +2 -0
  557. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/oss-fuzz/png.dict +39 -0
  558. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/README +5 -0
  559. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/decoder/README +10 -0
  560. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/decoder/makefile +151 -0
  561. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/decoder/pngusr.dfa +40 -0
  562. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/decoder/pngusr.h +23 -0
  563. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/encoder/README +10 -0
  564. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/encoder/makefile +150 -0
  565. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/encoder/pngusr.dfa +39 -0
  566. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/encoder/pngusr.h +23 -0
  567. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/preader/README +15 -0
  568. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/preader/makefile +166 -0
  569. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/preader/pngusr.dfa +40 -0
  570. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminim/preader/pngusr.h +23 -0
  571. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/CHANGES.txt +13 -0
  572. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/CMakeLists.txt +24 -0
  573. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/LICENSE.txt +22 -0
  574. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/Makefile +62 -0
  575. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/README.txt +120 -0
  576. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/makevms.com +92 -0
  577. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/png2pnm.bat +41 -0
  578. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/png2pnm.c +427 -0
  579. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/png2pnm.sh +42 -0
  580. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/pngminus.bat +4 -0
  581. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/pngminus.sh +5 -0
  582. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/pnm2png.bat +41 -0
  583. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/pnm2png.c +620 -0
  584. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngminus/pnm2png.sh +42 -0
  585. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/README +107 -0
  586. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/bad_interlace_conversions.txt +9 -0
  587. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn0g01.png +0 -0
  588. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn0g02.png +0 -0
  589. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn0g04.png +0 -0
  590. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn0g08.png +0 -0
  591. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn0g16.png +0 -0
  592. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn2c08.png +0 -0
  593. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn2c16.png +0 -0
  594. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn3p01.png +0 -0
  595. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn3p02.png +0 -0
  596. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn3p04.png +0 -0
  597. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn3p08.png +0 -0
  598. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn4a08.png +0 -0
  599. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn4a16.png +0 -0
  600. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn6a08.png +0 -0
  601. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/basn6a16.png +0 -0
  602. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbbn0g01.png +0 -0
  603. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbbn0g02.png +0 -0
  604. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbbn0g04.png +0 -0
  605. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbbn2c16.png +0 -0
  606. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbbn3p08.png +0 -0
  607. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbgn2c16.png +0 -0
  608. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbgn3p08.png +0 -0
  609. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbrn2c08.png +0 -0
  610. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbwn0g16.png +0 -0
  611. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbwn3p08.png +0 -0
  612. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftbyn3p08.png +0 -0
  613. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftp0n0g08.png +0 -0
  614. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftp0n2c08.png +0 -0
  615. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftp0n3p08.png +0 -0
  616. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ftp1n3p08.png +0 -0
  617. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn0g08.png +0 -0
  618. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn0g16.png +0 -0
  619. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn2c08.png +0 -0
  620. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn2c16.png +0 -0
  621. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn3p08.png +0 -0
  622. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn4a08.png +0 -0
  623. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn4a16.png +0 -0
  624. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn6a08.png +0 -0
  625. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/ibasn6a16.png +0 -0
  626. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbbn2c16.png +0 -0
  627. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbbn3p08.png +0 -0
  628. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbgn2c16.png +0 -0
  629. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbgn3p08.png +0 -0
  630. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbrn2c08.png +0 -0
  631. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbwn0g16.png +0 -0
  632. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbwn3p08.png +0 -0
  633. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftbyn3p08.png +0 -0
  634. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftp0n0g08.png +0 -0
  635. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftp0n2c08.png +0 -0
  636. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftp0n3p08.png +0 -0
  637. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/iftp1n3p08.png +0 -0
  638. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/README +2 -0
  639. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/ibasn0g01.png +0 -0
  640. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/ibasn0g02.png +0 -0
  641. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/ibasn0g04.png +0 -0
  642. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/ibasn3p01.png +0 -0
  643. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/ibasn3p02.png +0 -0
  644. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/ibasn3p04.png +0 -0
  645. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/iftbbn0g01.png +0 -0
  646. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/iftbbn0g02.png +0 -0
  647. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/pngsuite/interlaced/iftbbn0g04.png +0 -0
  648. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/powerpc-vsx/README +81 -0
  649. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/powerpc-vsx/linux.c +57 -0
  650. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/powerpc-vsx/linux_aux.c +34 -0
  651. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/bad_iCCP.png +0 -0
  652. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/badadler.png +0 -0
  653. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/badcrc.png +0 -0
  654. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/empty_ancillary_chunks.png +0 -0
  655. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_IDAT.png +0 -0
  656. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_bKGD_chunk.png +0 -0
  657. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_cHRM_chunk.png +0 -0
  658. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_eXIf_chunk.png +0 -0
  659. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_gAMA_chunk.png +0 -0
  660. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_hIST_chunk.png +0 -0
  661. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_iCCP_chunk.png +0 -0
  662. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_iTXt_chunk.png +0 -0
  663. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_juNK_unsafe_to_copy.png +0 -0
  664. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_juNk_safe_to_copy.png +0 -0
  665. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_pCAL_chunk.png +0 -0
  666. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_pHYs_chunk.png +0 -0
  667. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_sCAL_chunk.png +0 -0
  668. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_sPLT_chunk.png +0 -0
  669. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_sRGB_chunk.png +0 -0
  670. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_sTER_chunk.png +0 -0
  671. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_tEXt_chunk.png +0 -0
  672. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_tIME_chunk.png +0 -0
  673. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/crashers/huge_zTXt_chunk.png +0 -0
  674. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1-1.8-tRNS.png +0 -0
  675. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1-1.8.png +0 -0
  676. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1-linear-tRNS.png +0 -0
  677. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1-linear.png +0 -0
  678. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1-sRGB-tRNS.png +0 -0
  679. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1-sRGB.png +0 -0
  680. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1-tRNS.png +0 -0
  681. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-1.png +0 -0
  682. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16-1.8-tRNS.png +0 -0
  683. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16-1.8.png +0 -0
  684. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16-linear-tRNS.png +0 -0
  685. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16-linear.png +0 -0
  686. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16-sRGB-tRNS.png +0 -0
  687. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16-sRGB.png +0 -0
  688. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16-tRNS.png +0 -0
  689. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-16.png +0 -0
  690. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2-1.8-tRNS.png +0 -0
  691. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2-1.8.png +0 -0
  692. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2-linear-tRNS.png +0 -0
  693. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2-linear.png +0 -0
  694. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2-sRGB-tRNS.png +0 -0
  695. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2-sRGB.png +0 -0
  696. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2-tRNS.png +0 -0
  697. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-2.png +0 -0
  698. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4-1.8-tRNS.png +0 -0
  699. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4-1.8.png +0 -0
  700. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4-linear-tRNS.png +0 -0
  701. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4-linear.png +0 -0
  702. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4-sRGB-tRNS.png +0 -0
  703. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4-sRGB.png +0 -0
  704. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4-tRNS.png +0 -0
  705. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-4.png +0 -0
  706. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8-1.8-tRNS.png +0 -0
  707. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8-1.8.png +0 -0
  708. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8-linear-tRNS.png +0 -0
  709. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8-linear.png +0 -0
  710. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8-sRGB-tRNS.png +0 -0
  711. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8-sRGB.png +0 -0
  712. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8-tRNS.png +0 -0
  713. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-8.png +0 -0
  714. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-16-1.8.png +0 -0
  715. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-16-linear.png +0 -0
  716. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-16-sRGB.png +0 -0
  717. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-16.png +0 -0
  718. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-8-1.8.png +0 -0
  719. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-8-linear.png +0 -0
  720. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-8-sRGB.png +0 -0
  721. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/gray-alpha-8.png +0 -0
  722. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/makepngs.sh +94 -0
  723. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1-1.8-tRNS.png +0 -0
  724. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1-1.8.png +0 -0
  725. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1-linear-tRNS.png +0 -0
  726. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1-linear.png +0 -0
  727. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1-sRGB-tRNS.png +0 -0
  728. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1-sRGB.png +0 -0
  729. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1-tRNS.png +0 -0
  730. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-1.png +0 -0
  731. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2-1.8-tRNS.png +0 -0
  732. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2-1.8.png +0 -0
  733. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2-linear-tRNS.png +0 -0
  734. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2-linear.png +0 -0
  735. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2-sRGB-tRNS.png +0 -0
  736. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2-sRGB.png +0 -0
  737. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2-tRNS.png +0 -0
  738. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-2.png +0 -0
  739. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4-1.8-tRNS.png +0 -0
  740. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4-1.8.png +0 -0
  741. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4-linear-tRNS.png +0 -0
  742. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4-linear.png +0 -0
  743. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4-sRGB-tRNS.png +0 -0
  744. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4-sRGB.png +0 -0
  745. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4-tRNS.png +0 -0
  746. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-4.png +0 -0
  747. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8-1.8-tRNS.png +0 -0
  748. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8-1.8.png +0 -0
  749. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8-linear-tRNS.png +0 -0
  750. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8-linear.png +0 -0
  751. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8-sRGB-tRNS.png +0 -0
  752. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8-sRGB.png +0 -0
  753. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8-tRNS.png +0 -0
  754. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/palette-8.png +0 -0
  755. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16-1.8-tRNS.png +0 -0
  756. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16-1.8.png +0 -0
  757. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16-linear-tRNS.png +0 -0
  758. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16-linear.png +0 -0
  759. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16-sRGB-tRNS.png +0 -0
  760. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16-sRGB.png +0 -0
  761. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16-tRNS.png +0 -0
  762. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-16.png +0 -0
  763. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8-1.8-tRNS.png +0 -0
  764. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8-1.8.png +0 -0
  765. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8-linear-tRNS.png +0 -0
  766. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8-linear.png +0 -0
  767. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8-sRGB-tRNS.png +0 -0
  768. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8-sRGB.png +0 -0
  769. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8-tRNS.png +0 -0
  770. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-8.png +0 -0
  771. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-16-1.8.png +0 -0
  772. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-16-linear.png +0 -0
  773. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-16-sRGB.png +0 -0
  774. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-16.png +0 -0
  775. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-8-1.8.png +0 -0
  776. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-8-linear.png +0 -0
  777. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-8-sRGB.png +0 -0
  778. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/testpngs/rgb-alpha-8.png +0 -0
  779. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/README.txt +27 -0
  780. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/checksum-icc.c +102 -0
  781. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/chkfmt +144 -0
  782. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/cvtcolor.c +188 -0
  783. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/genpng.c +881 -0
  784. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/intgamma.sh +110 -0
  785. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/makesRGB.c +430 -0
  786. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/png-fix-itxt.c +164 -0
  787. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/pngcp.c +2453 -0
  788. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/pngfix.c +4049 -0
  789. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/reindent +25 -0
  790. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/tools/sRGB.h +48 -0
  791. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/PngFile.c +454 -0
  792. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/PngFile.h +30 -0
  793. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/README.txt +61 -0
  794. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/VisualPng.c +978 -0
  795. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/VisualPng.dsp +147 -0
  796. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/VisualPng.dsw +29 -0
  797. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/VisualPng.ico +0 -0
  798. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/VisualPng.png +0 -0
  799. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/VisualPng.rc +152 -0
  800. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/cexcept.h +248 -0
  801. package/mgba-bridge/vendor/mgba/src/third-party/libpng/contrib/visupng/resource.h +23 -0
  802. package/mgba-bridge/vendor/mgba/src/third-party/libpng/depcomp +791 -0
  803. package/mgba-bridge/vendor/mgba/src/third-party/libpng/example.c +1040 -0
  804. package/mgba-bridge/vendor/mgba/src/third-party/libpng/install-sh +518 -0
  805. package/mgba-bridge/vendor/mgba/src/third-party/libpng/intel/filter_sse2_intrinsics.c +391 -0
  806. package/mgba-bridge/vendor/mgba/src/third-party/libpng/intel/intel_init.c +52 -0
  807. package/mgba-bridge/vendor/mgba/src/third-party/libpng/libpng-config.in +127 -0
  808. package/mgba-bridge/vendor/mgba/src/third-party/libpng/libpng-manual.txt +5409 -0
  809. package/mgba-bridge/vendor/mgba/src/third-party/libpng/libpng.3 +6052 -0
  810. package/mgba-bridge/vendor/mgba/src/third-party/libpng/libpng.pc.in +12 -0
  811. package/mgba-bridge/vendor/mgba/src/third-party/libpng/libpngpf.3 +24 -0
  812. package/mgba-bridge/vendor/mgba/src/third-party/libpng/ltmain.sh +11147 -0
  813. package/mgba-bridge/vendor/mgba/src/third-party/libpng/mips/filter_msa_intrinsics.c +808 -0
  814. package/mgba-bridge/vendor/mgba/src/third-party/libpng/mips/mips_init.c +130 -0
  815. package/mgba-bridge/vendor/mgba/src/third-party/libpng/missing +215 -0
  816. package/mgba-bridge/vendor/mgba/src/third-party/libpng/png.5 +84 -0
  817. package/mgba-bridge/vendor/mgba/src/third-party/libpng/png.c +4607 -0
  818. package/mgba-bridge/vendor/mgba/src/third-party/libpng/png.h +3247 -0
  819. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngbar.jpg +0 -0
  820. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngbar.png +0 -0
  821. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngconf.h +623 -0
  822. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngdebug.h +153 -0
  823. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngerror.c +963 -0
  824. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngget.c +1249 -0
  825. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pnginfo.h +267 -0
  826. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngmem.c +284 -0
  827. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngnow.png +0 -0
  828. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngpread.c +1096 -0
  829. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngpriv.h +2152 -0
  830. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngread.c +4225 -0
  831. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngrio.c +120 -0
  832. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngrtran.c +5044 -0
  833. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngrutil.c +4681 -0
  834. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngset.c +1802 -0
  835. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngstruct.h +489 -0
  836. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngtest.c +2158 -0
  837. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngtest.png +0 -0
  838. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngtrans.c +864 -0
  839. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngusr.dfa +14 -0
  840. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngwio.c +168 -0
  841. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngwrite.c +2395 -0
  842. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngwtran.c +575 -0
  843. package/mgba-bridge/vendor/mgba/src/third-party/libpng/pngwutil.c +2781 -0
  844. package/mgba-bridge/vendor/mgba/src/third-party/libpng/powerpc/filter_vsx_intrinsics.c +768 -0
  845. package/mgba-bridge/vendor/mgba/src/third-party/libpng/powerpc/powerpc_init.c +126 -0
  846. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/owatcom/libpng.tgt +383 -0
  847. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/owatcom/libpng.wpj +112 -0
  848. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/owatcom/pngconfig.mak +160 -0
  849. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/owatcom/pngstest.tgt +219 -0
  850. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/owatcom/pngtest.tgt +179 -0
  851. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/owatcom/pngvalid.tgt +210 -0
  852. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/visualc71/PRJ0041.mak +21 -0
  853. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/visualc71/README.txt +58 -0
  854. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/visualc71/README_zlib.txt +44 -0
  855. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/visualc71/libpng.sln +60 -0
  856. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/visualc71/libpng.vcproj +419 -0
  857. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/visualc71/pngtest.vcproj +267 -0
  858. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/visualc71/zlib.vcproj +391 -0
  859. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/libpng/libpng.vcxproj +234 -0
  860. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/pnglibconf/pnglibconf.vcxproj +61 -0
  861. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/pngstest/pngstest.vcxproj +219 -0
  862. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/pngtest/pngtest.vcxproj +220 -0
  863. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/pngunknown/pngunknown.vcxproj +219 -0
  864. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/pngvalid/pngvalid.vcxproj +219 -0
  865. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/vstudio.sln +109 -0
  866. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/zlib/zlib.vcxproj +175 -0
  867. package/mgba-bridge/vendor/mgba/src/third-party/libpng/projects/vstudio/zlib.props +57 -0
  868. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/README.txt +79 -0
  869. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/SCOPTIONS.ppc +7 -0
  870. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/checksym.awk +173 -0
  871. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/descrip.mms +52 -0
  872. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/dfn.awk +203 -0
  873. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/genchk.cmake.in +37 -0
  874. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/genout.cmake.in +93 -0
  875. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/gensrc.cmake.in +138 -0
  876. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/intprefix.c +22 -0
  877. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/libpng-config-body.in +96 -0
  878. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/libpng-config-head.in +24 -0
  879. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/libpng.pc.in +10 -0
  880. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/libtool.m4 +8369 -0
  881. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/ltoptions.m4 +437 -0
  882. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/ltsugar.m4 +124 -0
  883. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/ltversion.m4 +23 -0
  884. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/lt~obsolete.m4 +99 -0
  885. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/macro.lst +3 -0
  886. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.32sunu +244 -0
  887. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.64sunu +244 -0
  888. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.acorn +57 -0
  889. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.aix +116 -0
  890. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.amiga +58 -0
  891. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.atari +71 -0
  892. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.bc32 +158 -0
  893. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.beos +222 -0
  894. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.cegcc +116 -0
  895. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.clang +87 -0
  896. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.clang-asan +87 -0
  897. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.darwin +225 -0
  898. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.dec +210 -0
  899. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.dj2 +72 -0
  900. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.freebsd +69 -0
  901. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.gcc +87 -0
  902. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.gcc-asan +87 -0
  903. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.hp64 +231 -0
  904. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.hpgcc +234 -0
  905. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.hpux +229 -0
  906. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.ibmc +90 -0
  907. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.intel +115 -0
  908. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.linux +246 -0
  909. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.linux-opt +265 -0
  910. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.mips +103 -0
  911. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.msys +202 -0
  912. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.netbsd +55 -0
  913. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.openbsd +86 -0
  914. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.sco +226 -0
  915. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.sggcc +236 -0
  916. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.sgi +237 -0
  917. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.so9 +247 -0
  918. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.solaris +243 -0
  919. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.std +134 -0
  920. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.sunos +115 -0
  921. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makefile.vcwin32 +113 -0
  922. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/makevms.com +142 -0
  923. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/options.awk +898 -0
  924. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/pnglibconf.dfa +920 -0
  925. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/pnglibconf.h.prebuilt +219 -0
  926. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/pnglibconf.mak +55 -0
  927. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/pngwin.rc +112 -0
  928. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/prefix.c +24 -0
  929. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/smakefile.ppc +34 -0
  930. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/sym.c +15 -0
  931. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/symbols.c +58 -0
  932. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/symbols.def +255 -0
  933. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/test.cmake.in +31 -0
  934. package/mgba-bridge/vendor/mgba/src/third-party/libpng/scripts/vers.c +19 -0
  935. package/mgba-bridge/vendor/mgba/src/third-party/libpng/test-driver +148 -0
  936. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7z.h +202 -0
  937. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zAlloc.c +80 -0
  938. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zAlloc.h +19 -0
  939. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zArcIn.c +1771 -0
  940. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zBuf.c +36 -0
  941. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zBuf.h +35 -0
  942. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zBuf2.c +52 -0
  943. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zCrc.c +128 -0
  944. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zCrc.h +25 -0
  945. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zCrcOpt.c +115 -0
  946. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zDec.c +591 -0
  947. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zFile.c +286 -0
  948. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zFile.h +83 -0
  949. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zStream.c +176 -0
  950. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zTypes.h +375 -0
  951. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zVersion.h +27 -0
  952. package/mgba-bridge/vendor/mgba/src/third-party/lzma/7zVersion.rc +55 -0
  953. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Aes.c +306 -0
  954. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Aes.h +38 -0
  955. package/mgba-bridge/vendor/mgba/src/third-party/lzma/AesOpt.c +184 -0
  956. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Alloc.c +455 -0
  957. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Alloc.h +51 -0
  958. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Bcj2.c +257 -0
  959. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Bcj2.h +146 -0
  960. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Bcj2Enc.c +311 -0
  961. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Bra.c +230 -0
  962. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Bra.h +64 -0
  963. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Bra86.c +82 -0
  964. package/mgba-bridge/vendor/mgba/src/third-party/lzma/BraIA64.c +53 -0
  965. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Compiler.h +33 -0
  966. package/mgba-bridge/vendor/mgba/src/third-party/lzma/CpuArch.c +218 -0
  967. package/mgba-bridge/vendor/mgba/src/third-party/lzma/CpuArch.h +336 -0
  968. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Delta.c +64 -0
  969. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Delta.h +19 -0
  970. package/mgba-bridge/vendor/mgba/src/third-party/lzma/DllSecur.c +108 -0
  971. package/mgba-bridge/vendor/mgba/src/third-party/lzma/DllSecur.h +20 -0
  972. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzFind.c +1127 -0
  973. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzFind.h +121 -0
  974. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzFindMt.c +853 -0
  975. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzFindMt.h +101 -0
  976. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzHash.h +57 -0
  977. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma2Dec.c +488 -0
  978. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma2Dec.h +120 -0
  979. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma2DecMt.c +1082 -0
  980. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma2DecMt.h +79 -0
  981. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma2Enc.c +803 -0
  982. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma2Enc.h +55 -0
  983. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma86.h +111 -0
  984. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma86Dec.c +54 -0
  985. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Lzma86Enc.c +106 -0
  986. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzmaDec.c +1185 -0
  987. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzmaDec.h +234 -0
  988. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzmaEnc.c +2976 -0
  989. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzmaEnc.h +76 -0
  990. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzmaLib.c +40 -0
  991. package/mgba-bridge/vendor/mgba/src/third-party/lzma/LzmaLib.h +131 -0
  992. package/mgba-bridge/vendor/mgba/src/third-party/lzma/MtCoder.c +601 -0
  993. package/mgba-bridge/vendor/mgba/src/third-party/lzma/MtCoder.h +141 -0
  994. package/mgba-bridge/vendor/mgba/src/third-party/lzma/MtDec.c +1138 -0
  995. package/mgba-bridge/vendor/mgba/src/third-party/lzma/MtDec.h +201 -0
  996. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Ppmd.h +85 -0
  997. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Ppmd7.c +712 -0
  998. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Ppmd7.h +142 -0
  999. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Ppmd7Dec.c +191 -0
  1000. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Ppmd7Enc.c +187 -0
  1001. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Precomp.h +10 -0
  1002. package/mgba-bridge/vendor/mgba/src/third-party/lzma/RotateDefs.h +30 -0
  1003. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Sha256.c +248 -0
  1004. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Sha256.h +26 -0
  1005. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Sort.c +141 -0
  1006. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Sort.h +18 -0
  1007. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Threads.c +95 -0
  1008. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Threads.h +68 -0
  1009. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/7z/7z.dsp +241 -0
  1010. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/7z/7z.dsw +29 -0
  1011. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/7z/7zMain.c +686 -0
  1012. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/7z/Precomp.c +4 -0
  1013. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/7z/Precomp.h +10 -0
  1014. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/7z/makefile +40 -0
  1015. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/7z/makefile.gcc +75 -0
  1016. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/Lzma/LzmaUtil.c +258 -0
  1017. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/Lzma/LzmaUtil.dsp +168 -0
  1018. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/Lzma/LzmaUtil.dsw +29 -0
  1019. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/Lzma/makefile +28 -0
  1020. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/Lzma/makefile.gcc +44 -0
  1021. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/LzmaLib/LzmaLib.def +4 -0
  1022. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/LzmaLib/LzmaLib.dsp +178 -0
  1023. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/LzmaLib/LzmaLib.dsw +29 -0
  1024. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/LzmaLib/LzmaLibExports.c +14 -0
  1025. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/LzmaLib/makefile +34 -0
  1026. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/LzmaLib/resource.rc +3 -0
  1027. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/Precomp.c +4 -0
  1028. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/Precomp.h +10 -0
  1029. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/SfxSetup.c +640 -0
  1030. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/SfxSetup.dsp +231 -0
  1031. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/SfxSetup.dsw +29 -0
  1032. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/makefile +37 -0
  1033. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/makefile_con +38 -0
  1034. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/resource.rc +5 -0
  1035. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Util/SfxSetup/setup.ico +0 -0
  1036. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Xz.c +90 -0
  1037. package/mgba-bridge/vendor/mgba/src/third-party/lzma/Xz.h +460 -0
  1038. package/mgba-bridge/vendor/mgba/src/third-party/lzma/XzCrc64.c +86 -0
  1039. package/mgba-bridge/vendor/mgba/src/third-party/lzma/XzCrc64.h +26 -0
  1040. package/mgba-bridge/vendor/mgba/src/third-party/lzma/XzCrc64Opt.c +69 -0
  1041. package/mgba-bridge/vendor/mgba/src/third-party/lzma/XzDec.c +2766 -0
  1042. package/mgba-bridge/vendor/mgba/src/third-party/lzma/XzEnc.c +1329 -0
  1043. package/mgba-bridge/vendor/mgba/src/third-party/lzma/XzEnc.h +60 -0
  1044. package/mgba-bridge/vendor/mgba/src/third-party/lzma/XzIn.c +319 -0
  1045. package/mgba-bridge/vendor/mgba/src/third-party/zlib/CMakeLists.txt +249 -0
  1046. package/mgba-bridge/vendor/mgba/src/third-party/zlib/ChangeLog +1578 -0
  1047. package/mgba-bridge/vendor/mgba/src/third-party/zlib/FAQ +368 -0
  1048. package/mgba-bridge/vendor/mgba/src/third-party/zlib/INDEX +68 -0
  1049. package/mgba-bridge/vendor/mgba/src/third-party/zlib/Makefile +5 -0
  1050. package/mgba-bridge/vendor/mgba/src/third-party/zlib/Makefile.in +408 -0
  1051. package/mgba-bridge/vendor/mgba/src/third-party/zlib/README +118 -0
  1052. package/mgba-bridge/vendor/mgba/src/third-party/zlib/adler32.c +186 -0
  1053. package/mgba-bridge/vendor/mgba/src/third-party/zlib/amiga/Makefile.pup +69 -0
  1054. package/mgba-bridge/vendor/mgba/src/third-party/zlib/amiga/Makefile.sas +68 -0
  1055. package/mgba-bridge/vendor/mgba/src/third-party/zlib/compress.c +86 -0
  1056. package/mgba-bridge/vendor/mgba/src/third-party/zlib/configure +927 -0
  1057. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/README.contrib +57 -0
  1058. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/buffer_demo.adb +106 -0
  1059. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/mtest.adb +156 -0
  1060. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/read.adb +156 -0
  1061. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/readme.txt +65 -0
  1062. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/test.adb +463 -0
  1063. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/zlib-streams.adb +225 -0
  1064. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/zlib-streams.ads +114 -0
  1065. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/zlib-thin.adb +141 -0
  1066. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/zlib-thin.ads +450 -0
  1067. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/zlib.adb +701 -0
  1068. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/zlib.ads +328 -0
  1069. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/ada/zlib.gpr +20 -0
  1070. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/blast/Makefile +8 -0
  1071. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/blast/README +4 -0
  1072. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/blast/blast.c +466 -0
  1073. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/blast/blast.h +83 -0
  1074. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/blast/test.pk +0 -0
  1075. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/blast/test.txt +1 -0
  1076. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/delphi/ZLib.pas +557 -0
  1077. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/delphi/ZLibConst.pas +11 -0
  1078. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/delphi/readme.txt +76 -0
  1079. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/delphi/zlibd32.mak +99 -0
  1080. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs +58 -0
  1081. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs +202 -0
  1082. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs +83 -0
  1083. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/CodecBase.cs +198 -0
  1084. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/Deflater.cs +106 -0
  1085. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/DotZLib.cs +288 -0
  1086. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj +141 -0
  1087. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/GZipStream.cs +301 -0
  1088. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/Inflater.cs +105 -0
  1089. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib/UnitTests.cs +274 -0
  1090. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib.build +33 -0
  1091. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib.chm +0 -0
  1092. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/DotZLib.sln +21 -0
  1093. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/LICENSE_1_0.txt +23 -0
  1094. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/dotzlib/readme.txt +58 -0
  1095. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/gcc_gvmat64/gvmat64.S +574 -0
  1096. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/infback9/README +1 -0
  1097. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/infback9/infback9.c +615 -0
  1098. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/infback9/infback9.h +37 -0
  1099. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/infback9/inffix9.h +107 -0
  1100. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/infback9/inflate9.h +47 -0
  1101. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/infback9/inftree9.c +324 -0
  1102. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/infback9/inftree9.h +61 -0
  1103. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream/test.cpp +24 -0
  1104. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream/zfstream.cpp +329 -0
  1105. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream/zfstream.h +128 -0
  1106. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream2/zstream.h +307 -0
  1107. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream2/zstream_test.cpp +25 -0
  1108. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream3/README +35 -0
  1109. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream3/TODO +17 -0
  1110. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream3/test.cc +50 -0
  1111. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream3/zfstream.cc +479 -0
  1112. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/iostream3/zfstream.h +466 -0
  1113. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/Makefile +29 -0
  1114. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/Makefile.am +45 -0
  1115. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/MiniZip64_Changes.txt +6 -0
  1116. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/MiniZip64_info.txt +74 -0
  1117. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/configure.ac +32 -0
  1118. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/crypt.h +132 -0
  1119. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/ioapi.c +257 -0
  1120. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/ioapi.h +210 -0
  1121. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/iowin32.c +462 -0
  1122. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/iowin32.h +28 -0
  1123. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/make_vms.com +25 -0
  1124. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/miniunz.c +659 -0
  1125. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/miniunzip.1 +63 -0
  1126. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/minizip.1 +46 -0
  1127. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/minizip.c +521 -0
  1128. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/minizip.pc.in +12 -0
  1129. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/mztools.c +291 -0
  1130. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/mztools.h +37 -0
  1131. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/unzip.c +2128 -0
  1132. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/unzip.h +437 -0
  1133. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/zip.c +2007 -0
  1134. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/minizip/zip.h +367 -0
  1135. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/pascal/example.pas +599 -0
  1136. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/pascal/readme.txt +76 -0
  1137. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/pascal/zlibd32.mak +99 -0
  1138. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/pascal/zlibpas.pas +276 -0
  1139. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/puff/Makefile +42 -0
  1140. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/puff/README +63 -0
  1141. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/puff/puff.c +840 -0
  1142. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/puff/puff.h +35 -0
  1143. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/puff/pufftest.c +165 -0
  1144. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/puff/zeros.raw +0 -0
  1145. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/testzlib/testzlib.c +275 -0
  1146. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/testzlib/testzlib.txt +10 -0
  1147. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/untgz/Makefile +14 -0
  1148. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/untgz/Makefile.msc +17 -0
  1149. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/untgz/untgz.c +674 -0
  1150. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/readme.txt +78 -0
  1151. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/miniunz.vcxproj +310 -0
  1152. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/miniunz.vcxproj.filters +22 -0
  1153. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/minizip.vcxproj +307 -0
  1154. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/minizip.vcxproj.filters +22 -0
  1155. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/testzlib.vcxproj +420 -0
  1156. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/testzlib.vcxproj.filters +58 -0
  1157. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj +310 -0
  1158. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.filters +22 -0
  1159. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/zlib.rc +32 -0
  1160. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/zlibstat.vcxproj +473 -0
  1161. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters +77 -0
  1162. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/zlibvc.def +158 -0
  1163. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/zlibvc.sln +135 -0
  1164. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/zlibvc.vcxproj +657 -0
  1165. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.filters +118 -0
  1166. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/miniunz.vcxproj +314 -0
  1167. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/minizip.vcxproj +311 -0
  1168. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/testzlib.vcxproj +426 -0
  1169. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/testzlibdll.vcxproj +314 -0
  1170. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/zlib.rc +32 -0
  1171. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/zlibstat.vcxproj +464 -0
  1172. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/zlibvc.def +158 -0
  1173. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/zlibvc.sln +117 -0
  1174. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc11/zlibvc.vcxproj +688 -0
  1175. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/miniunz.vcxproj +316 -0
  1176. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/minizip.vcxproj +313 -0
  1177. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/testzlib.vcxproj +430 -0
  1178. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/testzlibdll.vcxproj +316 -0
  1179. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/zlib.rc +32 -0
  1180. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/zlibstat.vcxproj +467 -0
  1181. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/zlibvc.def +158 -0
  1182. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/zlibvc.sln +119 -0
  1183. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc12/zlibvc.vcxproj +692 -0
  1184. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/miniunz.vcxproj +316 -0
  1185. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/minizip.vcxproj +313 -0
  1186. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/testzlib.vcxproj +430 -0
  1187. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/testzlibdll.vcxproj +316 -0
  1188. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/zlib.rc +32 -0
  1189. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/zlibstat.vcxproj +467 -0
  1190. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/zlibvc.def +158 -0
  1191. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/zlibvc.sln +119 -0
  1192. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc14/zlibvc.vcxproj +692 -0
  1193. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/miniunz.vcproj +565 -0
  1194. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/minizip.vcproj +562 -0
  1195. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/testzlib.vcproj +852 -0
  1196. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/testzlibdll.vcproj +565 -0
  1197. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/zlib.rc +32 -0
  1198. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/zlibstat.vcproj +835 -0
  1199. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/zlibvc.def +158 -0
  1200. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/zlibvc.sln +144 -0
  1201. package/mgba-bridge/vendor/mgba/src/third-party/zlib/contrib/vstudio/vc9/zlibvc.vcproj +1156 -0
  1202. package/mgba-bridge/vendor/mgba/src/third-party/zlib/crc32.c +1116 -0
  1203. package/mgba-bridge/vendor/mgba/src/third-party/zlib/crc32.h +9446 -0
  1204. package/mgba-bridge/vendor/mgba/src/third-party/zlib/deflate.c +2211 -0
  1205. package/mgba-bridge/vendor/mgba/src/third-party/zlib/deflate.h +346 -0
  1206. package/mgba-bridge/vendor/mgba/src/third-party/zlib/doc/algorithm.txt +209 -0
  1207. package/mgba-bridge/vendor/mgba/src/third-party/zlib/doc/crc-doc.1.0.pdf +0 -0
  1208. package/mgba-bridge/vendor/mgba/src/third-party/zlib/doc/rfc1950.txt +619 -0
  1209. package/mgba-bridge/vendor/mgba/src/third-party/zlib/doc/rfc1951.txt +955 -0
  1210. package/mgba-bridge/vendor/mgba/src/third-party/zlib/doc/rfc1952.txt +675 -0
  1211. package/mgba-bridge/vendor/mgba/src/third-party/zlib/doc/txtvsbin.txt +107 -0
  1212. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/README.examples +54 -0
  1213. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/enough.c +597 -0
  1214. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/fitblk.c +233 -0
  1215. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/gun.c +702 -0
  1216. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/gzappend.c +504 -0
  1217. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/gzjoin.c +449 -0
  1218. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/gzlog.c +1061 -0
  1219. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/gzlog.h +91 -0
  1220. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/gznorm.c +470 -0
  1221. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/zlib_how.html +545 -0
  1222. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/zpipe.c +205 -0
  1223. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/zran.c +479 -0
  1224. package/mgba-bridge/vendor/mgba/src/third-party/zlib/examples/zran.h +40 -0
  1225. package/mgba-bridge/vendor/mgba/src/third-party/zlib/gzclose.c +25 -0
  1226. package/mgba-bridge/vendor/mgba/src/third-party/zlib/gzguts.h +219 -0
  1227. package/mgba-bridge/vendor/mgba/src/third-party/zlib/gzlib.c +639 -0
  1228. package/mgba-bridge/vendor/mgba/src/third-party/zlib/gzread.c +652 -0
  1229. package/mgba-bridge/vendor/mgba/src/third-party/zlib/gzwrite.c +677 -0
  1230. package/mgba-bridge/vendor/mgba/src/third-party/zlib/infback.c +641 -0
  1231. package/mgba-bridge/vendor/mgba/src/third-party/zlib/inffast.c +323 -0
  1232. package/mgba-bridge/vendor/mgba/src/third-party/zlib/inffast.h +11 -0
  1233. package/mgba-bridge/vendor/mgba/src/third-party/zlib/inffixed.h +94 -0
  1234. package/mgba-bridge/vendor/mgba/src/third-party/zlib/inflate.c +1592 -0
  1235. package/mgba-bridge/vendor/mgba/src/third-party/zlib/inflate.h +126 -0
  1236. package/mgba-bridge/vendor/mgba/src/third-party/zlib/inftrees.c +304 -0
  1237. package/mgba-bridge/vendor/mgba/src/third-party/zlib/inftrees.h +62 -0
  1238. package/mgba-bridge/vendor/mgba/src/third-party/zlib/make_vms.com +867 -0
  1239. package/mgba-bridge/vendor/mgba/src/third-party/zlib/msdos/Makefile.bor +115 -0
  1240. package/mgba-bridge/vendor/mgba/src/third-party/zlib/msdos/Makefile.dj2 +104 -0
  1241. package/mgba-bridge/vendor/mgba/src/third-party/zlib/msdos/Makefile.emx +69 -0
  1242. package/mgba-bridge/vendor/mgba/src/third-party/zlib/msdos/Makefile.msc +112 -0
  1243. package/mgba-bridge/vendor/mgba/src/third-party/zlib/msdos/Makefile.tc +100 -0
  1244. package/mgba-bridge/vendor/mgba/src/third-party/zlib/nintendods/Makefile +126 -0
  1245. package/mgba-bridge/vendor/mgba/src/third-party/zlib/nintendods/README +5 -0
  1246. package/mgba-bridge/vendor/mgba/src/third-party/zlib/old/Makefile.emx +69 -0
  1247. package/mgba-bridge/vendor/mgba/src/third-party/zlib/old/Makefile.riscos +151 -0
  1248. package/mgba-bridge/vendor/mgba/src/third-party/zlib/old/README +3 -0
  1249. package/mgba-bridge/vendor/mgba/src/third-party/zlib/old/descrip.mms +48 -0
  1250. package/mgba-bridge/vendor/mgba/src/third-party/zlib/old/os2/Makefile.os2 +136 -0
  1251. package/mgba-bridge/vendor/mgba/src/third-party/zlib/old/os2/zlib.def +51 -0
  1252. package/mgba-bridge/vendor/mgba/src/third-party/zlib/old/visual-basic.txt +160 -0
  1253. package/mgba-bridge/vendor/mgba/src/third-party/zlib/os400/README400 +48 -0
  1254. package/mgba-bridge/vendor/mgba/src/third-party/zlib/os400/bndsrc +119 -0
  1255. package/mgba-bridge/vendor/mgba/src/third-party/zlib/os400/make.sh +366 -0
  1256. package/mgba-bridge/vendor/mgba/src/third-party/zlib/os400/zlib.inc +527 -0
  1257. package/mgba-bridge/vendor/mgba/src/third-party/zlib/qnx/package.qpg +141 -0
  1258. package/mgba-bridge/vendor/mgba/src/third-party/zlib/treebuild.xml +116 -0
  1259. package/mgba-bridge/vendor/mgba/src/third-party/zlib/trees.c +1182 -0
  1260. package/mgba-bridge/vendor/mgba/src/third-party/zlib/trees.h +128 -0
  1261. package/mgba-bridge/vendor/mgba/src/third-party/zlib/uncompr.c +93 -0
  1262. package/mgba-bridge/vendor/mgba/src/third-party/zlib/watcom/watcom_f.mak +43 -0
  1263. package/mgba-bridge/vendor/mgba/src/third-party/zlib/watcom/watcom_l.mak +43 -0
  1264. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/DLL_FAQ.txt +397 -0
  1265. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/Makefile.bor +109 -0
  1266. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/Makefile.gcc +177 -0
  1267. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/Makefile.msc +159 -0
  1268. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/README-WIN32.txt +103 -0
  1269. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/VisualC.txt +3 -0
  1270. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/zlib.def +97 -0
  1271. package/mgba-bridge/vendor/mgba/src/third-party/zlib/win32/zlib1.rc +40 -0
  1272. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zconf.h +534 -0
  1273. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zconf.h.cmakein +536 -0
  1274. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zconf.h.in +534 -0
  1275. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zlib.3 +149 -0
  1276. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zlib.3.pdf +0 -0
  1277. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zlib.h +1935 -0
  1278. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zlib.map +100 -0
  1279. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zlib.pc.cmakein +13 -0
  1280. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zlib.pc.in +13 -0
  1281. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zlib2ansi +152 -0
  1282. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zutil.c +325 -0
  1283. package/mgba-bridge/vendor/mgba/src/third-party/zlib/zutil.h +274 -0
  1284. package/mgba-bridge/vendor/mgba/src/tools/docgen.c +541 -0
  1285. package/mgba-bridge/vendor/mgba/src/tools/font-sdf.c +136 -0
  1286. package/mgba-bridge/vendor/mgba/src/tools/updater-main.c +377 -0
  1287. package/mgba-bridge/vendor/mgba/src/util/CMakeLists.txt +68 -0
  1288. package/mgba-bridge/vendor/mgba/src/util/audio-buffer.c +62 -0
  1289. package/mgba-bridge/vendor/mgba/src/util/audio-resampler.c +109 -0
  1290. package/mgba-bridge/vendor/mgba/src/util/circle-buffer.c +274 -0
  1291. package/mgba-bridge/vendor/mgba/src/util/configuration.c +233 -0
  1292. package/mgba-bridge/vendor/mgba/src/util/convolve.c +182 -0
  1293. package/mgba-bridge/vendor/mgba/src/util/crc32.c +138 -0
  1294. package/mgba-bridge/vendor/mgba/src/util/elf-read.c +128 -0
  1295. package/mgba-bridge/vendor/mgba/src/util/formatting.c +87 -0
  1296. package/mgba-bridge/vendor/mgba/src/util/gbk-table.c +129 -0
  1297. package/mgba-bridge/vendor/mgba/src/util/geometry.c +94 -0
  1298. package/mgba-bridge/vendor/mgba/src/util/gui/file-select.c +236 -0
  1299. package/mgba-bridge/vendor/mgba/src/util/gui/font-metrics.c +199 -0
  1300. package/mgba-bridge/vendor/mgba/src/util/gui/font.c +169 -0
  1301. package/mgba-bridge/vendor/mgba/src/util/gui/menu.c +412 -0
  1302. package/mgba-bridge/vendor/mgba/src/util/gui.c +81 -0
  1303. package/mgba-bridge/vendor/mgba/src/util/hash.c +108 -0
  1304. package/mgba-bridge/vendor/mgba/src/util/image/export.c +81 -0
  1305. package/mgba-bridge/vendor/mgba/src/util/image/font.c +274 -0
  1306. package/mgba-bridge/vendor/mgba/src/util/image/png-io.c +730 -0
  1307. package/mgba-bridge/vendor/mgba/src/util/image.c +1109 -0
  1308. package/mgba-bridge/vendor/mgba/src/util/interpolator.c +116 -0
  1309. package/mgba-bridge/vendor/mgba/src/util/md5.c +228 -0
  1310. package/mgba-bridge/vendor/mgba/src/util/memory.c +15 -0
  1311. package/mgba-bridge/vendor/mgba/src/util/patch-fast.c +130 -0
  1312. package/mgba-bridge/vendor/mgba/src/util/patch-ips.c +93 -0
  1313. package/mgba-bridge/vendor/mgba/src/util/patch-ups.c +254 -0
  1314. package/mgba-bridge/vendor/mgba/src/util/patch.c +25 -0
  1315. package/mgba-bridge/vendor/mgba/src/util/ring-fifo.c +104 -0
  1316. package/mgba-bridge/vendor/mgba/src/util/sfo.c +229 -0
  1317. package/mgba-bridge/vendor/mgba/src/util/sha1.c +258 -0
  1318. package/mgba-bridge/vendor/mgba/src/util/string.c +652 -0
  1319. package/mgba-bridge/vendor/mgba/src/util/table.c +682 -0
  1320. package/mgba-bridge/vendor/mgba/src/util/text-codec.c +197 -0
  1321. package/mgba-bridge/vendor/mgba/src/util/vector.c +18 -0
  1322. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-devlist.c +104 -0
  1323. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-dirent.c +173 -0
  1324. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-fd.c +282 -0
  1325. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-fifo.c +102 -0
  1326. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-file.c +159 -0
  1327. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-lzma.c +404 -0
  1328. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-mem.c +331 -0
  1329. package/mgba-bridge/vendor/mgba/src/util/vfs/vfs-zip.c +804 -0
  1330. package/mgba-bridge/vendor/mgba/src/util/vfs.c +320 -0
  1331. package/mgba-bridge/vendor/mgba/tools/deploy-mac.py +178 -0
  1332. package/mgba-bridge/vendor/mgba/tools/deploy-win.sh +27 -0
  1333. package/mgba-bridge/vendor/mgba/tools/dlls.gdb +3 -0
  1334. package/mgba-bridge/vendor/mgba/tools/make-dotcode.py +154 -0
  1335. package/mgba-bridge/vendor/mgba/tools/perf.py +230 -0
  1336. package/mgba-bridge/vendor/mgba/tools/sanitize-deb.sh +74 -0
  1337. package/mgba-bridge/vendor/mgba/tools/snes-tile.py +94 -0
  1338. package/mgba-bridge/vendor/mgba/version.cmake +62 -0
  1339. package/package.json +47 -0
  1340. package/src/audio-output.ts +387 -0
  1341. package/src/config.ts +114 -0
  1342. package/src/constants.ts +37 -0
  1343. package/src/extension.ts +570 -0
  1344. package/src/gameboy-mgba.ts +133 -0
  1345. package/src/gameboy-types.ts +24 -0
  1346. package/src/gameboy.ts +33 -0
  1347. package/src/index.ts +1 -0
  1348. package/src/mgba/bridge-bin.ts +66 -0
  1349. package/src/mgba/bridge.ts +145 -0
  1350. package/src/mgba/protocol.ts +30 -0
  1351. package/src/mgba/stdio.ts +74 -0
  1352. package/src/notify.ts +12 -0
  1353. package/src/pi-boy-component.ts +372 -0
  1354. package/src/render/ansi.ts +239 -0
  1355. package/src/render/kitty.ts +154 -0
  1356. package/src/roms.ts +163 -0
  1357. package/src/runtime.ts +36 -0
  1358. package/src/save-state.ts +94 -0
  1359. package/src/terminal.ts +18 -0
  1360. package/tsconfig.json +11 -0
  1361. package/types/shims.d.ts +121 -0
@@ -0,0 +1,4681 @@
1
+
2
+ /* pngrutil.c - utilities to read a PNG file
3
+ *
4
+ * Copyright (c) 2018 Cosmin Truta
5
+ * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
6
+ * Copyright (c) 1996-1997 Andreas Dilger
7
+ * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
8
+ *
9
+ * This code is released under the libpng license.
10
+ * For conditions of distribution and use, see the disclaimer
11
+ * and license in png.h
12
+ *
13
+ * This file contains routines that are only called from within
14
+ * libpng itself during the course of reading an image.
15
+ */
16
+
17
+ #include "pngpriv.h"
18
+
19
+ #ifdef PNG_READ_SUPPORTED
20
+
21
+ png_uint_32 PNGAPI
22
+ png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
23
+ {
24
+ png_uint_32 uval = png_get_uint_32(buf);
25
+
26
+ if (uval > PNG_UINT_31_MAX)
27
+ png_error(png_ptr, "PNG unsigned integer out of range");
28
+
29
+ return (uval);
30
+ }
31
+
32
+ #if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
33
+ /* The following is a variation on the above for use with the fixed
34
+ * point values used for gAMA and cHRM. Instead of png_error it
35
+ * issues a warning and returns (-1) - an invalid value because both
36
+ * gAMA and cHRM use *unsigned* integers for fixed point values.
37
+ */
38
+ #define PNG_FIXED_ERROR (-1)
39
+
40
+ static png_fixed_point /* PRIVATE */
41
+ png_get_fixed_point(png_structrp png_ptr, png_const_bytep buf)
42
+ {
43
+ png_uint_32 uval = png_get_uint_32(buf);
44
+
45
+ if (uval <= PNG_UINT_31_MAX)
46
+ return (png_fixed_point)uval; /* known to be in range */
47
+
48
+ /* The caller can turn off the warning by passing NULL. */
49
+ if (png_ptr != NULL)
50
+ png_warning(png_ptr, "PNG fixed point integer out of range");
51
+
52
+ return PNG_FIXED_ERROR;
53
+ }
54
+ #endif
55
+
56
+ #ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
57
+ /* NOTE: the read macros will obscure these definitions, so that if
58
+ * PNG_USE_READ_MACROS is set the library will not use them internally,
59
+ * but the APIs will still be available externally.
60
+ *
61
+ * The parentheses around "PNGAPI function_name" in the following three
62
+ * functions are necessary because they allow the macros to co-exist with
63
+ * these (unused but exported) functions.
64
+ */
65
+
66
+ /* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
67
+ png_uint_32 (PNGAPI
68
+ png_get_uint_32)(png_const_bytep buf)
69
+ {
70
+ png_uint_32 uval =
71
+ ((png_uint_32)(*(buf )) << 24) +
72
+ ((png_uint_32)(*(buf + 1)) << 16) +
73
+ ((png_uint_32)(*(buf + 2)) << 8) +
74
+ ((png_uint_32)(*(buf + 3)) ) ;
75
+
76
+ return uval;
77
+ }
78
+
79
+ /* Grab a signed 32-bit integer from a buffer in big-endian format. The
80
+ * data is stored in the PNG file in two's complement format and there
81
+ * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore
82
+ * the following code does a two's complement to native conversion.
83
+ */
84
+ png_int_32 (PNGAPI
85
+ png_get_int_32)(png_const_bytep buf)
86
+ {
87
+ png_uint_32 uval = png_get_uint_32(buf);
88
+ if ((uval & 0x80000000) == 0) /* non-negative */
89
+ return (png_int_32)uval;
90
+
91
+ uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
92
+ if ((uval & 0x80000000) == 0) /* no overflow */
93
+ return -(png_int_32)uval;
94
+ /* The following has to be safe; this function only gets called on PNG data
95
+ * and if we get here that data is invalid. 0 is the most safe value and
96
+ * if not then an attacker would surely just generate a PNG with 0 instead.
97
+ */
98
+ return 0;
99
+ }
100
+
101
+ /* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
102
+ png_uint_16 (PNGAPI
103
+ png_get_uint_16)(png_const_bytep buf)
104
+ {
105
+ /* ANSI-C requires an int value to accommodate at least 16 bits so this
106
+ * works and allows the compiler not to worry about possible narrowing
107
+ * on 32-bit systems. (Pre-ANSI systems did not make integers smaller
108
+ * than 16 bits either.)
109
+ */
110
+ unsigned int val =
111
+ ((unsigned int)(*buf) << 8) +
112
+ ((unsigned int)(*(buf + 1)));
113
+
114
+ return (png_uint_16)val;
115
+ }
116
+
117
+ #endif /* READ_INT_FUNCTIONS */
118
+
119
+ /* Read and check the PNG file signature */
120
+ void /* PRIVATE */
121
+ png_read_sig(png_structrp png_ptr, png_inforp info_ptr)
122
+ {
123
+ size_t num_checked, num_to_check;
124
+
125
+ /* Exit if the user application does not expect a signature. */
126
+ if (png_ptr->sig_bytes >= 8)
127
+ return;
128
+
129
+ num_checked = png_ptr->sig_bytes;
130
+ num_to_check = 8 - num_checked;
131
+
132
+ #ifdef PNG_IO_STATE_SUPPORTED
133
+ png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
134
+ #endif
135
+
136
+ /* The signature must be serialized in a single I/O call. */
137
+ png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
138
+ png_ptr->sig_bytes = 8;
139
+
140
+ if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0)
141
+ {
142
+ if (num_checked < 4 &&
143
+ png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
144
+ png_error(png_ptr, "Not a PNG file");
145
+ else
146
+ png_error(png_ptr, "PNG file corrupted by ASCII conversion");
147
+ }
148
+ if (num_checked < 3)
149
+ png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
150
+ }
151
+
152
+ /* Read the chunk header (length + type name).
153
+ * Put the type name into png_ptr->chunk_name, and return the length.
154
+ */
155
+ png_uint_32 /* PRIVATE */
156
+ png_read_chunk_header(png_structrp png_ptr)
157
+ {
158
+ png_byte buf[8];
159
+ png_uint_32 length;
160
+
161
+ #ifdef PNG_IO_STATE_SUPPORTED
162
+ png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR;
163
+ #endif
164
+
165
+ /* Read the length and the chunk name.
166
+ * This must be performed in a single I/O call.
167
+ */
168
+ png_read_data(png_ptr, buf, 8);
169
+ length = png_get_uint_31(png_ptr, buf);
170
+
171
+ /* Put the chunk name into png_ptr->chunk_name. */
172
+ png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4);
173
+
174
+ png_debug2(0, "Reading %lx chunk, length = %lu",
175
+ (unsigned long)png_ptr->chunk_name, (unsigned long)length);
176
+
177
+ /* Reset the crc and run it over the chunk name. */
178
+ png_reset_crc(png_ptr);
179
+ png_calculate_crc(png_ptr, buf + 4, 4);
180
+
181
+ /* Check to see if chunk name is valid. */
182
+ png_check_chunk_name(png_ptr, png_ptr->chunk_name);
183
+
184
+ /* Check for too-large chunk length */
185
+ png_check_chunk_length(png_ptr, length);
186
+
187
+ #ifdef PNG_IO_STATE_SUPPORTED
188
+ png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
189
+ #endif
190
+
191
+ return length;
192
+ }
193
+
194
+ /* Read data, and (optionally) run it through the CRC. */
195
+ void /* PRIVATE */
196
+ png_crc_read(png_structrp png_ptr, png_bytep buf, png_uint_32 length)
197
+ {
198
+ if (png_ptr == NULL)
199
+ return;
200
+
201
+ png_read_data(png_ptr, buf, length);
202
+ png_calculate_crc(png_ptr, buf, length);
203
+ }
204
+
205
+ /* Optionally skip data and then check the CRC. Depending on whether we
206
+ * are reading an ancillary or critical chunk, and how the program has set
207
+ * things up, we may calculate the CRC on the data and print a message.
208
+ * Returns '1' if there was a CRC error, '0' otherwise.
209
+ */
210
+ int /* PRIVATE */
211
+ png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
212
+ {
213
+ /* The size of the local buffer for inflate is a good guess as to a
214
+ * reasonable size to use for buffering reads from the application.
215
+ */
216
+ while (skip > 0)
217
+ {
218
+ png_uint_32 len;
219
+ png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];
220
+
221
+ len = (sizeof tmpbuf);
222
+ if (len > skip)
223
+ len = skip;
224
+ skip -= len;
225
+
226
+ png_crc_read(png_ptr, tmpbuf, len);
227
+ }
228
+
229
+ if (png_crc_error(png_ptr) != 0)
230
+ {
231
+ if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0 ?
232
+ (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0 :
233
+ (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE) != 0)
234
+ {
235
+ png_chunk_warning(png_ptr, "CRC error");
236
+ }
237
+
238
+ else
239
+ png_chunk_error(png_ptr, "CRC error");
240
+
241
+ return (1);
242
+ }
243
+
244
+ return (0);
245
+ }
246
+
247
+ /* Compare the CRC stored in the PNG file with that calculated by libpng from
248
+ * the data it has read thus far.
249
+ */
250
+ int /* PRIVATE */
251
+ png_crc_error(png_structrp png_ptr)
252
+ {
253
+ png_byte crc_bytes[4];
254
+ png_uint_32 crc;
255
+ int need_crc = 1;
256
+
257
+ if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)
258
+ {
259
+ if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
260
+ (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
261
+ need_crc = 0;
262
+ }
263
+
264
+ else /* critical */
265
+ {
266
+ if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
267
+ need_crc = 0;
268
+ }
269
+
270
+ #ifdef PNG_IO_STATE_SUPPORTED
271
+ png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
272
+ #endif
273
+
274
+ /* The chunk CRC must be serialized in a single I/O call. */
275
+ png_read_data(png_ptr, crc_bytes, 4);
276
+
277
+ if (need_crc != 0)
278
+ {
279
+ crc = png_get_uint_32(crc_bytes);
280
+ return ((int)(crc != png_ptr->crc));
281
+ }
282
+
283
+ else
284
+ return (0);
285
+ }
286
+
287
+ #if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\
288
+ defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\
289
+ defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\
290
+ defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_SEQUENTIAL_READ_SUPPORTED)
291
+ /* Manage the read buffer; this simply reallocates the buffer if it is not small
292
+ * enough (or if it is not allocated). The routine returns a pointer to the
293
+ * buffer; if an error occurs and 'warn' is set the routine returns NULL, else
294
+ * it will call png_error (via png_malloc) on failure. (warn == 2 means
295
+ * 'silent').
296
+ */
297
+ static png_bytep
298
+ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
299
+ {
300
+ png_bytep buffer = png_ptr->read_buffer;
301
+
302
+ if (buffer != NULL && new_size > png_ptr->read_buffer_size)
303
+ {
304
+ png_ptr->read_buffer = NULL;
305
+ png_ptr->read_buffer = NULL;
306
+ png_ptr->read_buffer_size = 0;
307
+ png_free(png_ptr, buffer);
308
+ buffer = NULL;
309
+ }
310
+
311
+ if (buffer == NULL)
312
+ {
313
+ buffer = png_voidcast(png_bytep, png_malloc_base(png_ptr, new_size));
314
+
315
+ if (buffer != NULL)
316
+ {
317
+ memset(buffer, 0, new_size); /* just in case */
318
+ png_ptr->read_buffer = buffer;
319
+ png_ptr->read_buffer_size = new_size;
320
+ }
321
+
322
+ else if (warn < 2) /* else silent */
323
+ {
324
+ if (warn != 0)
325
+ png_chunk_warning(png_ptr, "insufficient memory to read chunk");
326
+
327
+ else
328
+ png_chunk_error(png_ptr, "insufficient memory to read chunk");
329
+ }
330
+ }
331
+
332
+ return buffer;
333
+ }
334
+ #endif /* READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|SEQUENTIAL_READ */
335
+
336
+ /* png_inflate_claim: claim the zstream for some nefarious purpose that involves
337
+ * decompression. Returns Z_OK on success, else a zlib error code. It checks
338
+ * the owner but, in final release builds, just issues a warning if some other
339
+ * chunk apparently owns the stream. Prior to release it does a png_error.
340
+ */
341
+ static int
342
+ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
343
+ {
344
+ if (png_ptr->zowner != 0)
345
+ {
346
+ char msg[64];
347
+
348
+ PNG_STRING_FROM_CHUNK(msg, png_ptr->zowner);
349
+ /* So the message that results is "<chunk> using zstream"; this is an
350
+ * internal error, but is very useful for debugging. i18n requirements
351
+ * are minimal.
352
+ */
353
+ (void)png_safecat(msg, (sizeof msg), 4, " using zstream");
354
+ #if PNG_RELEASE_BUILD
355
+ png_chunk_warning(png_ptr, msg);
356
+ png_ptr->zowner = 0;
357
+ #else
358
+ png_chunk_error(png_ptr, msg);
359
+ #endif
360
+ }
361
+
362
+ /* Implementation note: unlike 'png_deflate_claim' this internal function
363
+ * does not take the size of the data as an argument. Some efficiency could
364
+ * be gained by using this when it is known *if* the zlib stream itself does
365
+ * not record the number; however, this is an illusion: the original writer
366
+ * of the PNG may have selected a lower window size, and we really must
367
+ * follow that because, for systems with with limited capabilities, we
368
+ * would otherwise reject the application's attempts to use a smaller window
369
+ * size (zlib doesn't have an interface to say "this or lower"!).
370
+ *
371
+ * inflateReset2 was added to zlib 1.2.4; before this the window could not be
372
+ * reset, therefore it is necessary to always allocate the maximum window
373
+ * size with earlier zlibs just in case later compressed chunks need it.
374
+ */
375
+ {
376
+ int ret; /* zlib return code */
377
+ #if ZLIB_VERNUM >= 0x1240
378
+ int window_bits = 0;
379
+
380
+ # if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)
381
+ if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
382
+ PNG_OPTION_ON)
383
+ {
384
+ window_bits = 15;
385
+ png_ptr->zstream_start = 0; /* fixed window size */
386
+ }
387
+
388
+ else
389
+ {
390
+ png_ptr->zstream_start = 1;
391
+ }
392
+ # endif
393
+
394
+ #endif /* ZLIB_VERNUM >= 0x1240 */
395
+
396
+ /* Set this for safety, just in case the previous owner left pointers to
397
+ * memory allocations.
398
+ */
399
+ png_ptr->zstream.next_in = NULL;
400
+ png_ptr->zstream.avail_in = 0;
401
+ png_ptr->zstream.next_out = NULL;
402
+ png_ptr->zstream.avail_out = 0;
403
+
404
+ if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
405
+ {
406
+ #if ZLIB_VERNUM >= 0x1240
407
+ ret = inflateReset2(&png_ptr->zstream, window_bits);
408
+ #else
409
+ ret = inflateReset(&png_ptr->zstream);
410
+ #endif
411
+ }
412
+
413
+ else
414
+ {
415
+ #if ZLIB_VERNUM >= 0x1240
416
+ ret = inflateInit2(&png_ptr->zstream, window_bits);
417
+ #else
418
+ ret = inflateInit(&png_ptr->zstream);
419
+ #endif
420
+
421
+ if (ret == Z_OK)
422
+ png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
423
+ }
424
+
425
+ #if ZLIB_VERNUM >= 0x1290 && \
426
+ defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)
427
+ if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON)
428
+ /* Turn off validation of the ADLER32 checksum in IDAT chunks */
429
+ ret = inflateValidate(&png_ptr->zstream, 0);
430
+ #endif
431
+
432
+ if (ret == Z_OK)
433
+ png_ptr->zowner = owner;
434
+
435
+ else
436
+ png_zstream_error(png_ptr, ret);
437
+
438
+ return ret;
439
+ }
440
+
441
+ #ifdef window_bits
442
+ # undef window_bits
443
+ #endif
444
+ }
445
+
446
+ #if ZLIB_VERNUM >= 0x1240
447
+ /* Handle the start of the inflate stream if we called inflateInit2(strm,0);
448
+ * in this case some zlib versions skip validation of the CINFO field and, in
449
+ * certain circumstances, libpng may end up displaying an invalid image, in
450
+ * contrast to implementations that call zlib in the normal way (e.g. libpng
451
+ * 1.5).
452
+ */
453
+ int /* PRIVATE */
454
+ png_zlib_inflate(png_structrp png_ptr, int flush)
455
+ {
456
+ if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0)
457
+ {
458
+ if ((*png_ptr->zstream.next_in >> 4) > 7)
459
+ {
460
+ png_ptr->zstream.msg = "invalid window size (libpng)";
461
+ return Z_DATA_ERROR;
462
+ }
463
+
464
+ png_ptr->zstream_start = 0;
465
+ }
466
+
467
+ return inflate(&png_ptr->zstream, flush);
468
+ }
469
+ #endif /* Zlib >= 1.2.4 */
470
+
471
+ #ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
472
+ #if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED)
473
+ /* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to
474
+ * allow the caller to do multiple calls if required. If the 'finish' flag is
475
+ * set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must
476
+ * be returned or there has been a problem, otherwise Z_SYNC_FLUSH is used and
477
+ * Z_OK or Z_STREAM_END will be returned on success.
478
+ *
479
+ * The input and output sizes are updated to the actual amounts of data consumed
480
+ * or written, not the amount available (as in a z_stream). The data pointers
481
+ * are not changed, so the next input is (data+input_size) and the next
482
+ * available output is (output+output_size).
483
+ */
484
+ static int
485
+ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
486
+ /* INPUT: */ png_const_bytep input, png_uint_32p input_size_ptr,
487
+ /* OUTPUT: */ png_bytep output, png_alloc_size_t *output_size_ptr)
488
+ {
489
+ if (png_ptr->zowner == owner) /* Else not claimed */
490
+ {
491
+ int ret;
492
+ png_alloc_size_t avail_out = *output_size_ptr;
493
+ png_uint_32 avail_in = *input_size_ptr;
494
+
495
+ /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it
496
+ * can't even necessarily handle 65536 bytes) because the type uInt is
497
+ * "16 bits or more". Consequently it is necessary to chunk the input to
498
+ * zlib. This code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the
499
+ * maximum value that can be stored in a uInt.) It is possible to set
500
+ * ZLIB_IO_MAX to a lower value in pngpriv.h and this may sometimes have
501
+ * a performance advantage, because it reduces the amount of data accessed
502
+ * at each step and that may give the OS more time to page it in.
503
+ */
504
+ png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input);
505
+ /* avail_in and avail_out are set below from 'size' */
506
+ png_ptr->zstream.avail_in = 0;
507
+ png_ptr->zstream.avail_out = 0;
508
+
509
+ /* Read directly into the output if it is available (this is set to
510
+ * a local buffer below if output is NULL).
511
+ */
512
+ if (output != NULL)
513
+ png_ptr->zstream.next_out = output;
514
+
515
+ do
516
+ {
517
+ uInt avail;
518
+ Byte local_buffer[PNG_INFLATE_BUF_SIZE];
519
+
520
+ /* zlib INPUT BUFFER */
521
+ /* The setting of 'avail_in' used to be outside the loop; by setting it
522
+ * inside it is possible to chunk the input to zlib and simply rely on
523
+ * zlib to advance the 'next_in' pointer. This allows arbitrary
524
+ * amounts of data to be passed through zlib at the unavoidable cost of
525
+ * requiring a window save (memcpy of up to 32768 output bytes)
526
+ * every ZLIB_IO_MAX input bytes.
527
+ */
528
+ avail_in += png_ptr->zstream.avail_in; /* not consumed last time */
529
+
530
+ avail = ZLIB_IO_MAX;
531
+
532
+ if (avail_in < avail)
533
+ avail = (uInt)avail_in; /* safe: < than ZLIB_IO_MAX */
534
+
535
+ avail_in -= avail;
536
+ png_ptr->zstream.avail_in = avail;
537
+
538
+ /* zlib OUTPUT BUFFER */
539
+ avail_out += png_ptr->zstream.avail_out; /* not written last time */
540
+
541
+ avail = ZLIB_IO_MAX; /* maximum zlib can process */
542
+
543
+ if (output == NULL)
544
+ {
545
+ /* Reset the output buffer each time round if output is NULL and
546
+ * make available the full buffer, up to 'remaining_space'
547
+ */
548
+ png_ptr->zstream.next_out = local_buffer;
549
+ if ((sizeof local_buffer) < avail)
550
+ avail = (sizeof local_buffer);
551
+ }
552
+
553
+ if (avail_out < avail)
554
+ avail = (uInt)avail_out; /* safe: < ZLIB_IO_MAX */
555
+
556
+ png_ptr->zstream.avail_out = avail;
557
+ avail_out -= avail;
558
+
559
+ /* zlib inflate call */
560
+ /* In fact 'avail_out' may be 0 at this point, that happens at the end
561
+ * of the read when the final LZ end code was not passed at the end of
562
+ * the previous chunk of input data. Tell zlib if we have reached the
563
+ * end of the output buffer.
564
+ */
565
+ ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH :
566
+ (finish ? Z_FINISH : Z_SYNC_FLUSH));
567
+ } while (ret == Z_OK);
568
+
569
+ /* For safety kill the local buffer pointer now */
570
+ if (output == NULL)
571
+ png_ptr->zstream.next_out = NULL;
572
+
573
+ /* Claw back the 'size' and 'remaining_space' byte counts. */
574
+ avail_in += png_ptr->zstream.avail_in;
575
+ avail_out += png_ptr->zstream.avail_out;
576
+
577
+ /* Update the input and output sizes; the updated values are the amount
578
+ * consumed or written, effectively the inverse of what zlib uses.
579
+ */
580
+ if (avail_out > 0)
581
+ *output_size_ptr -= avail_out;
582
+
583
+ if (avail_in > 0)
584
+ *input_size_ptr -= avail_in;
585
+
586
+ /* Ensure png_ptr->zstream.msg is set (even in the success case!) */
587
+ png_zstream_error(png_ptr, ret);
588
+ return ret;
589
+ }
590
+
591
+ else
592
+ {
593
+ /* This is a bad internal error. The recovery assigns to the zstream msg
594
+ * pointer, which is not owned by the caller, but this is safe; it's only
595
+ * used on errors!
596
+ */
597
+ png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed");
598
+ return Z_STREAM_ERROR;
599
+ }
600
+ }
601
+
602
+ /*
603
+ * Decompress trailing data in a chunk. The assumption is that read_buffer
604
+ * points at an allocated area holding the contents of a chunk with a
605
+ * trailing compressed part. What we get back is an allocated area
606
+ * holding the original prefix part and an uncompressed version of the
607
+ * trailing part (the malloc area passed in is freed).
608
+ */
609
+ static int
610
+ png_decompress_chunk(png_structrp png_ptr,
611
+ png_uint_32 chunklength, png_uint_32 prefix_size,
612
+ png_alloc_size_t *newlength /* must be initialized to the maximum! */,
613
+ int terminate /*add a '\0' to the end of the uncompressed data*/)
614
+ {
615
+ /* TODO: implement different limits for different types of chunk.
616
+ *
617
+ * The caller supplies *newlength set to the maximum length of the
618
+ * uncompressed data, but this routine allocates space for the prefix and
619
+ * maybe a '\0' terminator too. We have to assume that 'prefix_size' is
620
+ * limited only by the maximum chunk size.
621
+ */
622
+ png_alloc_size_t limit = PNG_SIZE_MAX;
623
+
624
+ # ifdef PNG_SET_USER_LIMITS_SUPPORTED
625
+ if (png_ptr->user_chunk_malloc_max > 0 &&
626
+ png_ptr->user_chunk_malloc_max < limit)
627
+ limit = png_ptr->user_chunk_malloc_max;
628
+ # elif PNG_USER_CHUNK_MALLOC_MAX > 0
629
+ if (PNG_USER_CHUNK_MALLOC_MAX < limit)
630
+ limit = PNG_USER_CHUNK_MALLOC_MAX;
631
+ # endif
632
+
633
+ if (limit >= prefix_size + (terminate != 0))
634
+ {
635
+ int ret;
636
+
637
+ limit -= prefix_size + (terminate != 0);
638
+
639
+ if (limit < *newlength)
640
+ *newlength = limit;
641
+
642
+ /* Now try to claim the stream. */
643
+ ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);
644
+
645
+ if (ret == Z_OK)
646
+ {
647
+ png_uint_32 lzsize = chunklength - prefix_size;
648
+
649
+ ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
650
+ /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
651
+ /* output: */ NULL, newlength);
652
+
653
+ if (ret == Z_STREAM_END)
654
+ {
655
+ /* Use 'inflateReset' here, not 'inflateReset2' because this
656
+ * preserves the previously decided window size (otherwise it would
657
+ * be necessary to store the previous window size.) In practice
658
+ * this doesn't matter anyway, because png_inflate will call inflate
659
+ * with Z_FINISH in almost all cases, so the window will not be
660
+ * maintained.
661
+ */
662
+ if (inflateReset(&png_ptr->zstream) == Z_OK)
663
+ {
664
+ /* Because of the limit checks above we know that the new,
665
+ * expanded, size will fit in a size_t (let alone an
666
+ * png_alloc_size_t). Use png_malloc_base here to avoid an
667
+ * extra OOM message.
668
+ */
669
+ png_alloc_size_t new_size = *newlength;
670
+ png_alloc_size_t buffer_size = prefix_size + new_size +
671
+ (terminate != 0);
672
+ png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,
673
+ buffer_size));
674
+
675
+ if (text != NULL)
676
+ {
677
+ memset(text, 0, buffer_size);
678
+
679
+ ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
680
+ png_ptr->read_buffer + prefix_size, &lzsize,
681
+ text + prefix_size, newlength);
682
+
683
+ if (ret == Z_STREAM_END)
684
+ {
685
+ if (new_size == *newlength)
686
+ {
687
+ if (terminate != 0)
688
+ text[prefix_size + *newlength] = 0;
689
+
690
+ if (prefix_size > 0)
691
+ memcpy(text, png_ptr->read_buffer, prefix_size);
692
+
693
+ {
694
+ png_bytep old_ptr = png_ptr->read_buffer;
695
+
696
+ png_ptr->read_buffer = text;
697
+ png_ptr->read_buffer_size = buffer_size;
698
+ text = old_ptr; /* freed below */
699
+ }
700
+ }
701
+
702
+ else
703
+ {
704
+ /* The size changed on the second read, there can be no
705
+ * guarantee that anything is correct at this point.
706
+ * The 'msg' pointer has been set to "unexpected end of
707
+ * LZ stream", which is fine, but return an error code
708
+ * that the caller won't accept.
709
+ */
710
+ ret = PNG_UNEXPECTED_ZLIB_RETURN;
711
+ }
712
+ }
713
+
714
+ else if (ret == Z_OK)
715
+ ret = PNG_UNEXPECTED_ZLIB_RETURN; /* for safety */
716
+
717
+ /* Free the text pointer (this is the old read_buffer on
718
+ * success)
719
+ */
720
+ png_free(png_ptr, text);
721
+
722
+ /* This really is very benign, but it's still an error because
723
+ * the extra space may otherwise be used as a Trojan Horse.
724
+ */
725
+ if (ret == Z_STREAM_END &&
726
+ chunklength - prefix_size != lzsize)
727
+ png_chunk_benign_error(png_ptr, "extra compressed data");
728
+ }
729
+
730
+ else
731
+ {
732
+ /* Out of memory allocating the buffer */
733
+ ret = Z_MEM_ERROR;
734
+ png_zstream_error(png_ptr, Z_MEM_ERROR);
735
+ }
736
+ }
737
+
738
+ else
739
+ {
740
+ /* inflateReset failed, store the error message */
741
+ png_zstream_error(png_ptr, ret);
742
+ ret = PNG_UNEXPECTED_ZLIB_RETURN;
743
+ }
744
+ }
745
+
746
+ else if (ret == Z_OK)
747
+ ret = PNG_UNEXPECTED_ZLIB_RETURN;
748
+
749
+ /* Release the claimed stream */
750
+ png_ptr->zowner = 0;
751
+ }
752
+
753
+ else /* the claim failed */ if (ret == Z_STREAM_END) /* impossible! */
754
+ ret = PNG_UNEXPECTED_ZLIB_RETURN;
755
+
756
+ return ret;
757
+ }
758
+
759
+ else
760
+ {
761
+ /* Application/configuration limits exceeded */
762
+ png_zstream_error(png_ptr, Z_MEM_ERROR);
763
+ return Z_MEM_ERROR;
764
+ }
765
+ }
766
+ #endif /* READ_zTXt || READ_iTXt */
767
+ #endif /* READ_COMPRESSED_TEXT */
768
+
769
+ #ifdef PNG_READ_iCCP_SUPPORTED
770
+ /* Perform a partial read and decompress, producing 'avail_out' bytes and
771
+ * reading from the current chunk as required.
772
+ */
773
+ static int
774
+ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
775
+ png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
776
+ int finish)
777
+ {
778
+ if (png_ptr->zowner == png_ptr->chunk_name)
779
+ {
780
+ int ret;
781
+
782
+ /* next_in and avail_in must have been initialized by the caller. */
783
+ png_ptr->zstream.next_out = next_out;
784
+ png_ptr->zstream.avail_out = 0; /* set in the loop */
785
+
786
+ do
787
+ {
788
+ if (png_ptr->zstream.avail_in == 0)
789
+ {
790
+ if (read_size > *chunk_bytes)
791
+ read_size = (uInt)*chunk_bytes;
792
+ *chunk_bytes -= read_size;
793
+
794
+ if (read_size > 0)
795
+ png_crc_read(png_ptr, read_buffer, read_size);
796
+
797
+ png_ptr->zstream.next_in = read_buffer;
798
+ png_ptr->zstream.avail_in = read_size;
799
+ }
800
+
801
+ if (png_ptr->zstream.avail_out == 0)
802
+ {
803
+ uInt avail = ZLIB_IO_MAX;
804
+ if (avail > *out_size)
805
+ avail = (uInt)*out_size;
806
+ *out_size -= avail;
807
+
808
+ png_ptr->zstream.avail_out = avail;
809
+ }
810
+
811
+ /* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all
812
+ * the available output is produced; this allows reading of truncated
813
+ * streams.
814
+ */
815
+ ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ?
816
+ Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));
817
+ }
818
+ while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0));
819
+
820
+ *out_size += png_ptr->zstream.avail_out;
821
+ png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */
822
+
823
+ /* Ensure the error message pointer is always set: */
824
+ png_zstream_error(png_ptr, ret);
825
+ return ret;
826
+ }
827
+
828
+ else
829
+ {
830
+ png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed");
831
+ return Z_STREAM_ERROR;
832
+ }
833
+ }
834
+ #endif /* READ_iCCP */
835
+
836
+ /* Read and check the IDHR chunk */
837
+
838
+ void /* PRIVATE */
839
+ png_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
840
+ {
841
+ png_byte buf[13];
842
+ png_uint_32 width, height;
843
+ int bit_depth, color_type, compression_type, filter_type;
844
+ int interlace_type;
845
+
846
+ png_debug(1, "in png_handle_IHDR");
847
+
848
+ if ((png_ptr->mode & PNG_HAVE_IHDR) != 0)
849
+ png_chunk_error(png_ptr, "out of place");
850
+
851
+ /* Check the length */
852
+ if (length != 13)
853
+ png_chunk_error(png_ptr, "invalid");
854
+
855
+ png_ptr->mode |= PNG_HAVE_IHDR;
856
+
857
+ png_crc_read(png_ptr, buf, 13);
858
+ png_crc_finish(png_ptr, 0);
859
+
860
+ width = png_get_uint_31(png_ptr, buf);
861
+ height = png_get_uint_31(png_ptr, buf + 4);
862
+ bit_depth = buf[8];
863
+ color_type = buf[9];
864
+ compression_type = buf[10];
865
+ filter_type = buf[11];
866
+ interlace_type = buf[12];
867
+
868
+ /* Set internal variables */
869
+ png_ptr->width = width;
870
+ png_ptr->height = height;
871
+ png_ptr->bit_depth = (png_byte)bit_depth;
872
+ png_ptr->interlaced = (png_byte)interlace_type;
873
+ png_ptr->color_type = (png_byte)color_type;
874
+ #ifdef PNG_MNG_FEATURES_SUPPORTED
875
+ png_ptr->filter_type = (png_byte)filter_type;
876
+ #endif
877
+ png_ptr->compression_type = (png_byte)compression_type;
878
+
879
+ /* Find number of channels */
880
+ switch (png_ptr->color_type)
881
+ {
882
+ default: /* invalid, png_set_IHDR calls png_error */
883
+ case PNG_COLOR_TYPE_GRAY:
884
+ case PNG_COLOR_TYPE_PALETTE:
885
+ png_ptr->channels = 1;
886
+ break;
887
+
888
+ case PNG_COLOR_TYPE_RGB:
889
+ png_ptr->channels = 3;
890
+ break;
891
+
892
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
893
+ png_ptr->channels = 2;
894
+ break;
895
+
896
+ case PNG_COLOR_TYPE_RGB_ALPHA:
897
+ png_ptr->channels = 4;
898
+ break;
899
+ }
900
+
901
+ /* Set up other useful info */
902
+ png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels);
903
+ png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
904
+ png_debug1(3, "bit_depth = %d", png_ptr->bit_depth);
905
+ png_debug1(3, "channels = %d", png_ptr->channels);
906
+ png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes);
907
+ png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
908
+ color_type, interlace_type, compression_type, filter_type);
909
+ }
910
+
911
+ /* Read and check the palette */
912
+ void /* PRIVATE */
913
+ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
914
+ {
915
+ png_color palette[PNG_MAX_PALETTE_LENGTH];
916
+ int max_palette_length, num, i;
917
+ #ifdef PNG_POINTER_INDEXING_SUPPORTED
918
+ png_colorp pal_ptr;
919
+ #endif
920
+
921
+ png_debug(1, "in png_handle_PLTE");
922
+
923
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
924
+ png_chunk_error(png_ptr, "missing IHDR");
925
+
926
+ /* Moved to before the 'after IDAT' check below because otherwise duplicate
927
+ * PLTE chunks are potentially ignored (the spec says there shall not be more
928
+ * than one PLTE, the error is not treated as benign, so this check trumps
929
+ * the requirement that PLTE appears before IDAT.)
930
+ */
931
+ else if ((png_ptr->mode & PNG_HAVE_PLTE) != 0)
932
+ png_chunk_error(png_ptr, "duplicate");
933
+
934
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
935
+ {
936
+ /* This is benign because the non-benign error happened before, when an
937
+ * IDAT was encountered in a color-mapped image with no PLTE.
938
+ */
939
+ png_crc_finish(png_ptr, length);
940
+ png_chunk_benign_error(png_ptr, "out of place");
941
+ return;
942
+ }
943
+
944
+ png_ptr->mode |= PNG_HAVE_PLTE;
945
+
946
+ if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
947
+ {
948
+ png_crc_finish(png_ptr, length);
949
+ png_chunk_benign_error(png_ptr, "ignored in grayscale PNG");
950
+ return;
951
+ }
952
+
953
+ #ifndef PNG_READ_OPT_PLTE_SUPPORTED
954
+ if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
955
+ {
956
+ png_crc_finish(png_ptr, length);
957
+ return;
958
+ }
959
+ #endif
960
+
961
+ if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
962
+ {
963
+ png_crc_finish(png_ptr, length);
964
+
965
+ if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
966
+ png_chunk_benign_error(png_ptr, "invalid");
967
+
968
+ else
969
+ png_chunk_error(png_ptr, "invalid");
970
+
971
+ return;
972
+ }
973
+
974
+ /* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */
975
+ num = (int)length / 3;
976
+
977
+ /* If the palette has 256 or fewer entries but is too large for the bit
978
+ * depth, we don't issue an error, to preserve the behavior of previous
979
+ * libpng versions. We silently truncate the unused extra palette entries
980
+ * here.
981
+ */
982
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
983
+ max_palette_length = (1 << png_ptr->bit_depth);
984
+ else
985
+ max_palette_length = PNG_MAX_PALETTE_LENGTH;
986
+
987
+ if (num > max_palette_length)
988
+ num = max_palette_length;
989
+
990
+ #ifdef PNG_POINTER_INDEXING_SUPPORTED
991
+ for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
992
+ {
993
+ png_byte buf[3];
994
+
995
+ png_crc_read(png_ptr, buf, 3);
996
+ pal_ptr->red = buf[0];
997
+ pal_ptr->green = buf[1];
998
+ pal_ptr->blue = buf[2];
999
+ }
1000
+ #else
1001
+ for (i = 0; i < num; i++)
1002
+ {
1003
+ png_byte buf[3];
1004
+
1005
+ png_crc_read(png_ptr, buf, 3);
1006
+ /* Don't depend upon png_color being any order */
1007
+ palette[i].red = buf[0];
1008
+ palette[i].green = buf[1];
1009
+ palette[i].blue = buf[2];
1010
+ }
1011
+ #endif
1012
+
1013
+ /* If we actually need the PLTE chunk (ie for a paletted image), we do
1014
+ * whatever the normal CRC configuration tells us. However, if we
1015
+ * have an RGB image, the PLTE can be considered ancillary, so
1016
+ * we will act as though it is.
1017
+ */
1018
+ #ifndef PNG_READ_OPT_PLTE_SUPPORTED
1019
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1020
+ #endif
1021
+ {
1022
+ png_crc_finish(png_ptr, (png_uint_32) (length - (unsigned int)num * 3));
1023
+ }
1024
+
1025
+ #ifndef PNG_READ_OPT_PLTE_SUPPORTED
1026
+ else if (png_crc_error(png_ptr) != 0) /* Only if we have a CRC error */
1027
+ {
1028
+ /* If we don't want to use the data from an ancillary chunk,
1029
+ * we have two options: an error abort, or a warning and we
1030
+ * ignore the data in this chunk (which should be OK, since
1031
+ * it's considered ancillary for a RGB or RGBA image).
1032
+ *
1033
+ * IMPLEMENTATION NOTE: this is only here because png_crc_finish uses the
1034
+ * chunk type to determine whether to check the ancillary or the critical
1035
+ * flags.
1036
+ */
1037
+ if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE) == 0)
1038
+ {
1039
+ if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) != 0)
1040
+ return;
1041
+
1042
+ else
1043
+ png_chunk_error(png_ptr, "CRC error");
1044
+ }
1045
+
1046
+ /* Otherwise, we (optionally) emit a warning and use the chunk. */
1047
+ else if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0)
1048
+ png_chunk_warning(png_ptr, "CRC error");
1049
+ }
1050
+ #endif
1051
+
1052
+ /* TODO: png_set_PLTE has the side effect of setting png_ptr->palette to its
1053
+ * own copy of the palette. This has the side effect that when png_start_row
1054
+ * is called (this happens after any call to png_read_update_info) the
1055
+ * info_ptr palette gets changed. This is extremely unexpected and
1056
+ * confusing.
1057
+ *
1058
+ * Fix this by not sharing the palette in this way.
1059
+ */
1060
+ png_set_PLTE(png_ptr, info_ptr, palette, num);
1061
+
1062
+ /* The three chunks, bKGD, hIST and tRNS *must* appear after PLTE and before
1063
+ * IDAT. Prior to 1.6.0 this was not checked; instead the code merely
1064
+ * checked the apparent validity of a tRNS chunk inserted before PLTE on a
1065
+ * palette PNG. 1.6.0 attempts to rigorously follow the standard and
1066
+ * therefore does a benign error if the erroneous condition is detected *and*
1067
+ * cancels the tRNS if the benign error returns. The alternative is to
1068
+ * amend the standard since it would be rather hypocritical of the standards
1069
+ * maintainers to ignore it.
1070
+ */
1071
+ #ifdef PNG_READ_tRNS_SUPPORTED
1072
+ if (png_ptr->num_trans > 0 ||
1073
+ (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0))
1074
+ {
1075
+ /* Cancel this because otherwise it would be used if the transforms
1076
+ * require it. Don't cancel the 'valid' flag because this would prevent
1077
+ * detection of duplicate chunks.
1078
+ */
1079
+ png_ptr->num_trans = 0;
1080
+
1081
+ if (info_ptr != NULL)
1082
+ info_ptr->num_trans = 0;
1083
+
1084
+ png_chunk_benign_error(png_ptr, "tRNS must be after");
1085
+ }
1086
+ #endif
1087
+
1088
+ #ifdef PNG_READ_hIST_SUPPORTED
1089
+ if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0)
1090
+ png_chunk_benign_error(png_ptr, "hIST must be after");
1091
+ #endif
1092
+
1093
+ #ifdef PNG_READ_bKGD_SUPPORTED
1094
+ if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0)
1095
+ png_chunk_benign_error(png_ptr, "bKGD must be after");
1096
+ #endif
1097
+ }
1098
+
1099
+ void /* PRIVATE */
1100
+ png_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1101
+ {
1102
+ png_debug(1, "in png_handle_IEND");
1103
+
1104
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0 ||
1105
+ (png_ptr->mode & PNG_HAVE_IDAT) == 0)
1106
+ png_chunk_error(png_ptr, "out of place");
1107
+
1108
+ png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
1109
+
1110
+ png_crc_finish(png_ptr, length);
1111
+
1112
+ if (length != 0)
1113
+ png_chunk_benign_error(png_ptr, "invalid");
1114
+
1115
+ PNG_UNUSED(info_ptr)
1116
+ }
1117
+
1118
+ #ifdef PNG_READ_gAMA_SUPPORTED
1119
+ void /* PRIVATE */
1120
+ png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1121
+ {
1122
+ png_fixed_point igamma;
1123
+ png_byte buf[4];
1124
+
1125
+ png_debug(1, "in png_handle_gAMA");
1126
+
1127
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1128
+ png_chunk_error(png_ptr, "missing IHDR");
1129
+
1130
+ else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
1131
+ {
1132
+ png_crc_finish(png_ptr, length);
1133
+ png_chunk_benign_error(png_ptr, "out of place");
1134
+ return;
1135
+ }
1136
+
1137
+ if (length != 4)
1138
+ {
1139
+ png_crc_finish(png_ptr, length);
1140
+ png_chunk_benign_error(png_ptr, "invalid");
1141
+ return;
1142
+ }
1143
+
1144
+ png_crc_read(png_ptr, buf, 4);
1145
+
1146
+ if (png_crc_finish(png_ptr, 0) != 0)
1147
+ return;
1148
+
1149
+ igamma = png_get_fixed_point(NULL, buf);
1150
+
1151
+ png_colorspace_set_gamma(png_ptr, &png_ptr->colorspace, igamma);
1152
+ png_colorspace_sync(png_ptr, info_ptr);
1153
+ }
1154
+ #endif
1155
+
1156
+ #ifdef PNG_READ_sBIT_SUPPORTED
1157
+ void /* PRIVATE */
1158
+ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1159
+ {
1160
+ unsigned int truelen, i;
1161
+ png_byte sample_depth;
1162
+ png_byte buf[4];
1163
+
1164
+ png_debug(1, "in png_handle_sBIT");
1165
+
1166
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1167
+ png_chunk_error(png_ptr, "missing IHDR");
1168
+
1169
+ else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
1170
+ {
1171
+ png_crc_finish(png_ptr, length);
1172
+ png_chunk_benign_error(png_ptr, "out of place");
1173
+ return;
1174
+ }
1175
+
1176
+ if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) != 0)
1177
+ {
1178
+ png_crc_finish(png_ptr, length);
1179
+ png_chunk_benign_error(png_ptr, "duplicate");
1180
+ return;
1181
+ }
1182
+
1183
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1184
+ {
1185
+ truelen = 3;
1186
+ sample_depth = 8;
1187
+ }
1188
+
1189
+ else
1190
+ {
1191
+ truelen = png_ptr->channels;
1192
+ sample_depth = png_ptr->bit_depth;
1193
+ }
1194
+
1195
+ if (length != truelen || length > 4)
1196
+ {
1197
+ png_chunk_benign_error(png_ptr, "invalid");
1198
+ png_crc_finish(png_ptr, length);
1199
+ return;
1200
+ }
1201
+
1202
+ buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;
1203
+ png_crc_read(png_ptr, buf, truelen);
1204
+
1205
+ if (png_crc_finish(png_ptr, 0) != 0)
1206
+ return;
1207
+
1208
+ for (i=0; i<truelen; ++i)
1209
+ {
1210
+ if (buf[i] == 0 || buf[i] > sample_depth)
1211
+ {
1212
+ png_chunk_benign_error(png_ptr, "invalid");
1213
+ return;
1214
+ }
1215
+ }
1216
+
1217
+ if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
1218
+ {
1219
+ png_ptr->sig_bit.red = buf[0];
1220
+ png_ptr->sig_bit.green = buf[1];
1221
+ png_ptr->sig_bit.blue = buf[2];
1222
+ png_ptr->sig_bit.alpha = buf[3];
1223
+ }
1224
+
1225
+ else
1226
+ {
1227
+ png_ptr->sig_bit.gray = buf[0];
1228
+ png_ptr->sig_bit.red = buf[0];
1229
+ png_ptr->sig_bit.green = buf[0];
1230
+ png_ptr->sig_bit.blue = buf[0];
1231
+ png_ptr->sig_bit.alpha = buf[1];
1232
+ }
1233
+
1234
+ png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
1235
+ }
1236
+ #endif
1237
+
1238
+ #ifdef PNG_READ_cHRM_SUPPORTED
1239
+ void /* PRIVATE */
1240
+ png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1241
+ {
1242
+ png_byte buf[32];
1243
+ png_xy xy;
1244
+
1245
+ png_debug(1, "in png_handle_cHRM");
1246
+
1247
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1248
+ png_chunk_error(png_ptr, "missing IHDR");
1249
+
1250
+ else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
1251
+ {
1252
+ png_crc_finish(png_ptr, length);
1253
+ png_chunk_benign_error(png_ptr, "out of place");
1254
+ return;
1255
+ }
1256
+
1257
+ if (length != 32)
1258
+ {
1259
+ png_crc_finish(png_ptr, length);
1260
+ png_chunk_benign_error(png_ptr, "invalid");
1261
+ return;
1262
+ }
1263
+
1264
+ png_crc_read(png_ptr, buf, 32);
1265
+
1266
+ if (png_crc_finish(png_ptr, 0) != 0)
1267
+ return;
1268
+
1269
+ xy.whitex = png_get_fixed_point(NULL, buf);
1270
+ xy.whitey = png_get_fixed_point(NULL, buf + 4);
1271
+ xy.redx = png_get_fixed_point(NULL, buf + 8);
1272
+ xy.redy = png_get_fixed_point(NULL, buf + 12);
1273
+ xy.greenx = png_get_fixed_point(NULL, buf + 16);
1274
+ xy.greeny = png_get_fixed_point(NULL, buf + 20);
1275
+ xy.bluex = png_get_fixed_point(NULL, buf + 24);
1276
+ xy.bluey = png_get_fixed_point(NULL, buf + 28);
1277
+
1278
+ if (xy.whitex == PNG_FIXED_ERROR ||
1279
+ xy.whitey == PNG_FIXED_ERROR ||
1280
+ xy.redx == PNG_FIXED_ERROR ||
1281
+ xy.redy == PNG_FIXED_ERROR ||
1282
+ xy.greenx == PNG_FIXED_ERROR ||
1283
+ xy.greeny == PNG_FIXED_ERROR ||
1284
+ xy.bluex == PNG_FIXED_ERROR ||
1285
+ xy.bluey == PNG_FIXED_ERROR)
1286
+ {
1287
+ png_chunk_benign_error(png_ptr, "invalid values");
1288
+ return;
1289
+ }
1290
+
1291
+ /* If a colorspace error has already been output skip this chunk */
1292
+ if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
1293
+ return;
1294
+
1295
+ if ((png_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0)
1296
+ {
1297
+ png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
1298
+ png_colorspace_sync(png_ptr, info_ptr);
1299
+ png_chunk_benign_error(png_ptr, "duplicate");
1300
+ return;
1301
+ }
1302
+
1303
+ png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
1304
+ (void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy,
1305
+ 1/*prefer cHRM values*/);
1306
+ png_colorspace_sync(png_ptr, info_ptr);
1307
+ }
1308
+ #endif
1309
+
1310
+ #ifdef PNG_READ_sRGB_SUPPORTED
1311
+ void /* PRIVATE */
1312
+ png_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1313
+ {
1314
+ png_byte intent;
1315
+
1316
+ png_debug(1, "in png_handle_sRGB");
1317
+
1318
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1319
+ png_chunk_error(png_ptr, "missing IHDR");
1320
+
1321
+ else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
1322
+ {
1323
+ png_crc_finish(png_ptr, length);
1324
+ png_chunk_benign_error(png_ptr, "out of place");
1325
+ return;
1326
+ }
1327
+
1328
+ if (length != 1)
1329
+ {
1330
+ png_crc_finish(png_ptr, length);
1331
+ png_chunk_benign_error(png_ptr, "invalid");
1332
+ return;
1333
+ }
1334
+
1335
+ png_crc_read(png_ptr, &intent, 1);
1336
+
1337
+ if (png_crc_finish(png_ptr, 0) != 0)
1338
+ return;
1339
+
1340
+ /* If a colorspace error has already been output skip this chunk */
1341
+ if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
1342
+ return;
1343
+
1344
+ /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect
1345
+ * this.
1346
+ */
1347
+ if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) != 0)
1348
+ {
1349
+ png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
1350
+ png_colorspace_sync(png_ptr, info_ptr);
1351
+ png_chunk_benign_error(png_ptr, "too many profiles");
1352
+ return;
1353
+ }
1354
+
1355
+ (void)png_colorspace_set_sRGB(png_ptr, &png_ptr->colorspace, intent);
1356
+ png_colorspace_sync(png_ptr, info_ptr);
1357
+ }
1358
+ #endif /* READ_sRGB */
1359
+
1360
+ #ifdef PNG_READ_iCCP_SUPPORTED
1361
+ void /* PRIVATE */
1362
+ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1363
+ /* Note: this does not properly handle profiles that are > 64K under DOS */
1364
+ {
1365
+ png_const_charp errmsg = NULL; /* error message output, or no error */
1366
+ int finished = 0; /* crc checked */
1367
+
1368
+ png_debug(1, "in png_handle_iCCP");
1369
+
1370
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1371
+ png_chunk_error(png_ptr, "missing IHDR");
1372
+
1373
+ else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
1374
+ {
1375
+ png_crc_finish(png_ptr, length);
1376
+ png_chunk_benign_error(png_ptr, "out of place");
1377
+ return;
1378
+ }
1379
+
1380
+ /* Consistent with all the above colorspace handling an obviously *invalid*
1381
+ * chunk is just ignored, so does not invalidate the color space. An
1382
+ * alternative is to set the 'invalid' flags at the start of this routine
1383
+ * and only clear them in they were not set before and all the tests pass.
1384
+ */
1385
+
1386
+ /* The keyword must be at least one character and there is a
1387
+ * terminator (0) byte and the compression method byte, and the
1388
+ * 'zlib' datastream is at least 11 bytes.
1389
+ */
1390
+ if (length < 14)
1391
+ {
1392
+ png_crc_finish(png_ptr, length);
1393
+ png_chunk_benign_error(png_ptr, "too short");
1394
+ return;
1395
+ }
1396
+
1397
+ /* If a colorspace error has already been output skip this chunk */
1398
+ if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
1399
+ {
1400
+ png_crc_finish(png_ptr, length);
1401
+ return;
1402
+ }
1403
+
1404
+ /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect
1405
+ * this.
1406
+ */
1407
+ if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) == 0)
1408
+ {
1409
+ uInt read_length, keyword_length;
1410
+ char keyword[81];
1411
+
1412
+ /* Find the keyword; the keyword plus separator and compression method
1413
+ * bytes can be at most 81 characters long.
1414
+ */
1415
+ read_length = 81; /* maximum */
1416
+ if (read_length > length)
1417
+ read_length = (uInt)length;
1418
+
1419
+ png_crc_read(png_ptr, (png_bytep)keyword, read_length);
1420
+ length -= read_length;
1421
+
1422
+ /* The minimum 'zlib' stream is assumed to be just the 2 byte header,
1423
+ * 5 bytes minimum 'deflate' stream, and the 4 byte checksum.
1424
+ */
1425
+ if (length < 11)
1426
+ {
1427
+ png_crc_finish(png_ptr, length);
1428
+ png_chunk_benign_error(png_ptr, "too short");
1429
+ return;
1430
+ }
1431
+
1432
+ keyword_length = 0;
1433
+ while (keyword_length < 80 && keyword_length < read_length &&
1434
+ keyword[keyword_length] != 0)
1435
+ ++keyword_length;
1436
+
1437
+ /* TODO: make the keyword checking common */
1438
+ if (keyword_length >= 1 && keyword_length <= 79)
1439
+ {
1440
+ /* We only understand '0' compression - deflate - so if we get a
1441
+ * different value we can't safely decode the chunk.
1442
+ */
1443
+ if (keyword_length+1 < read_length &&
1444
+ keyword[keyword_length+1] == PNG_COMPRESSION_TYPE_BASE)
1445
+ {
1446
+ read_length -= keyword_length+2;
1447
+
1448
+ if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)
1449
+ {
1450
+ Byte profile_header[132]={0};
1451
+ Byte local_buffer[PNG_INFLATE_BUF_SIZE];
1452
+ png_alloc_size_t size = (sizeof profile_header);
1453
+
1454
+ png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);
1455
+ png_ptr->zstream.avail_in = read_length;
1456
+ (void)png_inflate_read(png_ptr, local_buffer,
1457
+ (sizeof local_buffer), &length, profile_header, &size,
1458
+ 0/*finish: don't, because the output is too small*/);
1459
+
1460
+ if (size == 0)
1461
+ {
1462
+ /* We have the ICC profile header; do the basic header checks.
1463
+ */
1464
+ png_uint_32 profile_length = png_get_uint_32(profile_header);
1465
+
1466
+ if (png_icc_check_length(png_ptr, &png_ptr->colorspace,
1467
+ keyword, profile_length) != 0)
1468
+ {
1469
+ /* The length is apparently ok, so we can check the 132
1470
+ * byte header.
1471
+ */
1472
+ if (png_icc_check_header(png_ptr, &png_ptr->colorspace,
1473
+ keyword, profile_length, profile_header,
1474
+ png_ptr->color_type) != 0)
1475
+ {
1476
+ /* Now read the tag table; a variable size buffer is
1477
+ * needed at this point, allocate one for the whole
1478
+ * profile. The header check has already validated
1479
+ * that none of this stuff will overflow.
1480
+ */
1481
+ png_uint_32 tag_count =
1482
+ png_get_uint_32(profile_header + 128);
1483
+ png_bytep profile = png_read_buffer(png_ptr,
1484
+ profile_length, 2/*silent*/);
1485
+
1486
+ if (profile != NULL)
1487
+ {
1488
+ memcpy(profile, profile_header,
1489
+ (sizeof profile_header));
1490
+
1491
+ size = 12 * tag_count;
1492
+
1493
+ (void)png_inflate_read(png_ptr, local_buffer,
1494
+ (sizeof local_buffer), &length,
1495
+ profile + (sizeof profile_header), &size, 0);
1496
+
1497
+ /* Still expect a buffer error because we expect
1498
+ * there to be some tag data!
1499
+ */
1500
+ if (size == 0)
1501
+ {
1502
+ if (png_icc_check_tag_table(png_ptr,
1503
+ &png_ptr->colorspace, keyword, profile_length,
1504
+ profile) != 0)
1505
+ {
1506
+ /* The profile has been validated for basic
1507
+ * security issues, so read the whole thing in.
1508
+ */
1509
+ size = profile_length - (sizeof profile_header)
1510
+ - 12 * tag_count;
1511
+
1512
+ (void)png_inflate_read(png_ptr, local_buffer,
1513
+ (sizeof local_buffer), &length,
1514
+ profile + (sizeof profile_header) +
1515
+ 12 * tag_count, &size, 1/*finish*/);
1516
+
1517
+ if (length > 0 && !(png_ptr->flags &
1518
+ PNG_FLAG_BENIGN_ERRORS_WARN))
1519
+ errmsg = "extra compressed data";
1520
+
1521
+ /* But otherwise allow extra data: */
1522
+ else if (size == 0)
1523
+ {
1524
+ if (length > 0)
1525
+ {
1526
+ /* This can be handled completely, so
1527
+ * keep going.
1528
+ */
1529
+ png_chunk_warning(png_ptr,
1530
+ "extra compressed data");
1531
+ }
1532
+
1533
+ png_crc_finish(png_ptr, length);
1534
+ finished = 1;
1535
+
1536
+ # if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
1537
+ /* Check for a match against sRGB */
1538
+ png_icc_set_sRGB(png_ptr,
1539
+ &png_ptr->colorspace, profile,
1540
+ png_ptr->zstream.adler);
1541
+ # endif
1542
+
1543
+ /* Steal the profile for info_ptr. */
1544
+ if (info_ptr != NULL)
1545
+ {
1546
+ png_free_data(png_ptr, info_ptr,
1547
+ PNG_FREE_ICCP, 0);
1548
+
1549
+ info_ptr->iccp_name = png_voidcast(char*,
1550
+ png_malloc_base(png_ptr,
1551
+ keyword_length+1));
1552
+ if (info_ptr->iccp_name != NULL)
1553
+ {
1554
+ memcpy(info_ptr->iccp_name, keyword,
1555
+ keyword_length+1);
1556
+ info_ptr->iccp_proflen =
1557
+ profile_length;
1558
+ info_ptr->iccp_profile = profile;
1559
+ png_ptr->read_buffer = NULL; /*steal*/
1560
+ info_ptr->free_me |= PNG_FREE_ICCP;
1561
+ info_ptr->valid |= PNG_INFO_iCCP;
1562
+ }
1563
+
1564
+ else
1565
+ {
1566
+ png_ptr->colorspace.flags |=
1567
+ PNG_COLORSPACE_INVALID;
1568
+ errmsg = "out of memory";
1569
+ }
1570
+ }
1571
+
1572
+ /* else the profile remains in the read
1573
+ * buffer which gets reused for subsequent
1574
+ * chunks.
1575
+ */
1576
+
1577
+ if (info_ptr != NULL)
1578
+ png_colorspace_sync(png_ptr, info_ptr);
1579
+
1580
+ if (errmsg == NULL)
1581
+ {
1582
+ png_ptr->zowner = 0;
1583
+ return;
1584
+ }
1585
+ }
1586
+ if (errmsg == NULL)
1587
+ errmsg = png_ptr->zstream.msg;
1588
+ }
1589
+ /* else png_icc_check_tag_table output an error */
1590
+ }
1591
+ else /* profile truncated */
1592
+ errmsg = png_ptr->zstream.msg;
1593
+ }
1594
+
1595
+ else
1596
+ errmsg = "out of memory";
1597
+ }
1598
+
1599
+ /* else png_icc_check_header output an error */
1600
+ }
1601
+
1602
+ /* else png_icc_check_length output an error */
1603
+ }
1604
+
1605
+ else /* profile truncated */
1606
+ errmsg = png_ptr->zstream.msg;
1607
+
1608
+ /* Release the stream */
1609
+ png_ptr->zowner = 0;
1610
+ }
1611
+
1612
+ else /* png_inflate_claim failed */
1613
+ errmsg = png_ptr->zstream.msg;
1614
+ }
1615
+
1616
+ else
1617
+ errmsg = "bad compression method"; /* or missing */
1618
+ }
1619
+
1620
+ else
1621
+ errmsg = "bad keyword";
1622
+ }
1623
+
1624
+ else
1625
+ errmsg = "too many profiles";
1626
+
1627
+ /* Failure: the reason is in 'errmsg' */
1628
+ if (finished == 0)
1629
+ png_crc_finish(png_ptr, length);
1630
+
1631
+ png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
1632
+ png_colorspace_sync(png_ptr, info_ptr);
1633
+ if (errmsg != NULL) /* else already output */
1634
+ png_chunk_benign_error(png_ptr, errmsg);
1635
+ }
1636
+ #endif /* READ_iCCP */
1637
+
1638
+ #ifdef PNG_READ_sPLT_SUPPORTED
1639
+ void /* PRIVATE */
1640
+ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1641
+ /* Note: this does not properly handle chunks that are > 64K under DOS */
1642
+ {
1643
+ png_bytep entry_start, buffer;
1644
+ png_sPLT_t new_palette;
1645
+ png_sPLT_entryp pp;
1646
+ png_uint_32 data_length;
1647
+ int entry_size, i;
1648
+ png_uint_32 skip = 0;
1649
+ png_uint_32 dl;
1650
+ size_t max_dl;
1651
+
1652
+ png_debug(1, "in png_handle_sPLT");
1653
+
1654
+ #ifdef PNG_USER_LIMITS_SUPPORTED
1655
+ if (png_ptr->user_chunk_cache_max != 0)
1656
+ {
1657
+ if (png_ptr->user_chunk_cache_max == 1)
1658
+ {
1659
+ png_crc_finish(png_ptr, length);
1660
+ return;
1661
+ }
1662
+
1663
+ if (--png_ptr->user_chunk_cache_max == 1)
1664
+ {
1665
+ png_warning(png_ptr, "No space in chunk cache for sPLT");
1666
+ png_crc_finish(png_ptr, length);
1667
+ return;
1668
+ }
1669
+ }
1670
+ #endif
1671
+
1672
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1673
+ png_chunk_error(png_ptr, "missing IHDR");
1674
+
1675
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
1676
+ {
1677
+ png_crc_finish(png_ptr, length);
1678
+ png_chunk_benign_error(png_ptr, "out of place");
1679
+ return;
1680
+ }
1681
+
1682
+ #ifdef PNG_MAX_MALLOC_64K
1683
+ if (length > 65535U)
1684
+ {
1685
+ png_crc_finish(png_ptr, length);
1686
+ png_chunk_benign_error(png_ptr, "too large to fit in memory");
1687
+ return;
1688
+ }
1689
+ #endif
1690
+
1691
+ buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
1692
+ if (buffer == NULL)
1693
+ {
1694
+ png_crc_finish(png_ptr, length);
1695
+ png_chunk_benign_error(png_ptr, "out of memory");
1696
+ return;
1697
+ }
1698
+
1699
+
1700
+ /* WARNING: this may break if size_t is less than 32 bits; it is assumed
1701
+ * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a
1702
+ * potential breakage point if the types in pngconf.h aren't exactly right.
1703
+ */
1704
+ png_crc_read(png_ptr, buffer, length);
1705
+
1706
+ if (png_crc_finish(png_ptr, skip) != 0)
1707
+ return;
1708
+
1709
+ buffer[length] = 0;
1710
+
1711
+ for (entry_start = buffer; *entry_start; entry_start++)
1712
+ /* Empty loop to find end of name */ ;
1713
+
1714
+ ++entry_start;
1715
+
1716
+ /* A sample depth should follow the separator, and we should be on it */
1717
+ if (length < 2U || entry_start > buffer + (length - 2U))
1718
+ {
1719
+ png_warning(png_ptr, "malformed sPLT chunk");
1720
+ return;
1721
+ }
1722
+
1723
+ new_palette.depth = *entry_start++;
1724
+ entry_size = (new_palette.depth == 8 ? 6 : 10);
1725
+ /* This must fit in a png_uint_32 because it is derived from the original
1726
+ * chunk data length.
1727
+ */
1728
+ data_length = length - (png_uint_32)(entry_start - buffer);
1729
+
1730
+ /* Integrity-check the data length */
1731
+ if ((data_length % (unsigned int)entry_size) != 0)
1732
+ {
1733
+ png_warning(png_ptr, "sPLT chunk has bad length");
1734
+ return;
1735
+ }
1736
+
1737
+ dl = (png_uint_32)(data_length / (unsigned int)entry_size);
1738
+ max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));
1739
+
1740
+ if (dl > max_dl)
1741
+ {
1742
+ png_warning(png_ptr, "sPLT chunk too long");
1743
+ return;
1744
+ }
1745
+
1746
+ new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size);
1747
+
1748
+ new_palette.entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
1749
+ (png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry)));
1750
+
1751
+ if (new_palette.entries == NULL)
1752
+ {
1753
+ png_warning(png_ptr, "sPLT chunk requires too much memory");
1754
+ return;
1755
+ }
1756
+
1757
+ #ifdef PNG_POINTER_INDEXING_SUPPORTED
1758
+ for (i = 0; i < new_palette.nentries; i++)
1759
+ {
1760
+ pp = new_palette.entries + i;
1761
+
1762
+ if (new_palette.depth == 8)
1763
+ {
1764
+ pp->red = *entry_start++;
1765
+ pp->green = *entry_start++;
1766
+ pp->blue = *entry_start++;
1767
+ pp->alpha = *entry_start++;
1768
+ }
1769
+
1770
+ else
1771
+ {
1772
+ pp->red = png_get_uint_16(entry_start); entry_start += 2;
1773
+ pp->green = png_get_uint_16(entry_start); entry_start += 2;
1774
+ pp->blue = png_get_uint_16(entry_start); entry_start += 2;
1775
+ pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
1776
+ }
1777
+
1778
+ pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
1779
+ }
1780
+ #else
1781
+ pp = new_palette.entries;
1782
+
1783
+ for (i = 0; i < new_palette.nentries; i++)
1784
+ {
1785
+
1786
+ if (new_palette.depth == 8)
1787
+ {
1788
+ pp[i].red = *entry_start++;
1789
+ pp[i].green = *entry_start++;
1790
+ pp[i].blue = *entry_start++;
1791
+ pp[i].alpha = *entry_start++;
1792
+ }
1793
+
1794
+ else
1795
+ {
1796
+ pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
1797
+ pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
1798
+ pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
1799
+ pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
1800
+ }
1801
+
1802
+ pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2;
1803
+ }
1804
+ #endif
1805
+
1806
+ /* Discard all chunk data except the name and stash that */
1807
+ new_palette.name = (png_charp)buffer;
1808
+
1809
+ png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
1810
+
1811
+ png_free(png_ptr, new_palette.entries);
1812
+ }
1813
+ #endif /* READ_sPLT */
1814
+
1815
+ #ifdef PNG_READ_tRNS_SUPPORTED
1816
+ void /* PRIVATE */
1817
+ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1818
+ {
1819
+ png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
1820
+
1821
+ png_debug(1, "in png_handle_tRNS");
1822
+
1823
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1824
+ png_chunk_error(png_ptr, "missing IHDR");
1825
+
1826
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
1827
+ {
1828
+ png_crc_finish(png_ptr, length);
1829
+ png_chunk_benign_error(png_ptr, "out of place");
1830
+ return;
1831
+ }
1832
+
1833
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0)
1834
+ {
1835
+ png_crc_finish(png_ptr, length);
1836
+ png_chunk_benign_error(png_ptr, "duplicate");
1837
+ return;
1838
+ }
1839
+
1840
+ if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
1841
+ {
1842
+ png_byte buf[2];
1843
+
1844
+ if (length != 2)
1845
+ {
1846
+ png_crc_finish(png_ptr, length);
1847
+ png_chunk_benign_error(png_ptr, "invalid");
1848
+ return;
1849
+ }
1850
+
1851
+ png_crc_read(png_ptr, buf, 2);
1852
+ png_ptr->num_trans = 1;
1853
+ png_ptr->trans_color.gray = png_get_uint_16(buf);
1854
+ }
1855
+
1856
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
1857
+ {
1858
+ png_byte buf[6];
1859
+
1860
+ if (length != 6)
1861
+ {
1862
+ png_crc_finish(png_ptr, length);
1863
+ png_chunk_benign_error(png_ptr, "invalid");
1864
+ return;
1865
+ }
1866
+
1867
+ png_crc_read(png_ptr, buf, length);
1868
+ png_ptr->num_trans = 1;
1869
+ png_ptr->trans_color.red = png_get_uint_16(buf);
1870
+ png_ptr->trans_color.green = png_get_uint_16(buf + 2);
1871
+ png_ptr->trans_color.blue = png_get_uint_16(buf + 4);
1872
+ }
1873
+
1874
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1875
+ {
1876
+ if ((png_ptr->mode & PNG_HAVE_PLTE) == 0)
1877
+ {
1878
+ /* TODO: is this actually an error in the ISO spec? */
1879
+ png_crc_finish(png_ptr, length);
1880
+ png_chunk_benign_error(png_ptr, "out of place");
1881
+ return;
1882
+ }
1883
+
1884
+ if (length > (unsigned int) png_ptr->num_palette ||
1885
+ length > (unsigned int) PNG_MAX_PALETTE_LENGTH ||
1886
+ length == 0)
1887
+ {
1888
+ png_crc_finish(png_ptr, length);
1889
+ png_chunk_benign_error(png_ptr, "invalid");
1890
+ return;
1891
+ }
1892
+
1893
+ png_crc_read(png_ptr, readbuf, length);
1894
+ png_ptr->num_trans = (png_uint_16)length;
1895
+ }
1896
+
1897
+ else
1898
+ {
1899
+ png_crc_finish(png_ptr, length);
1900
+ png_chunk_benign_error(png_ptr, "invalid with alpha channel");
1901
+ return;
1902
+ }
1903
+
1904
+ if (png_crc_finish(png_ptr, 0) != 0)
1905
+ {
1906
+ png_ptr->num_trans = 0;
1907
+ return;
1908
+ }
1909
+
1910
+ /* TODO: this is a horrible side effect in the palette case because the
1911
+ * png_struct ends up with a pointer to the tRNS buffer owned by the
1912
+ * png_info. Fix this.
1913
+ */
1914
+ png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
1915
+ &(png_ptr->trans_color));
1916
+ }
1917
+ #endif
1918
+
1919
+ #ifdef PNG_READ_bKGD_SUPPORTED
1920
+ void /* PRIVATE */
1921
+ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1922
+ {
1923
+ unsigned int truelen;
1924
+ png_byte buf[6];
1925
+ png_color_16 background;
1926
+
1927
+ png_debug(1, "in png_handle_bKGD");
1928
+
1929
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1930
+ png_chunk_error(png_ptr, "missing IHDR");
1931
+
1932
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||
1933
+ (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
1934
+ (png_ptr->mode & PNG_HAVE_PLTE) == 0))
1935
+ {
1936
+ png_crc_finish(png_ptr, length);
1937
+ png_chunk_benign_error(png_ptr, "out of place");
1938
+ return;
1939
+ }
1940
+
1941
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0)
1942
+ {
1943
+ png_crc_finish(png_ptr, length);
1944
+ png_chunk_benign_error(png_ptr, "duplicate");
1945
+ return;
1946
+ }
1947
+
1948
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1949
+ truelen = 1;
1950
+
1951
+ else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
1952
+ truelen = 6;
1953
+
1954
+ else
1955
+ truelen = 2;
1956
+
1957
+ if (length != truelen)
1958
+ {
1959
+ png_crc_finish(png_ptr, length);
1960
+ png_chunk_benign_error(png_ptr, "invalid");
1961
+ return;
1962
+ }
1963
+
1964
+ png_crc_read(png_ptr, buf, truelen);
1965
+
1966
+ if (png_crc_finish(png_ptr, 0) != 0)
1967
+ return;
1968
+
1969
+ /* We convert the index value into RGB components so that we can allow
1970
+ * arbitrary RGB values for background when we have transparency, and
1971
+ * so it is easy to determine the RGB values of the background color
1972
+ * from the info_ptr struct.
1973
+ */
1974
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1975
+ {
1976
+ background.index = buf[0];
1977
+
1978
+ if (info_ptr != NULL && info_ptr->num_palette != 0)
1979
+ {
1980
+ if (buf[0] >= info_ptr->num_palette)
1981
+ {
1982
+ png_chunk_benign_error(png_ptr, "invalid index");
1983
+ return;
1984
+ }
1985
+
1986
+ background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
1987
+ background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
1988
+ background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
1989
+ }
1990
+
1991
+ else
1992
+ background.red = background.green = background.blue = 0;
1993
+
1994
+ background.gray = 0;
1995
+ }
1996
+
1997
+ else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */
1998
+ {
1999
+ if (png_ptr->bit_depth <= 8)
2000
+ {
2001
+ if (buf[0] != 0 || buf[1] >= (unsigned int)(1 << png_ptr->bit_depth))
2002
+ {
2003
+ png_chunk_benign_error(png_ptr, "invalid gray level");
2004
+ return;
2005
+ }
2006
+ }
2007
+
2008
+ background.index = 0;
2009
+ background.red =
2010
+ background.green =
2011
+ background.blue =
2012
+ background.gray = png_get_uint_16(buf);
2013
+ }
2014
+
2015
+ else
2016
+ {
2017
+ if (png_ptr->bit_depth <= 8)
2018
+ {
2019
+ if (buf[0] != 0 || buf[2] != 0 || buf[4] != 0)
2020
+ {
2021
+ png_chunk_benign_error(png_ptr, "invalid color");
2022
+ return;
2023
+ }
2024
+ }
2025
+
2026
+ background.index = 0;
2027
+ background.red = png_get_uint_16(buf);
2028
+ background.green = png_get_uint_16(buf + 2);
2029
+ background.blue = png_get_uint_16(buf + 4);
2030
+ background.gray = 0;
2031
+ }
2032
+
2033
+ png_set_bKGD(png_ptr, info_ptr, &background);
2034
+ }
2035
+ #endif
2036
+
2037
+ #ifdef PNG_READ_eXIf_SUPPORTED
2038
+ void /* PRIVATE */
2039
+ png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2040
+ {
2041
+ unsigned int i;
2042
+
2043
+ png_debug(1, "in png_handle_eXIf");
2044
+
2045
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2046
+ png_chunk_error(png_ptr, "missing IHDR");
2047
+
2048
+ if (length < 2)
2049
+ {
2050
+ png_crc_finish(png_ptr, length);
2051
+ png_chunk_benign_error(png_ptr, "too short");
2052
+ return;
2053
+ }
2054
+
2055
+ else if (info_ptr == NULL || (info_ptr->valid & PNG_INFO_eXIf) != 0)
2056
+ {
2057
+ png_crc_finish(png_ptr, length);
2058
+ png_chunk_benign_error(png_ptr, "duplicate");
2059
+ return;
2060
+ }
2061
+
2062
+ info_ptr->free_me |= PNG_FREE_EXIF;
2063
+
2064
+ info_ptr->eXIf_buf = png_voidcast(png_bytep,
2065
+ png_malloc_warn(png_ptr, length));
2066
+
2067
+ if (info_ptr->eXIf_buf == NULL)
2068
+ {
2069
+ png_crc_finish(png_ptr, length);
2070
+ png_chunk_benign_error(png_ptr, "out of memory");
2071
+ return;
2072
+ }
2073
+
2074
+ for (i = 0; i < length; i++)
2075
+ {
2076
+ png_byte buf[1];
2077
+ png_crc_read(png_ptr, buf, 1);
2078
+ info_ptr->eXIf_buf[i] = buf[0];
2079
+ if (i == 1 && buf[0] != 'M' && buf[0] != 'I'
2080
+ && info_ptr->eXIf_buf[0] != buf[0])
2081
+ {
2082
+ png_crc_finish(png_ptr, length);
2083
+ png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
2084
+ png_free(png_ptr, info_ptr->eXIf_buf);
2085
+ info_ptr->eXIf_buf = NULL;
2086
+ return;
2087
+ }
2088
+ }
2089
+
2090
+ if (png_crc_finish(png_ptr, 0) != 0)
2091
+ return;
2092
+
2093
+ png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
2094
+
2095
+ png_free(png_ptr, info_ptr->eXIf_buf);
2096
+ info_ptr->eXIf_buf = NULL;
2097
+ }
2098
+ #endif
2099
+
2100
+ #ifdef PNG_READ_hIST_SUPPORTED
2101
+ void /* PRIVATE */
2102
+ png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2103
+ {
2104
+ unsigned int num, i;
2105
+ png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
2106
+
2107
+ png_debug(1, "in png_handle_hIST");
2108
+
2109
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2110
+ png_chunk_error(png_ptr, "missing IHDR");
2111
+
2112
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||
2113
+ (png_ptr->mode & PNG_HAVE_PLTE) == 0)
2114
+ {
2115
+ png_crc_finish(png_ptr, length);
2116
+ png_chunk_benign_error(png_ptr, "out of place");
2117
+ return;
2118
+ }
2119
+
2120
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0)
2121
+ {
2122
+ png_crc_finish(png_ptr, length);
2123
+ png_chunk_benign_error(png_ptr, "duplicate");
2124
+ return;
2125
+ }
2126
+
2127
+ num = length / 2 ;
2128
+
2129
+ if (num != (unsigned int) png_ptr->num_palette ||
2130
+ num > (unsigned int) PNG_MAX_PALETTE_LENGTH)
2131
+ {
2132
+ png_crc_finish(png_ptr, length);
2133
+ png_chunk_benign_error(png_ptr, "invalid");
2134
+ return;
2135
+ }
2136
+
2137
+ for (i = 0; i < num; i++)
2138
+ {
2139
+ png_byte buf[2];
2140
+
2141
+ png_crc_read(png_ptr, buf, 2);
2142
+ readbuf[i] = png_get_uint_16(buf);
2143
+ }
2144
+
2145
+ if (png_crc_finish(png_ptr, 0) != 0)
2146
+ return;
2147
+
2148
+ png_set_hIST(png_ptr, info_ptr, readbuf);
2149
+ }
2150
+ #endif
2151
+
2152
+ #ifdef PNG_READ_pHYs_SUPPORTED
2153
+ void /* PRIVATE */
2154
+ png_handle_pHYs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2155
+ {
2156
+ png_byte buf[9];
2157
+ png_uint_32 res_x, res_y;
2158
+ int unit_type;
2159
+
2160
+ png_debug(1, "in png_handle_pHYs");
2161
+
2162
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2163
+ png_chunk_error(png_ptr, "missing IHDR");
2164
+
2165
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2166
+ {
2167
+ png_crc_finish(png_ptr, length);
2168
+ png_chunk_benign_error(png_ptr, "out of place");
2169
+ return;
2170
+ }
2171
+
2172
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) != 0)
2173
+ {
2174
+ png_crc_finish(png_ptr, length);
2175
+ png_chunk_benign_error(png_ptr, "duplicate");
2176
+ return;
2177
+ }
2178
+
2179
+ if (length != 9)
2180
+ {
2181
+ png_crc_finish(png_ptr, length);
2182
+ png_chunk_benign_error(png_ptr, "invalid");
2183
+ return;
2184
+ }
2185
+
2186
+ png_crc_read(png_ptr, buf, 9);
2187
+
2188
+ if (png_crc_finish(png_ptr, 0) != 0)
2189
+ return;
2190
+
2191
+ res_x = png_get_uint_32(buf);
2192
+ res_y = png_get_uint_32(buf + 4);
2193
+ unit_type = buf[8];
2194
+ png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
2195
+ }
2196
+ #endif
2197
+
2198
+ #ifdef PNG_READ_oFFs_SUPPORTED
2199
+ void /* PRIVATE */
2200
+ png_handle_oFFs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2201
+ {
2202
+ png_byte buf[9];
2203
+ png_int_32 offset_x, offset_y;
2204
+ int unit_type;
2205
+
2206
+ png_debug(1, "in png_handle_oFFs");
2207
+
2208
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2209
+ png_chunk_error(png_ptr, "missing IHDR");
2210
+
2211
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2212
+ {
2213
+ png_crc_finish(png_ptr, length);
2214
+ png_chunk_benign_error(png_ptr, "out of place");
2215
+ return;
2216
+ }
2217
+
2218
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) != 0)
2219
+ {
2220
+ png_crc_finish(png_ptr, length);
2221
+ png_chunk_benign_error(png_ptr, "duplicate");
2222
+ return;
2223
+ }
2224
+
2225
+ if (length != 9)
2226
+ {
2227
+ png_crc_finish(png_ptr, length);
2228
+ png_chunk_benign_error(png_ptr, "invalid");
2229
+ return;
2230
+ }
2231
+
2232
+ png_crc_read(png_ptr, buf, 9);
2233
+
2234
+ if (png_crc_finish(png_ptr, 0) != 0)
2235
+ return;
2236
+
2237
+ offset_x = png_get_int_32(buf);
2238
+ offset_y = png_get_int_32(buf + 4);
2239
+ unit_type = buf[8];
2240
+ png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
2241
+ }
2242
+ #endif
2243
+
2244
+ #ifdef PNG_READ_pCAL_SUPPORTED
2245
+ /* Read the pCAL chunk (described in the PNG Extensions document) */
2246
+ void /* PRIVATE */
2247
+ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2248
+ {
2249
+ png_int_32 X0, X1;
2250
+ png_byte type, nparams;
2251
+ png_bytep buffer, buf, units, endptr;
2252
+ png_charpp params;
2253
+ int i;
2254
+
2255
+ png_debug(1, "in png_handle_pCAL");
2256
+
2257
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2258
+ png_chunk_error(png_ptr, "missing IHDR");
2259
+
2260
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2261
+ {
2262
+ png_crc_finish(png_ptr, length);
2263
+ png_chunk_benign_error(png_ptr, "out of place");
2264
+ return;
2265
+ }
2266
+
2267
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) != 0)
2268
+ {
2269
+ png_crc_finish(png_ptr, length);
2270
+ png_chunk_benign_error(png_ptr, "duplicate");
2271
+ return;
2272
+ }
2273
+
2274
+ png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)",
2275
+ length + 1);
2276
+
2277
+ buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
2278
+
2279
+ if (buffer == NULL)
2280
+ {
2281
+ png_crc_finish(png_ptr, length);
2282
+ png_chunk_benign_error(png_ptr, "out of memory");
2283
+ return;
2284
+ }
2285
+
2286
+ png_crc_read(png_ptr, buffer, length);
2287
+
2288
+ if (png_crc_finish(png_ptr, 0) != 0)
2289
+ return;
2290
+
2291
+ buffer[length] = 0; /* Null terminate the last string */
2292
+
2293
+ png_debug(3, "Finding end of pCAL purpose string");
2294
+ for (buf = buffer; *buf; buf++)
2295
+ /* Empty loop */ ;
2296
+
2297
+ endptr = buffer + length;
2298
+
2299
+ /* We need to have at least 12 bytes after the purpose string
2300
+ * in order to get the parameter information.
2301
+ */
2302
+ if (endptr - buf <= 12)
2303
+ {
2304
+ png_chunk_benign_error(png_ptr, "invalid");
2305
+ return;
2306
+ }
2307
+
2308
+ png_debug(3, "Reading pCAL X0, X1, type, nparams, and units");
2309
+ X0 = png_get_int_32((png_bytep)buf+1);
2310
+ X1 = png_get_int_32((png_bytep)buf+5);
2311
+ type = buf[9];
2312
+ nparams = buf[10];
2313
+ units = buf + 11;
2314
+
2315
+ png_debug(3, "Checking pCAL equation type and number of parameters");
2316
+ /* Check that we have the right number of parameters for known
2317
+ * equation types.
2318
+ */
2319
+ if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
2320
+ (type == PNG_EQUATION_BASE_E && nparams != 3) ||
2321
+ (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
2322
+ (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
2323
+ {
2324
+ png_chunk_benign_error(png_ptr, "invalid parameter count");
2325
+ return;
2326
+ }
2327
+
2328
+ else if (type >= PNG_EQUATION_LAST)
2329
+ {
2330
+ png_chunk_benign_error(png_ptr, "unrecognized equation type");
2331
+ }
2332
+
2333
+ for (buf = units; *buf; buf++)
2334
+ /* Empty loop to move past the units string. */ ;
2335
+
2336
+ png_debug(3, "Allocating pCAL parameters array");
2337
+
2338
+ params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
2339
+ nparams * (sizeof (png_charp))));
2340
+
2341
+ if (params == NULL)
2342
+ {
2343
+ png_chunk_benign_error(png_ptr, "out of memory");
2344
+ return;
2345
+ }
2346
+
2347
+ /* Get pointers to the start of each parameter string. */
2348
+ for (i = 0; i < nparams; i++)
2349
+ {
2350
+ buf++; /* Skip the null string terminator from previous parameter. */
2351
+
2352
+ png_debug1(3, "Reading pCAL parameter %d", i);
2353
+
2354
+ for (params[i] = (png_charp)buf; buf <= endptr && *buf != 0; buf++)
2355
+ /* Empty loop to move past each parameter string */ ;
2356
+
2357
+ /* Make sure we haven't run out of data yet */
2358
+ if (buf > endptr)
2359
+ {
2360
+ png_free(png_ptr, params);
2361
+ png_chunk_benign_error(png_ptr, "invalid data");
2362
+ return;
2363
+ }
2364
+ }
2365
+
2366
+ png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,
2367
+ (png_charp)units, params);
2368
+
2369
+ png_free(png_ptr, params);
2370
+ }
2371
+ #endif
2372
+
2373
+ #ifdef PNG_READ_sCAL_SUPPORTED
2374
+ /* Read the sCAL chunk */
2375
+ void /* PRIVATE */
2376
+ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2377
+ {
2378
+ png_bytep buffer;
2379
+ size_t i;
2380
+ int state;
2381
+
2382
+ png_debug(1, "in png_handle_sCAL");
2383
+
2384
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2385
+ png_chunk_error(png_ptr, "missing IHDR");
2386
+
2387
+ else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2388
+ {
2389
+ png_crc_finish(png_ptr, length);
2390
+ png_chunk_benign_error(png_ptr, "out of place");
2391
+ return;
2392
+ }
2393
+
2394
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL) != 0)
2395
+ {
2396
+ png_crc_finish(png_ptr, length);
2397
+ png_chunk_benign_error(png_ptr, "duplicate");
2398
+ return;
2399
+ }
2400
+
2401
+ /* Need unit type, width, \0, height: minimum 4 bytes */
2402
+ else if (length < 4)
2403
+ {
2404
+ png_crc_finish(png_ptr, length);
2405
+ png_chunk_benign_error(png_ptr, "invalid");
2406
+ return;
2407
+ }
2408
+
2409
+ png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",
2410
+ length + 1);
2411
+
2412
+ buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
2413
+
2414
+ if (buffer == NULL)
2415
+ {
2416
+ png_chunk_benign_error(png_ptr, "out of memory");
2417
+ png_crc_finish(png_ptr, length);
2418
+ return;
2419
+ }
2420
+
2421
+ png_crc_read(png_ptr, buffer, length);
2422
+ buffer[length] = 0; /* Null terminate the last string */
2423
+
2424
+ if (png_crc_finish(png_ptr, 0) != 0)
2425
+ return;
2426
+
2427
+ /* Validate the unit. */
2428
+ if (buffer[0] != 1 && buffer[0] != 2)
2429
+ {
2430
+ png_chunk_benign_error(png_ptr, "invalid unit");
2431
+ return;
2432
+ }
2433
+
2434
+ /* Validate the ASCII numbers, need two ASCII numbers separated by
2435
+ * a '\0' and they need to fit exactly in the chunk data.
2436
+ */
2437
+ i = 1;
2438
+ state = 0;
2439
+
2440
+ if (png_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 ||
2441
+ i >= length || buffer[i++] != 0)
2442
+ png_chunk_benign_error(png_ptr, "bad width format");
2443
+
2444
+ else if (PNG_FP_IS_POSITIVE(state) == 0)
2445
+ png_chunk_benign_error(png_ptr, "non-positive width");
2446
+
2447
+ else
2448
+ {
2449
+ size_t heighti = i;
2450
+
2451
+ state = 0;
2452
+ if (png_check_fp_number((png_const_charp)buffer, length,
2453
+ &state, &i) == 0 || i != length)
2454
+ png_chunk_benign_error(png_ptr, "bad height format");
2455
+
2456
+ else if (PNG_FP_IS_POSITIVE(state) == 0)
2457
+ png_chunk_benign_error(png_ptr, "non-positive height");
2458
+
2459
+ else
2460
+ /* This is the (only) success case. */
2461
+ png_set_sCAL_s(png_ptr, info_ptr, buffer[0],
2462
+ (png_charp)buffer+1, (png_charp)buffer+heighti);
2463
+ }
2464
+ }
2465
+ #endif
2466
+
2467
+ #ifdef PNG_READ_tIME_SUPPORTED
2468
+ void /* PRIVATE */
2469
+ png_handle_tIME(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2470
+ {
2471
+ png_byte buf[7];
2472
+ png_time mod_time;
2473
+
2474
+ png_debug(1, "in png_handle_tIME");
2475
+
2476
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2477
+ png_chunk_error(png_ptr, "missing IHDR");
2478
+
2479
+ else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) != 0)
2480
+ {
2481
+ png_crc_finish(png_ptr, length);
2482
+ png_chunk_benign_error(png_ptr, "duplicate");
2483
+ return;
2484
+ }
2485
+
2486
+ if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2487
+ png_ptr->mode |= PNG_AFTER_IDAT;
2488
+
2489
+ if (length != 7)
2490
+ {
2491
+ png_crc_finish(png_ptr, length);
2492
+ png_chunk_benign_error(png_ptr, "invalid");
2493
+ return;
2494
+ }
2495
+
2496
+ png_crc_read(png_ptr, buf, 7);
2497
+
2498
+ if (png_crc_finish(png_ptr, 0) != 0)
2499
+ return;
2500
+
2501
+ mod_time.second = buf[6];
2502
+ mod_time.minute = buf[5];
2503
+ mod_time.hour = buf[4];
2504
+ mod_time.day = buf[3];
2505
+ mod_time.month = buf[2];
2506
+ mod_time.year = png_get_uint_16(buf);
2507
+
2508
+ png_set_tIME(png_ptr, info_ptr, &mod_time);
2509
+ }
2510
+ #endif
2511
+
2512
+ #ifdef PNG_READ_tEXt_SUPPORTED
2513
+ /* Note: this does not properly handle chunks that are > 64K under DOS */
2514
+ void /* PRIVATE */
2515
+ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2516
+ {
2517
+ png_text text_info;
2518
+ png_bytep buffer;
2519
+ png_charp key;
2520
+ png_charp text;
2521
+ png_uint_32 skip = 0;
2522
+
2523
+ png_debug(1, "in png_handle_tEXt");
2524
+
2525
+ #ifdef PNG_USER_LIMITS_SUPPORTED
2526
+ if (png_ptr->user_chunk_cache_max != 0)
2527
+ {
2528
+ if (png_ptr->user_chunk_cache_max == 1)
2529
+ {
2530
+ png_crc_finish(png_ptr, length);
2531
+ return;
2532
+ }
2533
+
2534
+ if (--png_ptr->user_chunk_cache_max == 1)
2535
+ {
2536
+ png_crc_finish(png_ptr, length);
2537
+ png_chunk_benign_error(png_ptr, "no space in chunk cache");
2538
+ return;
2539
+ }
2540
+ }
2541
+ #endif
2542
+
2543
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2544
+ png_chunk_error(png_ptr, "missing IHDR");
2545
+
2546
+ if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2547
+ png_ptr->mode |= PNG_AFTER_IDAT;
2548
+
2549
+ #ifdef PNG_MAX_MALLOC_64K
2550
+ if (length > 65535U)
2551
+ {
2552
+ png_crc_finish(png_ptr, length);
2553
+ png_chunk_benign_error(png_ptr, "too large to fit in memory");
2554
+ return;
2555
+ }
2556
+ #endif
2557
+
2558
+ buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/);
2559
+
2560
+ if (buffer == NULL)
2561
+ {
2562
+ png_chunk_benign_error(png_ptr, "out of memory");
2563
+ return;
2564
+ }
2565
+
2566
+ png_crc_read(png_ptr, buffer, length);
2567
+
2568
+ if (png_crc_finish(png_ptr, skip) != 0)
2569
+ return;
2570
+
2571
+ key = (png_charp)buffer;
2572
+ key[length] = 0;
2573
+
2574
+ for (text = key; *text; text++)
2575
+ /* Empty loop to find end of key */ ;
2576
+
2577
+ if (text != key + length)
2578
+ text++;
2579
+
2580
+ text_info.compression = PNG_TEXT_COMPRESSION_NONE;
2581
+ text_info.key = key;
2582
+ text_info.lang = NULL;
2583
+ text_info.lang_key = NULL;
2584
+ text_info.itxt_length = 0;
2585
+ text_info.text = text;
2586
+ text_info.text_length = strlen(text);
2587
+
2588
+ if (png_set_text_2(png_ptr, info_ptr, &text_info, 1) != 0)
2589
+ png_warning(png_ptr, "Insufficient memory to process text chunk");
2590
+ }
2591
+ #endif
2592
+
2593
+ #ifdef PNG_READ_zTXt_SUPPORTED
2594
+ /* Note: this does not correctly handle chunks that are > 64K under DOS */
2595
+ void /* PRIVATE */
2596
+ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2597
+ {
2598
+ png_const_charp errmsg = NULL;
2599
+ png_bytep buffer;
2600
+ png_uint_32 keyword_length;
2601
+
2602
+ png_debug(1, "in png_handle_zTXt");
2603
+
2604
+ #ifdef PNG_USER_LIMITS_SUPPORTED
2605
+ if (png_ptr->user_chunk_cache_max != 0)
2606
+ {
2607
+ if (png_ptr->user_chunk_cache_max == 1)
2608
+ {
2609
+ png_crc_finish(png_ptr, length);
2610
+ return;
2611
+ }
2612
+
2613
+ if (--png_ptr->user_chunk_cache_max == 1)
2614
+ {
2615
+ png_crc_finish(png_ptr, length);
2616
+ png_chunk_benign_error(png_ptr, "no space in chunk cache");
2617
+ return;
2618
+ }
2619
+ }
2620
+ #endif
2621
+
2622
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2623
+ png_chunk_error(png_ptr, "missing IHDR");
2624
+
2625
+ if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2626
+ png_ptr->mode |= PNG_AFTER_IDAT;
2627
+
2628
+ /* Note, "length" is sufficient here; we won't be adding
2629
+ * a null terminator later.
2630
+ */
2631
+ buffer = png_read_buffer(png_ptr, length, 2/*silent*/);
2632
+
2633
+ if (buffer == NULL)
2634
+ {
2635
+ png_crc_finish(png_ptr, length);
2636
+ png_chunk_benign_error(png_ptr, "out of memory");
2637
+ return;
2638
+ }
2639
+
2640
+ png_crc_read(png_ptr, buffer, length);
2641
+
2642
+ if (png_crc_finish(png_ptr, 0) != 0)
2643
+ return;
2644
+
2645
+ /* TODO: also check that the keyword contents match the spec! */
2646
+ for (keyword_length = 0;
2647
+ keyword_length < length && buffer[keyword_length] != 0;
2648
+ ++keyword_length)
2649
+ /* Empty loop to find end of name */ ;
2650
+
2651
+ if (keyword_length > 79 || keyword_length < 1)
2652
+ errmsg = "bad keyword";
2653
+
2654
+ /* zTXt must have some LZ data after the keyword, although it may expand to
2655
+ * zero bytes; we need a '\0' at the end of the keyword, the compression type
2656
+ * then the LZ data:
2657
+ */
2658
+ else if (keyword_length + 3 > length)
2659
+ errmsg = "truncated";
2660
+
2661
+ else if (buffer[keyword_length+1] != PNG_COMPRESSION_TYPE_BASE)
2662
+ errmsg = "unknown compression type";
2663
+
2664
+ else
2665
+ {
2666
+ png_alloc_size_t uncompressed_length = PNG_SIZE_MAX;
2667
+
2668
+ /* TODO: at present png_decompress_chunk imposes a single application
2669
+ * level memory limit, this should be split to different values for iCCP
2670
+ * and text chunks.
2671
+ */
2672
+ if (png_decompress_chunk(png_ptr, length, keyword_length+2,
2673
+ &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
2674
+ {
2675
+ png_text text;
2676
+
2677
+ if (png_ptr->read_buffer == NULL)
2678
+ errmsg="Read failure in png_handle_zTXt";
2679
+ else
2680
+ {
2681
+ /* It worked; png_ptr->read_buffer now looks like a tEXt chunk
2682
+ * except for the extra compression type byte and the fact that
2683
+ * it isn't necessarily '\0' terminated.
2684
+ */
2685
+ buffer = png_ptr->read_buffer;
2686
+ buffer[uncompressed_length+(keyword_length+2)] = 0;
2687
+
2688
+ text.compression = PNG_TEXT_COMPRESSION_zTXt;
2689
+ text.key = (png_charp)buffer;
2690
+ text.text = (png_charp)(buffer + keyword_length+2);
2691
+ text.text_length = uncompressed_length;
2692
+ text.itxt_length = 0;
2693
+ text.lang = NULL;
2694
+ text.lang_key = NULL;
2695
+
2696
+ if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
2697
+ errmsg = "insufficient memory";
2698
+ }
2699
+ }
2700
+
2701
+ else
2702
+ errmsg = png_ptr->zstream.msg;
2703
+ }
2704
+
2705
+ if (errmsg != NULL)
2706
+ png_chunk_benign_error(png_ptr, errmsg);
2707
+ }
2708
+ #endif
2709
+
2710
+ #ifdef PNG_READ_iTXt_SUPPORTED
2711
+ /* Note: this does not correctly handle chunks that are > 64K under DOS */
2712
+ void /* PRIVATE */
2713
+ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
2714
+ {
2715
+ png_const_charp errmsg = NULL;
2716
+ png_bytep buffer;
2717
+ png_uint_32 prefix_length;
2718
+
2719
+ png_debug(1, "in png_handle_iTXt");
2720
+
2721
+ #ifdef PNG_USER_LIMITS_SUPPORTED
2722
+ if (png_ptr->user_chunk_cache_max != 0)
2723
+ {
2724
+ if (png_ptr->user_chunk_cache_max == 1)
2725
+ {
2726
+ png_crc_finish(png_ptr, length);
2727
+ return;
2728
+ }
2729
+
2730
+ if (--png_ptr->user_chunk_cache_max == 1)
2731
+ {
2732
+ png_crc_finish(png_ptr, length);
2733
+ png_chunk_benign_error(png_ptr, "no space in chunk cache");
2734
+ return;
2735
+ }
2736
+ }
2737
+ #endif
2738
+
2739
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
2740
+ png_chunk_error(png_ptr, "missing IHDR");
2741
+
2742
+ if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
2743
+ png_ptr->mode |= PNG_AFTER_IDAT;
2744
+
2745
+ buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/);
2746
+
2747
+ if (buffer == NULL)
2748
+ {
2749
+ png_crc_finish(png_ptr, length);
2750
+ png_chunk_benign_error(png_ptr, "out of memory");
2751
+ return;
2752
+ }
2753
+
2754
+ png_crc_read(png_ptr, buffer, length);
2755
+
2756
+ if (png_crc_finish(png_ptr, 0) != 0)
2757
+ return;
2758
+
2759
+ /* First the keyword. */
2760
+ for (prefix_length=0;
2761
+ prefix_length < length && buffer[prefix_length] != 0;
2762
+ ++prefix_length)
2763
+ /* Empty loop */ ;
2764
+
2765
+ /* Perform a basic check on the keyword length here. */
2766
+ if (prefix_length > 79 || prefix_length < 1)
2767
+ errmsg = "bad keyword";
2768
+
2769
+ /* Expect keyword, compression flag, compression type, language, translated
2770
+ * keyword (both may be empty but are 0 terminated) then the text, which may
2771
+ * be empty.
2772
+ */
2773
+ else if (prefix_length + 5 > length)
2774
+ errmsg = "truncated";
2775
+
2776
+ else if (buffer[prefix_length+1] == 0 ||
2777
+ (buffer[prefix_length+1] == 1 &&
2778
+ buffer[prefix_length+2] == PNG_COMPRESSION_TYPE_BASE))
2779
+ {
2780
+ int compressed = buffer[prefix_length+1] != 0;
2781
+ png_uint_32 language_offset, translated_keyword_offset;
2782
+ png_alloc_size_t uncompressed_length = 0;
2783
+
2784
+ /* Now the language tag */
2785
+ prefix_length += 3;
2786
+ language_offset = prefix_length;
2787
+
2788
+ for (; prefix_length < length && buffer[prefix_length] != 0;
2789
+ ++prefix_length)
2790
+ /* Empty loop */ ;
2791
+
2792
+ /* WARNING: the length may be invalid here, this is checked below. */
2793
+ translated_keyword_offset = ++prefix_length;
2794
+
2795
+ for (; prefix_length < length && buffer[prefix_length] != 0;
2796
+ ++prefix_length)
2797
+ /* Empty loop */ ;
2798
+
2799
+ /* prefix_length should now be at the trailing '\0' of the translated
2800
+ * keyword, but it may already be over the end. None of this arithmetic
2801
+ * can overflow because chunks are at most 2^31 bytes long, but on 16-bit
2802
+ * systems the available allocation may overflow.
2803
+ */
2804
+ ++prefix_length;
2805
+
2806
+ if (compressed == 0 && prefix_length <= length)
2807
+ uncompressed_length = length - prefix_length;
2808
+
2809
+ else if (compressed != 0 && prefix_length < length)
2810
+ {
2811
+ uncompressed_length = PNG_SIZE_MAX;
2812
+
2813
+ /* TODO: at present png_decompress_chunk imposes a single application
2814
+ * level memory limit, this should be split to different values for
2815
+ * iCCP and text chunks.
2816
+ */
2817
+ if (png_decompress_chunk(png_ptr, length, prefix_length,
2818
+ &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
2819
+ buffer = png_ptr->read_buffer;
2820
+
2821
+ else
2822
+ errmsg = png_ptr->zstream.msg;
2823
+ }
2824
+
2825
+ else
2826
+ errmsg = "truncated";
2827
+
2828
+ if (errmsg == NULL)
2829
+ {
2830
+ png_text text;
2831
+
2832
+ buffer[uncompressed_length+prefix_length] = 0;
2833
+
2834
+ if (compressed == 0)
2835
+ text.compression = PNG_ITXT_COMPRESSION_NONE;
2836
+
2837
+ else
2838
+ text.compression = PNG_ITXT_COMPRESSION_zTXt;
2839
+
2840
+ text.key = (png_charp)buffer;
2841
+ text.lang = (png_charp)buffer + language_offset;
2842
+ text.lang_key = (png_charp)buffer + translated_keyword_offset;
2843
+ text.text = (png_charp)buffer + prefix_length;
2844
+ text.text_length = 0;
2845
+ text.itxt_length = uncompressed_length;
2846
+
2847
+ if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
2848
+ errmsg = "insufficient memory";
2849
+ }
2850
+ }
2851
+
2852
+ else
2853
+ errmsg = "bad compression info";
2854
+
2855
+ if (errmsg != NULL)
2856
+ png_chunk_benign_error(png_ptr, errmsg);
2857
+ }
2858
+ #endif
2859
+
2860
+ #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2861
+ /* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
2862
+ static int
2863
+ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
2864
+ {
2865
+ png_alloc_size_t limit = PNG_SIZE_MAX;
2866
+
2867
+ if (png_ptr->unknown_chunk.data != NULL)
2868
+ {
2869
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
2870
+ png_ptr->unknown_chunk.data = NULL;
2871
+ }
2872
+
2873
+ # ifdef PNG_SET_USER_LIMITS_SUPPORTED
2874
+ if (png_ptr->user_chunk_malloc_max > 0 &&
2875
+ png_ptr->user_chunk_malloc_max < limit)
2876
+ limit = png_ptr->user_chunk_malloc_max;
2877
+
2878
+ # elif PNG_USER_CHUNK_MALLOC_MAX > 0
2879
+ if (PNG_USER_CHUNK_MALLOC_MAX < limit)
2880
+ limit = PNG_USER_CHUNK_MALLOC_MAX;
2881
+ # endif
2882
+
2883
+ if (length <= limit)
2884
+ {
2885
+ PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);
2886
+ /* The following is safe because of the PNG_SIZE_MAX init above */
2887
+ png_ptr->unknown_chunk.size = (size_t)length/*SAFE*/;
2888
+ /* 'mode' is a flag array, only the bottom four bits matter here */
2889
+ png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;
2890
+
2891
+ if (length == 0)
2892
+ png_ptr->unknown_chunk.data = NULL;
2893
+
2894
+ else
2895
+ {
2896
+ /* Do a 'warn' here - it is handled below. */
2897
+ png_ptr->unknown_chunk.data = png_voidcast(png_bytep,
2898
+ png_malloc_warn(png_ptr, length));
2899
+ }
2900
+ }
2901
+
2902
+ if (png_ptr->unknown_chunk.data == NULL && length > 0)
2903
+ {
2904
+ /* This is benign because we clean up correctly */
2905
+ png_crc_finish(png_ptr, length);
2906
+ png_chunk_benign_error(png_ptr, "unknown chunk exceeds memory limits");
2907
+ return 0;
2908
+ }
2909
+
2910
+ else
2911
+ {
2912
+ if (length > 0)
2913
+ png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);
2914
+ png_crc_finish(png_ptr, 0);
2915
+ return 1;
2916
+ }
2917
+ }
2918
+ #endif /* READ_UNKNOWN_CHUNKS */
2919
+
2920
+ /* Handle an unknown, or known but disabled, chunk */
2921
+ void /* PRIVATE */
2922
+ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
2923
+ png_uint_32 length, int keep)
2924
+ {
2925
+ int handled = 0; /* the chunk was handled */
2926
+
2927
+ png_debug(1, "in png_handle_unknown");
2928
+
2929
+ #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2930
+ /* NOTE: this code is based on the code in libpng-1.4.12 except for fixing
2931
+ * the bug which meant that setting a non-default behavior for a specific
2932
+ * chunk would be ignored (the default was always used unless a user
2933
+ * callback was installed).
2934
+ *
2935
+ * 'keep' is the value from the png_chunk_unknown_handling, the setting for
2936
+ * this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it
2937
+ * will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here.
2938
+ * This is just an optimization to avoid multiple calls to the lookup
2939
+ * function.
2940
+ */
2941
+ # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2942
+ # ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
2943
+ keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name);
2944
+ # endif
2945
+ # endif
2946
+
2947
+ /* One of the following methods will read the chunk or skip it (at least one
2948
+ * of these is always defined because this is the only way to switch on
2949
+ * PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
2950
+ */
2951
+ # ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2952
+ /* The user callback takes precedence over the chunk keep value, but the
2953
+ * keep value is still required to validate a save of a critical chunk.
2954
+ */
2955
+ if (png_ptr->read_user_chunk_fn != NULL)
2956
+ {
2957
+ if (png_cache_unknown_chunk(png_ptr, length) != 0)
2958
+ {
2959
+ /* Callback to user unknown chunk handler */
2960
+ int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
2961
+ &png_ptr->unknown_chunk);
2962
+
2963
+ /* ret is:
2964
+ * negative: An error occurred; png_chunk_error will be called.
2965
+ * zero: The chunk was not handled, the chunk will be discarded
2966
+ * unless png_set_keep_unknown_chunks has been used to set
2967
+ * a 'keep' behavior for this particular chunk, in which
2968
+ * case that will be used. A critical chunk will cause an
2969
+ * error at this point unless it is to be saved.
2970
+ * positive: The chunk was handled, libpng will ignore/discard it.
2971
+ */
2972
+ if (ret < 0)
2973
+ png_chunk_error(png_ptr, "error in user chunk");
2974
+
2975
+ else if (ret == 0)
2976
+ {
2977
+ /* If the keep value is 'default' or 'never' override it, but
2978
+ * still error out on critical chunks unless the keep value is
2979
+ * 'always' While this is weird it is the behavior in 1.4.12.
2980
+ * A possible improvement would be to obey the value set for the
2981
+ * chunk, but this would be an API change that would probably
2982
+ * damage some applications.
2983
+ *
2984
+ * The png_app_warning below catches the case that matters, where
2985
+ * the application has not set specific save or ignore for this
2986
+ * chunk or global save or ignore.
2987
+ */
2988
+ if (keep < PNG_HANDLE_CHUNK_IF_SAFE)
2989
+ {
2990
+ # ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
2991
+ if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE)
2992
+ {
2993
+ png_chunk_warning(png_ptr, "Saving unknown chunk:");
2994
+ png_app_warning(png_ptr,
2995
+ "forcing save of an unhandled chunk;"
2996
+ " please call png_set_keep_unknown_chunks");
2997
+ /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
2998
+ }
2999
+ # endif
3000
+ keep = PNG_HANDLE_CHUNK_IF_SAFE;
3001
+ }
3002
+ }
3003
+
3004
+ else /* chunk was handled */
3005
+ {
3006
+ handled = 1;
3007
+ /* Critical chunks can be safely discarded at this point. */
3008
+ keep = PNG_HANDLE_CHUNK_NEVER;
3009
+ }
3010
+ }
3011
+
3012
+ else
3013
+ keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */
3014
+ }
3015
+
3016
+ else
3017
+ /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */
3018
+ # endif /* READ_USER_CHUNKS */
3019
+
3020
+ # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
3021
+ {
3022
+ /* keep is currently just the per-chunk setting, if there was no
3023
+ * setting change it to the global default now (not that this may
3024
+ * still be AS_DEFAULT) then obtain the cache of the chunk if required,
3025
+ * if not simply skip the chunk.
3026
+ */
3027
+ if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
3028
+ keep = png_ptr->unknown_default;
3029
+
3030
+ if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
3031
+ (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
3032
+ PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
3033
+ {
3034
+ if (png_cache_unknown_chunk(png_ptr, length) == 0)
3035
+ keep = PNG_HANDLE_CHUNK_NEVER;
3036
+ }
3037
+
3038
+ else
3039
+ png_crc_finish(png_ptr, length);
3040
+ }
3041
+ # else
3042
+ # ifndef PNG_READ_USER_CHUNKS_SUPPORTED
3043
+ # error no method to support READ_UNKNOWN_CHUNKS
3044
+ # endif
3045
+
3046
+ {
3047
+ /* If here there is no read callback pointer set and no support is
3048
+ * compiled in to just save the unknown chunks, so simply skip this
3049
+ * chunk. If 'keep' is something other than AS_DEFAULT or NEVER then
3050
+ * the app has erroneously asked for unknown chunk saving when there
3051
+ * is no support.
3052
+ */
3053
+ if (keep > PNG_HANDLE_CHUNK_NEVER)
3054
+ png_app_error(png_ptr, "no unknown chunk support available");
3055
+
3056
+ png_crc_finish(png_ptr, length);
3057
+ }
3058
+ # endif
3059
+
3060
+ # ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
3061
+ /* Now store the chunk in the chunk list if appropriate, and if the limits
3062
+ * permit it.
3063
+ */
3064
+ if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
3065
+ (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
3066
+ PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
3067
+ {
3068
+ # ifdef PNG_USER_LIMITS_SUPPORTED
3069
+ switch (png_ptr->user_chunk_cache_max)
3070
+ {
3071
+ case 2:
3072
+ png_ptr->user_chunk_cache_max = 1;
3073
+ png_chunk_benign_error(png_ptr, "no space in chunk cache");
3074
+ /* FALLTHROUGH */
3075
+ case 1:
3076
+ /* NOTE: prior to 1.6.0 this case resulted in an unknown critical
3077
+ * chunk being skipped, now there will be a hard error below.
3078
+ */
3079
+ break;
3080
+
3081
+ default: /* not at limit */
3082
+ --(png_ptr->user_chunk_cache_max);
3083
+ /* FALLTHROUGH */
3084
+ case 0: /* no limit */
3085
+ # endif /* USER_LIMITS */
3086
+ /* Here when the limit isn't reached or when limits are compiled
3087
+ * out; store the chunk.
3088
+ */
3089
+ png_set_unknown_chunks(png_ptr, info_ptr,
3090
+ &png_ptr->unknown_chunk, 1);
3091
+ handled = 1;
3092
+ # ifdef PNG_USER_LIMITS_SUPPORTED
3093
+ break;
3094
+ }
3095
+ # endif
3096
+ }
3097
+ # else /* no store support: the chunk must be handled by the user callback */
3098
+ PNG_UNUSED(info_ptr)
3099
+ # endif
3100
+
3101
+ /* Regardless of the error handling below the cached data (if any) can be
3102
+ * freed now. Notice that the data is not freed if there is a png_error, but
3103
+ * it will be freed by destroy_read_struct.
3104
+ */
3105
+ if (png_ptr->unknown_chunk.data != NULL)
3106
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
3107
+ png_ptr->unknown_chunk.data = NULL;
3108
+
3109
+ #else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
3110
+ /* There is no support to read an unknown chunk, so just skip it. */
3111
+ png_crc_finish(png_ptr, length);
3112
+ PNG_UNUSED(info_ptr)
3113
+ PNG_UNUSED(keep)
3114
+ #endif /* !READ_UNKNOWN_CHUNKS */
3115
+
3116
+ /* Check for unhandled critical chunks */
3117
+ if (handled == 0 && PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
3118
+ png_chunk_error(png_ptr, "unhandled critical chunk");
3119
+ }
3120
+
3121
+ /* This function is called to verify that a chunk name is valid.
3122
+ * This function can't have the "critical chunk check" incorporated
3123
+ * into it, since in the future we will need to be able to call user
3124
+ * functions to handle unknown critical chunks after we check that
3125
+ * the chunk name itself is valid.
3126
+ */
3127
+
3128
+ /* Bit hacking: the test for an invalid byte in the 4 byte chunk name is:
3129
+ *
3130
+ * ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
3131
+ */
3132
+
3133
+ void /* PRIVATE */
3134
+ png_check_chunk_name(png_const_structrp png_ptr, png_uint_32 chunk_name)
3135
+ {
3136
+ int i;
3137
+ png_uint_32 cn=chunk_name;
3138
+
3139
+ png_debug(1, "in png_check_chunk_name");
3140
+
3141
+ for (i=1; i<=4; ++i)
3142
+ {
3143
+ int c = cn & 0xff;
3144
+
3145
+ if (c < 65 || c > 122 || (c > 90 && c < 97))
3146
+ png_chunk_error(png_ptr, "invalid chunk type");
3147
+
3148
+ cn >>= 8;
3149
+ }
3150
+ }
3151
+
3152
+ void /* PRIVATE */
3153
+ png_check_chunk_length(png_const_structrp png_ptr, png_uint_32 length)
3154
+ {
3155
+ png_alloc_size_t limit = PNG_UINT_31_MAX;
3156
+
3157
+ # ifdef PNG_SET_USER_LIMITS_SUPPORTED
3158
+ if (png_ptr->user_chunk_malloc_max > 0 &&
3159
+ png_ptr->user_chunk_malloc_max < limit)
3160
+ limit = png_ptr->user_chunk_malloc_max;
3161
+ # elif PNG_USER_CHUNK_MALLOC_MAX > 0
3162
+ if (PNG_USER_CHUNK_MALLOC_MAX < limit)
3163
+ limit = PNG_USER_CHUNK_MALLOC_MAX;
3164
+ # endif
3165
+ if (png_ptr->chunk_name == png_IDAT)
3166
+ {
3167
+ png_alloc_size_t idat_limit = PNG_UINT_31_MAX;
3168
+ size_t row_factor =
3169
+ (size_t)png_ptr->width
3170
+ * (size_t)png_ptr->channels
3171
+ * (png_ptr->bit_depth > 8? 2: 1)
3172
+ + 1
3173
+ + (png_ptr->interlaced? 6: 0);
3174
+ if (png_ptr->height > PNG_UINT_32_MAX/row_factor)
3175
+ idat_limit = PNG_UINT_31_MAX;
3176
+ else
3177
+ idat_limit = png_ptr->height * row_factor;
3178
+ row_factor = row_factor > 32566? 32566 : row_factor;
3179
+ idat_limit += 6 + 5*(idat_limit/row_factor+1); /* zlib+deflate overhead */
3180
+ idat_limit=idat_limit < PNG_UINT_31_MAX? idat_limit : PNG_UINT_31_MAX;
3181
+ limit = limit < idat_limit? idat_limit : limit;
3182
+ }
3183
+
3184
+ if (length > limit)
3185
+ {
3186
+ png_debug2(0," length = %lu, limit = %lu",
3187
+ (unsigned long)length,(unsigned long)limit);
3188
+ png_chunk_error(png_ptr, "chunk data is too large");
3189
+ }
3190
+ }
3191
+
3192
+ /* Combines the row recently read in with the existing pixels in the row. This
3193
+ * routine takes care of alpha and transparency if requested. This routine also
3194
+ * handles the two methods of progressive display of interlaced images,
3195
+ * depending on the 'display' value; if 'display' is true then the whole row
3196
+ * (dp) is filled from the start by replicating the available pixels. If
3197
+ * 'display' is false only those pixels present in the pass are filled in.
3198
+ */
3199
+ void /* PRIVATE */
3200
+ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
3201
+ {
3202
+ unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
3203
+ png_const_bytep sp = png_ptr->row_buf + 1;
3204
+ png_alloc_size_t row_width = png_ptr->width;
3205
+ unsigned int pass = png_ptr->pass;
3206
+ png_bytep end_ptr = 0;
3207
+ png_byte end_byte = 0;
3208
+ unsigned int end_mask;
3209
+
3210
+ png_debug(1, "in png_combine_row");
3211
+
3212
+ /* Added in 1.5.6: it should not be possible to enter this routine until at
3213
+ * least one row has been read from the PNG data and transformed.
3214
+ */
3215
+ if (pixel_depth == 0)
3216
+ png_error(png_ptr, "internal row logic error");
3217
+
3218
+ /* Added in 1.5.4: the pixel depth should match the information returned by
3219
+ * any call to png_read_update_info at this point. Do not continue if we got
3220
+ * this wrong.
3221
+ */
3222
+ if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=
3223
+ PNG_ROWBYTES(pixel_depth, row_width))
3224
+ png_error(png_ptr, "internal row size calculation error");
3225
+
3226
+ /* Don't expect this to ever happen: */
3227
+ if (row_width == 0)
3228
+ png_error(png_ptr, "internal row width error");
3229
+
3230
+ /* Preserve the last byte in cases where only part of it will be overwritten,
3231
+ * the multiply below may overflow, we don't care because ANSI-C guarantees
3232
+ * we get the low bits.
3233
+ */
3234
+ end_mask = (pixel_depth * row_width) & 7;
3235
+ if (end_mask != 0)
3236
+ {
3237
+ /* end_ptr == NULL is a flag to say do nothing */
3238
+ end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1;
3239
+ end_byte = *end_ptr;
3240
+ # ifdef PNG_READ_PACKSWAP_SUPPORTED
3241
+ if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
3242
+ /* little-endian byte */
3243
+ end_mask = (unsigned int)(0xff << end_mask);
3244
+
3245
+ else /* big-endian byte */
3246
+ # endif
3247
+ end_mask = 0xff >> end_mask;
3248
+ /* end_mask is now the bits to *keep* from the destination row */
3249
+ }
3250
+
3251
+ /* For non-interlaced images this reduces to a memcpy(). A memcpy()
3252
+ * will also happen if interlacing isn't supported or if the application
3253
+ * does not call png_set_interlace_handling(). In the latter cases the
3254
+ * caller just gets a sequence of the unexpanded rows from each interlace
3255
+ * pass.
3256
+ */
3257
+ #ifdef PNG_READ_INTERLACING_SUPPORTED
3258
+ if (png_ptr->interlaced != 0 &&
3259
+ (png_ptr->transformations & PNG_INTERLACE) != 0 &&
3260
+ pass < 6 && (display == 0 ||
3261
+ /* The following copies everything for 'display' on passes 0, 2 and 4. */
3262
+ (display == 1 && (pass & 1) != 0)))
3263
+ {
3264
+ /* Narrow images may have no bits in a pass; the caller should handle
3265
+ * this, but this test is cheap:
3266
+ */
3267
+ if (row_width <= PNG_PASS_START_COL(pass))
3268
+ return;
3269
+
3270
+ if (pixel_depth < 8)
3271
+ {
3272
+ /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit
3273
+ * into 32 bits, then a single loop over the bytes using the four byte
3274
+ * values in the 32-bit mask can be used. For the 'display' option the
3275
+ * expanded mask may also not require any masking within a byte. To
3276
+ * make this work the PACKSWAP option must be taken into account - it
3277
+ * simply requires the pixels to be reversed in each byte.
3278
+ *
3279
+ * The 'regular' case requires a mask for each of the first 6 passes,
3280
+ * the 'display' case does a copy for the even passes in the range
3281
+ * 0..6. This has already been handled in the test above.
3282
+ *
3283
+ * The masks are arranged as four bytes with the first byte to use in
3284
+ * the lowest bits (little-endian) regardless of the order (PACKSWAP or
3285
+ * not) of the pixels in each byte.
3286
+ *
3287
+ * NOTE: the whole of this logic depends on the caller of this function
3288
+ * only calling it on rows appropriate to the pass. This function only
3289
+ * understands the 'x' logic; the 'y' logic is handled by the caller.
3290
+ *
3291
+ * The following defines allow generation of compile time constant bit
3292
+ * masks for each pixel depth and each possibility of swapped or not
3293
+ * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index,
3294
+ * is in the range 0..7; and the result is 1 if the pixel is to be
3295
+ * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B'
3296
+ * for the block method.
3297
+ *
3298
+ * With some compilers a compile time expression of the general form:
3299
+ *
3300
+ * (shift >= 32) ? (a >> (shift-32)) : (b >> shift)
3301
+ *
3302
+ * Produces warnings with values of 'shift' in the range 33 to 63
3303
+ * because the right hand side of the ?: expression is evaluated by
3304
+ * the compiler even though it isn't used. Microsoft Visual C (various
3305
+ * versions) and the Intel C compiler are known to do this. To avoid
3306
+ * this the following macros are used in 1.5.6. This is a temporary
3307
+ * solution to avoid destabilizing the code during the release process.
3308
+ */
3309
+ # if PNG_USE_COMPILE_TIME_MASKS
3310
+ # define PNG_LSR(x,s) ((x)>>((s) & 0x1f))
3311
+ # define PNG_LSL(x,s) ((x)<<((s) & 0x1f))
3312
+ # else
3313
+ # define PNG_LSR(x,s) ((x)>>(s))
3314
+ # define PNG_LSL(x,s) ((x)<<(s))
3315
+ # endif
3316
+ # define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\
3317
+ PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1)
3318
+ # define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\
3319
+ PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1)
3320
+
3321
+ /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is
3322
+ * little endian - the first pixel is at bit 0 - however the extra
3323
+ * parameter 's' can be set to cause the mask position to be swapped
3324
+ * within each byte, to match the PNG format. This is done by XOR of
3325
+ * the shift with 7, 6 or 4 for bit depths 1, 2 and 4.
3326
+ */
3327
+ # define PIXEL_MASK(p,x,d,s) \
3328
+ (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0))))
3329
+
3330
+ /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask.
3331
+ */
3332
+ # define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
3333
+ # define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
3334
+
3335
+ /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp
3336
+ * cases the result needs replicating, for the 4-bpp case the above
3337
+ * generates a full 32 bits.
3338
+ */
3339
+ # define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1)))
3340
+
3341
+ # define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\
3342
+ S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\
3343
+ S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d)
3344
+
3345
+ # define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\
3346
+ B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\
3347
+ B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d)
3348
+
3349
+ #if PNG_USE_COMPILE_TIME_MASKS
3350
+ /* Utility macros to construct all the masks for a depth/swap
3351
+ * combination. The 's' parameter says whether the format is PNG
3352
+ * (big endian bytes) or not. Only the three odd-numbered passes are
3353
+ * required for the display/block algorithm.
3354
+ */
3355
+ # define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\
3356
+ S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) }
3357
+
3358
+ # define B_MASKS(d,s) { B_MASK(1,d,s), B_MASK(3,d,s), B_MASK(5,d,s) }
3359
+
3360
+ # define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2))
3361
+
3362
+ /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
3363
+ * then pass:
3364
+ */
3365
+ static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
3366
+ {
3367
+ /* Little-endian byte masks for PACKSWAP */
3368
+ { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },
3369
+ /* Normal (big-endian byte) masks - PNG format */
3370
+ { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) }
3371
+ };
3372
+
3373
+ /* display_mask has only three entries for the odd passes, so index by
3374
+ * pass>>1.
3375
+ */
3376
+ static const png_uint_32 display_mask[2][3][3] =
3377
+ {
3378
+ /* Little-endian byte masks for PACKSWAP */
3379
+ { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },
3380
+ /* Normal (big-endian byte) masks - PNG format */
3381
+ { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) }
3382
+ };
3383
+
3384
+ # define MASK(pass,depth,display,png)\
3385
+ ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\
3386
+ row_mask[png][DEPTH_INDEX(depth)][pass])
3387
+
3388
+ #else /* !PNG_USE_COMPILE_TIME_MASKS */
3389
+ /* This is the runtime alternative: it seems unlikely that this will
3390
+ * ever be either smaller or faster than the compile time approach.
3391
+ */
3392
+ # define MASK(pass,depth,display,png)\
3393
+ ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png))
3394
+ #endif /* !USE_COMPILE_TIME_MASKS */
3395
+
3396
+ /* Use the appropriate mask to copy the required bits. In some cases
3397
+ * the byte mask will be 0 or 0xff; optimize these cases. row_width is
3398
+ * the number of pixels, but the code copies bytes, so it is necessary
3399
+ * to special case the end.
3400
+ */
3401
+ png_uint_32 pixels_per_byte = 8 / pixel_depth;
3402
+ png_uint_32 mask;
3403
+
3404
+ # ifdef PNG_READ_PACKSWAP_SUPPORTED
3405
+ if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
3406
+ mask = MASK(pass, pixel_depth, display, 0);
3407
+
3408
+ else
3409
+ # endif
3410
+ mask = MASK(pass, pixel_depth, display, 1);
3411
+
3412
+ for (;;)
3413
+ {
3414
+ png_uint_32 m;
3415
+
3416
+ /* It doesn't matter in the following if png_uint_32 has more than
3417
+ * 32 bits because the high bits always match those in m<<24; it is,
3418
+ * however, essential to use OR here, not +, because of this.
3419
+ */
3420
+ m = mask;
3421
+ mask = (m >> 8) | (m << 24); /* rotate right to good compilers */
3422
+ m &= 0xff;
3423
+
3424
+ if (m != 0) /* something to copy */
3425
+ {
3426
+ if (m != 0xff)
3427
+ *dp = (png_byte)((*dp & ~m) | (*sp & m));
3428
+ else
3429
+ *dp = *sp;
3430
+ }
3431
+
3432
+ /* NOTE: this may overwrite the last byte with garbage if the image
3433
+ * is not an exact number of bytes wide; libpng has always done
3434
+ * this.
3435
+ */
3436
+ if (row_width <= pixels_per_byte)
3437
+ break; /* May need to restore part of the last byte */
3438
+
3439
+ row_width -= pixels_per_byte;
3440
+ ++dp;
3441
+ ++sp;
3442
+ }
3443
+ }
3444
+
3445
+ else /* pixel_depth >= 8 */
3446
+ {
3447
+ unsigned int bytes_to_copy, bytes_to_jump;
3448
+
3449
+ /* Validate the depth - it must be a multiple of 8 */
3450
+ if (pixel_depth & 7)
3451
+ png_error(png_ptr, "invalid user transform pixel depth");
3452
+
3453
+ pixel_depth >>= 3; /* now in bytes */
3454
+ row_width *= pixel_depth;
3455
+
3456
+ /* Regardless of pass number the Adam 7 interlace always results in a
3457
+ * fixed number of pixels to copy then to skip. There may be a
3458
+ * different number of pixels to skip at the start though.
3459
+ */
3460
+ {
3461
+ unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth;
3462
+
3463
+ row_width -= offset;
3464
+ dp += offset;
3465
+ sp += offset;
3466
+ }
3467
+
3468
+ /* Work out the bytes to copy. */
3469
+ if (display != 0)
3470
+ {
3471
+ /* When doing the 'block' algorithm the pixel in the pass gets
3472
+ * replicated to adjacent pixels. This is why the even (0,2,4,6)
3473
+ * passes are skipped above - the entire expanded row is copied.
3474
+ */
3475
+ bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth;
3476
+
3477
+ /* But don't allow this number to exceed the actual row width. */
3478
+ if (bytes_to_copy > row_width)
3479
+ bytes_to_copy = (unsigned int)/*SAFE*/row_width;
3480
+ }
3481
+
3482
+ else /* normal row; Adam7 only ever gives us one pixel to copy. */
3483
+ bytes_to_copy = pixel_depth;
3484
+
3485
+ /* In Adam7 there is a constant offset between where the pixels go. */
3486
+ bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth;
3487
+
3488
+ /* And simply copy these bytes. Some optimization is possible here,
3489
+ * depending on the value of 'bytes_to_copy'. Special case the low
3490
+ * byte counts, which we know to be frequent.
3491
+ *
3492
+ * Notice that these cases all 'return' rather than 'break' - this
3493
+ * avoids an unnecessary test on whether to restore the last byte
3494
+ * below.
3495
+ */
3496
+ switch (bytes_to_copy)
3497
+ {
3498
+ case 1:
3499
+ for (;;)
3500
+ {
3501
+ *dp = *sp;
3502
+
3503
+ if (row_width <= bytes_to_jump)
3504
+ return;
3505
+
3506
+ dp += bytes_to_jump;
3507
+ sp += bytes_to_jump;
3508
+ row_width -= bytes_to_jump;
3509
+ }
3510
+
3511
+ case 2:
3512
+ /* There is a possibility of a partial copy at the end here; this
3513
+ * slows the code down somewhat.
3514
+ */
3515
+ do
3516
+ {
3517
+ dp[0] = sp[0]; dp[1] = sp[1];
3518
+
3519
+ if (row_width <= bytes_to_jump)
3520
+ return;
3521
+
3522
+ sp += bytes_to_jump;
3523
+ dp += bytes_to_jump;
3524
+ row_width -= bytes_to_jump;
3525
+ }
3526
+ while (row_width > 1);
3527
+
3528
+ /* And there can only be one byte left at this point: */
3529
+ *dp = *sp;
3530
+ return;
3531
+
3532
+ case 3:
3533
+ /* This can only be the RGB case, so each copy is exactly one
3534
+ * pixel and it is not necessary to check for a partial copy.
3535
+ */
3536
+ for (;;)
3537
+ {
3538
+ dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2];
3539
+
3540
+ if (row_width <= bytes_to_jump)
3541
+ return;
3542
+
3543
+ sp += bytes_to_jump;
3544
+ dp += bytes_to_jump;
3545
+ row_width -= bytes_to_jump;
3546
+ }
3547
+
3548
+ default:
3549
+ #if PNG_ALIGN_TYPE != PNG_ALIGN_NONE
3550
+ /* Check for double byte alignment and, if possible, use a
3551
+ * 16-bit copy. Don't attempt this for narrow images - ones that
3552
+ * are less than an interlace panel wide. Don't attempt it for
3553
+ * wide bytes_to_copy either - use the memcpy there.
3554
+ */
3555
+ if (bytes_to_copy < 16 /*else use memcpy*/ &&
3556
+ png_isaligned(dp, png_uint_16) &&
3557
+ png_isaligned(sp, png_uint_16) &&
3558
+ bytes_to_copy % (sizeof (png_uint_16)) == 0 &&
3559
+ bytes_to_jump % (sizeof (png_uint_16)) == 0)
3560
+ {
3561
+ /* Everything is aligned for png_uint_16 copies, but try for
3562
+ * png_uint_32 first.
3563
+ */
3564
+ if (png_isaligned(dp, png_uint_32) &&
3565
+ png_isaligned(sp, png_uint_32) &&
3566
+ bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
3567
+ bytes_to_jump % (sizeof (png_uint_32)) == 0)
3568
+ {
3569
+ png_uint_32p dp32 = png_aligncast(png_uint_32p,dp);
3570
+ png_const_uint_32p sp32 = png_aligncastconst(
3571
+ png_const_uint_32p, sp);
3572
+ size_t skip = (bytes_to_jump-bytes_to_copy) /
3573
+ (sizeof (png_uint_32));
3574
+
3575
+ do
3576
+ {
3577
+ size_t c = bytes_to_copy;
3578
+ do
3579
+ {
3580
+ *dp32++ = *sp32++;
3581
+ c -= (sizeof (png_uint_32));
3582
+ }
3583
+ while (c > 0);
3584
+
3585
+ if (row_width <= bytes_to_jump)
3586
+ return;
3587
+
3588
+ dp32 += skip;
3589
+ sp32 += skip;
3590
+ row_width -= bytes_to_jump;
3591
+ }
3592
+ while (bytes_to_copy <= row_width);
3593
+
3594
+ /* Get to here when the row_width truncates the final copy.
3595
+ * There will be 1-3 bytes left to copy, so don't try the
3596
+ * 16-bit loop below.
3597
+ */
3598
+ dp = (png_bytep)dp32;
3599
+ sp = (png_const_bytep)sp32;
3600
+ do
3601
+ *dp++ = *sp++;
3602
+ while (--row_width > 0);
3603
+ return;
3604
+ }
3605
+
3606
+ /* Else do it in 16-bit quantities, but only if the size is
3607
+ * not too large.
3608
+ */
3609
+ else
3610
+ {
3611
+ png_uint_16p dp16 = png_aligncast(png_uint_16p, dp);
3612
+ png_const_uint_16p sp16 = png_aligncastconst(
3613
+ png_const_uint_16p, sp);
3614
+ size_t skip = (bytes_to_jump-bytes_to_copy) /
3615
+ (sizeof (png_uint_16));
3616
+
3617
+ do
3618
+ {
3619
+ size_t c = bytes_to_copy;
3620
+ do
3621
+ {
3622
+ *dp16++ = *sp16++;
3623
+ c -= (sizeof (png_uint_16));
3624
+ }
3625
+ while (c > 0);
3626
+
3627
+ if (row_width <= bytes_to_jump)
3628
+ return;
3629
+
3630
+ dp16 += skip;
3631
+ sp16 += skip;
3632
+ row_width -= bytes_to_jump;
3633
+ }
3634
+ while (bytes_to_copy <= row_width);
3635
+
3636
+ /* End of row - 1 byte left, bytes_to_copy > row_width: */
3637
+ dp = (png_bytep)dp16;
3638
+ sp = (png_const_bytep)sp16;
3639
+ do
3640
+ *dp++ = *sp++;
3641
+ while (--row_width > 0);
3642
+ return;
3643
+ }
3644
+ }
3645
+ #endif /* ALIGN_TYPE code */
3646
+
3647
+ /* The true default - use a memcpy: */
3648
+ for (;;)
3649
+ {
3650
+ memcpy(dp, sp, bytes_to_copy);
3651
+
3652
+ if (row_width <= bytes_to_jump)
3653
+ return;
3654
+
3655
+ sp += bytes_to_jump;
3656
+ dp += bytes_to_jump;
3657
+ row_width -= bytes_to_jump;
3658
+ if (bytes_to_copy > row_width)
3659
+ bytes_to_copy = (unsigned int)/*SAFE*/row_width;
3660
+ }
3661
+ }
3662
+
3663
+ /* NOT REACHED*/
3664
+ } /* pixel_depth >= 8 */
3665
+
3666
+ /* Here if pixel_depth < 8 to check 'end_ptr' below. */
3667
+ }
3668
+ else
3669
+ #endif /* READ_INTERLACING */
3670
+
3671
+ /* If here then the switch above wasn't used so just memcpy the whole row
3672
+ * from the temporary row buffer (notice that this overwrites the end of the
3673
+ * destination row if it is a partial byte.)
3674
+ */
3675
+ memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width));
3676
+
3677
+ /* Restore the overwritten bits from the last byte if necessary. */
3678
+ if (end_ptr != NULL)
3679
+ *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask));
3680
+ }
3681
+
3682
+ #ifdef PNG_READ_INTERLACING_SUPPORTED
3683
+ void /* PRIVATE */
3684
+ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
3685
+ png_uint_32 transformations /* Because these may affect the byte layout */)
3686
+ {
3687
+ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
3688
+ /* Offset to next interlace block */
3689
+ static const unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
3690
+
3691
+ png_debug(1, "in png_do_read_interlace");
3692
+ if (row != NULL && row_info != NULL)
3693
+ {
3694
+ png_uint_32 final_width;
3695
+
3696
+ final_width = row_info->width * png_pass_inc[pass];
3697
+
3698
+ switch (row_info->pixel_depth)
3699
+ {
3700
+ case 1:
3701
+ {
3702
+ png_bytep sp = row + (size_t)((row_info->width - 1) >> 3);
3703
+ png_bytep dp = row + (size_t)((final_width - 1) >> 3);
3704
+ unsigned int sshift, dshift;
3705
+ unsigned int s_start, s_end;
3706
+ int s_inc;
3707
+ int jstop = (int)png_pass_inc[pass];
3708
+ png_byte v;
3709
+ png_uint_32 i;
3710
+ int j;
3711
+
3712
+ #ifdef PNG_READ_PACKSWAP_SUPPORTED
3713
+ if ((transformations & PNG_PACKSWAP) != 0)
3714
+ {
3715
+ sshift = ((row_info->width + 7) & 0x07);
3716
+ dshift = ((final_width + 7) & 0x07);
3717
+ s_start = 7;
3718
+ s_end = 0;
3719
+ s_inc = -1;
3720
+ }
3721
+
3722
+ else
3723
+ #endif
3724
+ {
3725
+ sshift = 7 - ((row_info->width + 7) & 0x07);
3726
+ dshift = 7 - ((final_width + 7) & 0x07);
3727
+ s_start = 0;
3728
+ s_end = 7;
3729
+ s_inc = 1;
3730
+ }
3731
+
3732
+ for (i = 0; i < row_info->width; i++)
3733
+ {
3734
+ v = (png_byte)((*sp >> sshift) & 0x01);
3735
+ for (j = 0; j < jstop; j++)
3736
+ {
3737
+ unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));
3738
+ tmp |= (unsigned int)(v << dshift);
3739
+ *dp = (png_byte)(tmp & 0xff);
3740
+
3741
+ if (dshift == s_end)
3742
+ {
3743
+ dshift = s_start;
3744
+ dp--;
3745
+ }
3746
+
3747
+ else
3748
+ dshift = (unsigned int)((int)dshift + s_inc);
3749
+ }
3750
+
3751
+ if (sshift == s_end)
3752
+ {
3753
+ sshift = s_start;
3754
+ sp--;
3755
+ }
3756
+
3757
+ else
3758
+ sshift = (unsigned int)((int)sshift + s_inc);
3759
+ }
3760
+ break;
3761
+ }
3762
+
3763
+ case 2:
3764
+ {
3765
+ png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
3766
+ png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
3767
+ unsigned int sshift, dshift;
3768
+ unsigned int s_start, s_end;
3769
+ int s_inc;
3770
+ int jstop = (int)png_pass_inc[pass];
3771
+ png_uint_32 i;
3772
+
3773
+ #ifdef PNG_READ_PACKSWAP_SUPPORTED
3774
+ if ((transformations & PNG_PACKSWAP) != 0)
3775
+ {
3776
+ sshift = (((row_info->width + 3) & 0x03) << 1);
3777
+ dshift = (((final_width + 3) & 0x03) << 1);
3778
+ s_start = 6;
3779
+ s_end = 0;
3780
+ s_inc = -2;
3781
+ }
3782
+
3783
+ else
3784
+ #endif
3785
+ {
3786
+ sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1);
3787
+ dshift = ((3 - ((final_width + 3) & 0x03)) << 1);
3788
+ s_start = 0;
3789
+ s_end = 6;
3790
+ s_inc = 2;
3791
+ }
3792
+
3793
+ for (i = 0; i < row_info->width; i++)
3794
+ {
3795
+ png_byte v;
3796
+ int j;
3797
+
3798
+ v = (png_byte)((*sp >> sshift) & 0x03);
3799
+ for (j = 0; j < jstop; j++)
3800
+ {
3801
+ unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));
3802
+ tmp |= (unsigned int)(v << dshift);
3803
+ *dp = (png_byte)(tmp & 0xff);
3804
+
3805
+ if (dshift == s_end)
3806
+ {
3807
+ dshift = s_start;
3808
+ dp--;
3809
+ }
3810
+
3811
+ else
3812
+ dshift = (unsigned int)((int)dshift + s_inc);
3813
+ }
3814
+
3815
+ if (sshift == s_end)
3816
+ {
3817
+ sshift = s_start;
3818
+ sp--;
3819
+ }
3820
+
3821
+ else
3822
+ sshift = (unsigned int)((int)sshift + s_inc);
3823
+ }
3824
+ break;
3825
+ }
3826
+
3827
+ case 4:
3828
+ {
3829
+ png_bytep sp = row + (size_t)((row_info->width - 1) >> 1);
3830
+ png_bytep dp = row + (size_t)((final_width - 1) >> 1);
3831
+ unsigned int sshift, dshift;
3832
+ unsigned int s_start, s_end;
3833
+ int s_inc;
3834
+ png_uint_32 i;
3835
+ int jstop = (int)png_pass_inc[pass];
3836
+
3837
+ #ifdef PNG_READ_PACKSWAP_SUPPORTED
3838
+ if ((transformations & PNG_PACKSWAP) != 0)
3839
+ {
3840
+ sshift = (((row_info->width + 1) & 0x01) << 2);
3841
+ dshift = (((final_width + 1) & 0x01) << 2);
3842
+ s_start = 4;
3843
+ s_end = 0;
3844
+ s_inc = -4;
3845
+ }
3846
+
3847
+ else
3848
+ #endif
3849
+ {
3850
+ sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2);
3851
+ dshift = ((1 - ((final_width + 1) & 0x01)) << 2);
3852
+ s_start = 0;
3853
+ s_end = 4;
3854
+ s_inc = 4;
3855
+ }
3856
+
3857
+ for (i = 0; i < row_info->width; i++)
3858
+ {
3859
+ png_byte v = (png_byte)((*sp >> sshift) & 0x0f);
3860
+ int j;
3861
+
3862
+ for (j = 0; j < jstop; j++)
3863
+ {
3864
+ unsigned int tmp = *dp & (0xf0f >> (4 - dshift));
3865
+ tmp |= (unsigned int)(v << dshift);
3866
+ *dp = (png_byte)(tmp & 0xff);
3867
+
3868
+ if (dshift == s_end)
3869
+ {
3870
+ dshift = s_start;
3871
+ dp--;
3872
+ }
3873
+
3874
+ else
3875
+ dshift = (unsigned int)((int)dshift + s_inc);
3876
+ }
3877
+
3878
+ if (sshift == s_end)
3879
+ {
3880
+ sshift = s_start;
3881
+ sp--;
3882
+ }
3883
+
3884
+ else
3885
+ sshift = (unsigned int)((int)sshift + s_inc);
3886
+ }
3887
+ break;
3888
+ }
3889
+
3890
+ default:
3891
+ {
3892
+ size_t pixel_bytes = (row_info->pixel_depth >> 3);
3893
+
3894
+ png_bytep sp = row + (size_t)(row_info->width - 1)
3895
+ * pixel_bytes;
3896
+
3897
+ png_bytep dp = row + (size_t)(final_width - 1) * pixel_bytes;
3898
+
3899
+ int jstop = (int)png_pass_inc[pass];
3900
+ png_uint_32 i;
3901
+
3902
+ for (i = 0; i < row_info->width; i++)
3903
+ {
3904
+ png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */
3905
+ int j;
3906
+
3907
+ memcpy(v, sp, pixel_bytes);
3908
+
3909
+ for (j = 0; j < jstop; j++)
3910
+ {
3911
+ memcpy(dp, v, pixel_bytes);
3912
+ dp -= pixel_bytes;
3913
+ }
3914
+
3915
+ sp -= pixel_bytes;
3916
+ }
3917
+ break;
3918
+ }
3919
+ }
3920
+
3921
+ row_info->width = final_width;
3922
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
3923
+ }
3924
+ #ifndef PNG_READ_PACKSWAP_SUPPORTED
3925
+ PNG_UNUSED(transformations) /* Silence compiler warning */
3926
+ #endif
3927
+ }
3928
+ #endif /* READ_INTERLACING */
3929
+
3930
+ static void
3931
+ png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
3932
+ png_const_bytep prev_row)
3933
+ {
3934
+ size_t i;
3935
+ size_t istop = row_info->rowbytes;
3936
+ unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
3937
+ png_bytep rp = row + bpp;
3938
+
3939
+ PNG_UNUSED(prev_row)
3940
+
3941
+ for (i = bpp; i < istop; i++)
3942
+ {
3943
+ *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff);
3944
+ rp++;
3945
+ }
3946
+ }
3947
+
3948
+ static void
3949
+ png_read_filter_row_up(png_row_infop row_info, png_bytep row,
3950
+ png_const_bytep prev_row)
3951
+ {
3952
+ size_t i;
3953
+ size_t istop = row_info->rowbytes;
3954
+ png_bytep rp = row;
3955
+ png_const_bytep pp = prev_row;
3956
+
3957
+ for (i = 0; i < istop; i++)
3958
+ {
3959
+ *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
3960
+ rp++;
3961
+ }
3962
+ }
3963
+
3964
+ static void
3965
+ png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
3966
+ png_const_bytep prev_row)
3967
+ {
3968
+ size_t i;
3969
+ png_bytep rp = row;
3970
+ png_const_bytep pp = prev_row;
3971
+ unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
3972
+ size_t istop = row_info->rowbytes - bpp;
3973
+
3974
+ for (i = 0; i < bpp; i++)
3975
+ {
3976
+ *rp = (png_byte)(((int)(*rp) +
3977
+ ((int)(*pp++) / 2 )) & 0xff);
3978
+
3979
+ rp++;
3980
+ }
3981
+
3982
+ for (i = 0; i < istop; i++)
3983
+ {
3984
+ *rp = (png_byte)(((int)(*rp) +
3985
+ (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);
3986
+
3987
+ rp++;
3988
+ }
3989
+ }
3990
+
3991
+ static void
3992
+ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
3993
+ png_const_bytep prev_row)
3994
+ {
3995
+ png_bytep rp_end = row + row_info->rowbytes;
3996
+ int a, c;
3997
+
3998
+ /* First pixel/byte */
3999
+ c = *prev_row++;
4000
+ a = *row + c;
4001
+ *row++ = (png_byte)a;
4002
+
4003
+ /* Remainder */
4004
+ while (row < rp_end)
4005
+ {
4006
+ int b, pa, pb, pc, p;
4007
+
4008
+ a &= 0xff; /* From previous iteration or start */
4009
+ b = *prev_row++;
4010
+
4011
+ p = b - c;
4012
+ pc = a - c;
4013
+
4014
+ #ifdef PNG_USE_ABS
4015
+ pa = abs(p);
4016
+ pb = abs(pc);
4017
+ pc = abs(p + pc);
4018
+ #else
4019
+ pa = p < 0 ? -p : p;
4020
+ pb = pc < 0 ? -pc : pc;
4021
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
4022
+ #endif
4023
+
4024
+ /* Find the best predictor, the least of pa, pb, pc favoring the earlier
4025
+ * ones in the case of a tie.
4026
+ */
4027
+ if (pb < pa)
4028
+ {
4029
+ pa = pb; a = b;
4030
+ }
4031
+ if (pc < pa) a = c;
4032
+
4033
+ /* Calculate the current pixel in a, and move the previous row pixel to c
4034
+ * for the next time round the loop
4035
+ */
4036
+ c = b;
4037
+ a += *row;
4038
+ *row++ = (png_byte)a;
4039
+ }
4040
+ }
4041
+
4042
+ static void
4043
+ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
4044
+ png_const_bytep prev_row)
4045
+ {
4046
+ unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
4047
+ png_bytep rp_end = row + bpp;
4048
+
4049
+ /* Process the first pixel in the row completely (this is the same as 'up'
4050
+ * because there is only one candidate predictor for the first row).
4051
+ */
4052
+ while (row < rp_end)
4053
+ {
4054
+ int a = *row + *prev_row++;
4055
+ *row++ = (png_byte)a;
4056
+ }
4057
+
4058
+ /* Remainder */
4059
+ rp_end = rp_end + (row_info->rowbytes - bpp);
4060
+
4061
+ while (row < rp_end)
4062
+ {
4063
+ int a, b, c, pa, pb, pc, p;
4064
+
4065
+ c = *(prev_row - bpp);
4066
+ a = *(row - bpp);
4067
+ b = *prev_row++;
4068
+
4069
+ p = b - c;
4070
+ pc = a - c;
4071
+
4072
+ #ifdef PNG_USE_ABS
4073
+ pa = abs(p);
4074
+ pb = abs(pc);
4075
+ pc = abs(p + pc);
4076
+ #else
4077
+ pa = p < 0 ? -p : p;
4078
+ pb = pc < 0 ? -pc : pc;
4079
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
4080
+ #endif
4081
+
4082
+ if (pb < pa)
4083
+ {
4084
+ pa = pb; a = b;
4085
+ }
4086
+ if (pc < pa) a = c;
4087
+
4088
+ a += *row;
4089
+ *row++ = (png_byte)a;
4090
+ }
4091
+ }
4092
+
4093
+ static void
4094
+ png_init_filter_functions(png_structrp pp)
4095
+ /* This function is called once for every PNG image (except for PNG images
4096
+ * that only use PNG_FILTER_VALUE_NONE for all rows) to set the
4097
+ * implementations required to reverse the filtering of PNG rows. Reversing
4098
+ * the filter is the first transformation performed on the row data. It is
4099
+ * performed in place, therefore an implementation can be selected based on
4100
+ * the image pixel format. If the implementation depends on image width then
4101
+ * take care to ensure that it works correctly if the image is interlaced -
4102
+ * interlacing causes the actual row width to vary.
4103
+ */
4104
+ {
4105
+ unsigned int bpp = (pp->pixel_depth + 7) >> 3;
4106
+
4107
+ pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub;
4108
+ pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up;
4109
+ pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg;
4110
+ if (bpp == 1)
4111
+ pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
4112
+ png_read_filter_row_paeth_1byte_pixel;
4113
+ else
4114
+ pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
4115
+ png_read_filter_row_paeth_multibyte_pixel;
4116
+
4117
+ #ifdef PNG_FILTER_OPTIMIZATIONS
4118
+ /* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to
4119
+ * call to install hardware optimizations for the above functions; simply
4120
+ * replace whatever elements of the pp->read_filter[] array with a hardware
4121
+ * specific (or, for that matter, generic) optimization.
4122
+ *
4123
+ * To see an example of this examine what configure.ac does when
4124
+ * --enable-arm-neon is specified on the command line.
4125
+ */
4126
+ PNG_FILTER_OPTIMIZATIONS(pp, bpp);
4127
+ #endif
4128
+ }
4129
+
4130
+ void /* PRIVATE */
4131
+ png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
4132
+ png_const_bytep prev_row, int filter)
4133
+ {
4134
+ /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
4135
+ * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
4136
+ * implementations. See png_init_filter_functions above.
4137
+ */
4138
+ if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)
4139
+ {
4140
+ if (pp->read_filter[0] == NULL)
4141
+ png_init_filter_functions(pp);
4142
+
4143
+ pp->read_filter[filter-1](row_info, row, prev_row);
4144
+ }
4145
+ }
4146
+
4147
+ #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
4148
+ void /* PRIVATE */
4149
+ png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
4150
+ png_alloc_size_t avail_out)
4151
+ {
4152
+ /* Loop reading IDATs and decompressing the result into output[avail_out] */
4153
+ png_ptr->zstream.next_out = output;
4154
+ png_ptr->zstream.avail_out = 0; /* safety: set below */
4155
+
4156
+ if (output == NULL)
4157
+ avail_out = 0;
4158
+
4159
+ do
4160
+ {
4161
+ int ret;
4162
+ png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];
4163
+
4164
+ if (png_ptr->zstream.avail_in == 0)
4165
+ {
4166
+ uInt avail_in;
4167
+ png_bytep buffer;
4168
+
4169
+ while (png_ptr->idat_size == 0)
4170
+ {
4171
+ png_crc_finish(png_ptr, 0);
4172
+
4173
+ png_ptr->idat_size = png_read_chunk_header(png_ptr);
4174
+ /* This is an error even in the 'check' case because the code just
4175
+ * consumed a non-IDAT header.
4176
+ */
4177
+ if (png_ptr->chunk_name != png_IDAT)
4178
+ png_error(png_ptr, "Not enough image data");
4179
+ }
4180
+
4181
+ avail_in = png_ptr->IDAT_read_size;
4182
+
4183
+ if (avail_in > png_ptr->idat_size)
4184
+ avail_in = (uInt)png_ptr->idat_size;
4185
+
4186
+ /* A PNG with a gradually increasing IDAT size will defeat this attempt
4187
+ * to minimize memory usage by causing lots of re-allocs, but
4188
+ * realistically doing IDAT_read_size re-allocs is not likely to be a
4189
+ * big problem.
4190
+ */
4191
+ buffer = png_read_buffer(png_ptr, avail_in, 0/*error*/);
4192
+
4193
+ png_crc_read(png_ptr, buffer, avail_in);
4194
+ png_ptr->idat_size -= avail_in;
4195
+
4196
+ png_ptr->zstream.next_in = buffer;
4197
+ png_ptr->zstream.avail_in = avail_in;
4198
+ }
4199
+
4200
+ /* And set up the output side. */
4201
+ if (output != NULL) /* standard read */
4202
+ {
4203
+ uInt out = ZLIB_IO_MAX;
4204
+
4205
+ if (out > avail_out)
4206
+ out = (uInt)avail_out;
4207
+
4208
+ avail_out -= out;
4209
+ png_ptr->zstream.avail_out = out;
4210
+ }
4211
+
4212
+ else /* after last row, checking for end */
4213
+ {
4214
+ png_ptr->zstream.next_out = tmpbuf;
4215
+ png_ptr->zstream.avail_out = (sizeof tmpbuf);
4216
+ }
4217
+
4218
+ /* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the
4219
+ * process. If the LZ stream is truncated the sequential reader will
4220
+ * terminally damage the stream, above, by reading the chunk header of the
4221
+ * following chunk (it then exits with png_error).
4222
+ *
4223
+ * TODO: deal more elegantly with truncated IDAT lists.
4224
+ */
4225
+ ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH);
4226
+
4227
+ /* Take the unconsumed output back. */
4228
+ if (output != NULL)
4229
+ avail_out += png_ptr->zstream.avail_out;
4230
+
4231
+ else /* avail_out counts the extra bytes */
4232
+ avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out;
4233
+
4234
+ png_ptr->zstream.avail_out = 0;
4235
+
4236
+ if (ret == Z_STREAM_END)
4237
+ {
4238
+ /* Do this for safety; we won't read any more into this row. */
4239
+ png_ptr->zstream.next_out = NULL;
4240
+
4241
+ png_ptr->mode |= PNG_AFTER_IDAT;
4242
+ png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
4243
+
4244
+ if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
4245
+ png_chunk_benign_error(png_ptr, "Extra compressed data");
4246
+ break;
4247
+ }
4248
+
4249
+ if (ret != Z_OK)
4250
+ {
4251
+ png_zstream_error(png_ptr, ret);
4252
+
4253
+ if (output != NULL)
4254
+ png_chunk_error(png_ptr, png_ptr->zstream.msg);
4255
+
4256
+ else /* checking */
4257
+ {
4258
+ png_chunk_benign_error(png_ptr, png_ptr->zstream.msg);
4259
+ return;
4260
+ }
4261
+ }
4262
+ } while (avail_out > 0);
4263
+
4264
+ if (avail_out > 0)
4265
+ {
4266
+ /* The stream ended before the image; this is the same as too few IDATs so
4267
+ * should be handled the same way.
4268
+ */
4269
+ if (output != NULL)
4270
+ png_error(png_ptr, "Not enough image data");
4271
+
4272
+ else /* the deflate stream contained extra data */
4273
+ png_chunk_benign_error(png_ptr, "Too much image data");
4274
+ }
4275
+ }
4276
+
4277
+ void /* PRIVATE */
4278
+ png_read_finish_IDAT(png_structrp png_ptr)
4279
+ {
4280
+ /* We don't need any more data and the stream should have ended, however the
4281
+ * LZ end code may actually not have been processed. In this case we must
4282
+ * read it otherwise stray unread IDAT data or, more likely, an IDAT chunk
4283
+ * may still remain to be consumed.
4284
+ */
4285
+ if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
4286
+ {
4287
+ /* The NULL causes png_read_IDAT_data to swallow any remaining bytes in
4288
+ * the compressed stream, but the stream may be damaged too, so even after
4289
+ * this call we may need to terminate the zstream ownership.
4290
+ */
4291
+ png_read_IDAT_data(png_ptr, NULL, 0);
4292
+ png_ptr->zstream.next_out = NULL; /* safety */
4293
+
4294
+ /* Now clear everything out for safety; the following may not have been
4295
+ * done.
4296
+ */
4297
+ if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
4298
+ {
4299
+ png_ptr->mode |= PNG_AFTER_IDAT;
4300
+ png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
4301
+ }
4302
+ }
4303
+
4304
+ /* If the zstream has not been released do it now *and* terminate the reading
4305
+ * of the final IDAT chunk.
4306
+ */
4307
+ if (png_ptr->zowner == png_IDAT)
4308
+ {
4309
+ /* Always do this; the pointers otherwise point into the read buffer. */
4310
+ png_ptr->zstream.next_in = NULL;
4311
+ png_ptr->zstream.avail_in = 0;
4312
+
4313
+ /* Now we no longer own the zstream. */
4314
+ png_ptr->zowner = 0;
4315
+
4316
+ /* The slightly weird semantics of the sequential IDAT reading is that we
4317
+ * are always in or at the end of an IDAT chunk, so we always need to do a
4318
+ * crc_finish here. If idat_size is non-zero we also need to read the
4319
+ * spurious bytes at the end of the chunk now.
4320
+ */
4321
+ (void)png_crc_finish(png_ptr, png_ptr->idat_size);
4322
+ }
4323
+ }
4324
+
4325
+ void /* PRIVATE */
4326
+ png_read_finish_row(png_structrp png_ptr)
4327
+ {
4328
+ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
4329
+
4330
+ /* Start of interlace block */
4331
+ static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
4332
+
4333
+ /* Offset to next interlace block */
4334
+ static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
4335
+
4336
+ /* Start of interlace block in the y direction */
4337
+ static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
4338
+
4339
+ /* Offset to next interlace block in the y direction */
4340
+ static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
4341
+
4342
+ png_debug(1, "in png_read_finish_row");
4343
+ png_ptr->row_number++;
4344
+ if (png_ptr->row_number < png_ptr->num_rows)
4345
+ return;
4346
+
4347
+ if (png_ptr->interlaced != 0)
4348
+ {
4349
+ png_ptr->row_number = 0;
4350
+
4351
+ /* TO DO: don't do this if prev_row isn't needed (requires
4352
+ * read-ahead of the next row's filter byte.
4353
+ */
4354
+ memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4355
+
4356
+ do
4357
+ {
4358
+ png_ptr->pass++;
4359
+
4360
+ if (png_ptr->pass >= 7)
4361
+ break;
4362
+
4363
+ png_ptr->iwidth = (png_ptr->width +
4364
+ png_pass_inc[png_ptr->pass] - 1 -
4365
+ png_pass_start[png_ptr->pass]) /
4366
+ png_pass_inc[png_ptr->pass];
4367
+
4368
+ if ((png_ptr->transformations & PNG_INTERLACE) == 0)
4369
+ {
4370
+ png_ptr->num_rows = (png_ptr->height +
4371
+ png_pass_yinc[png_ptr->pass] - 1 -
4372
+ png_pass_ystart[png_ptr->pass]) /
4373
+ png_pass_yinc[png_ptr->pass];
4374
+ }
4375
+
4376
+ else /* if (png_ptr->transformations & PNG_INTERLACE) */
4377
+ break; /* libpng deinterlacing sees every row */
4378
+
4379
+ } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);
4380
+
4381
+ if (png_ptr->pass < 7)
4382
+ return;
4383
+ }
4384
+
4385
+ /* Here after at the end of the last row of the last pass. */
4386
+ png_read_finish_IDAT(png_ptr);
4387
+ }
4388
+ #endif /* SEQUENTIAL_READ */
4389
+
4390
+ void /* PRIVATE */
4391
+ png_read_start_row(png_structrp png_ptr)
4392
+ {
4393
+ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
4394
+
4395
+ /* Start of interlace block */
4396
+ static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
4397
+
4398
+ /* Offset to next interlace block */
4399
+ static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
4400
+
4401
+ /* Start of interlace block in the y direction */
4402
+ static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
4403
+
4404
+ /* Offset to next interlace block in the y direction */
4405
+ static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
4406
+
4407
+ unsigned int max_pixel_depth;
4408
+ size_t row_bytes;
4409
+
4410
+ png_debug(1, "in png_read_start_row");
4411
+
4412
+ #ifdef PNG_READ_TRANSFORMS_SUPPORTED
4413
+ png_init_read_transformations(png_ptr);
4414
+ #endif
4415
+ if (png_ptr->interlaced != 0)
4416
+ {
4417
+ if ((png_ptr->transformations & PNG_INTERLACE) == 0)
4418
+ png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
4419
+ png_pass_ystart[0]) / png_pass_yinc[0];
4420
+
4421
+ else
4422
+ png_ptr->num_rows = png_ptr->height;
4423
+
4424
+ png_ptr->iwidth = (png_ptr->width +
4425
+ png_pass_inc[png_ptr->pass] - 1 -
4426
+ png_pass_start[png_ptr->pass]) /
4427
+ png_pass_inc[png_ptr->pass];
4428
+ }
4429
+
4430
+ else
4431
+ {
4432
+ png_ptr->num_rows = png_ptr->height;
4433
+ png_ptr->iwidth = png_ptr->width;
4434
+ }
4435
+
4436
+ max_pixel_depth = (unsigned int)png_ptr->pixel_depth;
4437
+
4438
+ /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
4439
+ * calculations to calculate the final pixel depth, then
4440
+ * png_do_read_transforms actually does the transforms. This means that the
4441
+ * code which effectively calculates this value is actually repeated in three
4442
+ * separate places. They must all match. Innocent changes to the order of
4443
+ * transformations can and will break libpng in a way that causes memory
4444
+ * overwrites.
4445
+ *
4446
+ * TODO: fix this.
4447
+ */
4448
+ #ifdef PNG_READ_PACK_SUPPORTED
4449
+ if ((png_ptr->transformations & PNG_PACK) != 0 && png_ptr->bit_depth < 8)
4450
+ max_pixel_depth = 8;
4451
+ #endif
4452
+
4453
+ #ifdef PNG_READ_EXPAND_SUPPORTED
4454
+ if ((png_ptr->transformations & PNG_EXPAND) != 0)
4455
+ {
4456
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
4457
+ {
4458
+ if (png_ptr->num_trans != 0)
4459
+ max_pixel_depth = 32;
4460
+
4461
+ else
4462
+ max_pixel_depth = 24;
4463
+ }
4464
+
4465
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
4466
+ {
4467
+ if (max_pixel_depth < 8)
4468
+ max_pixel_depth = 8;
4469
+
4470
+ if (png_ptr->num_trans != 0)
4471
+ max_pixel_depth *= 2;
4472
+ }
4473
+
4474
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
4475
+ {
4476
+ if (png_ptr->num_trans != 0)
4477
+ {
4478
+ max_pixel_depth *= 4;
4479
+ max_pixel_depth /= 3;
4480
+ }
4481
+ }
4482
+ }
4483
+ #endif
4484
+
4485
+ #ifdef PNG_READ_EXPAND_16_SUPPORTED
4486
+ if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
4487
+ {
4488
+ # ifdef PNG_READ_EXPAND_SUPPORTED
4489
+ /* In fact it is an error if it isn't supported, but checking is
4490
+ * the safe way.
4491
+ */
4492
+ if ((png_ptr->transformations & PNG_EXPAND) != 0)
4493
+ {
4494
+ if (png_ptr->bit_depth < 16)
4495
+ max_pixel_depth *= 2;
4496
+ }
4497
+ else
4498
+ # endif
4499
+ png_ptr->transformations &= ~PNG_EXPAND_16;
4500
+ }
4501
+ #endif
4502
+
4503
+ #ifdef PNG_READ_FILLER_SUPPORTED
4504
+ if ((png_ptr->transformations & (PNG_FILLER)) != 0)
4505
+ {
4506
+ if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
4507
+ {
4508
+ if (max_pixel_depth <= 8)
4509
+ max_pixel_depth = 16;
4510
+
4511
+ else
4512
+ max_pixel_depth = 32;
4513
+ }
4514
+
4515
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB ||
4516
+ png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
4517
+ {
4518
+ if (max_pixel_depth <= 32)
4519
+ max_pixel_depth = 32;
4520
+
4521
+ else
4522
+ max_pixel_depth = 64;
4523
+ }
4524
+ }
4525
+ #endif
4526
+
4527
+ #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
4528
+ if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
4529
+ {
4530
+ if (
4531
+ #ifdef PNG_READ_EXPAND_SUPPORTED
4532
+ (png_ptr->num_trans != 0 &&
4533
+ (png_ptr->transformations & PNG_EXPAND) != 0) ||
4534
+ #endif
4535
+ #ifdef PNG_READ_FILLER_SUPPORTED
4536
+ (png_ptr->transformations & (PNG_FILLER)) != 0 ||
4537
+ #endif
4538
+ png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
4539
+ {
4540
+ if (max_pixel_depth <= 16)
4541
+ max_pixel_depth = 32;
4542
+
4543
+ else
4544
+ max_pixel_depth = 64;
4545
+ }
4546
+
4547
+ else
4548
+ {
4549
+ if (max_pixel_depth <= 8)
4550
+ {
4551
+ if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
4552
+ max_pixel_depth = 32;
4553
+
4554
+ else
4555
+ max_pixel_depth = 24;
4556
+ }
4557
+
4558
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
4559
+ max_pixel_depth = 64;
4560
+
4561
+ else
4562
+ max_pixel_depth = 48;
4563
+ }
4564
+ }
4565
+ #endif
4566
+
4567
+ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
4568
+ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
4569
+ if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
4570
+ {
4571
+ unsigned int user_pixel_depth = png_ptr->user_transform_depth *
4572
+ png_ptr->user_transform_channels;
4573
+
4574
+ if (user_pixel_depth > max_pixel_depth)
4575
+ max_pixel_depth = user_pixel_depth;
4576
+ }
4577
+ #endif
4578
+
4579
+ /* This value is stored in png_struct and double checked in the row read
4580
+ * code.
4581
+ */
4582
+ png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth;
4583
+ png_ptr->transformed_pixel_depth = 0; /* calculated on demand */
4584
+
4585
+ /* Align the width on the next larger 8 pixels. Mainly used
4586
+ * for interlacing
4587
+ */
4588
+ row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
4589
+ /* Calculate the maximum bytes needed, adding a byte and a pixel
4590
+ * for safety's sake
4591
+ */
4592
+ row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
4593
+ 1 + ((max_pixel_depth + 7) >> 3U);
4594
+
4595
+ #ifdef PNG_MAX_MALLOC_64K
4596
+ if (row_bytes > (png_uint_32)65536L)
4597
+ png_error(png_ptr, "This image requires a row greater than 64KB");
4598
+ #endif
4599
+
4600
+ if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
4601
+ {
4602
+ png_free(png_ptr, png_ptr->big_row_buf);
4603
+ png_free(png_ptr, png_ptr->big_prev_row);
4604
+
4605
+ if (png_ptr->interlaced != 0)
4606
+ png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
4607
+ row_bytes + 48);
4608
+
4609
+ else
4610
+ png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
4611
+
4612
+ png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
4613
+
4614
+ #ifdef PNG_ALIGNED_MEMORY_SUPPORTED
4615
+ /* Use 16-byte aligned memory for row_buf with at least 16 bytes
4616
+ * of padding before and after row_buf; treat prev_row similarly.
4617
+ * NOTE: the alignment is to the start of the pixels, one beyond the start
4618
+ * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
4619
+ * was incorrect; the filter byte was aligned, which had the exact
4620
+ * opposite effect of that intended.
4621
+ */
4622
+ {
4623
+ png_bytep temp = png_ptr->big_row_buf + 32;
4624
+ int extra = (int)((temp - (png_bytep)0) & 0x0f);
4625
+ png_ptr->row_buf = temp - extra - 1/*filter byte*/;
4626
+
4627
+ temp = png_ptr->big_prev_row + 32;
4628
+ extra = (int)((temp - (png_bytep)0) & 0x0f);
4629
+ png_ptr->prev_row = temp - extra - 1/*filter byte*/;
4630
+ }
4631
+
4632
+ #else
4633
+ /* Use 31 bytes of padding before and 17 bytes after row_buf. */
4634
+ png_ptr->row_buf = png_ptr->big_row_buf + 31;
4635
+ png_ptr->prev_row = png_ptr->big_prev_row + 31;
4636
+ #endif
4637
+ png_ptr->old_big_row_buf_size = row_bytes + 48;
4638
+ }
4639
+
4640
+ #ifdef PNG_MAX_MALLOC_64K
4641
+ if (png_ptr->rowbytes > 65535)
4642
+ png_error(png_ptr, "This image requires a row greater than 64KB");
4643
+
4644
+ #endif
4645
+ if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1))
4646
+ png_error(png_ptr, "Row has too many bytes to allocate in memory");
4647
+
4648
+ memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4649
+
4650
+ png_debug1(3, "width = %u,", png_ptr->width);
4651
+ png_debug1(3, "height = %u,", png_ptr->height);
4652
+ png_debug1(3, "iwidth = %u,", png_ptr->iwidth);
4653
+ png_debug1(3, "num_rows = %u,", png_ptr->num_rows);
4654
+ png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes);
4655
+ png_debug1(3, "irowbytes = %lu",
4656
+ (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);
4657
+
4658
+ /* The sequential reader needs a buffer for IDAT, but the progressive reader
4659
+ * does not, so free the read buffer now regardless; the sequential reader
4660
+ * reallocates it on demand.
4661
+ */
4662
+ if (png_ptr->read_buffer != NULL)
4663
+ {
4664
+ png_bytep buffer = png_ptr->read_buffer;
4665
+
4666
+ png_ptr->read_buffer_size = 0;
4667
+ png_ptr->read_buffer = NULL;
4668
+ png_free(png_ptr, buffer);
4669
+ }
4670
+
4671
+ /* Finally claim the zstream for the inflate of the IDAT data, use the bits
4672
+ * value from the stream (note that this will result in a fatal error if the
4673
+ * IDAT stream has a bogus deflate header window_bits value, but this should
4674
+ * not be happening any longer!)
4675
+ */
4676
+ if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK)
4677
+ png_error(png_ptr, png_ptr->zstream.msg);
4678
+
4679
+ png_ptr->flags |= PNG_FLAG_ROW_INIT;
4680
+ }
4681
+ #endif /* READ */