libwz 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.
- package/LICENSE +21 -0
- package/README.md +165 -0
- package/binding.gyp +149 -0
- package/deps/tiny-aes/.github/workflows/c-cpp.yml +27 -0
- package/deps/tiny-aes/CMakeLists.txt +17 -0
- package/deps/tiny-aes/Makefile +61 -0
- package/deps/tiny-aes/README.md +83 -0
- package/deps/tiny-aes/aes.c +572 -0
- package/deps/tiny-aes/aes.h +91 -0
- package/deps/tiny-aes/aes.hpp +12 -0
- package/deps/tiny-aes/conanfile.py +73 -0
- package/deps/tiny-aes/library.json +19 -0
- package/deps/tiny-aes/library.properties +11 -0
- package/deps/tiny-aes/test.c +316 -0
- package/deps/tiny-aes/test.cpp +2 -0
- package/deps/tiny-aes/test_package/CMakeLists.txt +11 -0
- package/deps/tiny-aes/test_package/conanfile.py +17 -0
- package/deps/tiny-aes/unlicense.txt +24 -0
- package/deps/zlib/.cmake-format.yaml +245 -0
- package/deps/zlib/.github/workflows/c-std.yml +268 -0
- package/deps/zlib/.github/workflows/cmake.yml +147 -0
- package/deps/zlib/.github/workflows/configure.yml +146 -0
- package/deps/zlib/.github/workflows/contribs.yml +64 -0
- package/deps/zlib/.github/workflows/fuzz.yml +25 -0
- package/deps/zlib/.github/workflows/msys-cygwin.yml +92 -0
- package/deps/zlib/.github/workflows/others.yml +153 -0
- package/deps/zlib/BUILD.bazel +134 -0
- package/deps/zlib/CMakeLists.txt +310 -0
- package/deps/zlib/ChangeLog +1669 -0
- package/deps/zlib/FAQ +371 -0
- package/deps/zlib/INDEX +67 -0
- package/deps/zlib/LICENSE +22 -0
- package/deps/zlib/MODULE.bazel +9 -0
- package/deps/zlib/Makefile.in +426 -0
- package/deps/zlib/README +115 -0
- package/deps/zlib/README-cmake.md +79 -0
- package/deps/zlib/adler32.c +164 -0
- package/deps/zlib/amiga/Makefile.pup +69 -0
- package/deps/zlib/amiga/Makefile.sas +68 -0
- package/deps/zlib/compress.c +99 -0
- package/deps/zlib/configure +1078 -0
- package/deps/zlib/contrib/CMakeLists.txt +61 -0
- package/deps/zlib/contrib/README.contrib +57 -0
- package/deps/zlib/contrib/ada/CMakeLists.txt +217 -0
- package/deps/zlib/contrib/ada/buffer_demo.adb +106 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeADACompiler.cmake.in +23 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeADAInformation.cmake +133 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeDetermineADACompiler.cmake +33 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeTestADACompiler.cmake +46 -0
- package/deps/zlib/contrib/ada/cmake/binder_helper.cmake +47 -0
- package/deps/zlib/contrib/ada/cmake/compile_helper.cmake +32 -0
- package/deps/zlib/contrib/ada/cmake/exe_link_helper.cmake +53 -0
- package/deps/zlib/contrib/ada/cmake/shared_link_helper.cmake +52 -0
- package/deps/zlib/contrib/ada/cmake/static_link_helper.cmake +25 -0
- package/deps/zlib/contrib/ada/mtest.adb +156 -0
- package/deps/zlib/contrib/ada/read.adb +156 -0
- package/deps/zlib/contrib/ada/readme.txt +65 -0
- package/deps/zlib/contrib/ada/test.adb +463 -0
- package/deps/zlib/contrib/ada/zlib-streams.adb +225 -0
- package/deps/zlib/contrib/ada/zlib-streams.ads +114 -0
- package/deps/zlib/contrib/ada/zlib-thin.adb +142 -0
- package/deps/zlib/contrib/ada/zlib-thin.ads +450 -0
- package/deps/zlib/contrib/ada/zlib.adb +701 -0
- package/deps/zlib/contrib/ada/zlib.ads +328 -0
- package/deps/zlib/contrib/ada/zlib.gpr +20 -0
- package/deps/zlib/contrib/blast/CMakeLists.txt +166 -0
- package/deps/zlib/contrib/blast/Makefile +14 -0
- package/deps/zlib/contrib/blast/README +4 -0
- package/deps/zlib/contrib/blast/blast-test.c +42 -0
- package/deps/zlib/contrib/blast/blast.c +422 -0
- package/deps/zlib/contrib/blast/blast.h +84 -0
- package/deps/zlib/contrib/blast/blastConfig.cmake.in +18 -0
- package/deps/zlib/contrib/blast/test/CMakeLists.txt +193 -0
- package/deps/zlib/contrib/blast/test/add_subdirectory_exclude_test.cmake.in +27 -0
- package/deps/zlib/contrib/blast/test/add_subdirectory_test.cmake.in +25 -0
- package/deps/zlib/contrib/blast/test/find_package_no_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/blast/test/find_package_test.cmake.in +24 -0
- package/deps/zlib/contrib/blast/test/find_package_wrong_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/blast/test.pk +0 -0
- package/deps/zlib/contrib/blast/test.txt +1 -0
- package/deps/zlib/contrib/blast/tester.cmake +28 -0
- package/deps/zlib/contrib/crc32vx/CMakeLists.txt +67 -0
- package/deps/zlib/contrib/crc32vx/README +9 -0
- package/deps/zlib/contrib/crc32vx/crc32_vx.c +254 -0
- package/deps/zlib/contrib/crc32vx/crc32_vx_hooks.h +9 -0
- package/deps/zlib/contrib/delphi/ZLib.pas +557 -0
- package/deps/zlib/contrib/delphi/ZLibConst.pas +11 -0
- package/deps/zlib/contrib/delphi/readme.txt +76 -0
- package/deps/zlib/contrib/delphi/zlibd32.mak +99 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs +58 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs +202 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs +83 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/CodecBase.cs +198 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/Deflater.cs +106 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.cs +288 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj +141 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/GZipStream.cs +301 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/Inflater.cs +105 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/UnitTests.cs +274 -0
- package/deps/zlib/contrib/dotzlib/DotZLib.build +33 -0
- package/deps/zlib/contrib/dotzlib/DotZLib.chm +0 -0
- package/deps/zlib/contrib/dotzlib/DotZLib.sln +21 -0
- package/deps/zlib/contrib/dotzlib/LICENSE_1_0.txt +23 -0
- package/deps/zlib/contrib/dotzlib/readme.txt +58 -0
- package/deps/zlib/contrib/gcc_gvmat64/CMakeLists.txt +19 -0
- package/deps/zlib/contrib/gcc_gvmat64/gvmat64.S +570 -0
- package/deps/zlib/contrib/infback9/CMakeLists.txt +19 -0
- package/deps/zlib/contrib/infback9/README +1 -0
- package/deps/zlib/contrib/infback9/infback9.c +603 -0
- package/deps/zlib/contrib/infback9/infback9.h +37 -0
- package/deps/zlib/contrib/infback9/inffix9.h +107 -0
- package/deps/zlib/contrib/infback9/inflate9.h +47 -0
- package/deps/zlib/contrib/infback9/inftree9.c +319 -0
- package/deps/zlib/contrib/infback9/inftree9.h +61 -0
- package/deps/zlib/contrib/iostream/test.cpp +24 -0
- package/deps/zlib/contrib/iostream/zfstream.cpp +329 -0
- package/deps/zlib/contrib/iostream/zfstream.h +128 -0
- package/deps/zlib/contrib/iostream2/zstream.h +306 -0
- package/deps/zlib/contrib/iostream2/zstream_test.cpp +25 -0
- package/deps/zlib/contrib/iostream3/CMakeLists.txt +200 -0
- package/deps/zlib/contrib/iostream3/README +35 -0
- package/deps/zlib/contrib/iostream3/TODO +17 -0
- package/deps/zlib/contrib/iostream3/iostream3Config.cmake.in +23 -0
- package/deps/zlib/contrib/iostream3/test/CMakeLists.txt +191 -0
- package/deps/zlib/contrib/iostream3/test/add_subdirectory_exclude_test.cmake.in +27 -0
- package/deps/zlib/contrib/iostream3/test/add_subdirectory_test.cmake.in +25 -0
- package/deps/zlib/contrib/iostream3/test/find_package_no_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/iostream3/test/find_package_test.cmake.in +24 -0
- package/deps/zlib/contrib/iostream3/test/find_package_wrong_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/iostream3/test.cc +50 -0
- package/deps/zlib/contrib/iostream3/zfstream.cc +479 -0
- package/deps/zlib/contrib/iostream3/zfstream.h +466 -0
- package/deps/zlib/contrib/minizip/CMakeLists.txt +387 -0
- package/deps/zlib/contrib/minizip/LICENSE.Info-Zip +58 -0
- package/deps/zlib/contrib/minizip/Makefile +33 -0
- package/deps/zlib/contrib/minizip/Makefile.am +45 -0
- package/deps/zlib/contrib/minizip/MiniZip64_Changes.txt +6 -0
- package/deps/zlib/contrib/minizip/MiniZip64_info.txt +69 -0
- package/deps/zlib/contrib/minizip/configure.ac +32 -0
- package/deps/zlib/contrib/minizip/crypt.h +125 -0
- package/deps/zlib/contrib/minizip/ints.h +57 -0
- package/deps/zlib/contrib/minizip/ioapi.c +231 -0
- package/deps/zlib/contrib/minizip/ioapi.h +183 -0
- package/deps/zlib/contrib/minizip/iowin32.c +447 -0
- package/deps/zlib/contrib/minizip/iowin32.h +27 -0
- package/deps/zlib/contrib/minizip/make_vms.com +25 -0
- package/deps/zlib/contrib/minizip/miniunz.c +647 -0
- package/deps/zlib/contrib/minizip/miniunzip.1 +63 -0
- package/deps/zlib/contrib/minizip/minizip.1 +46 -0
- package/deps/zlib/contrib/minizip/minizip.c +511 -0
- package/deps/zlib/contrib/minizip/minizip.pc.in +13 -0
- package/deps/zlib/contrib/minizip/minizip.pc.txt +13 -0
- package/deps/zlib/contrib/minizip/minizipConfig.cmake.in +27 -0
- package/deps/zlib/contrib/minizip/mztools.c +294 -0
- package/deps/zlib/contrib/minizip/mztools.h +37 -0
- package/deps/zlib/contrib/minizip/skipset.h +366 -0
- package/deps/zlib/contrib/minizip/test/CMakeLists.txt +176 -0
- package/deps/zlib/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in +29 -0
- package/deps/zlib/contrib/minizip/test/add_subdirectory_test.cmake.in +28 -0
- package/deps/zlib/contrib/minizip/test/find_package_no_components_test.cmake.in +26 -0
- package/deps/zlib/contrib/minizip/test/find_package_test.cmake.in +26 -0
- package/deps/zlib/contrib/minizip/test/find_package_wrong_components_test.cmake.in +26 -0
- package/deps/zlib/contrib/minizip/test/test_helper.cm +32 -0
- package/deps/zlib/contrib/minizip/unzip.c +1984 -0
- package/deps/zlib/contrib/minizip/unzip.h +442 -0
- package/deps/zlib/contrib/minizip/zip.c +2246 -0
- package/deps/zlib/contrib/minizip/zip.h +371 -0
- package/deps/zlib/contrib/nuget/nuget.csproj +45 -0
- package/deps/zlib/contrib/nuget/nuget.sln +22 -0
- package/deps/zlib/contrib/pascal/example.pas +599 -0
- package/deps/zlib/contrib/pascal/readme.txt +76 -0
- package/deps/zlib/contrib/pascal/zlibd32.mak +99 -0
- package/deps/zlib/contrib/pascal/zlibpas.pas +276 -0
- package/deps/zlib/contrib/puff/CMakeLists.txt +154 -0
- package/deps/zlib/contrib/puff/Makefile +42 -0
- package/deps/zlib/contrib/puff/README +63 -0
- package/deps/zlib/contrib/puff/bin-writer.c +26 -0
- package/deps/zlib/contrib/puff/puff.c +840 -0
- package/deps/zlib/contrib/puff/puff.h +35 -0
- package/deps/zlib/contrib/puff/puffConfig.cmake.in +18 -0
- package/deps/zlib/contrib/puff/pufftest.c +168 -0
- package/deps/zlib/contrib/puff/test/CMakeLists.txt +262 -0
- package/deps/zlib/contrib/puff/test/add_subdirectory_exclude_test.cmake.in +26 -0
- package/deps/zlib/contrib/puff/test/add_subdirectory_test.cmake.in +25 -0
- package/deps/zlib/contrib/puff/test/find_package_no_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/puff/test/find_package_test.cmake.in +24 -0
- package/deps/zlib/contrib/puff/test/find_package_wrong_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/puff/test/tester-cov.cmake +58 -0
- package/deps/zlib/contrib/puff/test/tester.cmake +16 -0
- package/deps/zlib/contrib/puff/zeros.raw +0 -0
- package/deps/zlib/contrib/testzlib/CMakeLists.txt +44 -0
- package/deps/zlib/contrib/testzlib/testzlib.c +275 -0
- package/deps/zlib/contrib/testzlib/testzlib.txt +10 -0
- package/deps/zlib/contrib/vstudio/readme.txt +22 -0
- package/deps/zlib/contrib/zlib1-dll/CMakeLists.txt +196 -0
- package/deps/zlib/contrib/zlib1-dll/readme.txt +21 -0
- package/deps/zlib/crc32.c +983 -0
- package/deps/zlib/crc32.h +9446 -0
- package/deps/zlib/deflate.c +2185 -0
- package/deps/zlib/deflate.h +383 -0
- package/deps/zlib/doc/algorithm.txt +209 -0
- package/deps/zlib/doc/crc-doc.1.0.pdf +0 -0
- package/deps/zlib/doc/rfc1950.txt +619 -0
- package/deps/zlib/doc/rfc1951.txt +955 -0
- package/deps/zlib/doc/rfc1952.txt +675 -0
- package/deps/zlib/doc/txtvsbin.txt +107 -0
- package/deps/zlib/examples/README.examples +54 -0
- package/deps/zlib/examples/enough.c +597 -0
- package/deps/zlib/examples/fitblk.c +233 -0
- package/deps/zlib/examples/gun.c +702 -0
- package/deps/zlib/examples/gzappend.c +504 -0
- package/deps/zlib/examples/gzjoin.c +449 -0
- package/deps/zlib/examples/gzlog.c +1061 -0
- package/deps/zlib/examples/gzlog.h +91 -0
- package/deps/zlib/examples/gznorm.c +474 -0
- package/deps/zlib/examples/zlib_how.html +550 -0
- package/deps/zlib/examples/zpipe.c +206 -0
- package/deps/zlib/examples/zran.c +546 -0
- package/deps/zlib/examples/zran.h +53 -0
- package/deps/zlib/gzclose.c +23 -0
- package/deps/zlib/gzguts.h +216 -0
- package/deps/zlib/gzlib.c +609 -0
- package/deps/zlib/gzread.c +668 -0
- package/deps/zlib/gzwrite.c +700 -0
- package/deps/zlib/infback.c +581 -0
- package/deps/zlib/inffast.c +321 -0
- package/deps/zlib/inffast.h +11 -0
- package/deps/zlib/inffixed.h +94 -0
- package/deps/zlib/inflate.c +1413 -0
- package/deps/zlib/inflate.h +126 -0
- package/deps/zlib/inftrees.c +424 -0
- package/deps/zlib/inftrees.h +64 -0
- package/deps/zlib/make_vms.com +867 -0
- package/deps/zlib/msdos/Makefile.bor +115 -0
- package/deps/zlib/msdos/Makefile.dj2 +104 -0
- package/deps/zlib/msdos/Makefile.emx +69 -0
- package/deps/zlib/msdos/Makefile.msc +112 -0
- package/deps/zlib/msdos/Makefile.tc +100 -0
- package/deps/zlib/os400/README400 +48 -0
- package/deps/zlib/os400/bndsrc +144 -0
- package/deps/zlib/os400/make.sh +383 -0
- package/deps/zlib/os400/zlibfixed.rpgle +578 -0
- package/deps/zlib/os400/zlibfree.rpgle +634 -0
- package/deps/zlib/qnx/package.qpg +141 -0
- package/deps/zlib/test/CMakeLists.txt +318 -0
- package/deps/zlib/test/add_subdirectory_exclude_test.cmake.in +29 -0
- package/deps/zlib/test/add_subdirectory_test.cmake.in +28 -0
- package/deps/zlib/test/example.c +552 -0
- package/deps/zlib/test/find_package_no_components_test.cmake.in +27 -0
- package/deps/zlib/test/find_package_test.cmake.in +27 -0
- package/deps/zlib/test/find_package_wrong_components_test.cmake.in +27 -0
- package/deps/zlib/test/infcover.c +672 -0
- package/deps/zlib/test/minigzip.c +592 -0
- package/deps/zlib/treebuild.xml +116 -0
- package/deps/zlib/trees.c +1119 -0
- package/deps/zlib/trees.h +128 -0
- package/deps/zlib/uncompr.c +101 -0
- package/deps/zlib/watcom/watcom_f.mak +43 -0
- package/deps/zlib/watcom/watcom_l.mak +43 -0
- package/deps/zlib/win32/DLL_FAQ.txt +381 -0
- package/deps/zlib/win32/Makefile.bor +109 -0
- package/deps/zlib/win32/Makefile.gcc +177 -0
- package/deps/zlib/win32/Makefile.msc +159 -0
- package/deps/zlib/win32/README-WIN32.txt +103 -0
- package/deps/zlib/win32/VisualC.txt +3 -0
- package/deps/zlib/win32/zlib.def +104 -0
- package/deps/zlib/win32/zlib1.rc +37 -0
- package/deps/zlib/zconf.h.in +551 -0
- package/deps/zlib/zlib.3 +149 -0
- package/deps/zlib/zlib.3.pdf +0 -0
- package/deps/zlib/zlib.h +2057 -0
- package/deps/zlib/zlib.map +116 -0
- package/deps/zlib/zlib.pc.cmakein +14 -0
- package/deps/zlib/zlib.pc.in +14 -0
- package/deps/zlib/zlibConfig.cmake.in +18 -0
- package/deps/zlib/zutil.c +313 -0
- package/deps/zlib/zutil.h +331 -0
- package/dist/index.d.ts +266 -0
- package/dist/index.js +1146 -0
- package/dist/libwz.js +5632 -0
- package/dist/libwz.wasm +0 -0
- package/include/wz/CRC32.h +182 -0
- package/include/wz/PngUtility.h +72 -0
- package/include/wz/PortalType.h +124 -0
- package/include/wz/Properties/WzBinaryProperty.h +70 -0
- package/include/wz/Properties/WzCanvasProperty.h +55 -0
- package/include/wz/Properties/WzConvexProperty.h +34 -0
- package/include/wz/Properties/WzDoubleProperty.h +32 -0
- package/include/wz/Properties/WzFloatProperty.h +30 -0
- package/include/wz/Properties/WzIntProperty.h +30 -0
- package/include/wz/Properties/WzLongProperty.h +30 -0
- package/include/wz/Properties/WzLuaProperty.h +31 -0
- package/include/wz/Properties/WzNullProperty.h +15 -0
- package/include/wz/Properties/WzPngProperty.h +53 -0
- package/include/wz/Properties/WzRawDataProperty.h +46 -0
- package/include/wz/Properties/WzShortProperty.h +31 -0
- package/include/wz/Properties/WzStringProperty.h +32 -0
- package/include/wz/Properties/WzSubProperty.h +35 -0
- package/include/wz/Properties/WzUOLProperty.h +44 -0
- package/include/wz/Properties/WzVectorProperty.h +40 -0
- package/include/wz/Properties/WzVideoProperty.h +43 -0
- package/include/wz/Result.h +58 -0
- package/include/wz/Util/Defines.h +16 -0
- package/include/wz/Util/ListFileParser.h +20 -0
- package/include/wz/Util/WzBinaryReader.h +95 -0
- package/include/wz/Util/WzBinaryWriter.h +72 -0
- package/include/wz/Util/WzBlobDataSource.h +30 -0
- package/include/wz/Util/WzDataSource.h +49 -0
- package/include/wz/Util/WzKeyGenerator.h +28 -0
- package/include/wz/Util/WzMutableKey.h +39 -0
- package/include/wz/Util/WzPath.h +37 -0
- package/include/wz/Util/WzStream.h +86 -0
- package/include/wz/Util/WzTool.h +42 -0
- package/include/wz/WzAESConstant.h +17 -0
- package/include/wz/WzDirectory.h +97 -0
- package/include/wz/WzEnums.h +76 -0
- package/include/wz/WzFile.h +99 -0
- package/include/wz/WzHeader.h +47 -0
- package/include/wz/WzImage.h +97 -0
- package/include/wz/WzImageProperty.h +92 -0
- package/include/wz/WzObject.h +55 -0
- package/include/wz/WzPropertyCollection.h +115 -0
- package/include/wz/wz.h +41 -0
- package/include/wz/wz_api.h +432 -0
- package/package.json +93 -0
- package/src/PngUtility.cpp +328 -0
- package/src/Properties/WzBinaryProperty.cpp +183 -0
- package/src/Properties/WzCanvasProperty.cpp +262 -0
- package/src/Properties/WzConvexProperty.cpp +159 -0
- package/src/Properties/WzDoubleProperty.cpp +12 -0
- package/src/Properties/WzFloatProperty.cpp +17 -0
- package/src/Properties/WzIntProperty.cpp +12 -0
- package/src/Properties/WzLongProperty.cpp +12 -0
- package/src/Properties/WzLuaProperty.cpp +37 -0
- package/src/Properties/WzNullProperty.cpp +11 -0
- package/src/Properties/WzPngProperty.cpp +637 -0
- package/src/Properties/WzRawDataProperty.cpp +116 -0
- package/src/Properties/WzShortProperty.cpp +12 -0
- package/src/Properties/WzStringProperty.cpp +44 -0
- package/src/Properties/WzSubProperty.cpp +129 -0
- package/src/Properties/WzUOLProperty.cpp +136 -0
- package/src/Properties/WzVectorProperty.cpp +22 -0
- package/src/Properties/WzVideoProperty.cpp +115 -0
- package/src/Util/ListFileParser.cpp +48 -0
- package/src/Util/WzBinaryReader.cpp +368 -0
- package/src/Util/WzBinaryWriter.cpp +305 -0
- package/src/Util/WzBlobDataSource.cpp +47 -0
- package/src/Util/WzDataSource.cpp +61 -0
- package/src/Util/WzKeyGenerator.cpp +43 -0
- package/src/Util/WzMutableKey.cpp +59 -0
- package/src/Util/WzStream.cpp +196 -0
- package/src/Util/WzTool.cpp +266 -0
- package/src/WzAESConstant.cpp +12 -0
- package/src/WzDirectory.cpp +669 -0
- package/src/WzEnums.cpp +20 -0
- package/src/WzFile.cpp +450 -0
- package/src/WzImage.cpp +350 -0
- package/src/WzImageProperty.cpp +469 -0
- package/src/WzObject.cpp +174 -0
- package/src/WzPropertyCollection.cpp +84 -0
- package/src/capi/wz_api.cpp +1996 -0
- package/src/node/binding.cpp +1776 -0
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
#include "wz/Properties/WzPngProperty.h"
|
|
2
|
+
#include <zlib.h>
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <array>
|
|
5
|
+
#include <cstring>
|
|
6
|
+
#include <filesystem>
|
|
7
|
+
#include <mutex>
|
|
8
|
+
#include "wz/PngUtility.h"
|
|
9
|
+
#include "wz/Util/WzBinaryReader.h"
|
|
10
|
+
#include "wz/Util/WzPath.h"
|
|
11
|
+
#include "wz/Util/WzStream.h"
|
|
12
|
+
#include "wz/WzImage.h"
|
|
13
|
+
|
|
14
|
+
namespace wz {
|
|
15
|
+
|
|
16
|
+
namespace {
|
|
17
|
+
|
|
18
|
+
static const std::array<uint32_t, 256>& PngCrc32Table() {
|
|
19
|
+
static const std::array<uint32_t, 256> table = [] {
|
|
20
|
+
std::array<uint32_t, 256> result{};
|
|
21
|
+
for (uint32_t i = 0; i < result.size(); i++) {
|
|
22
|
+
uint32_t crc = i;
|
|
23
|
+
for (int j = 0; j < 8; j++)
|
|
24
|
+
crc = (crc >> 1) ^ ((crc & 1) ? 0xEDB88320u : 0);
|
|
25
|
+
result[i] = crc;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}();
|
|
29
|
+
return table;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static uint32_t PngCrc32(const uint8_t* data, size_t len) {
|
|
33
|
+
const auto& table = PngCrc32Table();
|
|
34
|
+
uint32_t crc = 0xFFFFFFFFu;
|
|
35
|
+
for (size_t i = 0; i < len; i++)
|
|
36
|
+
crc = table[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);
|
|
37
|
+
return crc ^ 0xFFFFFFFFu;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static uint32_t ToBigEndian32(uint32_t x) {
|
|
41
|
+
return ((x & 0x000000FFu) << 24) | ((x & 0x0000FF00u) << 8) |
|
|
42
|
+
((x & 0x00FF0000u) >> 8) | ((x & 0xFF000000u) >> 24);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static bool WritePngChunk(WzFileStream* out,
|
|
46
|
+
const char type[4],
|
|
47
|
+
const uint8_t* data,
|
|
48
|
+
uint32_t len) {
|
|
49
|
+
uint32_t beLen = ToBigEndian32(len);
|
|
50
|
+
if (!out->Write(&beLen, 4)) return false;
|
|
51
|
+
if (!out->Write(type, 4)) return false;
|
|
52
|
+
if (len > 0 && !out->Write(data, len)) return false;
|
|
53
|
+
|
|
54
|
+
std::vector<uint8_t> crcInput(4 + len);
|
|
55
|
+
std::memcpy(crcInput.data(), type, 4);
|
|
56
|
+
if (len > 0) std::memcpy(crcInput.data() + 4, data, len);
|
|
57
|
+
uint32_t crc = PngCrc32(crcInput.data(), 4 + len);
|
|
58
|
+
uint32_t beCrc = ToBigEndian32(crc);
|
|
59
|
+
return out->Write(&beCrc, 4);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static uint32_t ReadBigEndian32(const uint8_t* p) {
|
|
63
|
+
return (static_cast<uint32_t>(p[0]) << 24) |
|
|
64
|
+
(static_cast<uint32_t>(p[1]) << 16) |
|
|
65
|
+
(static_cast<uint32_t>(p[2]) << 8) | static_cast<uint32_t>(p[3]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static uint8_t PaethPredictor(uint8_t left, uint8_t up, uint8_t upLeft) {
|
|
69
|
+
int p = static_cast<int>(left) + static_cast<int>(up) -
|
|
70
|
+
static_cast<int>(upLeft);
|
|
71
|
+
int pa = std::abs(p - static_cast<int>(left));
|
|
72
|
+
int pb = std::abs(p - static_cast<int>(up));
|
|
73
|
+
int pc = std::abs(p - static_cast<int>(upLeft));
|
|
74
|
+
if (pa <= pb && pa <= pc) return left;
|
|
75
|
+
if (pb <= pc) return up;
|
|
76
|
+
return upLeft;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static Result<std::vector<uint8_t>> InflatePngData(
|
|
80
|
+
const std::vector<uint8_t>& compressed,
|
|
81
|
+
size_t expectedSize) {
|
|
82
|
+
std::vector<uint8_t> result(expectedSize);
|
|
83
|
+
z_stream zs = {};
|
|
84
|
+
zs.next_in = const_cast<Bytef*>(compressed.data()); // NOLINT
|
|
85
|
+
zs.avail_in = static_cast<uInt>(compressed.size());
|
|
86
|
+
zs.next_out = result.data();
|
|
87
|
+
zs.avail_out = static_cast<uInt>(result.size());
|
|
88
|
+
|
|
89
|
+
if (inflateInit(&zs) != Z_OK)
|
|
90
|
+
return std::unexpected(Error::DataError("inflateInit failed"));
|
|
91
|
+
|
|
92
|
+
int ret = inflate(&zs, Z_FINISH);
|
|
93
|
+
inflateEnd(&zs);
|
|
94
|
+
if (ret != Z_STREAM_END || zs.total_out != expectedSize)
|
|
95
|
+
return std::unexpected(Error::DataError("PNG inflate failed"));
|
|
96
|
+
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
} // namespace
|
|
101
|
+
|
|
102
|
+
WzPngProperty::WzPngProperty() = default;
|
|
103
|
+
|
|
104
|
+
Result<std::unique_ptr<WzPngProperty>> WzPngProperty::FromPngFile(
|
|
105
|
+
const std::string& filePath) {
|
|
106
|
+
auto inputPath = wz::to_path(filePath);
|
|
107
|
+
WzFileStream in(inputPath, "rb");
|
|
108
|
+
if (!in.IsOpen())
|
|
109
|
+
return std::unexpected(Error::IoError("Failed to open PNG file"));
|
|
110
|
+
|
|
111
|
+
const int64_t inputSize = in.Size();
|
|
112
|
+
if (inputSize < 0)
|
|
113
|
+
return std::unexpected(Error::IoError("Failed to get PNG file size"));
|
|
114
|
+
std::vector<uint8_t> png(static_cast<size_t>(inputSize));
|
|
115
|
+
if (!png.empty() && in.Read(png.data(), png.size()) != png.size())
|
|
116
|
+
return std::unexpected(Error::IoError("Failed to read PNG file"));
|
|
117
|
+
static const uint8_t signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
|
118
|
+
if (png.size() < 33 || std::memcmp(png.data(), signature, 8) != 0)
|
|
119
|
+
return std::unexpected(Error::DataError("Invalid PNG signature"));
|
|
120
|
+
|
|
121
|
+
int width = 0;
|
|
122
|
+
int height = 0;
|
|
123
|
+
uint8_t bitDepth = 0;
|
|
124
|
+
uint8_t colorType = 0;
|
|
125
|
+
std::vector<uint8_t> idat;
|
|
126
|
+
|
|
127
|
+
size_t pos = 8;
|
|
128
|
+
while (pos + 8 <= png.size()) {
|
|
129
|
+
uint32_t len = ReadBigEndian32(png.data() + pos);
|
|
130
|
+
pos += 4;
|
|
131
|
+
if (pos + 4 + len + 4 > png.size())
|
|
132
|
+
return std::unexpected(Error::DataError("Truncated PNG chunk"));
|
|
133
|
+
|
|
134
|
+
const uint8_t* type = png.data() + pos;
|
|
135
|
+
pos += 4;
|
|
136
|
+
const uint8_t* data = png.data() + pos;
|
|
137
|
+
|
|
138
|
+
if (std::memcmp(type, "IHDR", 4) == 0) {
|
|
139
|
+
if (len != 13)
|
|
140
|
+
return std::unexpected(Error::DataError("Invalid PNG IHDR"));
|
|
141
|
+
width = static_cast<int>(ReadBigEndian32(data));
|
|
142
|
+
height = static_cast<int>(ReadBigEndian32(data + 4));
|
|
143
|
+
bitDepth = data[8];
|
|
144
|
+
colorType = data[9];
|
|
145
|
+
if (data[10] != 0 || data[11] != 0 || data[12] != 0)
|
|
146
|
+
return std::unexpected(
|
|
147
|
+
Error::DataError("Unsupported PNG compression/filter/interlace"));
|
|
148
|
+
} else if (std::memcmp(type, "IDAT", 4) == 0) {
|
|
149
|
+
idat.insert(idat.end(), data, data + len);
|
|
150
|
+
} else if (std::memcmp(type, "IEND", 4) == 0) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
pos += len + 4; // skip data and CRC
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (width <= 0 || height <= 0 || idat.empty())
|
|
158
|
+
return std::unexpected(Error::DataError("PNG image is empty"));
|
|
159
|
+
if (bitDepth != 8 || (colorType != 6 && colorType != 2))
|
|
160
|
+
return std::unexpected(
|
|
161
|
+
Error::DataError("Only 8-bit RGB/RGBA PNG files are supported"));
|
|
162
|
+
|
|
163
|
+
const size_t channels = colorType == 6 ? 4 : 3;
|
|
164
|
+
const size_t rowSize = static_cast<size_t>(width) * channels;
|
|
165
|
+
const size_t inflatedSize = static_cast<size_t>(height) * (rowSize + 1);
|
|
166
|
+
auto inflatedResult = InflatePngData(idat, inflatedSize);
|
|
167
|
+
if (!inflatedResult.has_value())
|
|
168
|
+
return std::unexpected(inflatedResult.error());
|
|
169
|
+
auto& inflated = inflatedResult.value();
|
|
170
|
+
|
|
171
|
+
std::vector<uint8_t> bgra(static_cast<size_t>(width) * height * 4);
|
|
172
|
+
std::vector<uint8_t> previous(rowSize, 0);
|
|
173
|
+
std::vector<uint8_t> current(rowSize, 0);
|
|
174
|
+
size_t sourceOffset = 0;
|
|
175
|
+
|
|
176
|
+
for (int y = 0; y < height; y++) {
|
|
177
|
+
uint8_t filter = inflated[sourceOffset++];
|
|
178
|
+
const uint8_t* scanline = inflated.data() + sourceOffset;
|
|
179
|
+
sourceOffset += rowSize;
|
|
180
|
+
|
|
181
|
+
for (size_t x = 0; x < rowSize; x++) {
|
|
182
|
+
uint8_t left = x >= channels ? current[x - channels] : 0;
|
|
183
|
+
uint8_t up = previous[x];
|
|
184
|
+
uint8_t upLeft = x >= channels ? previous[x - channels] : 0;
|
|
185
|
+
uint8_t value = scanline[x];
|
|
186
|
+
switch (filter) {
|
|
187
|
+
case 0:
|
|
188
|
+
break;
|
|
189
|
+
case 1:
|
|
190
|
+
value = static_cast<uint8_t>(value + left);
|
|
191
|
+
break;
|
|
192
|
+
case 2:
|
|
193
|
+
value = static_cast<uint8_t>(value + up);
|
|
194
|
+
break;
|
|
195
|
+
case 3:
|
|
196
|
+
value = static_cast<uint8_t>(
|
|
197
|
+
value + static_cast<uint8_t>((static_cast<int>(left) +
|
|
198
|
+
static_cast<int>(up)) /
|
|
199
|
+
2));
|
|
200
|
+
break;
|
|
201
|
+
case 4:
|
|
202
|
+
value = static_cast<uint8_t>(
|
|
203
|
+
value + PaethPredictor(left, up, upLeft));
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
return std::unexpected(Error::DataError("Unsupported PNG filter"));
|
|
207
|
+
}
|
|
208
|
+
current[x] = value;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
for (int x = 0; x < width; x++) {
|
|
212
|
+
size_t src = static_cast<size_t>(x) * channels;
|
|
213
|
+
size_t dst = (static_cast<size_t>(y) * width + x) * 4;
|
|
214
|
+
bgra[dst] = current[src + 2];
|
|
215
|
+
bgra[dst + 1] = current[src + 1];
|
|
216
|
+
bgra[dst + 2] = current[src];
|
|
217
|
+
bgra[dst + 3] = channels == 4 ? current[src + 3] : 255;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
std::swap(previous, current);
|
|
221
|
+
std::fill(current.begin(), current.end(), 0);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
uLongf compressedSize = compressBound(static_cast<uLong>(bgra.size()));
|
|
225
|
+
std::vector<uint8_t> compressed(compressedSize);
|
|
226
|
+
if (compress2(compressed.data(),
|
|
227
|
+
&compressedSize,
|
|
228
|
+
bgra.data(),
|
|
229
|
+
static_cast<uLong>(bgra.size()),
|
|
230
|
+
Z_DEFAULT_COMPRESSION) != Z_OK) {
|
|
231
|
+
return std::unexpected(Error::DataError("PNG recompress failed"));
|
|
232
|
+
}
|
|
233
|
+
compressed.resize(compressedSize);
|
|
234
|
+
|
|
235
|
+
auto property = std::make_unique<WzPngProperty>();
|
|
236
|
+
property->width_ = width;
|
|
237
|
+
property->height_ = height;
|
|
238
|
+
property->format_ = WzPngFormat::Format2;
|
|
239
|
+
property->compressedImageBytes_ = std::move(compressed);
|
|
240
|
+
property->pngData_ = std::move(bgra);
|
|
241
|
+
property->listWzUsed_ = false;
|
|
242
|
+
return property;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
WzPngProperty::WzPngProperty(WzBinaryReader* reader, bool parseNow)
|
|
246
|
+
: wzReader_(reader) {
|
|
247
|
+
width_ = reader->ReadCompressedInt();
|
|
248
|
+
height_ = reader->ReadCompressedInt();
|
|
249
|
+
|
|
250
|
+
int format1 = reader->ReadCompressedInt();
|
|
251
|
+
int format2 = reader->ReadCompressedInt();
|
|
252
|
+
format_ = static_cast<WzPngFormat>(format1 + (format2 << 8));
|
|
253
|
+
|
|
254
|
+
reader->SetPosition(reader->Position() + 4);
|
|
255
|
+
offs_ = reader->Position();
|
|
256
|
+
int len = reader->ReadInt32() - 1;
|
|
257
|
+
reader->ReadByte(); // skip 1
|
|
258
|
+
|
|
259
|
+
if (len > 0) {
|
|
260
|
+
if (parseNow) {
|
|
261
|
+
compressedImageBytes_ = wzReader_->ReadBytes(len);
|
|
262
|
+
auto parseResult = ParsePng(true);
|
|
263
|
+
(void)parseResult;
|
|
264
|
+
} else {
|
|
265
|
+
reader->SetPosition(reader->Position() + len);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
int WzPngProperty::GetUncompressedSize() const {
|
|
271
|
+
switch (format_) {
|
|
272
|
+
case WzPngFormat::Format1:
|
|
273
|
+
return width_ * height_ * 2;
|
|
274
|
+
case WzPngFormat::Format2:
|
|
275
|
+
return width_ * height_ * 4;
|
|
276
|
+
case WzPngFormat::Format3:
|
|
277
|
+
return width_ * height_ * 4;
|
|
278
|
+
case WzPngFormat::Format257:
|
|
279
|
+
return width_ * height_ * 2;
|
|
280
|
+
case WzPngFormat::Format513:
|
|
281
|
+
return width_ * height_ * 2;
|
|
282
|
+
case WzPngFormat::Format517:
|
|
283
|
+
return width_ * height_ / 128;
|
|
284
|
+
case WzPngFormat::Format1026:
|
|
285
|
+
return width_ * height_ * 4;
|
|
286
|
+
case WzPngFormat::Format2050:
|
|
287
|
+
return width_ * height_;
|
|
288
|
+
default:
|
|
289
|
+
return width_ * height_ * 4;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
Result<std::vector<uint8_t>> WzPngProperty::GetCompressedBytes(
|
|
294
|
+
bool saveInMemory) {
|
|
295
|
+
std::unique_lock<std::recursive_mutex> lock;
|
|
296
|
+
if (wzReader_)
|
|
297
|
+
lock = std::unique_lock<std::recursive_mutex>(wzReader_->Mutex());
|
|
298
|
+
if (compressedImageBytes_.empty()) {
|
|
299
|
+
if (!wzReader_) {
|
|
300
|
+
return std::unexpected(
|
|
301
|
+
Error::DataError("No reader for compressed bytes"));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
auto pos = wzReader_->Position();
|
|
305
|
+
wzReader_->SetPosition(offs_);
|
|
306
|
+
int len = wzReader_->ReadInt32() - 1;
|
|
307
|
+
wzReader_->ReadByte(); // skip 1
|
|
308
|
+
|
|
309
|
+
if (len <= 0)
|
|
310
|
+
return std::unexpected(
|
|
311
|
+
Error::DataError("The length of the image is negative. Wrong WzIV?"));
|
|
312
|
+
|
|
313
|
+
compressedImageBytes_ = wzReader_->ReadBytes(len);
|
|
314
|
+
wzReader_->SetPosition(pos);
|
|
315
|
+
|
|
316
|
+
if (!saveInMemory) {
|
|
317
|
+
auto result = compressedImageBytes_;
|
|
318
|
+
compressedImageBytes_.clear();
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return compressedImageBytes_;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
Result<std::vector<uint8_t>> WzPngProperty::GetRawImage(bool saveInMemory) {
|
|
326
|
+
auto rawImageBytes = GetCompressedBytes(saveInMemory);
|
|
327
|
+
if (!rawImageBytes.has_value()) return std::unexpected(rawImageBytes.error());
|
|
328
|
+
auto& rawBytes = rawImageBytes.value();
|
|
329
|
+
if (rawBytes.size() < 2)
|
|
330
|
+
return std::unexpected(Error::DataError("Raw image too small"));
|
|
331
|
+
|
|
332
|
+
uint16_t header = rawBytes[0] | (static_cast<uint16_t>(rawBytes[1]) << 8);
|
|
333
|
+
bool isListWz = (header != 0x9C78 && header != 0xDA78 && header != 0x0178 &&
|
|
334
|
+
header != 0x5E78);
|
|
335
|
+
listWzUsed_ = isListWz;
|
|
336
|
+
|
|
337
|
+
if (!isListWz) {
|
|
338
|
+
z_stream infstream;
|
|
339
|
+
std::vector<uint8_t> result(GetUncompressedSize());
|
|
340
|
+
infstream.zalloc = Z_NULL;
|
|
341
|
+
infstream.zfree = Z_NULL;
|
|
342
|
+
infstream.opaque = Z_NULL;
|
|
343
|
+
infstream.avail_in = (uInt)rawBytes.size(); // size of input
|
|
344
|
+
infstream.next_in = (Bytef*)rawBytes.data(); // input char array NOLINT
|
|
345
|
+
infstream.avail_out = (uInt)result.size(); // size of output
|
|
346
|
+
infstream.next_out = (Bytef*)result.data(); // output char array NOLINT
|
|
347
|
+
|
|
348
|
+
inflateInit(&infstream);
|
|
349
|
+
int r = inflate(&infstream, Z_NO_FLUSH);
|
|
350
|
+
inflateEnd(&infstream);
|
|
351
|
+
if (r == Z_OK || r == Z_STREAM_END) return result;
|
|
352
|
+
return std::unexpected(Error::DataError("inflate failed"));
|
|
353
|
+
} else {
|
|
354
|
+
// List.wz format - decrypt then decompress
|
|
355
|
+
if (!wzReader_)
|
|
356
|
+
return std::unexpected(
|
|
357
|
+
Error::DataError("No reader for list.wz decompression"));
|
|
358
|
+
|
|
359
|
+
std::vector<uint8_t> decryptedData;
|
|
360
|
+
size_t pos = 0;
|
|
361
|
+
std::lock_guard<std::recursive_mutex> lock(wzReader_->Mutex());
|
|
362
|
+
auto& wzKey = wzReader_->GetWzKey();
|
|
363
|
+
|
|
364
|
+
while (pos < rawBytes.size()) {
|
|
365
|
+
int32_t blockSize =
|
|
366
|
+
*reinterpret_cast<const int32_t*>(rawBytes.data() + pos);
|
|
367
|
+
pos += 4;
|
|
368
|
+
for (int i = 0; i < blockSize && pos < rawBytes.size(); i++, pos++) {
|
|
369
|
+
decryptedData.push_back(rawBytes[pos] ^ wzKey[i]);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (decryptedData.size() < 3)
|
|
374
|
+
return std::unexpected(Error::DataError("Decrypted data too small"));
|
|
375
|
+
|
|
376
|
+
z_stream infstream;
|
|
377
|
+
std::vector<uint8_t> result(GetUncompressedSize());
|
|
378
|
+
infstream.zalloc = Z_NULL;
|
|
379
|
+
infstream.zfree = Z_NULL;
|
|
380
|
+
infstream.opaque = Z_NULL;
|
|
381
|
+
infstream.avail_in = static_cast<uInt>(decryptedData.size());
|
|
382
|
+
infstream.next_in = decryptedData.data();
|
|
383
|
+
infstream.avail_out = (uInt)result.size(); // size of output
|
|
384
|
+
infstream.next_out = (Bytef*)result.data(); // output char array NOLINT
|
|
385
|
+
|
|
386
|
+
inflateInit(&infstream);
|
|
387
|
+
int r = inflate(&infstream, Z_NO_FLUSH);
|
|
388
|
+
inflateEnd(&infstream);
|
|
389
|
+
if (r == Z_OK || r == Z_STREAM_END) return result;
|
|
390
|
+
return std::unexpected(Error::DataError("inflate failed"));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
Result<std::vector<uint8_t>> WzPngProperty::GetCompressedBytesForExtraction(
|
|
395
|
+
bool saveInMemory) {
|
|
396
|
+
auto rawBytes = GetCompressedBytes(saveInMemory);
|
|
397
|
+
if (!rawBytes.has_value()) return std::unexpected(rawBytes.error());
|
|
398
|
+
auto& rawData = rawBytes.value();
|
|
399
|
+
if (rawData.size() < 2) return std::move(rawData);
|
|
400
|
+
|
|
401
|
+
uint16_t header = rawData[0] | (static_cast<uint16_t>(rawData[1]) << 8);
|
|
402
|
+
bool isListWz = (header != 0x9C78 && header != 0xDA78 && header != 0x0178 &&
|
|
403
|
+
header != 0x5E78);
|
|
404
|
+
if (!isListWz) return rawData;
|
|
405
|
+
|
|
406
|
+
// Convert listWz to standard zlib
|
|
407
|
+
auto raw = GetRawImage(true);
|
|
408
|
+
if (!raw.has_value()) return rawData;
|
|
409
|
+
|
|
410
|
+
// Re-compress to standard zlib
|
|
411
|
+
auto& rawImg = raw.value();
|
|
412
|
+
uLongf destLen = compressBound(static_cast<uLong>(rawImg.size()));
|
|
413
|
+
std::vector<uint8_t> compressed(destLen);
|
|
414
|
+
|
|
415
|
+
if (compress2(compressed.data(),
|
|
416
|
+
&destLen,
|
|
417
|
+
rawImg.data(),
|
|
418
|
+
static_cast<uLong>(rawImg.size()),
|
|
419
|
+
Z_DEFAULT_COMPRESSION) != Z_OK)
|
|
420
|
+
return rawData;
|
|
421
|
+
|
|
422
|
+
compressed.resize(destLen);
|
|
423
|
+
return compressed;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
Result<void> WzPngProperty::ParsePng(bool saveInMemory) {
|
|
427
|
+
auto rawResult = GetRawImage(saveInMemory);
|
|
428
|
+
if (!rawResult.has_value()) return std::unexpected(rawResult.error());
|
|
429
|
+
auto rawBytes = std::move(rawResult.value());
|
|
430
|
+
|
|
431
|
+
switch (format_) {
|
|
432
|
+
case WzPngFormat::Format1: {
|
|
433
|
+
int pixelCount = width_ * height_;
|
|
434
|
+
pngData_.resize(pixelCount * 4);
|
|
435
|
+
auto decodeResult = PngUtility::DecompressImagePixelDataBgra4444(
|
|
436
|
+
rawBytes, width_, height_, pngData_);
|
|
437
|
+
if (!decodeResult.has_value()) {
|
|
438
|
+
pngData_.clear();
|
|
439
|
+
return std::unexpected(decodeResult.error());
|
|
440
|
+
}
|
|
441
|
+
} break;
|
|
442
|
+
case WzPngFormat::Format2:
|
|
443
|
+
pngData_ = std::move(rawBytes);
|
|
444
|
+
break;
|
|
445
|
+
case WzPngFormat::Format3: {
|
|
446
|
+
pngData_.resize(width_ * height_ * 4);
|
|
447
|
+
auto decodeResult =
|
|
448
|
+
PngUtility::DecompressImageDXT3(rawBytes, width_, height_, pngData_);
|
|
449
|
+
if (!decodeResult.has_value()) {
|
|
450
|
+
pngData_.clear();
|
|
451
|
+
return std::unexpected(decodeResult.error());
|
|
452
|
+
}
|
|
453
|
+
} break;
|
|
454
|
+
case WzPngFormat::Format257: {
|
|
455
|
+
// ARGB1555 (16bpp) -> BGRA32 upconversion
|
|
456
|
+
int pixelCount = width_ * height_;
|
|
457
|
+
pngData_.resize(pixelCount * 4);
|
|
458
|
+
for (int i = 0; i < pixelCount; i++) {
|
|
459
|
+
uint8_t low = rawBytes[i * 2];
|
|
460
|
+
uint8_t high = rawBytes[i * 2 + 1];
|
|
461
|
+
uint16_t val = static_cast<uint16_t>(low | (high << 8));
|
|
462
|
+
// ARGB1555: bit 15 = alpha, 14-10 = R (5 bits), 9-5 = G (5 bits), 4-0 =
|
|
463
|
+
// B (5 bits)
|
|
464
|
+
uint8_t a = (val & 0x8000) ? 255 : 0;
|
|
465
|
+
uint8_t r = static_cast<uint8_t>(((val >> 10) & 0x1F) << 3);
|
|
466
|
+
uint8_t g = static_cast<uint8_t>(((val >> 5) & 0x1F) << 3);
|
|
467
|
+
uint8_t b = static_cast<uint8_t>((val & 0x1F) << 3);
|
|
468
|
+
pngData_[i * 4] = b;
|
|
469
|
+
pngData_[i * 4 + 1] = g;
|
|
470
|
+
pngData_[i * 4 + 2] = r;
|
|
471
|
+
pngData_[i * 4 + 3] = a;
|
|
472
|
+
}
|
|
473
|
+
} break;
|
|
474
|
+
case WzPngFormat::Format513: {
|
|
475
|
+
// RGB565 (16bpp) -> BGRA32 upconversion
|
|
476
|
+
int pixelCount = width_ * height_;
|
|
477
|
+
pngData_.resize(pixelCount * 4);
|
|
478
|
+
for (int i = 0; i < pixelCount; i++) {
|
|
479
|
+
uint8_t low = rawBytes[i * 2];
|
|
480
|
+
uint8_t high = rawBytes[i * 2 + 1];
|
|
481
|
+
uint16_t val = static_cast<uint16_t>(low | (high << 8));
|
|
482
|
+
auto c = PngUtility::RGB565ToColor(val);
|
|
483
|
+
pngData_[i * 4] = c.B;
|
|
484
|
+
pngData_[i * 4 + 1] = c.G;
|
|
485
|
+
pngData_[i * 4 + 2] = c.R;
|
|
486
|
+
pngData_[i * 4 + 3] = 255;
|
|
487
|
+
}
|
|
488
|
+
} break;
|
|
489
|
+
case WzPngFormat::Format517: {
|
|
490
|
+
int pixelCount = width_ * height_;
|
|
491
|
+
std::vector<uint8_t> dec517(pixelCount * 2);
|
|
492
|
+
PngUtility::DecompressImagePixelDataForm517(
|
|
493
|
+
rawBytes, width_, height_, dec517);
|
|
494
|
+
pngData_.resize(pixelCount * 4);
|
|
495
|
+
for (int i = 0; i < pixelCount; i++) {
|
|
496
|
+
uint8_t low = dec517[i * 2];
|
|
497
|
+
uint8_t high = dec517[i * 2 + 1];
|
|
498
|
+
uint16_t val = static_cast<uint16_t>(low | (high << 8));
|
|
499
|
+
auto c = PngUtility::RGB565ToColor(val);
|
|
500
|
+
pngData_[i * 4] = c.B;
|
|
501
|
+
pngData_[i * 4 + 1] = c.G;
|
|
502
|
+
pngData_[i * 4 + 2] = c.R;
|
|
503
|
+
pngData_[i * 4 + 3] = 255;
|
|
504
|
+
}
|
|
505
|
+
} break;
|
|
506
|
+
case WzPngFormat::Format1026: {
|
|
507
|
+
pngData_.resize(width_ * height_ * 4);
|
|
508
|
+
auto decodeResult =
|
|
509
|
+
PngUtility::DecompressImageDXT3(rawBytes, width_, height_, pngData_);
|
|
510
|
+
if (!decodeResult.has_value()) {
|
|
511
|
+
pngData_.clear();
|
|
512
|
+
return std::unexpected(decodeResult.error());
|
|
513
|
+
}
|
|
514
|
+
} break;
|
|
515
|
+
case WzPngFormat::Format2050: {
|
|
516
|
+
pngData_.resize(width_ * height_ * 4);
|
|
517
|
+
auto decodeResult =
|
|
518
|
+
PngUtility::DecompressImageDXT5(rawBytes, width_, height_, pngData_);
|
|
519
|
+
if (!decodeResult.has_value()) {
|
|
520
|
+
pngData_.clear();
|
|
521
|
+
return std::unexpected(decodeResult.error());
|
|
522
|
+
}
|
|
523
|
+
} break;
|
|
524
|
+
default:
|
|
525
|
+
pngData_.resize(width_ * height_ * 4);
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
return {};
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
Result<std::vector<uint8_t>> WzPngProperty::GetImage(bool saveInMemory) {
|
|
532
|
+
std::unique_lock<std::recursive_mutex> lock;
|
|
533
|
+
if (wzReader_)
|
|
534
|
+
lock = std::unique_lock<std::recursive_mutex>(wzReader_->Mutex());
|
|
535
|
+
if (pngData_.empty()) {
|
|
536
|
+
auto parseResult = ParsePng(saveInMemory);
|
|
537
|
+
if (!parseResult.has_value()) return std::unexpected(parseResult.error());
|
|
538
|
+
}
|
|
539
|
+
if (pngData_.empty())
|
|
540
|
+
return std::unexpected(Error::DataError("Failed to parse PNG"));
|
|
541
|
+
return pngData_;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
Result<void> WzPngProperty::SaveToFile(const std::string& filePath) {
|
|
545
|
+
auto result = GetImage(false);
|
|
546
|
+
if (!result.has_value()) return std::unexpected(result.error());
|
|
547
|
+
auto& bgra = result.value();
|
|
548
|
+
if (bgra.empty())
|
|
549
|
+
return std::unexpected(Error::DataError("PNG image data is empty"));
|
|
550
|
+
|
|
551
|
+
std::vector<uint8_t> rgba(bgra.size());
|
|
552
|
+
for (size_t i = 0; i < bgra.size(); i += 4) {
|
|
553
|
+
rgba[i] = bgra[i + 2];
|
|
554
|
+
rgba[i + 1] = bgra[i + 1];
|
|
555
|
+
rgba[i + 2] = bgra[i];
|
|
556
|
+
rgba[i + 3] = bgra[i + 3];
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
size_t rowSize = static_cast<size_t>(width_) * 4;
|
|
560
|
+
std::vector<uint8_t> rawData(static_cast<size_t>(height_) * (1 + rowSize), 0);
|
|
561
|
+
for (int y = 0; y < height_; y++) {
|
|
562
|
+
rawData[y * (1 + rowSize)] = 0;
|
|
563
|
+
std::memcpy(rawData.data() + y * (1 + rowSize) + 1,
|
|
564
|
+
rgba.data() + static_cast<size_t>(y) * rowSize,
|
|
565
|
+
rowSize);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
z_stream zs = {};
|
|
569
|
+
if (deflateInit2(
|
|
570
|
+
&zs, Z_BEST_COMPRESSION, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) !=
|
|
571
|
+
Z_OK) {
|
|
572
|
+
return std::unexpected(Error::DataError("deflateInit2 failed"));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
zs.next_in = rawData.data();
|
|
576
|
+
zs.avail_in = static_cast<uInt>(rawData.size());
|
|
577
|
+
|
|
578
|
+
size_t compBound = deflateBound(&zs, static_cast<uLong>(rawData.size()));
|
|
579
|
+
std::vector<uint8_t> compressed(compBound);
|
|
580
|
+
zs.next_out = compressed.data();
|
|
581
|
+
zs.avail_out = static_cast<uInt>(compressed.size());
|
|
582
|
+
|
|
583
|
+
int ret = deflate(&zs, Z_FINISH);
|
|
584
|
+
if (ret != Z_STREAM_END) {
|
|
585
|
+
deflateEnd(&zs);
|
|
586
|
+
return std::unexpected(Error::DataError("deflate failed"));
|
|
587
|
+
}
|
|
588
|
+
size_t compressedSize = zs.total_out;
|
|
589
|
+
deflateEnd(&zs);
|
|
590
|
+
|
|
591
|
+
auto outPath = wz::to_path(filePath);
|
|
592
|
+
auto parentPath = outPath.parent_path();
|
|
593
|
+
std::error_code ec;
|
|
594
|
+
if (!parentPath.empty()) {
|
|
595
|
+
std::filesystem::create_directories(parentPath, ec);
|
|
596
|
+
if (ec) return std::unexpected(Error::IoError(ec.message()));
|
|
597
|
+
}
|
|
598
|
+
WzFileStream out;
|
|
599
|
+
if (!out.Open(outPath, "wb"))
|
|
600
|
+
return std::unexpected(Error::IoError("Failed to open file for writing"));
|
|
601
|
+
|
|
602
|
+
const uint8_t signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
|
603
|
+
if (!out.Write(signature, sizeof(signature))) {
|
|
604
|
+
return std::unexpected(Error::IoError("Failed to write PNG signature"));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
struct {
|
|
608
|
+
uint32_t w, h;
|
|
609
|
+
uint8_t bitDepth, colorType, compression, filter, interlace;
|
|
610
|
+
} ihdr;
|
|
611
|
+
ihdr.w = ToBigEndian32(static_cast<uint32_t>(width_));
|
|
612
|
+
ihdr.h = ToBigEndian32(static_cast<uint32_t>(height_));
|
|
613
|
+
ihdr.bitDepth = 8;
|
|
614
|
+
ihdr.colorType = 6;
|
|
615
|
+
ihdr.compression = 0;
|
|
616
|
+
ihdr.filter = 0;
|
|
617
|
+
ihdr.interlace = 0;
|
|
618
|
+
if (!WritePngChunk(
|
|
619
|
+
&out, "IHDR", reinterpret_cast<const uint8_t*>(&ihdr), 13)) {
|
|
620
|
+
return std::unexpected(Error::IoError("Failed to write PNG IHDR"));
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (!WritePngChunk(&out,
|
|
624
|
+
"IDAT",
|
|
625
|
+
compressed.data(),
|
|
626
|
+
static_cast<uint32_t>(compressedSize))) {
|
|
627
|
+
return std::unexpected(Error::IoError("Failed to write PNG IDAT"));
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (!WritePngChunk(&out, "IEND", nullptr, 0)) {
|
|
631
|
+
return std::unexpected(Error::IoError("Failed to write PNG IEND"));
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
return {};
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
} // namespace wz
|